Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88605805
datamanager.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 19, 17:24
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Oct 21, 17:24 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21797056
Attached To
R11586 sausage-api
datamanager.py
View Options
# © All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE,
# Switzerland
# SCITAS - Scientific IT and Application Support, 2021
# See the LICENSE.txt file for more details.
import
falcon
from
sausage.esoperations
import
ESOp
from
sausage.dboperations
import
DBOp
from
sausage.esquery
import
ESQuery
from
sausage.printer
import
PrintJson
from
sausage.loadconf
import
LoadConf
from
sausage.readconf
import
ReadConf
class
DataManager
(
object
):
def
__init__
(
self
):
self
.
entities
=
[
"account"
,
"user"
]
newconf
=
LoadConf
()
self
.
currencies
=
newconf
.
currencies
server_opt
=
ReadConf
()
self
.
es_server
=
server_opt
.
es_server
def
on_get_update
(
self
,
req
,
resp
):
response
=
{
"operation"
:
"update database"
,
"return"
:
"OK"
}
resp
.
status
=
falcon
.
HTTP_200
for
entity
in
self
.
entities
:
for
currency
in
self
.
currencies
:
try
:
oqueries
=
ESQuery
(
currency
,
entity
)
self
.
doc
=
oqueries
.
query
query
=
ESOp
(
self
.
es_server
)
esdata
=
query
.
esget
(
"slurm"
,
self
.
doc
)
try
:
newdb
=
DBOp
()
newdb
.
populate
(
esdata
,
entity
,
currency
)
except
BaseException
:
response
=
{
"operation"
:
"update database"
,
"return"
:
"Database connection error"
}
resp
.
media
=
response
except
BaseException
:
response
=
{
"operation"
:
"getting data"
,
"return"
:
"Elasticsearch Service Unavailable"
}
resp
.
media
=
response
resp
.
media
=
response
def
on_get_show
(
self
,
req
,
resp
):
resp
.
status
=
falcon
.
HTTP_200
response
=
{}
for
entity
in
self
.
entities
:
try
:
newdb
=
DBOp
()
table_data
=
newdb
.
show_table
(
entity
)
if
table_data
:
pjson
=
PrintJson
(
entity
,
table_data
)
response
[
entity
]
=
pjson
.
response
resp
.
media
=
response
except
BaseException
:
response
=
{
"operation"
:
"show table"
,
"return"
:
"Database connection error"
}
resp
.
media
=
response
def
on_get_purge
(
self
,
req
,
resp
):
resp
.
status
=
falcon
.
HTTP_200
response
=
{
"operation"
:
"purge database"
,
"return"
:
"OK"
}
for
entity
in
self
.
entities
:
try
:
newdb
=
DBOp
()
newdb
.
purge_table
(
entity
)
resp
.
media
=
response
except
BaseException
:
response
=
{
"operation"
:
"purge database"
,
"return"
:
"Database connection error"
}
resp
.
media
=
response
Event Timeline
Log In to Comment