forked from kaiiyer/UBA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
151 lines (124 loc) · 3.77 KB
/
Copy pathcore.py
File metadata and controls
151 lines (124 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'''
Copyright 2019-Present The OpenUB Platform Authors
This file is part of the OpenUB Platform library.
The OpenUB Platform is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The OpenUB Platform is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the OpenUB Platform. If not, see <http://www.gnu.org/licenses/>.
'''
'''
@name core
@description manage the overall state of the platform
'''
from flask import Flask
import logging
import threading
import time
from model import ModelLibrary
from test import Test
from process import ProcessEngine
from api import API
from display import Display
import unittest
import trace, sys
import coloredlogs
coloredlogs.install()
'''
single server instance
'''
server = Flask(__name__)
'''
@name scheduler_run
@description function to start process engine
'''
def scheduler_run(name):
logging.info("scheduler_run: "+str(name))
process_engine_instance = ProcessEngine()
process_engine_instance.execute()
'''
@description endpoint to get varied display information
'''
@server.route("/display/<string:name>/")
def display(name):
logging.info("Getting display info"+str(name))
return API.get_display(name)
'''
@description endpoint to remove a model
'''
@server.route("/delete_model/<string:model_name>/")
def delete_model(model_name):
logging.warning("deleting model.... from api")
return str(ModelLibrary.remove_model())
'''
@description endpoint to fetch a model
'''
@server.route("/fetch_model/<string:model_name>/")
def fetch_model(model_name):
return ModelLibrary.fetch_model()
'''
@name core
@description manage core system
'''
class Core:
def __init__(self):
pass
'''
@name initiate
@description start core services
'''
def initiate(self):
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logging.info("Core: creating run_scheduler_job thread")
######run scheduler
self.run_scheduler_job()
logging.warning("Core: creating get_display_information thread")
#reset display storage
self.run_display_information_job()
# get a model
logging.info("Core: creating fetch_model_library thread")
self.run_fetch_model_job()
#begin flask server, after initiation tasks
server.run()
'''
@name run_scheduler_job
@description start scheduler on a new thread.
scheduler runs:
- process engine,
- risk engine
- model engine,
- anomaly engine
'''
def run_scheduler_job(self):
x = threading.Thread(target=scheduler_run, args=("Test parameter to scheduler_run",))
logging.info("core: before running thread")
x.start()
logging.info("core: wait for the thread to finish")
'''
@name run_display_information_job
@description run display information job
'''
def run_display_information_job(self):
print("Getting display information")
self.display = Display()
self.display.get_system_display()
'''
@name run_fetch_model
@description get model
'''
def run_fetch_model_job(self):
print("Getting model")
ModelLibrary.fetch_model()
if __name__ == "__main__":
print("Core Start")
###############
# Run all tests
Test.Run()
core: Core = Core()
core.initiate()