Add auditor for resource pool, pserver and cpu/memory/port/interface for pserver... 06/7206/3
authorZhang Rong(Jon) <rong.zhang@windriver.com>
Fri, 3 Dec 2021 03:47:51 +0000 (11:47 +0800)
committerZhang Rong(Jon) <rong.zhang@windriver.com>
Fri, 3 Dec 2021 03:56:14 +0000 (11:56 +0800)
1. Add auditor for resource pool, pserver and cpu/memory/port/interface of pserver
2. CUpdate resource type column, auto create resource type before create cpu/memory/port/interface resource
3. Give the git clone parameters to make download size lesser

Issue-ID: INF-236
Issue-ID: INF-235
Issue-ID: INF-234
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
Change-Id: I7ddc7d8c18b7f3c17b22cdd35bdf68864f32f780

31 files changed:
Dockerfile
README-o2imsbuilder.md
README.md
o2app/entrypoints/resource_watcher.py
o2app/service/handlers.py
o2common/domain/base.py
o2ims/adapter/clients/ocloud_sa_client.py
o2ims/adapter/ocloud_repository.py
o2ims/adapter/orm.py
o2ims/domain/commands.py
o2ims/domain/events.py
o2ims/domain/ocloud.py
o2ims/domain/resource_type.py
o2ims/domain/stx_object.py
o2ims/service/auditor/dms_handler.py
o2ims/service/auditor/ocloud_handler.py
o2ims/service/auditor/pserver_cpu_handler.py [new file with mode: 0644]
o2ims/service/auditor/pserver_handler.py [new file with mode: 0644]
o2ims/service/auditor/pserver_if_handler.py [new file with mode: 0644]
o2ims/service/auditor/pserver_mem_handler.py [new file with mode: 0644]
o2ims/service/auditor/pserver_port_handler.py [new file with mode: 0644]
o2ims/service/auditor/resourcepool_handler.py [new file with mode: 0644]
o2ims/service/watcher/pserver_cpu_watcher.py
o2ims/service/watcher/pserver_if_watcher.py [new file with mode: 0644]
o2ims/service/watcher/pserver_mem_watcher.py [new file with mode: 0644]
o2ims/service/watcher/pserver_port_watcher.py [new file with mode: 0644]
o2ims/service/watcher/pserver_watcher.py
o2ims/views/ocloud_route.py
o2ims/views/ocloud_view.py
tests/integration-ocloud/test_clientdriver_stx_sa.py
tests/unit/test_watcher.py

index 3cbe00a..db2258d 100644 (file)
@@ -5,12 +5,12 @@ RUN apt-get update; apt-get install -y git gcc
 # in case git repo is not accessable\r
 # RUN mkdir -p /cgtsclient\r
 # COPY temp/config /cgtsclient/\r
-RUN git clone https://opendev.org/starlingx/config.git /cgtsclient\r
+RUN git clone --depth 1 --branch master https://opendev.org/starlingx/config.git /cgtsclient\r
 RUN pip install -e /cgtsclient/sysinv/cgts-client/cgts-client/\r
 \r
 # RUN mkdir -p /distcloud-client\r
 # COPY temp/distcloud-client /distcloud-client/\r
-RUN git clone https://opendev.org/starlingx/distcloud-client.git /distcloud-client/\r
+RUN git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git /distcloud-client/\r
 RUN pip install -e /distcloud-client/distributedcloud-client\r
 # in case git repo is not accessable\r
 \r
index 4ab644f..6e00564 100644 (file)
@@ -36,8 +36,8 @@ cd o2
 \r
 mkdir -p temp\r
 cd temp\r
-git clone https://opendev.org/starlingx/config.git\r
-git clone https://opendev.org/starlingx/distcloud-client.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/config.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git\r
 cd -\r
 \r
 docker-compose build\r
index 1612e8e..0782690 100644 (file)
--- a/README.md
+++ b/README.md
@@ -6,8 +6,8 @@ cloned into temp before docker building
 ```sh\r
 mkdir -p temp\r
 cd temp\r
-git clone https://opendev.org/starlingx/config.git\r
-git clone https://opendev.org/starlingx/distcloud-client.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/config.git\r
+git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git\r
 cd -\r
 ```\r
 \r
index 8a9b0cc..b7ad799 100644 (file)
@@ -31,6 +31,15 @@ from o2ims.adapter.clients.ocloud_sa_client import StxPserverClient
 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.pserver_mem_watcher import PServerMemWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxMemClient\r
+\r
+from o2ims.service.watcher.pserver_if_watcher import PServerIfWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxIfClient\r
+\r
+from o2ims.service.watcher.pserver_port_watcher import PServerPortWatcher\r
+from o2ims.adapter.clients.ocloud_sa_client import StxPortClient\r
+\r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
 \r
@@ -58,6 +67,12 @@ class WatcherService(cotyledon.Service):
                 PServerWatcher(StxPserverClient(), self.bus))\r
             child_pserver.addchild(\r
                 PServerCpuWatcher(StxCpuClient(), self.bus))\r
+            child_pserver.addchild(\r
+                PServerMemWatcher(StxMemClient(), self.bus))\r
+            child_pserver.addchild(\r
+                PServerIfWatcher(StxIfClient(), self.bus))\r
+            child_pserver.addchild(\r
+                PServerPortWatcher(StxPortClient(), self.bus))\r
 \r
             self.worker.add_watcher(root)\r
 \r
index 830e1ff..f3b3d6d 100644 (file)
 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
+from o2ims.service.auditor import ocloud_handler, dms_handler, \
+    resourcepool_handler, pserver_handler, pserver_cpu_handler, \
+    pserver_mem_handler, pserver_port_handler, pserver_if_handler
 
 # if TYPE_CHECKING:
 #     from . import unit_of_work
@@ -35,5 +36,11 @@ EVENT_HANDLERS = {
 
 COMMAND_HANDLERS = {
     commands.UpdateOCloud: ocloud_handler.update_ocloud,
-    commands.UpdateDms: dms_handler.update_dms
+    commands.UpdateDms: dms_handler.update_dms,
+    commands.UpdateResourcePool: resourcepool_handler.update_resourcepool,
+    commands.UpdatePserver: pserver_handler.update_pserver,
+    commands.UpdatePserverCpu: pserver_cpu_handler.update_pserver_cpu,
+    commands.UpdatePserverMem: pserver_mem_handler.update_pserver_mem,
+    commands.UpdatePserverIf: pserver_if_handler.update_pserver_if,
+    commands.UpdatePserverPort: pserver_port_handler.update_pserver_port,
 }  # type: Dict[Type[commands.Command], Callable]
index 8a673da..dfd4b25 100644 (file)
@@ -20,7 +20,7 @@ from .events import Event
 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
+        # self.id = ""\r
index e8f1685..31c9069 100644 (file)
@@ -89,9 +89,47 @@ class StxCpuClient(BaseClient):
     def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
         return self.driver.getCpuList(**filters)\r
 \r
-# internal driver which implement client call to Stx Standalone instance\r
+\r
+class StxMemClient(BaseClient):\r
+    def __init__(self):\r
+        super().__init__()\r
+        # self._pserver_id = pserver_id\r
+        self.driver = StxSaClientImp()\r
+\r
+    def _get(self, id) -> ocloudModel.StxGenericModel:\r
+        return self.driver.getMem(id)\r
+\r
+    def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        return self.driver.getMemList(**filters)\r
+\r
+\r
+class StxPortClient(BaseClient):\r
+    def __init__(self):\r
+        super().__init__()\r
+        # self._pserver_id = pserver_id\r
+        self.driver = StxSaClientImp()\r
+\r
+    def _get(self, id) -> ocloudModel.StxGenericModel:\r
+        return self.driver.getPort(id)\r
+\r
+    def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        return self.driver.getPortList(**filters)\r
+\r
+\r
+class StxIfClient(BaseClient):\r
+    def __init__(self):\r
+        super().__init__()\r
+        # self._pserver_id = pserver_id\r
+        self.driver = StxSaClientImp()\r
+\r
+    def _get(self, id) -> ocloudModel.StxGenericModel:\r
+        return self.driver.getIf(id)\r
+\r
+    def _list(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        return self.driver.getIfList(**filters)\r
 \r
 \r
+# internal driver which implement client call to Stx Standalone instance\r
 class StxSaClientImp(object):\r
     def __init__(self, stx_client=None):\r
         super().__init__()\r
@@ -114,7 +152,7 @@ class StxSaClientImp(object):
         logger.debug("host 1:" + str(hosts[0].to_dict()))\r
         return [ocloudModel.StxGenericModel(\r
             ResourceTypeEnum.PSERVER, self._hostconverter(host))\r
-                for host in hosts if host]\r
+            for host in hosts if host]\r
 \r
     def getPserver(self, id) -> ocloudModel.StxGenericModel:\r
         host = self.stxclient.ihost.get(id)\r
@@ -158,6 +196,45 @@ class StxSaClientImp(object):
         return ocloudModel.StxGenericModel(\r
             ResourceTypeEnum.PSERVER_CPU, self._cpuconverter(cpuinfo))\r
 \r
+    def getMemList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        hostid = filters.get("hostid", None)\r
+        assert (hostid is not None), "missing hostid to query imem list"\r
+        memlist = self.stxclient.imemory.list(hostid)\r
+        return [ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_RAM,\r
+            self._memconverter(memories)) for memories in memlist if memories]\r
+\r
+    def getMem(self, id) -> ocloudModel.StxGenericModel:\r
+        meminfo = self.stxclient.imemory.get(id)\r
+        return ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_RAM, self._memconverter(meminfo))\r
+\r
+    def getPortList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        hostid = filters.get("hostid", None)\r
+        assert (hostid is not None), "missing hostid to query port list"\r
+        portlist = self.stxclient.port.list(hostid)\r
+        return [ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_PORT,\r
+            port) for port in portlist if port]\r
+\r
+    def getPort(self, id) -> ocloudModel.StxGenericModel:\r
+        portinfo = self.stxclient.port.get(id)\r
+        return ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_PORT, portinfo)\r
+\r
+    def getIfList(self, **filters) -> List[ocloudModel.StxGenericModel]:\r
+        hostid = filters.get("hostid", None)\r
+        assert (hostid is not None), "missing hostid to query iinterface list"\r
+        iflist = self.stxclient.iinterface.list(hostid)\r
+        return [ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_IF,\r
+            self._ifconverter(ifs)) for ifs in iflist if ifs]\r
+\r
+    def getIf(self, id) -> ocloudModel.StxGenericModel:\r
+        ifinfo = self.stxclient.iinterface.get(id)\r
+        return ocloudModel.StxGenericModel(\r
+            ResourceTypeEnum.PSERVER_IF, self._ifconverter(ifinfo))\r
+\r
     def _getIsystems(self):\r
         return self.stxclient.isystem.list()\r
 \r
@@ -171,28 +248,41 @@ class StxSaClientImp(object):
                                 'more than one system exists in the account.')\r
             return isystems[0]\r
 \r
-    @staticmethod\r
+    @ staticmethod\r
     def _hostconverter(host):\r
         setattr(host, "name", host.hostname)\r
         return host\r
 \r
-    @staticmethod\r
+    @ staticmethod\r
     def _cpuconverter(cpu):\r
-        setattr(cpu, "name", "core-"+str(cpu.core))\r
+        setattr(cpu, "name", "cpu-"+str(cpu.cpu))\r
         return cpu\r
 \r
-    @staticmethod\r
+    @ staticmethod\r
+    def _memconverter(mem):\r
+        setattr(mem, "name", "mem-node-"+str(mem.numa_node))\r
+        return mem\r
+\r
+    @ staticmethod\r
+    def _ifconverter(ifs):\r
+        setattr(ifs, "name", ifs.ifname)\r
+        setattr(ifs, 'updated_at', None)\r
+        setattr(ifs, 'created_at', None)\r
+        return ifs\r
+\r
+    @ staticmethod\r
     def _k8sconverter(cluster):\r
         setattr(cluster, "name", cluster.cluster_name)\r
         setattr(cluster, "uuid",\r
                 uuid.uuid3(uuid.NAMESPACE_URL, cluster.cluster_name))\r
         setattr(cluster, 'updated_at', None)\r
         setattr(cluster, 'created_at', None)\r
+        setattr(cluster, 'events', [])\r
         logger.debug("k8s cluster name/uuid:" +\r
                      cluster.name + "/" + str(cluster.uuid))\r
         return cluster\r
 \r
-    @staticmethod\r
+    @ staticmethod\r
     def _k8shasher(cluster):\r
         return str(hash((cluster.cluster_name,\r
                          cluster.cluster_api_endpoint, cluster.admin_user)))\r
index 0826cf0..bc3557d 100644 (file)
@@ -18,6 +18,8 @@ from o2ims.domain import ocloud
 from o2ims.domain.ocloud_repo import OcloudRepository, ResourceTypeRepository,\
     ResourcePoolRepository, ResourceRepository, DeploymentManagerRepository,\
     SubscriptionRepository
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
 
 
 class OcloudSqlAlchemyRepository(OcloudRepository):
index 7aafde5..05a8dc7 100644 (file)
 #  See the License for the specific language governing permissions and\r
 #  limitations under the License.\r
 \r
+# from typing_extensions import Required\r
 from sqlalchemy import (\r
     Table,\r
     MetaData,\r
     Column,\r
     Integer,\r
     String,\r
+    Text,\r
+    Enum,\r
     # Date,\r
     DateTime,\r
     ForeignKey,\r
@@ -29,6 +32,7 @@ from sqlalchemy.orm import mapper, relationship
 # from sqlalchemy.sql.sqltypes import Integer\r
 \r
 from o2ims.domain import ocloud as ocloudModel\r
+from o2ims.domain.resource_type import ResourceTypeEnum\r
 \r
 from o2common.helper import o2logging\r
 logger = o2logging.get_logger(__name__)\r
@@ -59,6 +63,7 @@ resourcetype = Table(
     Column("hash", String(255)),\r
 \r
     Column("resourceTypeId", String(255), primary_key=True),\r
+    Column("resourceTypeEnum", Enum(ResourceTypeEnum), nullable=False),\r
     Column("oCloudId", ForeignKey("ocloud.oCloudId")),\r
     Column("name", String(255)),\r
     Column("vendor", String(255)),\r
@@ -98,10 +103,9 @@ resource = Table(
     Column("resourceTypeId", ForeignKey("resourcetype.resourceTypeId")),\r
     Column("resourcePoolId", ForeignKey("resourcepool.resourcePoolId")),\r
     # Column("globalAssetId", String(255)),\r
-    # Column("oCloudId", ForeignKey("ocloud.oCloudId")),\r
     Column("parentId", String(255)),\r
     Column("description", String(255)),\r
-    # Column("elements", String(255))\r
+    Column("elements", Text())\r
     # Column("extensions", String(1024))\r
 )\r
 \r
index 1a31f0e..8cd8243 100644 (file)
@@ -42,16 +42,36 @@ class UpdateResourcePool(UpdateStxObject):
     parentid: str
 
 
+@dataclass
+class UpdateResourceType(UpdateStxObject):
+    parentid: str
+
+
 @dataclass
 class UpdateResource(UpdateStxObject):
     parentid: str
 
 
+@dataclass
+class UpdatePserver(UpdateResource):
+    pass
+
+
 @dataclass
 class UpdatePserverCpu(UpdateResource):
     pass
 
 
 @dataclass
-class UpdatePserver(UpdateResource):
+class UpdatePserverMem(UpdateResource):
+    pass
+
+
+@dataclass
+class UpdatePserverIf(UpdateResource):
+    pass
+
+
+@dataclass
+class UpdatePserverPort(UpdateResource):
     pass
index c97c688..7ab04a0 100644 (file)
@@ -20,3 +20,8 @@ from o2common.domain.events import Event
 @dataclass
 class OcloudUpdated(Event):
     oCloudId: str
+
+
+@dataclass
+class ResourceTypeUpdated(Event):
+    oCloudId: str
index 0829fb9..ec41c0e 100644 (file)
@@ -73,8 +73,9 @@ class ResourceType(AgRoot):
                  description: str = '') -> None:\r
         super().__init__()\r
         self.resourceTypeId = typeid\r
+        self.version_number = 0\r
         self.oCloudId = ocloudid\r
-        self.resourceTypeEnum = typeEnum.value\r
+        self.resourceTypeEnum = typeEnum\r
         self.name = name\r
         self.vender = vender\r
         self.model = model\r
@@ -85,17 +86,16 @@ class ResourceType(AgRoot):
 \r
 class Resource(AgRoot):\r
     def __init__(self, resourceId: str, resourceTypeId: str,\r
-                 resourcePoolId: str, oCloudId: str = '',\r
-                 parentId: str = '', elements: list = [],\r
+                 resourcePoolId: str, parentId: str = '',\r
+                 gAssetId: str = '', elements: str = '',\r
                  description: str = '') -> None:\r
         super().__init__()\r
         self.resourceId = resourceId\r
         self.version_number = 0\r
-        self.oCloudId = oCloudId\r
         self.resourceTypeId = resourceTypeId\r
         self.resourcePoolId = resourcePoolId\r
+        self.globalAssetId = gAssetId\r
         self.parentId = parentId\r
-        self.path = str()\r
         self.elements = elements\r
         self.description = description\r
         self.extensions = []\r
@@ -116,7 +116,6 @@ class Ocloud(AgRoot):
         self.deploymentManagers = []\r
         self.resourceTypes = []\r
         self.extensions = []\r
-        # self.events = []\r
 \r
     # def addDeploymentManager(self,\r
     #                          deploymentManager: DeploymentManager):\r
index 79b36fd..f94e688 100644 (file)
@@ -2,12 +2,14 @@ from enum import Enum
 \r
 \r
 class ResourceTypeEnum(Enum):\r
-    OCLOUD = 1,\r
-    RESOURCE_POOL = 2,\r
-    DMS = 3,\r
+    OCLOUD = 1\r
+    RESOURCE_POOL = 2\r
+    DMS = 3\r
     PSERVER = 11\r
     PSERVER_CPU = 12\r
     PSERVER_RAM = 13\r
+    PSERVER_PORT = 14\r
+    PSERVER_IF = 15\r
 \r
 \r
 class InvalidOcloudState(Exception):\r
index 5e4d660..be668b6 100644 (file)
@@ -25,6 +25,7 @@ logger = o2logging.get_logger(__name__)
 class StxGenericModel(AgRoot):\r
     def __init__(self, type: ResourceTypeEnum,\r
                  api_response: dict = None, content_hash=None) -> None:\r
+        super().__init__()\r
         if api_response:\r
             self.id = str(api_response.uuid)\r
             self.type = type\r
index c3d4a77..9ef0a77 100644 (file)
@@ -77,7 +77,7 @@ def is_outdated(ocloud: DeploymentManager, stxobj: StxGenericModel):
 
 def create_by(stxobj: StxGenericModel, parentid: str) -> DeploymentManager:
     dmsendpoint = config.get_api_url() +\
-                  config.get_o2dms_api_base() + "/" + stxobj.id
+        config.get_o2dms_api_base() + "/" + stxobj.id
     description = "A DMS"
     ocloudid = parentid
     supportedLocations = ''
@@ -104,3 +104,4 @@ def update_by(target: DeploymentManager, stxobj: StxGenericModel,
     target.hash = stxobj.hash
     target.oCloudId = parentid
     target.version_number = target.version_number + 1
+    target.events = []
index 554b2e1..c8c1e1b 100644 (file)
@@ -99,3 +99,4 @@ def update_by(ocloud: Ocloud, stxobj: StxGenericModel) -> None:
     # ocloud.content = stxobj.content
     ocloud.hash = stxobj.hash
     ocloud.version_number = ocloud.version_number + 1
+    ocloud.events = []
diff --git a/o2ims/service/auditor/pserver_cpu_handler.py b/o2ims/service/auditor/pserver_cpu_handler.py
new file mode 100644 (file)
index 0000000..d447057
--- /dev/null
@@ -0,0 +1,116 @@
+# 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
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_pserver_cpu(
+    cmd: commands.UpdatePserverCpu,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        p_resource = uow.resources.get(cmd.parentid)
+        resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+        res = uow.session.execute(
+            '''
+            SELECT "resourceTypeId", "oCloudId", "name"
+            FROM resourcetype
+            WHERE "resourceTypeEnum" = :resource_type_enum
+            ''',
+            dict(resource_type_enum=stxobj.type.name)
+        )
+        first = res.first()
+        if first is None:
+            resourcetype_id = str(uuid.uuid4())
+            uow.resource_types.add(ResourceType(
+                resourcetype_id,
+                'pserver_cpu', stxobj.type,
+                resourcepool.oCloudId))
+        else:
+            resourcetype_id = first['resourceTypeId']
+
+        resource = uow.resources.get(stxobj.id)
+        if not resource:
+            logger.info("add the cpu of pserver:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, p_resource, resourcetype_id)
+            uow.resources.add(localmodel)
+
+            logger.info("Add the cpu of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource
+            if is_outdated(localmodel, stxobj):
+                logger.info("update cpu of pserver:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, p_resource)
+                uow.resources.update(localmodel)
+
+            logger.info("Update the cpu of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+    return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+        -> Resource:
+    # content = json.loads(stxobj.content)
+    resourcetype_id = resourcetype_id
+    resourcepool_id = parent.resourcePoolId
+    parent_id = parent.resourceId
+    gAssetId = ''  # TODO: global ID
+    description = "A CPU resource of the physical server"
+    resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+                        parent_id, gAssetId, stxobj.content, description)
+    resource.createtime = stxobj.createtime
+    resource.updatetime = stxobj.updatetime
+    resource.hash = stxobj.hash
+
+    return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourceId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.version_number = target.version_number + 1
+    target.events = []
diff --git a/o2ims/service/auditor/pserver_handler.py b/o2ims/service/auditor/pserver_handler.py
new file mode 100644 (file)
index 0000000..f5f526a
--- /dev/null
@@ -0,0 +1,117 @@
+# 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
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_pserver(
+    cmd: commands.UpdatePserver,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        resourcepool = uow.resource_pools.get(cmd.parentid)
+
+        # res = uow.session.execute(select(resourcetype).where(
+        #     resourcetype.c.resourceTypeEnum == stxobj.type))
+        res = uow.session.execute(
+            '''
+            SELECT "resourceTypeId", "oCloudId", "name"
+            FROM resourcetype
+            WHERE "resourceTypeEnum" = :resource_type_enum
+            ''',
+            dict(resource_type_enum=stxobj.type.name)
+        )
+        first = res.first()
+        if first is None:
+            resourcetype_id = str(uuid.uuid4())
+            uow.resource_types.add(ResourceType(
+                resourcetype_id,
+                'pserver', stxobj.type,
+                resourcepool.oCloudId))
+        else:
+            resourcetype_id = first['resourceTypeId']
+
+        resource = uow.resources.get(stxobj.id)
+        if not resource:
+            logger.info("add pserver:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, cmd.parentid, resourcetype_id)
+            uow.resources.add(localmodel)
+
+            logger.info("Add the pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource
+            if is_outdated(localmodel, stxobj):
+                logger.info("update pserver:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, cmd.parentid)
+                uow.resources.update(localmodel)
+
+            logger.info("Update the pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+    return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parentid: str, resourcetype_id: str) \
+        -> Resource:
+    # content = json.loads(stxobj.content)
+    resourcetype_id = resourcetype_id
+    resourcepool_id = parentid
+    parent_id = parentid
+    gAssetId = ''  # TODO: global ID
+    description = "A physical server resource"
+    resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+                        parent_id, gAssetId, stxobj.content, description)
+    resource.createtime = stxobj.createtime
+    resource.updatetime = stxobj.updatetime
+    resource.hash = stxobj.hash
+
+    return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourceId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.version_number = target.version_number + 1
+    target.events = []
diff --git a/o2ims/service/auditor/pserver_if_handler.py b/o2ims/service/auditor/pserver_if_handler.py
new file mode 100644 (file)
index 0000000..174f709
--- /dev/null
@@ -0,0 +1,116 @@
+# 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
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_pserver_if(
+    cmd: commands.UpdatePserverIf,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        p_resource = uow.resources.get(cmd.parentid)
+        resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+        res = uow.session.execute(
+            '''
+            SELECT "resourceTypeId", "oCloudId", "name"
+            FROM resourcetype
+            WHERE "resourceTypeEnum" = :resource_type_enum
+            ''',
+            dict(resource_type_enum=stxobj.type.name)
+        )
+        first = res.first()
+        if first is None:
+            resourcetype_id = str(uuid.uuid4())
+            uow.resource_types.add(ResourceType(
+                resourcetype_id,
+                'pserver_if', stxobj.type,
+                resourcepool.oCloudId))
+        else:
+            resourcetype_id = first['resourceTypeId']
+
+        resource = uow.resources.get(stxobj.id)
+        if not resource:
+            logger.info("add the interface of pserver:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, p_resource, resourcetype_id)
+            uow.resources.add(localmodel)
+
+            logger.info("Add the interface of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource
+            if is_outdated(localmodel, stxobj):
+                logger.info("update interface of pserver:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, p_resource)
+                uow.resources.update(localmodel)
+
+            logger.info("Update the interface of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+    return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+        -> Resource:
+    # content = json.loads(stxobj.content)
+    resourcetype_id = resourcetype_id
+    resourcepool_id = parent.resourcePoolId
+    parent_id = parent.resourceId
+    gAssetId = ''  # TODO: global ID
+    description = "A interface resource of the physical server"
+    resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+                        parent_id, gAssetId, stxobj.content, description)
+    resource.createtime = stxobj.createtime
+    resource.updatetime = stxobj.updatetime
+    resource.hash = stxobj.hash
+
+    return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourceId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.version_number = target.version_number + 1
+    target.events = []
diff --git a/o2ims/service/auditor/pserver_mem_handler.py b/o2ims/service/auditor/pserver_mem_handler.py
new file mode 100644 (file)
index 0000000..42bccb7
--- /dev/null
@@ -0,0 +1,116 @@
+# 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
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_pserver_mem(
+    cmd: commands.UpdatePserverMem,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        p_resource = uow.resources.get(cmd.parentid)
+        resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+        res = uow.session.execute(
+            '''
+            SELECT "resourceTypeId", "oCloudId", "name"
+            FROM resourcetype
+            WHERE "resourceTypeEnum" = :resource_type_enum
+            ''',
+            dict(resource_type_enum=stxobj.type.name)
+        )
+        first = res.first()
+        if first is None:
+            resourcetype_id = str(uuid.uuid4())
+            uow.resource_types.add(ResourceType(
+                resourcetype_id,
+                'pserver_mem', stxobj.type,
+                resourcepool.oCloudId))
+        else:
+            resourcetype_id = first['resourceTypeId']
+
+        resource = uow.resources.get(stxobj.id)
+        if not resource:
+            logger.info("add the memory of pserver:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, p_resource, resourcetype_id)
+            uow.resources.add(localmodel)
+
+            logger.info("Add the memory of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource
+            if is_outdated(localmodel, stxobj):
+                logger.info("update memory of pserver:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, p_resource)
+                uow.resources.update(localmodel)
+
+            logger.info("Update the memory of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+    return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+        -> Resource:
+    # content = json.loads(stxobj.content)
+    resourcetype_id = resourcetype_id
+    resourcepool_id = parent.resourcePoolId
+    parent_id = parent.resourceId
+    gAssetId = ''  # TODO: global ID
+    description = "A memory resource of the physical server"
+    resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+                        parent_id, gAssetId, stxobj.content, description)
+    resource.createtime = stxobj.createtime
+    resource.updatetime = stxobj.updatetime
+    resource.hash = stxobj.hash
+
+    return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourceId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.version_number = target.version_number + 1
+    target.events = []
diff --git a/o2ims/service/auditor/pserver_port_handler.py b/o2ims/service/auditor/pserver_port_handler.py
new file mode 100644 (file)
index 0000000..df62f14
--- /dev/null
@@ -0,0 +1,116 @@
+# 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
+import uuid
+# import json
+
+from o2ims.domain import commands
+from o2ims.domain.stx_object import StxGenericModel
+from o2common.service.unit_of_work import AbstractUnitOfWork
+from o2ims.domain.resource_type import MismatchedModel
+from o2ims.domain.ocloud import Resource, ResourceType
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_pserver_port(
+    cmd: commands.UpdatePserverPort,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        p_resource = uow.resources.get(cmd.parentid)
+        resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
+
+        res = uow.session.execute(
+            '''
+            SELECT "resourceTypeId", "oCloudId", "name"
+            FROM resourcetype
+            WHERE "resourceTypeEnum" = :resource_type_enum
+            ''',
+            dict(resource_type_enum=stxobj.type.name)
+        )
+        first = res.first()
+        if first is None:
+            resourcetype_id = str(uuid.uuid4())
+            uow.resource_types.add(ResourceType(
+                resourcetype_id,
+                'pserver_port', stxobj.type,
+                resourcepool.oCloudId))
+        else:
+            resourcetype_id = first['resourceTypeId']
+
+        resource = uow.resources.get(stxobj.id)
+        if not resource:
+            logger.info("add the port of pserver:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, p_resource, resourcetype_id)
+            uow.resources.add(localmodel)
+
+            logger.info("Add the port of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource
+            if is_outdated(localmodel, stxobj):
+                logger.info("update port of pserver:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, p_resource)
+                uow.resources.update(localmodel)
+
+            logger.info("Update the port of pserver: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resource: Resource, stxobj: StxGenericModel):
+    return True if resource.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parent: Resource, resourcetype_id: str)\
+        -> Resource:
+    # content = json.loads(stxobj.content)
+    resourcetype_id = resourcetype_id
+    resourcepool_id = parent.resourcePoolId
+    parent_id = parent.resourceId
+    gAssetId = ''  # TODO: global ID
+    description = "A port resource of the physical server"
+    resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
+                        parent_id, gAssetId, stxobj.content, description)
+    resource.createtime = stxobj.createtime
+    resource.updatetime = stxobj.updatetime
+    resource.hash = stxobj.hash
+
+    return resource
+
+
+def update_by(target: Resource, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourceId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.version_number = target.version_number + 1
+    target.events = []
diff --git a/o2ims/service/auditor/resourcepool_handler.py b/o2ims/service/auditor/resourcepool_handler.py
new file mode 100644 (file)
index 0000000..88cf182
--- /dev/null
@@ -0,0 +1,101 @@
+# 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
+import json
+
+from o2ims.domain.stx_object import StxGenericModel
+# from dataclasses import asdict
+# from typing import List, Dict, Callable, Type
+# TYPE_CHECKING
+from o2ims.domain import commands
+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 ResourcePool
+# if TYPE_CHECKING:
+#     from . import unit_of_work
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class InvalidResourceType(Exception):
+    pass
+
+
+def update_resourcepool(
+    cmd: commands.UpdateResourcePool,
+    uow: AbstractUnitOfWork
+):
+    stxobj = cmd.data
+    with uow:
+        resource_pool = uow.resource_pools.get(stxobj.id)
+        if not resource_pool:
+            logger.info("add resource pool:" + stxobj.name
+                        + " update_at: " + str(stxobj.updatetime)
+                        + " id: " + str(stxobj.id)
+                        + " hash: " + str(stxobj.hash))
+            localmodel = create_by(stxobj, cmd.parentid)
+            uow.resource_pools.add(localmodel)
+
+            logger.info("Add the resource pool: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        else:
+            localmodel = resource_pool
+            if is_outdated(localmodel, stxobj):
+                logger.info("update resource pool:" + stxobj.name
+                            + " update_at: " + str(stxobj.updatetime)
+                            + " id: " + str(stxobj.id)
+                            + " hash: " + str(stxobj.hash))
+                update_by(localmodel, stxobj, cmd.parentid)
+                uow.resource_pools.update(localmodel)
+
+            logger.info("Update the resource pool: " + stxobj.id
+                        + ", name: " + stxobj.name)
+        uow.commit()
+
+
+def is_outdated(resourcepool: ResourcePool, stxobj: StxGenericModel):
+    return True if resourcepool.hash != stxobj.hash else False
+
+
+def create_by(stxobj: StxGenericModel, parentid: str) -> ResourcePool:
+    content = json.loads(stxobj.content)
+    globalcloudId = stxobj.id  # to be updated
+    description = "A Resource Pool"
+    resourcepool = ResourcePool(stxobj.id, stxobj.name,
+                                content['location'],
+                                parentid, globalcloudId, description)
+    resourcepool.createtime = stxobj.createtime
+    resourcepool.updatetime = stxobj.updatetime
+    resourcepool.hash = stxobj.hash
+
+    return resourcepool
+
+
+def update_by(target: ResourcePool, stxobj: StxGenericModel,
+              parentid: str) -> None:
+    if target.resourcePoolId != stxobj.id:
+        raise MismatchedModel("Mismatched Id")
+    content = json.loads(stxobj.content)
+    target.name = stxobj.name
+    target.location = content['location']
+    target.createtime = stxobj.createtime
+    target.updatetime = stxobj.updatetime
+    target.hash = stxobj.hash
+    target.oCloudId = parentid
+    target.version_number = target.version_number + 1
+    target.events = []
index cf471a4..51a5a76 100644 (file)
@@ -34,8 +34,5 @@ class PServerCpuWatcher(ResourceWatcher):
     def _probe(self, parent: StxGenericModel):\r
         hostid = parent.id\r
         newmodels = self._client.list(hostid=hostid)\r
-        # for newmodel in newmodels:\r
-        #     super()._compare_and_update(newmodel)\r
-        # return newmodels\r
         return [commands.UpdatePserverCpu(data=m, parentid=hostid)\r
                 for m in newmodels]\r
diff --git a/o2ims/service/watcher/pserver_if_watcher.py b/o2ims/service/watcher/pserver_if_watcher.py
new file mode 100644 (file)
index 0000000..8bdde89
--- /dev/null
@@ -0,0 +1,38 @@
+# 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 o2ims.domain.stx_object import StxGenericModel\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 o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerIfWatcher(ResourceWatcher):\r
+    def __init__(self, client: BaseClient,\r
+                 bus: MessageBus) -> None:\r
+        super().__init__(client, bus)\r
+\r
+    def _targetname(self):\r
+        return "pserver_if"\r
+\r
+    def _probe(self, parent: StxGenericModel):\r
+        hostid = parent.id\r
+        newmodels = self._client.list(hostid=hostid)\r
+        return [commands.UpdatePserverIf(data=m, parentid=hostid)\r
+                for m in newmodels]\r
diff --git a/o2ims/service/watcher/pserver_mem_watcher.py b/o2ims/service/watcher/pserver_mem_watcher.py
new file mode 100644 (file)
index 0000000..ddeb3ef
--- /dev/null
@@ -0,0 +1,38 @@
+# 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 o2ims.domain.stx_object import StxGenericModel\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 o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerMemWatcher(ResourceWatcher):\r
+    def __init__(self, client: BaseClient,\r
+                 bus: MessageBus) -> None:\r
+        super().__init__(client, bus)\r
+\r
+    def _targetname(self):\r
+        return "pserver_mem"\r
+\r
+    def _probe(self, parent: StxGenericModel):\r
+        hostid = parent.id\r
+        newmodels = self._client.list(hostid=hostid)\r
+        return [commands.UpdatePserverMem(data=m, parentid=hostid)\r
+                for m in newmodels]\r
diff --git a/o2ims/service/watcher/pserver_port_watcher.py b/o2ims/service/watcher/pserver_port_watcher.py
new file mode 100644 (file)
index 0000000..9ab6c7d
--- /dev/null
@@ -0,0 +1,38 @@
+# 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 o2ims.domain.stx_object import StxGenericModel\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 o2common.service.messagebus import MessageBus\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+class PServerPortWatcher(ResourceWatcher):\r
+    def __init__(self, client: BaseClient,\r
+                 bus: MessageBus) -> None:\r
+        super().__init__(client, bus)\r
+\r
+    def _targetname(self):\r
+        return "pserver_port"\r
+\r
+    def _probe(self, parent: StxGenericModel):\r
+        hostid = parent.id\r
+        newmodels = self._client.list(hostid=hostid)\r
+        return [commands.UpdatePserverPort(data=m, parentid=hostid)\r
+                for m in newmodels]\r
index ca3e898..8222cc3 100644 (file)
@@ -34,5 +34,5 @@ class PServerWatcher(ResourceWatcher):
     def _probe(self, parent: StxGenericModel):\r
         resourcepoolid = parent.id\r
         newmodels = self._client.list(resourcepoolid=resourcepoolid)\r
-        return [commands.UpdatePserverCpu(data=m, parentid=resourcepoolid)\r
+        return [commands.UpdatePserver(data=m, parentid=resourcepoolid)\r
                 for m in newmodels]\r
index bb4e63f..6d5e8e3 100644 (file)
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-import uuid
 from flask_restx import Resource
 
 from o2ims.views import ocloud_view, api_ims_inventory_v1
 from o2common.config import config
-from o2ims.domain.ocloud import Subscription
 from o2ims.views.ocloud_dto import OcloudDTO, ResourceTypeDTO,\
     ResourcePoolDTO, ResourceDTO, DeploymentManagerDTO, SubscriptionDTO
 
@@ -180,12 +178,8 @@ class SubscriptionsListRouter(Resource):
     @api_ims_inventory_v1.marshal_with(post_resp, code=201)
     def post(self):
         data = api_ims_inventory_v1.payload
-        sub_uuid = str(uuid.uuid4())
-        subscription = Subscription(
-            sub_uuid, data['callback'], data['consumerSubscriptionId'],
-            data['filter'])
-        ocloud_view.subscription_create(subscription, bus.uow)
-        return {"subscriptionId": sub_uuid}, 201
+        result = ocloud_view.subscription_create(data, bus.uow)
+        return result, 201
 
 
 @api_ims_inventory_v1.route("/subscriptions/<subscriptionID>")
@@ -208,10 +202,8 @@ class SubscriptionGetDelRouter(Resource):
     @api_ims_inventory_v1.doc('Delete subscription by ID')
     @api_ims_inventory_v1.response(204, 'Subscription deleted')
     def delete(self, subscriptionID):
-        with bus.uow:
-            bus.uow.subscriptions.delete(subscriptionID)
-            bus.uow.commit()
-        return '', 204
+        result = ocloud_view.subscription_delete(subscriptionID, bus.uow)
+        return result, 204
 
 
 def configure_namespace(app, bus_new):
index 9a1a595..9404d9a 100644 (file)
 #  See the License for the specific language governing permissions and\r
 #  limitations under the License.\r
 \r
+import uuid\r
 from sqlalchemy import select\r
 \r
 from o2ims.adapter.orm import ocloud, resource, resourcetype, \\r
     resourcepool, deploymentmanager, subscription\r
 from o2common.service import unit_of_work\r
+from o2ims.views.ocloud_dto import SubscriptionDTO\r
 from o2ims.domain.ocloud import Subscription\r
 \r
 \r
@@ -115,11 +117,18 @@ def subscription_one(subscriptionId: str,
     return None if first is None else dict(first)\r
 \r
 \r
-def subscription_create(subscription: Subscription,\r
+def subscription_create(subscriptionDto: SubscriptionDTO.subscription,\r
                         uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+    sub_uuid = str(uuid.uuid4())\r
+    subscription = Subscription(\r
+        sub_uuid, subscriptionDto['callback'],\r
+        subscriptionDto['consumerSubscriptionId'],\r
+        subscriptionDto['filter'])\r
     with uow:\r
         uow.subscriptions.add(subscription)\r
         uow.commit()\r
+    return {"subscriptionId": sub_uuid}\r
 \r
 \r
 def subscription_delete(subscriptionId: str,\r
index 7ece56b..5423953 100644 (file)
 #  See the License for the specific language governing permissions and\r
 #  limitations under the License.\r
 \r
-import sys\r
+# import sys\r
+# import logging\r
 import pytest\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
-import logging\r
-\r
 \r
 @pytest.fixture\r
 def real_stx_aio_client():\r
@@ -32,7 +31,7 @@ def real_stx_aio_client():
 \r
 \r
 def test_get_instanceinfo(real_stx_aio_client):\r
-    logger = logging.getLogger(__name__)\r
+    logger = logging.getLogger(__name__)\r
     stxclientimp = StxSaClientImp(real_stx_aio_client)\r
     assert stxclientimp is not None\r
     systeminfo = stxclientimp.getInstanceInfo()\r
@@ -61,6 +60,7 @@ def test_get_pserver(real_stx_aio_client):
     assert host1 != host2\r
     assert host1.id == host2.id\r
 \r
+\r
 def test_get_k8s_list(real_stx_aio_client):\r
     stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
     assert stxSaClientImp is not None\r
@@ -73,6 +73,7 @@ def test_get_k8s_list(real_stx_aio_client):
     assert k8s1.name == k8s2.name\r
     assert k8s1.id == k8s2.id\r
 \r
+\r
 def test_get_cpu_list(real_stx_aio_client):\r
     stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
     assert stxSaClientImp is not None\r
@@ -85,3 +86,45 @@ def test_get_cpu_list(real_stx_aio_client):
     cpu2 = stxSaClientImp.getCpu(cpu1.id)\r
     assert cpu1 != cpu2\r
     assert cpu1.id == cpu2.id\r
+\r
+\r
+def test_get_mem_list(real_stx_aio_client):\r
+    stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+    assert stxSaClientImp is not None\r
+    hostlist = stxSaClientImp.getPserverList()\r
+    assert len(hostlist) > 0\r
+\r
+    memlist = stxSaClientImp.getMemList(hostid=hostlist[0].id)\r
+    assert len(memlist) > 0\r
+    mem1 = memlist[0]\r
+    mem2 = stxSaClientImp.getMem(mem1.id)\r
+    assert mem1 != mem2\r
+    assert mem1.id == mem2.id\r
+\r
+\r
+def test_get_if_list(real_stx_aio_client):\r
+    stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+    assert stxSaClientImp is not None\r
+    hostlist = stxSaClientImp.getPserverList()\r
+    assert len(hostlist) > 0\r
+\r
+    iflist = stxSaClientImp.getIfList(hostid=hostlist[0].id)\r
+    assert len(iflist) > 0\r
+    if1 = iflist[0]\r
+    if2 = stxSaClientImp.getIf(if1.id)\r
+    assert if1 != if2\r
+    assert if1.id == if2.id\r
+\r
+\r
+def test_get_port_list(real_stx_aio_client):\r
+    stxSaClientImp = StxSaClientImp(real_stx_aio_client)\r
+    assert stxSaClientImp is not None\r
+    hostlist = stxSaClientImp.getPserverList()\r
+    assert len(hostlist) > 0\r
+\r
+    portlist = stxSaClientImp.getPortList(hostid=hostlist[0].id)\r
+    assert len(portlist) > 0\r
+    port1 = portlist[0]\r
+    port2 = stxSaClientImp.getPort(port1.id)\r
+    assert port1 != port2\r
+    assert port1.id == port2.id\r
index 8c1afac..c4b134d 100644 (file)
@@ -77,7 +77,6 @@ class FakeOcloudRepo(OcloudRepository):
         ocloud1.update_by(ocloud)\r
 \r
 \r
-\r
 class FakeStxObjRepo(StxObjectRepository):\r
     def __init__(self):\r
         super().__init__()\r
@@ -129,8 +128,8 @@ class FakeUnitOfWork(AbstractUnitOfWork):
 \r
 def create_fake_bus(uow):\r
     def update_ocloud(\r
-        cmd: commands.UpdateOCloud,\r
-        uow: AbstractUnitOfWork):\r
+            cmd: commands.UpdateOCloud,\r
+            uow: AbstractUnitOfWork):\r
         return\r
 \r
     fakeuow = FakeUnitOfWork()\r
@@ -169,7 +168,7 @@ def test_watchers_worker():
         def _targetname(self):\r
             return "fakeocloudwatcher"\r
 \r
-        def _probe(self, parent: object=None):\r
+        def _probe(self, parent: object = None):\r
             # import pdb; pdb.set_trace()\r
             self.fakeOcloudWatcherCounter += 1\r
             # hacking to stop the blocking sched task\r
@@ -177,7 +176,6 @@ def test_watchers_worker():
                 testedworker.stop()\r
             return []\r
 \r
-\r
     # fakeRepo = FakeOcloudRepo()\r
     fakeuow = FakeUnitOfWork()\r
     bus = create_fake_bus(fakeuow)\r