Add subscription and notification for resource changes; fix a bug while pserver node...
[pti/o2.git] / o2ims / domain / subscription_repo.py
diff --git a/o2ims/domain/subscription_repo.py b/o2ims/domain/subscription_repo.py
new file mode 100644 (file)
index 0000000..d12c00d
--- /dev/null
@@ -0,0 +1,57 @@
+# 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 abc
+from typing import List, Set
+from o2ims.domain import subscription_obj as subobj
+
+
+class SubscriptionRepository(abc.ABC):
+    def __init__(self):
+        self.seen = set()  # type: Set[subobj.Subscription]
+
+    def add(self, subscription: subobj.Subscription):
+        self._add(subscription)
+        self.seen.add(subscription)
+
+    def get(self, subscription_id) -> subobj.Subscription:
+        subscription = self._get(subscription_id)
+        if subscription:
+            self.seen.add(subscription)
+        return subscription
+
+    def list(self) -> List[subobj.Subscription]:
+        return self._list()
+
+    def update(self, subscription: subobj.Subscription):
+        self._update(subscription)
+
+    def delete(self, subscription_id):
+        self._delete(subscription_id)
+
+    @abc.abstractmethod
+    def _add(self, subscription: subobj.Subscription):
+        raise NotImplementedError
+
+    @abc.abstractmethod
+    def _get(self, subscription_id) -> subobj.Subscription:
+        raise NotImplementedError
+
+    @abc.abstractmethod
+    def _update(self, subscription: subobj.Subscription):
+        raise NotImplementedError
+
+    @abc.abstractmethod
+    def _delete(self, subscription_id):
+        raise NotImplementedError