# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from flask import Flask, render_template, request, redirect, url_for, jsonify import sys, os from bson.objectid import ObjectId import json import nodemanager import devicemanager import rulebaselinkage import configmanager DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') class WebManager: app = Flask(__name__) def __init__(self, debug: bool): self.app.debug = debug def start(self): self.app.run(host='0.0.0.0') @app.route('/') def index(): title = 'Central Manager' return render_template('index.html', title=title)
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import importlib import os import sys import shutil from bson.objectid import ObjectId from nodes.node import Node import datastoremanager import databasehelper import configmanager import logmanager DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') DB_COLLECTION_NODES = configmanager.get_key('DATABASE', 'nodescollection') DB_COLLECTION_NODE_MODULES = configmanager.get_key('DATABASE', 'nodemodulescollection') DB_COLLECTION_PARENT_NODE_MODULES = configmanager.get_key( 'DATABASE', 'parentnodemodulescollection') DB_COLLECTION_PARENT_NODES = configmanager.get_key('DATABASE', 'parentnodescollection') DIR_NODES = configmanager.get_key('PATHS', 'Dirnodes') TAG = 'NodeManager' __nodes = {} __parent_nodes = {} sys.path.append(os.getcwd() + '/nodes')
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import databasehelper as dbhelper import configmanager import nodemanager import threading import time import pymongo import logmanager from bson.objectid import ObjectId DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') DB_COLLECTION_RULES = configmanager.get_key('DATABASE', 'RulesCollection') DB_COLLECTION_TEMP_DATASTORE = configmanager.get_key( 'DATABASE', 'DataStoreCollectionTemp') INTERVAL = float(configmanager.get_key('INTERVALS', 'RulebaseInterval')) BUFFER_SIZE = int(configmanager.get_key('OTHER', 'buffersize')) TAG = 'RuleBaseLinkage' class RuleBaseLinkageThread(threading.Thread): __instance = None def __new__(cls, *args, **keys): if cls.__instance is None: cls.__instance = object.__new__(cls)
import sys sys.path.append('..') import databasehelper from bson.objectid import ObjectId import configmanager DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') DB_COLLECTION_LOCALAPPS = configmanager.get_key('DATABASE', 'NodesCollection') DB_COLLECTION_GLOBALAPPS = configmanager.get_key('DATABASE', 'NodeModulesCollection') DB_COLLECTION_RULES = configmanager.get_key('DATABASE', 'RulesCollection') DB_COLLECTION_DEVICES = configmanager.get_key('DATABASE', 'DevicesCollection') DB_COLLECTION_TEMP_DATASTORE = configmanager.get_key( 'DATABASE', 'DataStoreCollectionTemp') INTERVAL = float(configmanager.get_key('INTERVALS', 'RulebaseInterval')) # Drop global apps def drop_globalapps(): db = databasehelper.get_database(DB_NAME) col = databasehelper.get_collection(db, DB_COLLECTION_GLOBALAPPS) databasehelper.drop(col) # Add global apps def add_globalapp(): db = databasehelper.get_database(DB_NAME) col = databasehelper.get_collection(db, DB_COLLECTION_GLOBALAPPS) app_id = ObjectId()
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import databasehelper as dbhelper import configmanager import nodemanager from bson.objectid import ObjectId DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') DB_COLLECTION_DEVICES = configmanager.get_key('DATABASE', 'DevicesCollection') def list_devices() -> list: db = dbhelper.get_database(DB_NAME) col = dbhelper.get_collection(db, DB_COLLECTION_DEVICES) listdevices = list(dbhelper.find(col, {})) return listdevices def find_device_info(device_id: str) -> dict: db = dbhelper.get_database(DB_NAME) col = dbhelper.get_collection(db, DB_COLLECTION_DEVICES) listdevices = list(dbhelper.find(col, {'_id': ObjectId(device_id)})) return listdevices[0]
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from bson.objectid import ObjectId import pymongo import databasehelper import threading import time import sys from nodes.node import Node import configmanager import logmanager DB_NAME = configmanager.get_key('DATABASE', 'DatabaseName') DB_COLLECTION_TEMP_DATASTORE = configmanager.get_key( 'DATABASE', 'DataStoreCollectionTemp') INTERVAL = float(configmanager.get_key('INTERVALS', 'DatastoreInterval')) TAG = 'DataStoreManager' class DataStoreThread(threading.Thread): def __init__(self, node: Node, node_id: str) -> None: super(DataStoreThread, self).__init__() self.interval = INTERVAL self.__node = node self.__id = node_id
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import pymongo import configmanager from bson.codec_options import CodecOptions __addr = configmanager.get_key('DATABASE', 'DatabaseAddr') __port = int(configmanager.get_key('DATABASE', 'DatabasePort')) __client = pymongo.MongoClient(__addr, __port) def get_database(name: str) -> pymongo.database: database = __client[name] return database def isExistCollection(database, name: str) -> bool: collist = list_collection_names(database) for colname in collist: if colname == name: return True return False