summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service
diff options
context:
space:
mode:
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service')
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/__init__.py17
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/healthcheck.py30
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/pmsh_swagger.yml34
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/pmsh_service_main.py9
4 files changed, 83 insertions, 7 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/__init__.py b/components/pm-subscription-handler/pmsh_service/mod/__init__.py
index 722188ae..e09ec285 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/__init__.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/__init__.py
@@ -25,11 +25,26 @@ import mod.pmsh_logging as logger
db = SQLAlchemy()
basedir = os.path.abspath(os.path.dirname(__file__))
+_connexion_app = None
+
+
+def _get_app():
+ global _connexion_app
+ if not _connexion_app:
+ _connexion_app = App(__name__, specification_dir=basedir)
+ return _connexion_app
+
+
+def launch_api_server(app_config):
+ connex_app = _get_app()
+ connex_app.add_api('pmsh_swagger.yml')
+ connex_app.run(port=os.environ.get('PMSH_API_PORT', '8443'),
+ ssl_context=(app_config.cert_path, app_config.key_path))
def create_app():
logger.create_loggers(os.getenv('LOGS_PATH'))
- connex_app = App(__name__, specification_dir=basedir)
+ connex_app = _get_app()
app = connex_app.app
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_RECORD_QUERIES'] = True
diff --git a/components/pm-subscription-handler/pmsh_service/mod/healthcheck.py b/components/pm-subscription-handler/pmsh_service/mod/healthcheck.py
new file mode 100755
index 00000000..af82fc4e
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/healthcheck.py
@@ -0,0 +1,30 @@
+# ============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=====================================================
+
+
+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'}
diff --git a/components/pm-subscription-handler/pmsh_service/mod/pmsh_swagger.yml b/components/pm-subscription-handler/pmsh_service/mod/pmsh_swagger.yml
new file mode 100644
index 00000000..7bfecd81
--- /dev/null
+++ b/components/pm-subscription-handler/pmsh_service/mod/pmsh_swagger.yml
@@ -0,0 +1,34 @@
+swagger: "2.0"
+info:
+ title: PM Subscription Handler Service
+ version: "1.0.0"
+ description: This is the swagger file that outlines the PM subscription handler api
+consumes:
+ - "application/json"
+produces:
+ - "application/json"
+
+schemes:
+ - https
+
+# Paths supported by the server application
+paths:
+ /healthcheck:
+ get:
+ operationId: "mod.healthcheck.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
diff --git a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
index ab330320..5c81250f 100755
--- a/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
+++ b/components/pm-subscription-handler/pmsh_service/pmsh_service_main.py
@@ -16,12 +16,11 @@
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=====================================================
import sys
-import time
import threading
import mod.aai_client as aai
import mod.pmsh_logging as logger
-from mod import db, create_app
+from mod import db, create_app, launch_api_server
from mod.config_handler import ConfigHandler
from mod.pmsh_utils import AppConfig
from mod.subscription import Subscription, AdministrativeState
@@ -81,14 +80,12 @@ def main():
threading.Timer(20.0, mr_sub.poll_policy_topic, [sub.subscriptionName, app]).start()
+ launch_api_server(app_conf)
+
except Exception as e:
logger.debug(f'Failed to Init PMSH: {e}')
sys.exit(e)
- while True:
- logger.debug(Subscription.get_all_nfs_subscription_relations())
- time.sleep(5)
-
if __name__ == '__main__':
main()