verion which did not include the handling in RTService wth creating the
Json file
This commit is contained in:
@@ -1,22 +1,39 @@
|
||||
import time
|
||||
from uuid import uuid4
|
||||
import uuid
|
||||
from flask import jsonify
|
||||
import json
|
||||
from extensions.rt_service import rt_service as rts
|
||||
|
||||
# from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
|
||||
# from vrpmdvmonitoring import VRPMDV_Monitoring
|
||||
|
||||
from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
|
||||
#from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
|
||||
#from vrpmdvcreatemonschema import VRPMDV_CreateMonSchema
|
||||
#from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
|
||||
#from vrpmdvdeletemonschema import VRPMDV_DeleteMonSchema
|
||||
from vrpmdvmonitoring import VRPMDV_Monitoring
|
||||
from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
|
||||
from vrpmdvmonreqschema import VRPMDV_MonReqSchema
|
||||
from vrpmdvntlink import trySend
|
||||
|
||||
from extensions.rt_service import rt_service as rts
|
||||
from vrpmdvmonitoringState import VRPMDVMonitoringState
|
||||
#from vrpmdvlogging import createCoproLoggingTask
|
||||
import logging
|
||||
|
||||
|
||||
class VRPMDV_Data:
|
||||
|
||||
def __init__(self):
|
||||
#self.loaded = False
|
||||
format = "%(asctime)s: %(message)s"
|
||||
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
|
||||
self.mons:list = []
|
||||
self.loaded = self.loadFile()
|
||||
self.rtservice = rts.RT_Service()
|
||||
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
|
||||
self.logTask = None #createCoproLoggingTask()
|
||||
self.loaded = self.loadFile()
|
||||
#start the monitorings
|
||||
time.sleep(1)
|
||||
self.startMons();
|
||||
|
||||
|
||||
|
||||
def loadFile(self):
|
||||
try:
|
||||
@@ -47,6 +64,17 @@ class VRPMDV_Data:
|
||||
#nothing todo
|
||||
print("could not write file")
|
||||
|
||||
def startMons(self):
|
||||
try:
|
||||
logging.info("MainThread: startMons")
|
||||
# for i, val in enumerate(self.mons):
|
||||
# if (val.status == 'started') :
|
||||
# val.startMonitoring()
|
||||
except:
|
||||
print("could not start monitorings")
|
||||
|
||||
|
||||
|
||||
def findMon(mon):
|
||||
return mon
|
||||
|
||||
@@ -68,7 +96,9 @@ class VRPMDV_Data:
|
||||
# we find it and we return it
|
||||
schema = VRPMDV_MonitoringSchema()
|
||||
return schema.dumps(matched_obj)
|
||||
|
||||
|
||||
|
||||
|
||||
def setMonitoring(self, id, request):
|
||||
try:
|
||||
matched_obj = next(x for x in self.mons if str(x.id) == id)
|
||||
@@ -79,7 +109,16 @@ class VRPMDV_Data:
|
||||
if 'samplerate' in request : matched_obj.samplerate = request['samplerate']
|
||||
if 'sampleperiod' in request : matched_obj.sampleperiod = request['sampleperiod']
|
||||
if 'downtime' in request : matched_obj.downtime = request['downtime']
|
||||
if 'status' in request : matched_obj.setStatus(request['status'])
|
||||
if 'status' in request :
|
||||
if (request['status'] == 'started'):
|
||||
if (matched_obj.status == VRPMDVMonitoringState.STOPPED):
|
||||
logging.info("MainThread: started %s", matched_obj.id)
|
||||
matched_obj.startMonitoring()
|
||||
# matched_obj.setStatus(self.createMonOnDevice(matched_obj))
|
||||
elif (matched_obj.status == 'started') :
|
||||
logging.info("MainThread: stopped %s", matched_obj.id)
|
||||
# matched_obj.setStatus(self._stopMonitoring(matched_obj))
|
||||
matched_obj.stopMonitoring()
|
||||
self.saveFile()
|
||||
|
||||
# we find it and we return it
|
||||
@@ -87,34 +126,22 @@ class VRPMDV_Data:
|
||||
return schema.dumps(matched_obj)
|
||||
|
||||
|
||||
# try:
|
||||
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
# matched_obj.name = request.name
|
||||
# matched_obj.samplerate = request.samplerate
|
||||
# matched_obj.sampleperiod = request.sampleperiod
|
||||
# matched_obj.downtime = request.downtime
|
||||
# self.saveFile()
|
||||
|
||||
# except:
|
||||
# return "no Item found"
|
||||
|
||||
|
||||
# # we find it and we return it
|
||||
# schema = VRPMDV_MonitoringSchema()
|
||||
# return schema.dumps(matched_obj)
|
||||
|
||||
|
||||
|
||||
def createMonitoring(self, request):
|
||||
#mon = VRPMDV_Monitoring(request["name"], request["samplerate"], request["sampleperiod"], request["downtime"], request["owner"])
|
||||
id = uuid.uuid4()
|
||||
mon = VRPMDV_Monitoring(id, request.name, request.samplerate, request.sampleperiod, request.downtime, request.status, request.owner)
|
||||
iscreated = mon.createMonitoring()
|
||||
#iscreated = self.rtservice.createMonitoring(str(id))
|
||||
createjson = request.get_json()
|
||||
vrpmreq = VRPMDV_MonReqSchema().load(createjson)
|
||||
|
||||
mon = VRPMDV_Monitoring(0, id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
|
||||
logging.info("Monitoring %s: creating", str(id))
|
||||
|
||||
# create Monitoring on the realtime side
|
||||
if (vrpmreq.status == 'started'):
|
||||
logging.info("Monitoring %s: createMonOnDevice", str(id))
|
||||
mon.startMonitoring()
|
||||
# status = self.createMonOnDevice(mon)
|
||||
# logging.info("Monitoring %s: _start executed. status:%s", str(id), str(status))
|
||||
# mon.status = status
|
||||
|
||||
# if not self.loaded :
|
||||
# self.loaded = self.loadFile()
|
||||
# create monitoring
|
||||
self.mons.append(mon)
|
||||
#save to file
|
||||
self.saveFile()
|
||||
@@ -122,6 +149,7 @@ class VRPMDV_Data:
|
||||
schema = VRPMDV_MonitoringSchema()
|
||||
return schema.dumps(mon)
|
||||
|
||||
|
||||
def deleteMonitoring(self, vrpmid):
|
||||
# if not self.loaded :
|
||||
# self.loaded = self.loadFile()
|
||||
@@ -135,7 +163,7 @@ class VRPMDV_Data:
|
||||
|
||||
|
||||
# we find it, delete on realtime side and now remove from list
|
||||
matched_obj.deleteMonitoring()
|
||||
matched_obj.stopMonitoring()
|
||||
self.mons.remove(matched_obj)
|
||||
#save the list
|
||||
self.saveFile()
|
||||
@@ -144,48 +172,172 @@ class VRPMDV_Data:
|
||||
return schema.dump(matched_obj)
|
||||
|
||||
|
||||
def startMonitoring(self, vrpmid):
|
||||
# if not self.loaded :
|
||||
# self.loaded = self.loadFile()
|
||||
# internal helper function
|
||||
|
||||
#call the start API of the c++ driver
|
||||
try:
|
||||
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
except:
|
||||
return "no Item found"
|
||||
# ML: transfer to Monitoring class
|
||||
# def createMonOnDevice(self, monitoring):
|
||||
# #call the start API of the c++ driver
|
||||
# try:
|
||||
|
||||
# logging.info("MainThread: createMonOnDevice => before vrpmdCreateCmd samplerate:%d, samplerate:%d, samplerate:%d", monitoring.samplerate, monitoring.sampleperiod, monitoring.downtime)
|
||||
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(monitoring.samplerate, monitoring.sampleperiod, monitoring.downtime)
|
||||
# logging.info("MainThread: createMonOnDevice => before schemaCreateCmd")
|
||||
# schemaCreateCmd = VRPMDV_CreateMonSchema()
|
||||
# logging.info("MainThread: try send start monitoring starting %s", schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
# #res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
# #logging.info("MainThread: try send start monitoring done %s", res)
|
||||
# self.status = "started"
|
||||
# # set status if we have a success TODO
|
||||
# except:
|
||||
# self.status = "stopped"
|
||||
# return "stopped"
|
||||
# return "started"
|
||||
|
||||
if matched_obj.startMonitoring() :
|
||||
#TODO ML return the state
|
||||
return "started"
|
||||
|
||||
return "created"
|
||||
# def _stopMonitoring(self, monitoring):
|
||||
# #call the stop API of the c++ driver
|
||||
# try:
|
||||
# logging.info("MainThread: stop monitoring")
|
||||
# vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(2, monitoring.id)
|
||||
# schemaDeleteCmd = VRPMDV_DeleteMonSchema()
|
||||
|
||||
# #trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
|
||||
# self.status = "stopped"
|
||||
# logging.info("MainThread: stop monitoring done")
|
||||
|
||||
def stopMonitoring(self, vrpmid):
|
||||
# if not self.loaded :
|
||||
# self.loaded = self.loadFile()
|
||||
# except:
|
||||
# self.status = "started"
|
||||
# return "started"
|
||||
|
||||
#call the start API of the c++ driver
|
||||
try:
|
||||
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
except:
|
||||
return "no Item found"
|
||||
# return monitoring.status
|
||||
|
||||
matched_obj.startMonitoring()
|
||||
return matched_obj.monstate.name
|
||||
|
||||
# old impl ML
|
||||
#
|
||||
# def createMonitoring(self, request):
|
||||
# id = uuid.uuid4()
|
||||
|
||||
# createjson = request.get_json()
|
||||
# vrpmreq = VRPMDV_MonReqSchema().load(createjson)
|
||||
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(1, id , vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status)
|
||||
# schemaCreateCmd = VRPMDV_CreateMonSchema()
|
||||
|
||||
# valstr = schemaCreateCmd.dumps(vrpmdCreateCmd)
|
||||
# trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
|
||||
# mon = VRPMDV_Monitoring(id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
|
||||
# logging.info("Monitoring %s: starting", str(id))
|
||||
# mon.startMonitoring()
|
||||
|
||||
# self.mons.append(mon)
|
||||
# #save to file
|
||||
# self.saveFile()
|
||||
# #create result Object in json
|
||||
# schema = VRPMDV_MonitoringSchema()
|
||||
# return schema.dumps(mon)
|
||||
|
||||
|
||||
|
||||
|
||||
# def createMonitoring(self, request):
|
||||
# id = uuid.uuid4()
|
||||
|
||||
# createjson = request.get_json()
|
||||
# vrpmreq = VRPMDV_MonReqSchema().load(createjson)
|
||||
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(1, id , vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status)
|
||||
# schemaCreateCmd = VRPMDV_CreateMonSchema()
|
||||
|
||||
# valstr = schemaCreateCmd.dumps(vrpmdCreateCmd)
|
||||
# trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
|
||||
# mon = VRPMDV_Monitoring(id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
|
||||
# logging.info("Monitoring %s: starting", str(id))
|
||||
# mon.startMonitoring()
|
||||
|
||||
# self.mons.append(mon)
|
||||
# #save to file
|
||||
# self.saveFile()
|
||||
# #create result Object in json
|
||||
# schema = VRPMDV_MonitoringSchema()
|
||||
# return schema.dumps(mon)
|
||||
|
||||
|
||||
# def deleteMonitoring(self, vrpmid):
|
||||
# # if not self.loaded :
|
||||
# # self.loaded = self.loadFile()
|
||||
|
||||
# # find monitoring with uuid
|
||||
# #result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons)
|
||||
# try:
|
||||
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
# except:
|
||||
# return "no Item found"
|
||||
|
||||
|
||||
# # we find it, delete on realtime side and now remove from list
|
||||
# #matched_obj.deleteMonitoring()
|
||||
# self.mons.remove(matched_obj)
|
||||
# #save the list
|
||||
# self.saveFile()
|
||||
# #make result
|
||||
# schema = VRPMDV_MonitoringSchema()
|
||||
# return schema.dump(matched_obj)
|
||||
|
||||
|
||||
# def startMonitoring(self, vrpmid):
|
||||
# # if not self.loaded :
|
||||
# # self.loaded = self.loadFile()
|
||||
|
||||
# #call the start API of the c++ driver
|
||||
# try:
|
||||
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
|
||||
# except:
|
||||
# return "no Item found"
|
||||
|
||||
# if matched_obj.startMonitoring() :
|
||||
# #TODO ML return the state
|
||||
# return "started"
|
||||
|
||||
# return "created"
|
||||
|
||||
# def stopMonitoring(self, vrpmid):
|
||||
# # if not self.loaded :
|
||||
# # self.loaded = self.loadFile()
|
||||
|
||||
# #call the stop API of the c++ driver
|
||||
# try:
|
||||
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
|
||||
# logging.info("MainThread: stop monitoring starting")
|
||||
# vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(2, matched_obj.id)
|
||||
# schemaDeleteCmd = VRPMDV_DeleteMonSchema()
|
||||
# valstr = schemaDeleteCmd.dumps(vrpmdDeleteCmd)
|
||||
# trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
|
||||
# logging.info("MainThread: stop monitoring done")
|
||||
|
||||
# except:
|
||||
# return "no Item found"
|
||||
|
||||
# matched_obj.stopMonitoring()
|
||||
# return matched_obj.monstate.name
|
||||
|
||||
|
||||
def setStatus(self, id, vrpmStatus):
|
||||
if 'status' in vrpmStatus :
|
||||
matched_obj = self.findMonitoring(id)
|
||||
# matched_obj = self.findMonitoring(id)
|
||||
#call the start API of the c++ driver
|
||||
matched_obj.setStatus(vrpmStatus['status'])
|
||||
return matched_obj.status
|
||||
if (vrpmStatus['status'] == 'started'):
|
||||
return self.startMonitoring(id)
|
||||
else :
|
||||
return self.stopMonitoring(id)
|
||||
|
||||
# return matched_obj.status
|
||||
|
||||
return ""
|
||||
# return ""
|
||||
|
||||
def findMonitoring(self, id):
|
||||
try:
|
||||
return next(x for x in self.mons if str(x.id) == id)
|
||||
except:
|
||||
return "no Item found"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user