summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service/mod/api
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2020-05-20 15:18:41 +0100
committerefiacor <fiachra.corcoran@est.tech>2020-05-25 08:50:24 +0100
commit5ed9b7d3cad56c6438bca305b6d2931bd320352b (patch)
treeb05cbb4e7215e9b6b9aead2a1ae45d63330c0761 /components/pm-subscription-handler/pmsh_service/mod/api
parent9a57e9a2e2357f267c6a7c804488011ac97beab5 (diff)
[PMSH] Adding 'subscriptions' api endpoint
Signed-off-by: efiacor <fiachra.corcoran@est.tech> Change-Id: I837045b3b618a98d4aabe190359d0ad47f27ca9f Issue-ID: DCAEGEN2-2154
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/api')
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/__init__.py0
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/api/controller.py42
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/api/db_models.py107
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml89
4 files changed, 238 insertions, 0 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/api/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/__init__.py
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/controller.py b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py
new file mode 100755
index 00000000..21d29caf
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/controller.py
@@ -0,0 +1,42 @@
+# ============LICENSE_START===================================================
+# Copyright (C) 2019-2020 Nordix Foundation.
+# ============================================================================
+# 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.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=====================================================
+
+from mod.subscription import Subscription
+
+
+def status():
+ """
+ Returns the health of the PMSH service
+ Args:
+ NA
+ Returns:
+ Dictionary detailing 'status' of either 'healthy' or 'unhealthy'.
+ Raises:
+ NA
+ """
+ return {'status': 'healthy'}
+
+
+def get_all_sub_to_nf_relations():
+ """ Retrieves all subscription to nf relations
+
+ Returns:
+ list: of Subscriptions and it's related Network Functions, else empty
+ """
+ subs_dict = [s.serialize() for s in Subscription.get_all()]
+ return subs_dict
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py b/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
new file mode 100755
index 00000000..1d6f72b3
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
@@ -0,0 +1,107 @@
+# ============LICENSE_START===================================================
+# Copyright (C) 2019-2020 Nordix Foundation.
+# ============================================================================
+# 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.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=====================================================
+
+from sqlalchemy import Column, Integer, String, ForeignKey
+from sqlalchemy.orm import relationship
+
+from mod import db
+
+
+class SubscriptionModel(db.Model):
+ __tablename__ = 'subscriptions'
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ subscription_name = Column(String(100), unique=True)
+ status = Column(String(20))
+
+ nfs = relationship(
+ 'NfSubRelationalModel',
+ cascade='all, delete-orphan',
+ backref='subscription')
+
+ def __init__(self, subscription_name, status):
+ self.subscription_name = subscription_name
+ self.status = status
+
+ def __repr__(self):
+ return f'subscription_name: {self.subscription_name}, status: {self.status}'
+
+ def __eq__(self, other):
+ if isinstance(self, other.__class__):
+ return self.subscription_name == other.subscription_name
+ return False
+
+ def serialize(self):
+ sub_nfs = NfSubRelationalModel.query.filter(
+ NfSubRelationalModel.subscription_name == self.subscription_name).all()
+ return {'subscription_name': self.subscription_name, 'subscription_status': self.status,
+ 'network_functions': [sub_nf.serialize_nf() for sub_nf in sub_nfs]}
+
+
+class NetworkFunctionModel(db.Model):
+ __tablename__ = 'network_functions'
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ nf_name = Column(String(100), unique=True)
+ orchestration_status = Column(String(100))
+
+ subscriptions = relationship(
+ 'NfSubRelationalModel',
+ cascade='all, delete-orphan',
+ backref='nf')
+
+ def __init__(self, nf_name, orchestration_status):
+ self.nf_name = nf_name
+ self.orchestration_status = orchestration_status
+
+ def __repr__(self):
+ return f'nf_name: {self.nf_name}, orchestration_status: {self.orchestration_status}'
+
+
+class NfSubRelationalModel(db.Model):
+ __tablename__ = 'nf_to_sub_rel'
+ __mapper_args__ = {
+ 'confirm_deleted_rows': False
+ }
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ subscription_name = Column(
+ String,
+ ForeignKey(SubscriptionModel.subscription_name, ondelete='cascade', onupdate='cascade')
+ )
+ nf_name = Column(
+ String,
+ ForeignKey(NetworkFunctionModel.nf_name, ondelete='cascade', onupdate='cascade')
+ )
+ nf_sub_status = Column(String(20))
+
+ def __init__(self, subscription_name, nf_name, nf_sub_status=None):
+ self.subscription_name = subscription_name
+ self.nf_name = nf_name
+ self.nf_sub_status = nf_sub_status
+
+ def __repr__(self):
+ return f'subscription_name: {self.subscription_name}, ' \
+ f'nf_name: {self.nf_name}, nf_sub_status: {self.nf_sub_status}'
+
+ def serialize(self):
+ return {'subscription_name': self.subscription_name, 'nf_name': self.nf_name,
+ 'nf_sub_status': self.nf_sub_status}
+
+ def serialize_nf(self):
+ nf_orch_status = NetworkFunctionModel.query.filter(
+ NetworkFunctionModel.nf_name == self.nf_name).one_or_none().orchestration_status
+ return {'nf_name': self.nf_name, 'orchestration_status': nf_orch_status,
+ 'nf_sub_status': self.nf_sub_status}
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml b/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml
new file mode 100644
index 00000000..58e6a788
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/pmsh_swagger.yml
@@ -0,0 +1,89 @@
+# ============LICENSE_START=======================================================
+# Copyright (C) 2020 Nordix Foundation.
+# ================================================================================
+# 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.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+swagger: "2.0"
+info:
+ title: PM Subscription Handler Service
+ version: "1.1.0"
+ description: PM subscription handler enables control of performance management jobs on network functions in ONAP
+produces:
+ - "application/json"
+basePath: "/"
+schemes:
+ - https
+# Paths supported by the server application
+paths:
+ /subscriptions:
+ get:
+ description: >-
+ Get all defined Subscriptions and their related Network Functions from ONAP.
+ operationId: mod.api.controller.get_all_sub_to_nf_relations
+ responses:
+ 200:
+ description: OK; Array of subscriptions are returned as an object
+ schema:
+ type: array
+ items:
+ type: object
+ properties:
+ subscription_name:
+ type: string
+ description: Name of the Subscription
+ subscription_status:
+ type: string
+ description: Status of the Subscription
+ network_functions:
+ type: array
+ items:
+ type: object
+ properties:
+ nf_name:
+ type: string
+ description: Name of the Network Function
+ nf_sub_status:
+ type: string
+ description: Status of the Subscription on the Network Function
+ orchestration_status:
+ type: string
+ description: Orchestration status of the Network Function
+ 401:
+ description: Unauthorized
+ 403:
+ description: Forbidden
+ 404:
+ description: there are no subscriptions defined
+
+ /healthcheck:
+ get:
+ operationId: mod.api.controller.status
+ tags:
+ - "HealthCheck"
+ description: >-
+ This is the health check endpoint. If this returns a 200, the server is alive.
+ responses:
+ 200:
+ description: Successful response
+ schema:
+ type: object
+ properties:
+ status:
+ type: string
+ description: Overall health of PMSH
+ enum: [healthy, unhealthy]
+ 503:
+ description: the pmsh service is unavailable