Refactor code layout 05/7105/1
authorBin Yang <bin.yang@windriver.com>
Tue, 23 Nov 2021 07:35:35 +0000 (15:35 +0800)
committerBin Yang <bin.yang@windriver.com>
Tue, 23 Nov 2021 07:54:04 +0000 (15:54 +0800)
add o2app to integrate o2ims and o2dms

Signed-off-by: Bin Yang <bin.yang@windriver.com>
Change-Id: Iab47a7e2a40a8ca6e76a084e9ebb902e77899629

53 files changed:
README-o2imsbuilder.md
o2app/adapter/unit_of_work.py
o2app/bootstrap.py
o2app/entrypoints/flask_application.py
o2app/entrypoints/resource_watcher.py
o2common/adapter/notifications.py
o2common/adapter/redis_eventpublisher.py
o2common/domain/commands.py
o2common/domain/events.py
o2common/service/client/__init__.py [moved from o2ims/entrypoints/__init__.py with 100% similarity]
o2common/service/client/base_client.py [moved from o2ims/service/client/base_client.py with 76% similarity]
o2common/service/messagebus.py [moved from o2app/service/messagebus.py with 98% similarity]
o2common/service/unit_of_work.py
o2common/service/watcher/base.py
o2common/service/watcher/worker.py [moved from o2ims/service/watcher/worker.py with 94% similarity]
o2dms/domain/__init__.py [moved from o2ims/service/client/__init__.py with 100% similarity]
o2dms/domain/dms.py
o2ims/adapter/clients/ocloud_sa_client.py
o2ims/adapter/clients/orm_stx.py
o2ims/adapter/notifications.py [deleted file]
o2ims/adapter/redis_eventpublisher.py [deleted file]
o2ims/adapter/unit_of_work.py [deleted file]
o2ims/bootstrap.py [deleted file]
o2ims/config.py [deleted file]
o2ims/domain/base.py [deleted file]
o2ims/domain/commands.py
o2ims/domain/events.py
o2ims/domain/ocloud.py
o2ims/domain/stx_object.py
o2ims/entrypoints/flask_application.py [deleted file]
o2ims/entrypoints/redis_eventconsumer.py [deleted file]
o2ims/entrypoints/resource_watcher.py [deleted file]
o2ims/service/auditor/dms_handler.py
o2ims/service/auditor/ocloud_handler.py
o2ims/service/handlers.py [deleted file]
o2ims/service/messagebus.py [deleted file]
o2ims/service/unit_of_work.py [deleted file]
o2ims/service/watcher/base.py [deleted file]
o2ims/service/watcher/ocloud_watcher.py
o2ims/service/watcher/pserver_cpu_watcher.py
o2ims/service/watcher/pserver_watcher.py
o2ims/service/watcher/resource_watcher.py
o2ims/service/watcher/resourcepool_watcher.py
o2ims/views/ocloud_route.py
o2ims/views/ocloud_view.py
tests/conftest.py
tests/integration-ocloud/test_clientdriver_stx_sa.py
tests/integration-ocloud/test_watcher_w_stx_sa.py
tests/integration/test_clientdriver_fake_stx_sa.py
tests/integration/test_ocloud_repository.py
tests/integration/test_ocloud_view.py
tests/unit/test_ocloud.py
tests/unit/test_watcher.py

index a143301..4ab644f 100644 (file)
@@ -49,8 +49,8 @@ exit
 ### Push O2 service images to local registry (with auth user admin)\r
 \r
 ```sh\r
-sudo docker tag o2imsdms:latest registry.local:9001/admin/o2imsdms:0.1.1\r
-sudo docker image push registry.local:9001/admin/o2imsdms:0.1.1\r
+sudo docker tag o2imsdms:latest registry.local:9001/admin/o2imsdms:0.1.4\r
+sudo docker image push registry.local:9001/admin/o2imsdms:0.1.4\r
 \r
 ```\r
 \r
@@ -67,7 +67,7 @@ o2ims:
   imagePullSecrets: admin-orano2-registry-secret\r
   image:\r
     repository: registry.local:9001/admin/o2imsdms\r
-    tag: 0.1.1\r
+    tag: 0.1.4\r
     pullPolicy: IfNotPresent\r
   logginglevel: "DEBUG"\r
 \r
index 0faba56..2a8663d 100644 (file)
@@ -46,6 +46,8 @@ class SqlAlchemyUnitOfWork(AbstractUnitOfWork):
             .ResourcePoolSqlAlchemyRepository(self.session)\r
         self.resources = ocloud_repository\\r
             .ResourceSqlAlchemyRepository(self.session)\r
+        self.subscriptions = ocloud_repository\\r
+            .SubscriptionSqlAlchemyRepository(self.session)\r
         self.deployment_managers = ocloud_repository\\r
             .DeploymentManagerSqlAlchemyRepository(self.session)\r
         self.nfdeployment_descs = dms_repository\\r
index 7a074f6..2e90768 100644 (file)
@@ -20,8 +20,9 @@ from o2common.adapter.notifications import AbstractNotifications,\
     SmoO2Notifications
 from o2common.adapter import redis_eventpublisher
 from o2common.service import unit_of_work
+from o2common.service import messagebus
 
-from o2app.service import handlers, messagebus
+from o2app.service import handlers
 from o2app.adapter.unit_of_work import SqlAlchemyUnitOfWork
 
 from o2ims.adapter import orm as o2ims_orm
index 45c0436..65dab57 100644 (file)
@@ -16,14 +16,13 @@ from flask import Flask
 from flask_restx import Api\r
 \r
 from o2app import bootstrap\r
-# from o2ims import config\r
-# from o2ims.views.ocloud_route import configure_routes\r
 from o2ims.views import ocloud_route as ims_route\r
 from o2dms.views import dms_route\r
 \r
 \r
 # apibase = config.get_o2ims_api_base()\r
 app = Flask(__name__)\r
+app.config.SWAGGER_UI_DOC_EXPANSION = 'list'\r
 api = Api(app, version='1.0.0',\r
           title='O-Cloud O2 Services',\r
           description='Swagger OpenAPI document for \\r
index 036596c..8a9b0cc 100644 (file)
@@ -16,8 +16,8 @@ import cotyledon
 \r
 from o2app import bootstrap\r
 from o2common.service.watcher.base import WatcherTree\r
+from o2common.service.watcher.worker import PollWorker\r
 \r
-from o2ims.service.watcher.worker import PollWorker\r
 from o2ims.service.watcher.ocloud_watcher import OcloudWatcher\r
 from o2ims.service.watcher.ocloud_watcher import DmsWatcher\r
 from o2ims.service.watcher.resourcepool_watcher import ResourcePoolWatcher\r
index 4c49c1b..e6ba8b2 100644 (file)
@@ -1,6 +1,6 @@
 # pylint: disable=too-few-public-methods
 import abc
-from o2ims import config
+from o2common.config import config
 
 
 SMO_O2_ENDPOINT = config.get_smo_o2endpoint()
index 4df167e..9fac313 100644 (file)
@@ -16,8 +16,8 @@ import json
 from dataclasses import asdict
 import redis
 
-from o2ims import config
-from o2ims.domain import events
+from o2common.config import config
+from o2common.domain import events
 
 from o2common.helper import o2logging
 logger = o2logging.get_logger(__name__)
index 8383f47..51d695f 100644 (file)
 #  limitations under the License.
 
 # pylint: disable=too-few-public-methods
-# from datetime import date
-# from typing import Optional
-from dataclasses import dataclass
-# from datetime import datetime
-# from o2ims.domain.resource_type import ResourceTypeEnum
-from o2ims.domain.stx_object import StxGenericModel
+# from dataclasses import dataclass
 
 
 class Command:
     pass
-
-
-@dataclass
-class UpdateStxObject(Command):
-    data: StxGenericModel
-
-
-@dataclass
-class UpdateOCloud(UpdateStxObject):
-    pass
-
-
-@dataclass
-class UpdateDms(UpdateStxObject):
-    parentid: str
-
-
-@dataclass
-class UpdateResourcePool(UpdateStxObject):
-    parentid: str
-
-
-@dataclass
-class UpdateResource(UpdateStxObject):
-    parentid: str
-
-
-@dataclass
-class UpdatePserverCpu(UpdateResource):
-    pass
-
-
-@dataclass
-class UpdatePserver(UpdateResource):
-    pass
index 591662f..19d7e11 100644 (file)
 #  limitations under the License.
 
 # pylint: disable=too-few-public-methods
-from dataclasses import dataclass
+from dataclasses import dataclass
 
 
 class Event:
     pass
-
-
-@dataclass
-class OcloudUpdated(Event):
-    oCloudId: str
similarity index 76%
rename from o2ims/service/client/base_client.py
rename to o2common/service/client/base_client.py
index 0c35fee..d346e1c 100644 (file)
 \r
 import abc\r
 # from typing import Optional, List, Set\r
-from typing import List\r
-from o2ims.domain import stx_object as ocloudModel\r
+# from typing import List\r
 \r
 \r
 class BaseClient(abc.ABC):\r
     def __init__(self):\r
         pass\r
 \r
-    def list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+    def list(self, **filters):\r
         return self._list(**filters)\r
 \r
-    def get(self, id) -> ocloudModel.StxGenericModel:\r
+    def get(self, id):\r
         return self._get(id)\r
 \r
     @abc.abstractmethod\r
-    def _get(self, id) -> ocloudModel.StxGenericModel:\r
+    def _get(self, id):\r
         raise NotImplementedError\r
 \r
     @abc.abstractmethod\r
similarity index 98%
rename from o2app/service/messagebus.py
rename to o2common/service/messagebus.py
index 297aa8f..6c60c28 100644 (file)
@@ -15,7 +15,7 @@
 # pylint: disable=broad-except, attribute-defined-outside-init
 from __future__ import annotations
 from typing import Callable, Dict, List, Union, Type, TYPE_CHECKING
-from o2ims.domain import commands, events
+from o2common.domain import commands, events
 
 if TYPE_CHECKING:
     from . import unit_of_work
index 3bef2a3..2f6ff5e 100644 (file)
 from __future__ import annotations
 import abc
 
-from o2ims.domain.ocloud_repo import OcloudRepository,\
-    ResourcePoolRepository, ResourceRepository, ResourceTypeRepository,\
-    DeploymentManagerRepository
-from o2ims.domain.stx_repo import StxObjectRepository
-
 
 class AbstractUnitOfWork(abc.ABC):
-    oclouds: OcloudRepository
-    resource_types: ResourceTypeRepository
-    resource_pools: ResourcePoolRepository
-    resources: ResourceRepository
-    deployment_managers: DeploymentManagerRepository
-    stxobjects: StxObjectRepository
+    # oclouds: OcloudRepository
+    # resource_types: ResourceTypeRepository
+    # resource_pools: ResourcePoolRepository
+    # resources: ResourceRepository
+    # deployment_managers: DeploymentManagerRepository
 
     def __enter__(self):
         return self
index 0daf8d4..6e1eb9e 100644 (file)
 \r
 # from logging import exception\r
 # from cgtsclient import exc\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.domain.stx_object import StxGenericModel\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.client.base_client import BaseClient\r
+from o2common.domain import commands\r
+from o2common.service.messagebus import MessageBus\r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
 \r
@@ -34,7 +32,7 @@ class BaseWatcher(object):
     def targetname(self) -> str:\r
         return self._targetname()\r
 \r
-    def probe(self, parent: commands.UpdateStxObject = None):\r
+    def probe(self, parent: commands.Command = None):\r
         try:\r
             cmds = self._probe(parent.data if parent else None)\r
             for cmd in cmds:\r
@@ -46,7 +44,7 @@ class BaseWatcher(object):
             logger.warning("Failed to probe resource due to: " + str(ex))\r
             return []\r
 \r
-    def _probe(self, parent: object = None) -> commands.UpdateStxObject:\r
+    def _probe(self, parent: object = None) -> commands.Command:\r
         raise NotImplementedError\r
 \r
     def _targetname(self):\r
similarity index 94%
rename from o2ims/service/watcher/worker.py
rename to o2common/service/watcher/worker.py
index 888ecd6..64d189d 100644 (file)
@@ -14,7 +14,7 @@
 \r
 import time\r
 import sched\r
-from o2ims.service.watcher.base import WatcherTree\r
+from o2common.service.watcher.base import WatcherTree\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index d80b4a6..ceef458 100644 (file)
@@ -14,7 +14,7 @@
 \r
 from __future__ import annotations\r
 \r
-from o2ims.domain.base import AgRoot\r
+from o2common.domain.base import AgRoot\r
 \r
 \r
 class NfDeploymentDesc(AgRoot):\r
index 0ec88e2..e8f1685 100644 (file)
 # client talking to Stx standalone\r
 \r
 import uuid\r
-from o2ims.service.client.base_client import BaseClient\r
+from o2common.service.client.base_client import BaseClient\r
 from typing import List\r
 # Optional,  Set\r
 from o2ims.domain import stx_object as ocloudModel\r
-from o2ims import config\r
+from o2common.config import config\r
 from o2ims.domain.resource_type import ResourceTypeEnum\r
 \r
 # from dcmanagerclient.api import client\r
index 46ebdb7..dd65402 100644 (file)
@@ -31,8 +31,8 @@ from sqlalchemy import (
 \r
 # from o2ims.domain import stx_object as ocloudModel\r
 \r
-from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.adapter.unit_of_work import SqlAlchemyUnitOfWork\r
+from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2ims.adapter.unit_of_work import SqlAlchemyUnitOfWork\r
 from o2ims.domain.resource_type import ResourceTypeEnum\r
 \r
 from o2common.helper import o2logging\r
@@ -53,7 +53,7 @@ stxobject = Table(
 )\r
 \r
 \r
-def start_o2ims_stx_mappers(uow: AbstractUnitOfWork = SqlAlchemyUnitOfWork()):\r
+def start_o2ims_stx_mappers(uow: AbstractUnitOfWork):\r
     return\r
     # logger.info("Starting O2 IMS Stx mappers")\r
     # mapper(ocloudModel.StxGenericModel, stxobject)\r
diff --git a/o2ims/adapter/notifications.py b/o2ims/adapter/notifications.py
deleted file mode 100644 (file)
index 4c49c1b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# pylint: disable=too-few-public-methods
-import abc
-from o2ims import config
-
-
-SMO_O2_ENDPOINT = config.get_smo_o2endpoint()
-
-
-class AbstractNotifications(abc.ABC):
-    @abc.abstractmethod
-    def send(self, message):
-        raise NotImplementedError
-
-
-class SmoO2Notifications(AbstractNotifications):
-    def __init__(self, smoO2Endpoint=SMO_O2_ENDPOINT):
-        self.smoO2Endpoint = smoO2Endpoint
-
-    def send(self, message):
-        pass
diff --git a/o2ims/adapter/redis_eventpublisher.py b/o2ims/adapter/redis_eventpublisher.py
deleted file mode 100644 (file)
index 4df167e..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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 json
-from dataclasses import asdict
-import redis
-
-from o2ims import config
-from o2ims.domain import events
-
-from o2common.helper import o2logging
-logger = o2logging.get_logger(__name__)
-
-
-r = redis.Redis(**config.get_redis_host_and_port())
-
-
-def publish(channel, event: events.Event):
-    logger.info("publishing: channel=%s, event=%s", channel, event)
-    r.publish(channel, json.dumps(asdict(event)))
diff --git a/o2ims/adapter/unit_of_work.py b/o2ims/adapter/unit_of_work.py
deleted file mode 100644 (file)
index 8b96fbc..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-# pylint: disable=attribute-defined-outside-init\r
-from __future__ import annotations\r
-from sqlalchemy import create_engine\r
-from sqlalchemy.orm import sessionmaker\r
-from sqlalchemy.orm.session import Session\r
-\r
-from o2ims import config\r
-from o2ims.adapter import ocloud_repository\r
-from o2ims.adapter.stx_repository import StxObjectSqlAlchemyRepository\r
-from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-\r
-\r
-DEFAULT_SESSION_FACTORY = sessionmaker(\r
-    bind=create_engine(\r
-        config.get_postgres_uri(),\r
-        isolation_level="REPEATABLE READ",\r
-    )\r
-)\r
-\r
-\r
-class SqlAlchemyUnitOfWork(AbstractUnitOfWork):\r
-    def __init__(self, session_factory=DEFAULT_SESSION_FACTORY):\r
-        self.session_factory = session_factory\r
-\r
-    def __enter__(self):\r
-        self.session = self.session_factory()  # type: Session\r
-        self.oclouds = ocloud_repository\\r
-            .OcloudSqlAlchemyRepository(self.session)\r
-        self.resource_types = ocloud_repository\\r
-            .ResouceTypeSqlAlchemyRepository(self.session)\r
-        self.resource_pools = ocloud_repository\\r
-            .ResourcePoolSqlAlchemyRepository(self.session)\r
-        self.resources = ocloud_repository\\r
-            .ResourceSqlAlchemyRepository(self.session)\r
-        self.deployment_managers = ocloud_repository\\r
-            .DeploymentManagerSqlAlchemyRepository(self.session)\r
-        self.subscriptions = ocloud_repository\\r
-            .SubscriptionSqlAlchemyRepository(self.session)\r
-        self.stxobjects = StxObjectSqlAlchemyRepository(self.session)\r
-        return super().__enter__()\r
-\r
-    def __exit__(self, *args):\r
-        super().__exit__(*args)\r
-        self.session.close()\r
-\r
-    def _commit(self):\r
-        self.session.commit()\r
-\r
-    def rollback(self):\r
-        self.session.rollback()\r
diff --git a/o2ims/bootstrap.py b/o2ims/bootstrap.py
deleted file mode 100644 (file)
index 595fd91..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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.
-
-from retry import retry
-import inspect
-from typing import Callable
-from o2ims.adapter import orm, redis_eventpublisher
-from o2ims.adapter.notifications import AbstractNotifications,\
-    SmoO2Notifications
-
-from o2ims.service import handlers, messagebus, unit_of_work
-from o2ims.adapter.unit_of_work import SqlAlchemyUnitOfWork
-from o2ims.adapter.clients import orm_stx
-from o2common.helper import o2logging
-logger = o2logging.get_logger(__name__)
-
-
-@retry(tries=100, delay=2, backoff=1)
-def wait_for_db_ready(engine):
-    # wait for db up
-    logger.info("Wait for DB ready ...")
-    engine.connect()
-    logger.info("DB is ready")
-
-
-def bootstrap(
-    start_orm: bool = True,
-    uow: unit_of_work.AbstractUnitOfWork = SqlAlchemyUnitOfWork(),
-    notifications: AbstractNotifications = None,
-    publish: Callable = redis_eventpublisher.publish,
-) -> messagebus.MessageBus:
-
-    if notifications is None:
-        notifications = SmoO2Notifications()
-
-    if start_orm:
-        with uow:
-            # get default engine if uow is by default
-            engine = uow.session.get_bind()
-            wait_for_db_ready(engine)
-            orm.start_o2ims_mappers(engine)
-
-        orm_stx.start_o2ims_stx_mappers(uow)
-
-    dependencies = {"uow": uow, "notifications": notifications,
-                    "publish": publish}
-    injected_event_handlers = {
-        event_type: [
-            inject_dependencies(handler, dependencies)
-            for handler in event_handlers
-        ]
-        for event_type, event_handlers in handlers.EVENT_HANDLERS.items()
-    }
-    injected_command_handlers = {
-        command_type: inject_dependencies(handler, dependencies)
-        for command_type, handler in handlers.COMMAND_HANDLERS.items()
-    }
-
-    return messagebus.MessageBus(
-        uow=uow,
-        event_handlers=injected_event_handlers,
-        command_handlers=injected_command_handlers,
-    )
-
-
-def inject_dependencies(handler, dependencies):
-    params = inspect.signature(handler).parameters
-    deps = {
-        name: dependency
-        for name, dependency in dependencies.items()
-        if name in params
-    }
-    return lambda message: handler(message, **deps)
diff --git a/o2ims/config.py b/o2ims/config.py
deleted file mode 100644 (file)
index 55d4755..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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 os
-import sys
-
-from o2common.helper import o2logging
-logger = o2logging.get_logger(__name__)
-
-
-def get_postgres_uri():
-    host = os.environ.get("DB_HOST", "localhost")
-    port = 54321 if host == "localhost" else 5432
-    password = os.environ.get("DB_PASSWORD", "o2ims123")
-    user, db_name = "o2ims", "o2ims"
-    return f"postgresql://{user}:{password}@{host}:{port}/{db_name}"
-
-
-def get_api_url():
-    host = os.environ.get("API_HOST", "localhost")
-    port = 5005 if host == "localhost" else 80
-    return f"http://{host}:{port}"
-
-
-def get_root_api_base():
-    return "/"
-
-
-def get_o2ims_api_base():
-    return get_root_api_base() + 'o2ims_infrastructureInventory/v1'
-
-
-def get_o2dms_api_base():
-    return get_root_api_base() + "o2dms/v1"
-
-
-def get_redis_host_and_port():
-    host = os.environ.get("REDIS_HOST", "localhost")
-    port = 63791 if host == "localhost" else 6379
-    return dict(host=host, port=port)
-
-
-def get_smo_o2endpoint():
-    smo_o2endpoint = os.environ.get(
-        "SMO_O2_ENDPOINT", "http://localhost/smo_sim")
-    return smo_o2endpoint
-
-
-def get_stx_access_info():
-    # authurl = os.environ.get("STX_AUTH_URL", "http://192.168.204.1:5000/v3")
-    # username = os.environ.get("STX_USERNAME", "admin")
-    # pswd = os.environ.get("STX_PASSWORD", "passwd1")
-    # stx_access_info = (authurl, username, pswd)
-    try:
-        client_args = dict(
-            auth_url=os.environ.get('OS_AUTH_URL',
-                                    "http://192.168.204.1:5000/v3"),
-            username=os.environ.get('OS_USERNAME', "admin"),
-            api_key=os.environ.get('OS_PASSWORD', "fakepasswd1"),
-            project_name=os.environ.get('OS_PROJECT_NAME', "admin"),
-        )
-        # dc_client_args = dict(
-        #     auth_url=os.environ['OS_AUTH_URL'],
-        #     username=os.environ['OS_USERNAME'],
-        #     api_key=os.environ['OS_PASSWORD'],
-        #     project_name=os.environ['OS_PROJECT_NAME'],
-        #     user_domain_name=os.environ['OS_USER_DOMAIN_NAME'],
-        #     project_domain_name=os.environ['OS_PROJECT_NAME'],
-        #     project_domain_id=os.environ['OS_PROJECT_DOMAIN_ID']
-        # )
-    except KeyError:
-        logger.error('Please source your RC file before execution, '
-                     'e.g.: `source ~/downloads/admin-rc.sh`')
-        sys.exit(1)
-
-    os_client_args = {}
-    for key, val in client_args.items():
-        os_client_args['os_{key}'.format(key=key)] = val
-    os_client_args['os_password'] = os_client_args.pop('os_api_key')
-    os_client_args['os_region_name'] = 'RegionOne'
-    os_client_args['api_version'] = 1
-    return os_client_args
diff --git a/o2ims/domain/base.py b/o2ims/domain/base.py
deleted file mode 100644 (file)
index 8a673da..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-from datetime import datetime\r
-from typing import List\r
-from .events import Event\r
-\r
-\r
-class AgRoot:\r
-    def __init__(self) -> None:\r
-        self.hash = ""\r
-        # self.id = ""\r
-        self.updatetime = datetime.now()\r
-        self.createtime = datetime.now()\r
-        self.events = []  # type: List[Event]\r
index 8383f47..1a31f0e 100644 (file)
@@ -19,10 +19,7 @@ from dataclasses import dataclass
 # from datetime import datetime
 # from o2ims.domain.resource_type import ResourceTypeEnum
 from o2ims.domain.stx_object import StxGenericModel
-
-
-class Command:
-    pass
+from o2common.domain.commands import Command
 
 
 @dataclass
index 591662f..c97c688 100644 (file)
 
 # pylint: disable=too-few-public-methods
 from dataclasses import dataclass
-
-
-class Event:
-    pass
+from o2common.domain.events import Event
 
 
 @dataclass
index 0c5d232..0829fb9 100644 (file)
@@ -14,7 +14,7 @@
 \r
 from __future__ import annotations\r
 \r
-from o2ims.domain.base import AgRoot\r
+from o2common.domain.base import AgRoot\r
 # from dataclasses import dataclass\r
 # from datetime import date\r
 # from typing import Optional, List, Set\r
index 9629652..5e4d660 100644 (file)
@@ -15,7 +15,7 @@
 # from dataclasses import dataclass\r
 import datetime\r
 import json\r
-from o2ims.domain.base import AgRoot\r
+from o2common.domain.base import AgRoot\r
 \r
 from o2ims.domain.resource_type import ResourceTypeEnum, MismatchedModel\r
 from o2common.helper import o2logging\r
diff --git a/o2ims/entrypoints/flask_application.py b/o2ims/entrypoints/flask_application.py
deleted file mode 100644 (file)
index c439173..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-from flask import Flask\r
-from flask_restx import Api\r
-\r
-from o2ims import bootstrap\r
-# from o2ims import config\r
-from o2ims.views.ocloud_route import configure_namespace\r
-from o2dms.views import dms_route\r
-\r
-\r
-# apibase = config.get_o2ims_api_base()\r
-app = Flask(__name__)\r
-app.config.SWAGGER_UI_DOC_EXPANSION = 'list'\r
-api = Api(app, version='1.0.0',\r
-          title='O-Cloud O2 Interface Application',\r
-          description='Swagger OpenAPI document for \\r
-          O-Cloud O2 interface application',\r
-          )\r
-bus = bootstrap.bootstrap()\r
-configure_namespace(api, bus)\r
-\r
-dms_route.configure_namespace(api, bus)\r
diff --git a/o2ims/entrypoints/redis_eventconsumer.py b/o2ims/entrypoints/redis_eventconsumer.py
deleted file mode 100644 (file)
index 15312bf..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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 json
-import redis
-
-from o2ims import bootstrap, config
-# from o2ims.domain import commands
-
-from o2common.helper import o2logging
-logger = o2logging.get_logger(__name__)
-
-r = redis.Redis(**config.get_redis_host_and_port())
-
-
-def main():
-    logger.info("Redis pubsub starting")
-    bus = bootstrap.bootstrap()
-    pubsub = r.pubsub(ignore_subscribe_messages=True)
-    pubsub.subscribe("dms_changed")
-
-    for m in pubsub.listen():
-        handle_dms_changed(m, bus)
-
-
-def handle_dms_changed(m, bus):
-    logger.info("handling %s", m)
-    # data = json.loads(m["data"])
-    # cmd = commands.UpdateDms(ref=data["dmsid"])
-    # bus.handle(cmd)
-
-
-if __name__ == "__main__":
-    main()
diff --git a/o2ims/entrypoints/resource_watcher.py b/o2ims/entrypoints/resource_watcher.py
deleted file mode 100644 (file)
index 9e17485..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-import cotyledon\r
-\r
-from o2ims.service.watcher.worker import PollWorker\r
-from o2ims.service.watcher.ocloud_watcher import OcloudWatcher\r
-from o2ims.service.watcher.ocloud_watcher import DmsWatcher\r
-from o2ims.service.watcher.resourcepool_watcher import ResourcePoolWatcher\r
-from o2ims.adapter.clients.ocloud_sa_client import StxSaDmsClient\r
-from o2ims.adapter.clients.ocloud_sa_client import StxSaOcloudClient\r
-from o2ims.adapter.clients.ocloud_sa_client import StxSaResourcePoolClient\r
-\r
-from o2ims.service.watcher.pserver_watcher import PServerWatcher\r
-from o2ims.adapter.clients.ocloud_sa_client import StxPserverClient\r
-\r
-from o2ims.service.watcher.pserver_cpu_watcher import PServerCpuWatcher\r
-from o2ims.adapter.clients.ocloud_sa_client import StxCpuClient\r
-\r
-from o2ims.service.watcher.base import WatcherTree\r
-\r
-from o2ims import bootstrap\r
-# from o2ims import config\r
-# import redis\r
-\r
-from o2common.helper import o2logging\r
-logger = o2logging.get_logger(__name__)\r
-\r
-# r = redis.Redis(**config.get_redis_host_and_port())\r
-\r
-\r
-class WatcherService(cotyledon.Service):\r
-    def __init__(self, worker_id, args=None) -> None:\r
-        super().__init__(worker_id)\r
-        self.args = args\r
-        self.bus = bootstrap.bootstrap()\r
-        self.worker = PollWorker()\r
-\r
-    def run(self):\r
-        try:\r
-            root = WatcherTree(OcloudWatcher(\r
-                StxSaOcloudClient(), self.bus))\r
-            root.addchild(\r
-                DmsWatcher(StxSaDmsClient(), self.bus))\r
-\r
-            child_respool = root.addchild(\r
-                ResourcePoolWatcher(StxSaResourcePoolClient(),\r
-                                    self.bus))\r
-            child_pserver = child_respool.addchild(\r
-                PServerWatcher(StxPserverClient(), self.bus))\r
-            child_pserver.addchild(\r
-                PServerCpuWatcher(StxCpuClient(), self.bus))\r
-\r
-            self.worker.add_watcher(root)\r
-\r
-            self.worker.start()\r
-        except Exception as ex:\r
-            logger.warning("WorkerService Exception:" + str(ex))\r
-        finally:\r
-            self.worker.stop()\r
-\r
-\r
-def start_watchers(sm: cotyledon.ServiceManager = None):\r
-    watchersm = sm if sm else cotyledon.ServiceManager()\r
-    watchersm.add(WatcherService, workers=1, args=())\r
-    watchersm.run()\r
-\r
-\r
-def main():\r
-    logger.info("Resource watcher starting")\r
-    start_watchers()\r
-\r
-\r
-if __name__ == "__main__":\r
-    main()\r
index 207f6e2..c3d4a77 100644 (file)
@@ -20,10 +20,10 @@ from o2ims.domain.stx_object import StxGenericModel
 # from typing import List, Dict, Callable, Type
 # TYPE_CHECKING
 from o2ims.domain import commands
-from o2ims.service.unit_of_work import AbstractUnitOfWork
+from o2common.service.unit_of_work import AbstractUnitOfWork
 from o2ims.domain.resource_type import MismatchedModel
 from o2ims.domain.ocloud import DeploymentManager
-from o2ims import config
+from o2common.config import config
 # if TYPE_CHECKING:
 #     from . import unit_of_work
 
index 9dd4f0e..554b2e1 100644 (file)
@@ -20,11 +20,11 @@ from o2ims.domain.stx_object import StxGenericModel
 # from typing import List, Dict, Callable, Type
 # TYPE_CHECKING
 from o2ims.domain import commands
-from o2ims.service.unit_of_work import AbstractUnitOfWork
+from o2common.service.unit_of_work import AbstractUnitOfWork
 from o2ims.domain.resource_type import InvalidOcloudState
 from o2ims.domain.resource_type import MismatchedModel
 from o2ims.domain.ocloud import Ocloud
-from o2ims import config
+from o2common.config import config
 # if TYPE_CHECKING:
 #     from . import unit_of_work
 
diff --git a/o2ims/service/handlers.py b/o2ims/service/handlers.py
deleted file mode 100644 (file)
index 830e1ff..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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.
-
-# pylint: disable=unused-argument
-from __future__ import annotations
-# from dataclasses import asdict
-from typing import List, Dict, Callable, Type
-from o2ims.service.auditor import dms_handler
-# TYPE_CHECKING
-from o2ims.domain import commands, events
-from o2ims.service.auditor import ocloud_handler
-
-# if TYPE_CHECKING:
-#     from . import unit_of_work
-
-
-class InvalidResourceType(Exception):
-    pass
-
-
-EVENT_HANDLERS = {
-}  # type: Dict[Type[events.Event], List[Callable]]
-
-
-COMMAND_HANDLERS = {
-    commands.UpdateOCloud: ocloud_handler.update_ocloud,
-    commands.UpdateDms: dms_handler.update_dms
-}  # type: Dict[Type[commands.Command], Callable]
diff --git a/o2ims/service/messagebus.py b/o2ims/service/messagebus.py
deleted file mode 100644 (file)
index 297aa8f..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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.
-
-# pylint: disable=broad-except, attribute-defined-outside-init
-from __future__ import annotations
-from typing import Callable, Dict, List, Union, Type, TYPE_CHECKING
-from o2ims.domain import commands, events
-
-if TYPE_CHECKING:
-    from . import unit_of_work
-
-from o2common.helper import o2logging
-logger = o2logging.get_logger(__name__)
-
-Message = Union[commands.Command, events.Event]
-
-
-class MessageBus:
-    def __init__(
-        self,
-        uow: unit_of_work.AbstractUnitOfWork,
-        event_handlers: Dict[Type[events.Event], List[Callable]],
-        command_handlers: Dict[Type[commands.Command], Callable],
-    ):
-        self.uow = uow
-        self.event_handlers = event_handlers
-        self.command_handlers = command_handlers
-
-    def handle(self, message: Message):
-        self.queue = [message]
-        while self.queue:
-            message = self.queue.pop(0)
-            if not message:
-                continue
-            elif isinstance(message, events.Event):
-                self.handle_event(message)
-            elif isinstance(message, commands.Command):
-                self.handle_command(message)
-            else:
-                raise Exception(f"{message} was not an Event or Command")
-
-    def handle_event(self, event: events.Event):
-        for handler in self.event_handlers[type(event)]:
-            try:
-                logger.debug("handling event %s with handler %s",
-                             event, handler)
-                handler(event)
-                self.queue.extend(self.uow.collect_new_events())
-            except Exception:
-                logger.exception("Exception handling event %s", event)
-                continue
-
-    def handle_command(self, command: commands.Command):
-        logger.debug("handling command %s", command)
-        try:
-            handler = self.command_handlers[type(command)]
-            handler(command)
-            self.queue.extend(self.uow.collect_new_events())
-        except Exception as ex:
-            logger.exception("Exception handling command %s", command)
-            raise ex
diff --git a/o2ims/service/unit_of_work.py b/o2ims/service/unit_of_work.py
deleted file mode 100644 (file)
index 0445996..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.
-#
-#  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.
-
-# pylint: disable=attribute-defined-outside-init
-from __future__ import annotations
-import abc
-
-from o2ims.domain.ocloud_repo import OcloudRepository,\
-    ResourcePoolRepository, ResourceRepository, ResourceTypeRepository,\
-    DeploymentManagerRepository
-from o2ims.domain.stx_repo import StxObjectRepository
-
-
-class AbstractUnitOfWork(abc.ABC):
-    oclouds: OcloudRepository
-    resource_types: ResourceTypeRepository
-    resource_pools: ResourcePoolRepository
-    resources: ResourceRepository
-    deployment_managers: DeploymentManagerRepository
-    stxobjects: StxObjectRepository
-
-    def __enter__(self):
-        return self
-
-    def __exit__(self, *args):
-        self.rollback()
-
-    def commit(self):
-        self._commit()
-
-    def collect_new_events(self):
-        for entry in self.oclouds.seen:
-            while entry.events:
-                yield entry.events.pop(0)
-        for entry in self.resource_pools.seen:
-            while entry.events:
-                yield entry.events.pop(0)
-        for entry in self.resources.seen:
-            while entry.events:
-                yield entry.events.pop(0)
-        for entry in self.resource_types.seen:
-            while entry.events:
-                yield entry.events.pop(0)
-        # for entry in self.stxobjects.seen:
-        #     while entry.events:
-        #         yield entry.events.pop(0)
-        for entry in self.deployment_managers.seen:
-            while entry.events:
-                yield entry.events.pop(0)
-
-    @abc.abstractmethod
-    def _commit(self):
-        raise NotImplementedError
-
-    @abc.abstractmethod
-    def rollback(self):
-        raise NotImplementedError
diff --git a/o2ims/service/watcher/base.py b/o2ims/service/watcher/base.py
deleted file mode 100644 (file)
index 0daf8d4..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-# from logging import exception\r
-# from cgtsclient import exc\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.domain.stx_object import StxGenericModel\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
-from o2common.helper import o2logging\r
-logger = o2logging.get_logger(__name__)\r
-\r
-\r
-class BaseWatcher(object):\r
-    def __init__(self, client: BaseClient,\r
-                 bus: MessageBus) -> None:\r
-        super().__init__()\r
-        self._client = client\r
-        self._bus = bus\r
-        # self._uow = bus.uow\r
-\r
-    def targetname(self) -> str:\r
-        return self._targetname()\r
-\r
-    def probe(self, parent: commands.UpdateStxObject = None):\r
-        try:\r
-            cmds = self._probe(parent.data if parent else None)\r
-            for cmd in cmds:\r
-                self._bus.handle(cmd)\r
-\r
-            # return self._probe(parent)\r
-            return cmds\r
-        except Exception as ex:\r
-            logger.warning("Failed to probe resource due to: " + str(ex))\r
-            return []\r
-\r
-    def _probe(self, parent: object = None) -> commands.UpdateStxObject:\r
-        raise NotImplementedError\r
-\r
-    def _targetname(self):\r
-        raise NotImplementedError\r
-\r
-    # def _compare_and_update(self, newmodel: StxGenericModel) -> bool:\r
-    #     with self._uow:\r
-    #         # localmodel = self._uow.stxobjects.get(ocloudmodel.id)\r
-    #         localmodel = self._uow.stxobjects.get(str(newmodel.id))\r
-    #         if not localmodel:\r
-    #             logger.info("add entry:" + newmodel.name)\r
-    #             self._uow.stxobjects.add(newmodel)\r
-    #         elif localmodel.is_outdated(newmodel):\r
-    #             logger.info("update entry:" + newmodel.name)\r
-    #             localmodel.update_by(newmodel)\r
-    #             self._uow.stxobjects.update(localmodel)\r
-    #         self._uow.commit()\r
-\r
-\r
-# node to organize watchers in tree hierachy\r
-class WatcherTree(object):\r
-    def __init__(self, watcher: BaseWatcher) -> None:\r
-        super().__init__()\r
-        self.watcher = watcher\r
-        self.children = {}\r
-\r
-    def addchild(self, watcher: BaseWatcher) -> object:\r
-        child = WatcherTree(watcher)\r
-        self.children[watcher.targetname()] = child\r
-        return child\r
-\r
-    def removechild(self, targetname: str) -> object:\r
-        return self.children.pop(targetname)\r
-\r
-    # probe all resources by parent, depth = 0 for indefinite recursive\r
-    def probe(self, parentresource=None, depth: int = 0):\r
-        logger.debug("probe resources with watcher: "\r
-                     + self.watcher.targetname())\r
-        childdepth = depth - 1 if depth > 0 else 0\r
-        resources = self.watcher.probe(parentresource)\r
-        logger.debug("probe returns " + str(len(resources)) + " resources")\r
-\r
-        if depth == 1:\r
-            # stop recursive\r
-            return\r
-\r
-        for res in resources:\r
-            for targetname in self.children.keys():\r
-                self.children[targetname].probe(res, childdepth)\r
index 31e2f1b..1d0c0ae 100644 (file)
 #  limitations under the License.\r
 \r
 # from o2ims.domain.resource_type import ResourceTypeEnum\r
-from o2ims.service.client.base_client import BaseClient\r
+from o2common.service.client.base_client import BaseClient\r
 from o2ims.domain.stx_object import StxGenericModel\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.service.watcher.base import BaseWatcher\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service.watcher.base import BaseWatcher\r
 from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.messagebus import MessageBus\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index 66f2294..cf471a4 100644 (file)
 #  limitations under the License.\r
 \r
 from o2ims.domain.stx_object import StxGenericModel\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
 from o2ims.service.watcher.resource_watcher import ResourceWatcher\r
 from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.messagebus import MessageBus\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index befc2f6..ca3e898 100644 (file)
 #  limitations under the License.\r
 \r
 from o2ims.domain.stx_object import StxGenericModel\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
 from o2ims.service.watcher.resource_watcher import ResourceWatcher\r
 from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.messagebus import MessageBus\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index 7ca4093..86416e3 100644 (file)
 #  limitations under the License.\r
 \r
 from o2ims.domain.stx_object import StxGenericModel\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.service.watcher.base import BaseWatcher\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service.watcher.base import BaseWatcher\r
 from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.messagebus import MessageBus\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index a8fd4f6..214041f 100644 (file)
 #  limitations under the License.\r
 \r
 from o2ims.domain.stx_object import StxGenericModel\r
-from o2ims.service.client.base_client import BaseClient\r
-# from o2ims.service.unit_of_work import AbstractUnitOfWork\r
-from o2ims.service.watcher.base import BaseWatcher\r
+from o2common.service.client.base_client import BaseClient\r
+# from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service.watcher.base import BaseWatcher\r
 from o2ims.domain import commands\r
-from o2ims.service.messagebus import MessageBus\r
+from o2common.service.messagebus import MessageBus\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
index a6f1847..5a2b259 100644 (file)
@@ -16,7 +16,7 @@ import uuid
 from flask_restx import Resource
 
 from o2ims.views import ocloud_view, api
-from o2ims import config
+from o2common.config import config
 from o2ims.domain.ocloud import Subscription
 from o2ims.views.ocloud_dto import OcloudDTO, ResourceTypeDTO,\
     ResourcePoolDTO, ResourceDTO, DeploymentManagerDTO, SubscriptionDTO
index 90850e8..9a1a595 100644 (file)
@@ -16,11 +16,11 @@ from sqlalchemy import select
 \r
 from o2ims.adapter.orm import ocloud, resource, resourcetype, \\r
     resourcepool, deploymentmanager, subscription\r
-from o2ims.adapter import unit_of_work\r
+from o2common.service import unit_of_work\r
 from o2ims.domain.ocloud import Subscription\r
 \r
 \r
-def oclouds(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def oclouds(uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(ocloud))\r
     return [dict(r) for r in res]\r
@@ -34,14 +34,14 @@ def ocloud_one(ocloudid: str, uow: unit_of_work.AbstractUnitOfWork):
     return None if first is None else dict(first)\r
 \r
 \r
-def resource_types(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_types(uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(resourcetype))\r
     return [dict(r) for r in res]\r
 \r
 \r
 def resource_type_one(resourceTypeId: str,\r
-                      uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                      uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(resourcetype).where(\r
             resourcetype.c.resourceTypeId == resourceTypeId))\r
@@ -49,14 +49,14 @@ def resource_type_one(resourceTypeId: str,
     return None if first is None else dict(first)\r
 \r
 \r
-def resource_pools(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_pools(uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(resourcepool))\r
     return [dict(r) for r in res]\r
 \r
 \r
 def resource_pool_one(resourcePoolId: str,\r
-                      uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                      uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(resourcepool).where(\r
             resourcepool.c.resourcePoolId == resourcePoolId))\r
@@ -64,14 +64,14 @@ def resource_pool_one(resourcePoolId: str,
     return None if first is None else dict(first)\r
 \r
 \r
-def resources(resourcePoolId: str, uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(resource).where(\r
             resource.c.resourcePoolId == resourcePoolId))\r
     return [dict(r) for r in res]\r
 \r
 \r
-def resource_one(resourceId: str, uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         # topq = uow.session.query(resource).filter(\r
         #     resource.c.resourceId == resourceId).cte('cte', recursive=True)\r
@@ -85,14 +85,14 @@ def resource_one(resourceId: str, uow: unit_of_work.SqlAlchemyUnitOfWork):
     return None if first is None else dict(first)\r
 \r
 \r
-def deployment_managers(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(deploymentmanager))\r
     return [dict(r) for r in res]\r
 \r
 \r
 def deployment_manager_one(deploymentManagerId: str,\r
-                           uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                           uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(deploymentmanager).where(\r
             deploymentmanager.c.deploymentManagerId == deploymentManagerId))\r
@@ -100,14 +100,14 @@ def deployment_manager_one(deploymentManagerId: str,
     return None if first is None else dict(first)\r
 \r
 \r
-def subscriptions(uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+def subscriptions(uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(subscription))\r
     return [dict(r) for r in res]\r
 \r
 \r
 def subscription_one(subscriptionId: str,\r
-                     uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                     uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         res = uow.session.execute(select(subscription).where(\r
             subscription.c.subscriptionId == subscriptionId))\r
@@ -116,14 +116,14 @@ def subscription_one(subscriptionId: str,
 \r
 \r
 def subscription_create(subscription: Subscription,\r
-                        uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                        uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         uow.subscriptions.add(subscription)\r
         uow.commit()\r
 \r
 \r
 def subscription_delete(subscriptionId: str,\r
-                        uow: unit_of_work.SqlAlchemyUnitOfWork):\r
+                        uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         uow.subscriptions.delete(subscriptionId)\r
         uow.commit()\r
index a3359a9..60f3d2e 100644 (file)
@@ -14,12 +14,15 @@ from sqlalchemy.orm import sessionmaker, clear_mappers
 from tenacity import retry, stop_after_delay\r
 from unittest.mock import MagicMock\r
 \r
-from o2ims import config\r
+from o2common.config import config\r
+\r
 from o2ims.adapter.orm import metadata, start_o2ims_mappers\r
-from o2ims.adapter.clients.orm_stx import start_o2ims_stx_mappers\r
-from o2ims.adapter import unit_of_work\r
+# from o2ims.adapter.clients.orm_stx import start_o2ims_stx_mappers\r
+\r
+from o2app.adapter import unit_of_work\r
 from o2ims.views.ocloud_route import configure_namespace\r
-from o2ims.bootstrap import bootstrap\r
+\r
+from o2app.bootstrap import bootstrap\r
 \r
 \r
 @pytest.fixture\r
@@ -81,7 +84,7 @@ def sqlite_flask_uow(sqlite_uow):
 @pytest.fixture\r
 def mappers():\r
     start_o2ims_mappers()\r
-    start_o2ims_stx_mappers()\r
+    start_o2ims_stx_mappers()\r
     yield\r
     clear_mappers()\r
 \r
index 4cf4c64..7ece56b 100644 (file)
 \r
 import sys\r
 import pytest\r
-from o2ims.adapter import ocloud_repository as repository\r
-from o2ims.domain import ocloud\r
-from o2ims import config\r
-import uuid\r
+\r
+from o2common.config import config\r
 from o2ims.adapter.clients.ocloud_sa_client import StxSaClientImp\r
 from cgtsclient.client import get_client\r
 \r
index d722ee7..1525ab1 100644 (file)
@@ -14,7 +14,7 @@
 \r
 from multiprocessing.queues import Queue\r
 import pytest\r
-from o2ims.entrypoints.resource_watcher import start_watchers\r
+from o2app.entrypoints.resource_watcher import start_watchers\r
 from multiprocessing import Process\r
 from multiprocessing import Pipe\r
 # pipe = Pipe()\r
index 25bc3ad..8dc84d9 100644 (file)
@@ -17,7 +17,7 @@ import sys
 import pytest\r
 from o2ims.adapter import ocloud_repository as repository\r
 from o2ims.domain import ocloud\r
-from o2ims import config\r
+from o2common.config import config\r
 import logging\r
 import uuid\r
 import json\r
index 75800a3..38bce21 100644 (file)
@@ -18,7 +18,7 @@ import pytest
 from o2ims.domain import resource_type as rt
 from o2ims.adapter import ocloud_repository as repository
 from o2ims.domain import ocloud
-from o2ims import config
+from o2common.config import config
 
 pytestmark = pytest.mark.usefixtures("mappers")
 
index e295a94..2fb7d73 100644 (file)
@@ -15,7 +15,7 @@
 import uuid
 import pytest
 
-from o2ims import config
+from o2common.config import config
 from o2ims.views import ocloud_view
 from o2ims.domain import ocloud
 from o2ims.domain import resource_type as rt
index a556295..a2904b7 100644 (file)
@@ -17,7 +17,7 @@ import uuid
 from o2ims.domain import ocloud
 from o2ims.domain import resource_type as rt
 from o2ims.views import ocloud_view
-from o2ims import config
+from o2common.config import config
 
 
 def setup_ocloud():
index 69c3e91..8c1afac 100644 (file)
@@ -16,22 +16,25 @@ import time
 from datetime import datetime\r
 import json\r
 from typing import List\r
-from o2ims.service import handlers\r
-from o2ims.domain.resource_type import ResourceTypeEnum\r
-from o2ims.service.client.base_client import BaseClient\r
-from o2ims.domain import ocloud\r
-from o2ims import config\r
+# from o2common.config import config\r
 import uuid\r
-from o2ims.service.watcher.base import BaseWatcher, WatcherTree\r
+from o2common.service.watcher.base import BaseWatcher, WatcherTree\r
+from o2common.service.watcher import worker\r
+from o2common.service.unit_of_work import AbstractUnitOfWork\r
+from o2common.service import messagebus\r
+\r
+from o2ims.domain.resource_type import ResourceTypeEnum\r
 from o2ims.domain import stx_object as ocloudModel\r
 from o2ims.adapter.ocloud_repository import OcloudRepository\r
 from o2ims.domain.stx_repo import StxObjectRepository\r
-from o2ims.service.watcher import worker\r
-from o2ims.service.unit_of_work import AbstractUnitOfWork\r
 from o2ims.service.watcher.ocloud_watcher import OcloudWatcher\r
-from o2ims.service import messagebus\r
-from o2ims import bootstrap\r
 from o2ims.domain import commands\r
+from o2common.service.client.base_client import BaseClient\r
+from o2ims.domain import ocloud\r
+\r
+from o2app.service import handlers\r
+from o2app import bootstrap\r
+\r
 \r
 class FakeOcloudClient(BaseClient):\r
     def __init__(self):\r