diff --git a/src/context/database/__init__.py b/src/common/database/__init__.py similarity index 100% rename from src/context/database/__init__.py rename to src/common/database/__init__.py diff --git a/src/context/database/inmemory/InMemoryDatabase.py b/src/common/database/inmemory/InMemoryDatabase.py similarity index 87% rename from src/context/database/inmemory/InMemoryDatabase.py rename to src/common/database/inmemory/InMemoryDatabase.py index 13ef3e876a53b6f2b8fcf514736ddcb1db04e505..59a2274a9785501ffb902015a066c5ae3792a1d8 100644 --- a/src/context/database/inmemory/InMemoryDatabase.py +++ b/src/common/database/inmemory/InMemoryDatabase.py @@ -1,7 +1,8 @@ import logging, json LOGGER = logging.getLogger(__name__) -FILEPATH = 'context/data/topo_nsfnet.json' + +FILEPATH = 'data/topo_nsfnet.json' class InMemoryDatabase: def __init__(self, filepath=FILEPATH, **parameters): diff --git a/src/context/database/inmemory/__init__.py b/src/common/database/inmemory/__init__.py similarity index 100% rename from src/context/database/inmemory/__init__.py rename to src/common/database/inmemory/__init__.py diff --git a/src/context/database/redis/RedisDatabase.py b/src/common/database/redis/RedisDatabase.py similarity index 97% rename from src/context/database/redis/RedisDatabase.py rename to src/common/database/redis/RedisDatabase.py index 883e1f8804cb430131712e9e125c71cc9c3c65ed..38b0bf34b8db01bd2fc93712876ce93a56294fed 100644 --- a/src/context/database/redis/RedisDatabase.py +++ b/src/common/database/redis/RedisDatabase.py @@ -10,6 +10,8 @@ MAX_RETRIES = 15 URL_TEMPLATE = 'redis://{host}:{port}/{dbid}' +FILEPATH = 'data/topo_nsfnet.json' + class RedisDatabase: def __init__(self, **parameters): host = os.environ.get('REDISDB_SERVICE_HOST') @@ -32,7 +34,7 @@ class RedisDatabase: def get_topology(self): str_topology = self.handler.get('topology') if(str_topology is None): - with open('context/data/topo_nsfnet.json', 'r') as f: + with open(FILEPATH, 'r') as f: json_topology = json.loads(f.read()) str_topology = json.dumps(json_topology) self.handler.setnx('topology', str_topology) diff --git a/src/context/database/redis/__init__.py b/src/common/database/redis/__init__.py similarity index 100% rename from src/context/database/redis/__init__.py rename to src/common/database/redis/__init__.py diff --git a/src/context/data/topo_nsfnet.json b/src/context/data/topo_nsfnet.json deleted file mode 100644 index f2cbb53a8f3f9648c4a8b60f97c2212485ac5cc9..0000000000000000000000000000000000000000 --- a/src/context/data/topo_nsfnet.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "topoId": { - "contextId": {"contextUuid": {"uuid": "default"}}, - "topoId": {"uuid": "topo0-nsfnet"} - }, - "device" : [ - {"device_id": {"device_id": {"uuid": "1" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "1" }}, "port_id": {"uuid" : "101"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "2" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "2" }}, "port_id": {"uuid" : "201"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "3" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "3" }}, "port_id": {"uuid" : "301"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "4" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "4" }}, "port_id": {"uuid" : "401"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "5" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "5" }}, "port_id": {"uuid" : "501"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "6" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "6" }}, "port_id": {"uuid" : "601"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "7" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "7" }}, "port_id": {"uuid" : "701"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "8" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "8" }}, "port_id": {"uuid" : "801"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "9" }}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "9" }}, "port_id": {"uuid" : "901"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "10"}}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "10"}}, "port_id": {"uuid" : "1001"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "11"}}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "11"}}, "port_id": {"uuid" : "1101"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "12"}}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "12"}}, "port_id": {"uuid" : "1201"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "13"}}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "13"}}, "port_id": {"uuid" : "1301"}}, "port_type": "LINE"} - ]}, - {"device_id": {"device_id": {"uuid": "14"}}, "device_type": "ROADM", "device_config": {"device_config": ""}, "devOperationalStatus": 1, "endpointList" : [ - {"port_id": {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "14"}}, "port_id": {"uuid" : "1401"}}, "port_type": "LINE"} - ]} - ], - "link" : [ - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "1" }}, "port_id": {"uuid": "101" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "2" }}, "port_id": {"uuid": "201" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "1" }}, "port_id": {"uuid": "101" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "3" }}, "port_id": {"uuid": "301" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "1" }}, "port_id": {"uuid": "101" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "8" }}, "port_id": {"uuid": "801" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "2" }}, "port_id": {"uuid": "201" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "3" }}, "port_id": {"uuid": "301" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "2" }}, "port_id": {"uuid": "201" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "4" }}, "port_id": {"uuid": "401" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "3" }}, "port_id": {"uuid": "301" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "6" }}, "port_id": {"uuid": "601" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "4" }}, "port_id": {"uuid": "401" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "5" }}, "port_id": {"uuid": "501" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "4" }}, "port_id": {"uuid": "401" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "11"}}, "port_id": {"uuid": "1101"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "5" }}, "port_id": {"uuid": "501" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "6" }}, "port_id": {"uuid": "601" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "5" }}, "port_id": {"uuid": "501" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "7" }}, "port_id": {"uuid": "701" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "6" }}, "port_id": {"uuid": "601" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "10"}}, "port_id": {"uuid": "1001"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "6" }}, "port_id": {"uuid": "601" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "13"}}, "port_id": {"uuid": "1301"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "7" }}, "port_id": {"uuid": "701" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "8" }}, "port_id": {"uuid": "801" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "8" }}, "port_id": {"uuid": "801" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "9" }}, "port_id": {"uuid": "901" }} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "9" }}, "port_id": {"uuid": "901" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "10"}}, "port_id": {"uuid": "1001"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "9" }}, "port_id": {"uuid": "901" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "12"}}, "port_id": {"uuid": "1201"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "9" }}, "port_id": {"uuid": "901" }}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "14"}}, "port_id": {"uuid": "1401"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "11"}}, "port_id": {"uuid": "1101"}}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "12"}}, "port_id": {"uuid": "1201"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "11"}}, "port_id": {"uuid": "1101"}}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "14"}}, "port_id": {"uuid": "1401"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "12"}}, "port_id": {"uuid": "1201"}}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "13"}}, "port_id": {"uuid": "1301"}} - ]}, - {"endpointList" : [ - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "13"}}, "port_id": {"uuid": "1301"}}, - {"topoId": {"topoId": {"uuid": "topo0-nsfnet"}}, "dev_id": {"device_id": {"uuid": "14"}}, "port_id": {"uuid": "1401"}} - ]} - ] -} diff --git a/src/context/database/Factory.py b/src/context/database/Factory.py deleted file mode 100644 index 9edd9ac251c69bf0efa28c52a888372443a32c25..0000000000000000000000000000000000000000 --- a/src/context/database/Factory.py +++ /dev/null @@ -1,31 +0,0 @@ -import logging, os -from enum import Enum -from .inmemory.InMemoryDatabase import InMemoryDatabase -from .redis.RedisDatabase import RedisDatabase - -LOGGER = logging.getLogger(__name__) - -class DatabaseEngineEnum(Enum): - INMEMORY = 'inmemory' - REDIS = 'redis' - #MONGO = 'mongo' - #RETHINK = 'rethink' - #ETCD = 'etcd' - -ENGINES = { - DatabaseEngineEnum.INMEMORY.value: InMemoryDatabase, - DatabaseEngineEnum.REDIS.value: RedisDatabase, - #DatabaseEngineEnum.MONGO.value: MongoDatabase, - #DatabaseEngineEnum.RETHINK.value: RethinkDatabase, - #DatabaseEngineEnum.ETCD.value: EtcdDatabase, -} - -DEFAULT_DB_ENGINE = DatabaseEngineEnum.INMEMORY - -def get_database(engine=None, **parameters): - if engine is None: engine = os.environ.get('DB_ENGINE', DEFAULT_DB_ENGINE) - if(isinstance(engine, DatabaseEngineEnum)): engine = engine.value - LOGGER.info('Selected Database Engine: {}'.format(engine)) - engine_class = ENGINES.get(engine) - if engine_class is None: raise Exception('Unsupported Engine({})'.format(engine)) - return engine_class(**parameters) diff --git a/src/context/service/ContextService.py b/src/context/service/ContextService.py index 49c3fe18f9cb7ad3cc5b8a365ff63324f9affc47..41c23266592b6e7b83cc03472777b21c68616280 100644 --- a/src/context/service/ContextService.py +++ b/src/context/service/ContextService.py @@ -1,4 +1,4 @@ -import grpc, os +import grpc import logging from concurrent import futures from grpc_health.v1.health import HealthServicer, OVERALL_HEALTH diff --git a/src/context/service/ContextServiceServicerImpl.py b/src/context/service/ContextServiceServicerImpl.py index e796f7ad5cac4843478f0b470a0cd8136624f990..599c8b2c4985957426c56b922937fc529283e5fb 100644 --- a/src/context/service/ContextServiceServicerImpl.py +++ b/src/context/service/ContextServiceServicerImpl.py @@ -1,7 +1,6 @@ import grpc, logging from prometheus_client import Counter, Histogram -from google.protobuf.json_format import MessageToDict -from context.proto.context_pb2 import Topology, Empty +from context.proto.context_pb2 import Topology from context.proto.context_pb2_grpc import ContextServiceServicer LOGGER = logging.getLogger(__name__) diff --git a/src/context/service/__main__.py b/src/context/service/__main__.py index 7590608ca21e01ed6df99791fc8c4c79cad5223c..5c20c3cec3c67c8d5a00d32d4b44a63758c9461c 100644 --- a/src/context/service/__main__.py +++ b/src/context/service/__main__.py @@ -1,6 +1,6 @@ import logging, os, signal, sys, threading from prometheus_client import start_http_server -from context.database.Factory import get_database +from common.database.Factory import get_database from context.service.ContextService import ContextService from context.Config import SERVICE_PORT, MAX_WORKERS, GRACE_PERIOD, LOG_LEVEL, METRICS_PORT