Page MenuHomec4science

datamanager.py
No OneTemporary

File Metadata

Created
Sat, Oct 19, 17:24

datamanager.py

# © 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