Upcoming maintenance: Thursday 21 August @ 12:00-14:00 CEST.
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
8bd84c7c
Commit
8bd84c7c
authored
1 year ago
by
Waleed Akbar
Browse files
Options
Downloads
Patches
Plain Diff
Exception added
parent
58fd2c5a
No related branches found
No related tags found
2 merge requests
!294
Release TeraFlowSDN 4.0
,
!207
Resolve "(CTTC) Separation of Monitoring"
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/run_tests_locally-kpi-DB.sh
+2
-2
2 additions, 2 deletions
scripts/run_tests_locally-kpi-DB.sh
src/kpi_manager/database/KpiModel.py
+1
-3
1 addition, 3 deletions
src/kpi_manager/database/KpiModel.py
src/kpi_manager/database/Kpi_DB.py
+11
-10
11 additions, 10 deletions
src/kpi_manager/database/Kpi_DB.py
with
14 additions
and
15 deletions
scripts/run_tests_locally-kpi-DB.sh
+
2
−
2
View file @
8bd84c7c
...
@@ -24,5 +24,5 @@ cd $PROJECTDIR/src
...
@@ -24,5 +24,5 @@ cd $PROJECTDIR/src
# python3 kpi_manager/tests/test_unitary.py
# python3 kpi_manager/tests/test_unitary.py
RCFILE
=
$PROJECTDIR
/coverage/.coveragerc
RCFILE
=
$PROJECTDIR
/coverage/.coveragerc
python3
-m
pytest
--log-level
=
INFO
--log-cli-level
=
INFO
--verbose
\
python3
-m
pytest
--log-level
=
DEBUG
--log-cli-level
=
DEBUG
--verbose
\
kpi_manager/database/tests/KpiDBtests.py
kpi_manager/tests/test_kpi_db.py
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/kpi_manager/database/KpiModel.py
+
1
−
3
View file @
8bd84c7c
...
@@ -14,10 +14,8 @@
...
@@ -14,10 +14,8 @@
import
logging
import
logging
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy.dialects.postgresql
import
UUID
from
sqlalchemy
import
Column
,
Integer
,
String
,
Float
,
Text
,
ForeignKey
from
sqlalchemy
import
Column
,
Integer
,
String
,
Float
,
Text
# from sqlalchemy.ext.declarative import declarative_base
from
sqlalchemy.orm
import
registry
from
sqlalchemy.orm
import
registry
from
sqlalchemy.orm
import
sessionmaker
,
relationship
from
common.proto.kpi_management_pb2
import
KpiDescriptor
from
common.proto.kpi_management_pb2
import
KpiDescriptor
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
...
...
This diff is collapsed.
Click to expand it.
src/kpi_manager/database/Kpi_DB.py
+
11
−
10
View file @
8bd84c7c
...
@@ -12,14 +12,13 @@
...
@@ -12,14 +12,13 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
logging
,
time
import
logging
from
typing
import
List
,
Tuple
from
sqlalchemy
import
select
,
and_
import
sqlalchemy_utils
import
sqlalchemy_utils
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
kpi_manager.database.KpiEngine
import
KpiEngine
from
kpi_manager.database.KpiEngine
import
KpiEngine
from
kpi_manager.database.KpiModel
import
Kpi
as
KpiModel
from
kpi_manager.database.KpiModel
import
Kpi
as
KpiModel
from
common.method_wrappers.ServiceExceptions
import
(
AlreadyExistsException
,
OperationFailedException
)
LOGGER
=
logging
.
getLogger
(
__name__
)
LOGGER
=
logging
.
getLogger
(
__name__
)
DB_NAME
=
"
kpi
"
DB_NAME
=
"
kpi
"
...
@@ -31,8 +30,6 @@ class KpiDB:
...
@@ -31,8 +30,6 @@ class KpiDB:
LOGGER
.
error
(
'
Unable to get SQLAlchemy DB Engine...
'
)
LOGGER
.
error
(
'
Unable to get SQLAlchemy DB Engine...
'
)
return
False
return
False
self
.
db_name
=
DB_NAME
self
.
db_name
=
DB_NAME
# self.drop_database(self.db_engine) # added to test
# self.create_database(self.db_engine) # to add database
self
.
Session
=
sessionmaker
(
bind
=
self
.
db_engine
)
self
.
Session
=
sessionmaker
(
bind
=
self
.
db_engine
)
def
create_database
(
self
)
->
None
:
def
create_database
(
self
)
->
None
:
...
@@ -50,6 +47,7 @@ class KpiDB:
...
@@ -50,6 +47,7 @@ class KpiDB:
LOGGER
.
debug
(
"
Tables created in the DB Name: {:}
"
.
format
(
self
.
db_name
))
LOGGER
.
debug
(
"
Tables created in the DB Name: {:}
"
.
format
(
self
.
db_name
))
except
Exception
as
e
:
except
Exception
as
e
:
LOGGER
.
debug
(
"
Tables cannot be created in the kpi database. {:s}
"
.
format
(
str
(
e
)))
LOGGER
.
debug
(
"
Tables cannot be created in the kpi database. {:s}
"
.
format
(
str
(
e
)))
raise
OperationFailedException
(
"
Tables can
'
t be created
"
,
extra_details
=
[
"
unable to create table {:}
"
.
format
(
e
)])
def
verify_tables
(
self
):
def
verify_tables
(
self
):
try
:
try
:
...
@@ -70,10 +68,12 @@ class KpiDB:
...
@@ -70,10 +68,12 @@ class KpiDB:
except
Exception
as
e
:
except
Exception
as
e
:
session
.
rollback
()
session
.
rollback
()
if
"
psycopg2.errors.UniqueViolation
"
in
str
(
e
):
if
"
psycopg2.errors.UniqueViolation
"
in
str
(
e
):
LOGGER
.
debug
(
f
"
Unique key voilation:
{
row
.
__class__
.
__name__
}
table.
{
str
(
e
)
}
"
)
LOGGER
.
error
(
f
"
Unique key voilation:
{
row
.
__class__
.
__name__
}
table.
{
str
(
e
)
}
"
)
raise
AlreadyExistsException
(
row
.
__class__
.
__name__
,
row
,
extra_details
=
[
"
Unique key voilation: {:}
"
.
format
(
e
)]
)
else
:
else
:
LOGGER
.
error
(
f
"
Failed to insert new row into
{
row
.
__class__
.
__name__
}
table.
{
str
(
e
)
}
"
)
LOGGER
.
error
(
f
"
Failed to insert new row into
{
row
.
__class__
.
__name__
}
table.
{
str
(
e
)
}
"
)
return
False
raise
OperationFailedException
(
"
Deletion by column id
"
,
extra_details
=
[
"
unable to delete row {:}
"
.
format
(
e
)])
finally
:
finally
:
session
.
close
()
session
.
close
()
...
@@ -90,7 +90,7 @@ class KpiDB:
...
@@ -90,7 +90,7 @@ class KpiDB:
except
Exception
as
e
:
except
Exception
as
e
:
session
.
rollback
()
session
.
rollback
()
LOGGER
.
debug
(
f
"
Failed to retrieve
{
model
.
__name__
}
ID.
{
str
(
e
)
}
"
)
LOGGER
.
debug
(
f
"
Failed to retrieve
{
model
.
__name__
}
ID.
{
str
(
e
)
}
"
)
raise
raise
OperationFailedException
(
"
search by column id
"
,
extra_details
=
[
"
unable to search row {:}
"
.
format
(
e
)])
finally
:
finally
:
session
.
close
()
session
.
close
()
...
@@ -108,6 +108,7 @@ class KpiDB:
...
@@ -108,6 +108,7 @@ class KpiDB:
except
Exception
as
e
:
except
Exception
as
e
:
session
.
rollback
()
session
.
rollback
()
LOGGER
.
error
(
"
Error deleting %s with %s %s: %s
"
,
model
.
__name__
,
col_name
,
id_to_search
,
e
)
LOGGER
.
error
(
"
Error deleting %s with %s %s: %s
"
,
model
.
__name__
,
col_name
,
id_to_search
,
e
)
raise
OperationFailedException
(
"
Deletion by column id
"
,
extra_details
=
[
"
unable to delete row {:}
"
.
format
(
e
)])
finally
:
finally
:
session
.
close
()
session
.
close
()
...
@@ -148,6 +149,6 @@ class KpiDB:
...
@@ -148,6 +149,6 @@ class KpiDB:
return
result
return
result
except
Exception
as
e
:
except
Exception
as
e
:
LOGGER
.
error
(
f
"
Error fetching filtered rows from
{
model
.
__name__
}
table with filters
{
filter_object
}
:::
{
e
}
"
)
LOGGER
.
error
(
f
"
Error fetching filtered rows from
{
model
.
__name__
}
table with filters
{
filter_object
}
:::
{
e
}
"
)
r
eturn
[]
r
aise
OperationFailedException
(
"
Select by filter
"
,
extra_details
=
[
"
unable to apply the filter {:}
"
.
format
(
e
)])
finally
:
finally
:
session
.
close
()
session
.
close
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment