USER $PMSHUSER
# run the app
-ENTRYPOINT ["python", "./bin/pmsh_service.py"]
\ No newline at end of file
+ENTRYPOINT ["python", "./bin/pmsh_service_main.py"]
\ No newline at end of file
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
--- /dev/null
+# ============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'}
--- /dev/null
+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
# 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
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()
--- /dev/null
+# ============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=====================================================
+
+import unittest
+
+from pmsh_service.mod.healthcheck import status
+
+
+class HealthcheckTestCase(unittest.TestCase):
+
+ def test_status_response_healthy(self):
+ self.assertEqual(status()['status'], 'healthy')