Update watcher worker
[pti/o2.git] / o2ims / domain / ocloud_repo.py
diff --git a/o2ims/domain/ocloud_repo.py b/o2ims/domain/ocloud_repo.py
new file mode 100644 (file)
index 0000000..2c486bd
--- /dev/null
@@ -0,0 +1,53 @@
+# 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 abc\r
+from typing import List, Set\r
+from o2ims.domain import ocloud\r
+\r
+\r
+class OcloudRepository(abc.ABC):\r
+    def __init__(self):\r
+        self.seen = set()  # type: Set[ocloud.Ocloud]\r
+\r
+    def add(self, ocloud: ocloud.Ocloud):\r
+        self._add(ocloud)\r
+        self.seen.add(ocloud)\r
+\r
+    def get(self, ocloudid) -> ocloud.Ocloud:\r
+        ocloud = self._get(ocloudid)\r
+        if ocloud:\r
+            self.seen.add(ocloud)\r
+        return ocloud\r
+\r
+    def list(self) -> List[ocloud.Ocloud]:\r
+        return self._list()\r
+\r
+    def update(self, ocloud: ocloud.Ocloud):\r
+        self._update(ocloud)\r
+\r
+    # def update_fields(self, ocloudid: str, updatefields: dict):\r
+    #     self._update(ocloudid, updatefields)\r
+\r
+    @abc.abstractmethod\r
+    def _add(self, ocloud: ocloud.Ocloud):\r
+        raise NotImplementedError\r
+\r
+    @abc.abstractmethod\r
+    def _get(self, ocloudid) -> ocloud.Ocloud:\r
+        raise NotImplementedError\r
+\r
+    @abc.abstractmethod\r
+    def _update(self, ocloud: ocloud.Ocloud):\r
+        raise NotImplementedError\r