Skip to content

Commit

Permalink
Merge pull request medianetlab#91 from medianetlab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JFrgs authored Nov 15, 2023
2 parents 0d769d8 + a4ee045 commit 1656a2f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## v2.2.3
***Summary:***
> - *Minor fixes on service initialisation*
<br><br>
## v2.2.2
***Summary:***
> - *Split jwt token authorisation for NEF and CAPIF. If NEF is deployed as a standalone component then only nef token authorisation is required. If capif is integrated with nef, jwt token acquired from CAPIF is required [commit](https://github.com/medianetlab/NEF_emulator/commit/16483f55d2d14b61d804c00eb8774119e6acffdc)*
Expand Down
49 changes: 2 additions & 47 deletions backend/app/app/backend_pre_start.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging, requests
from evolved5g.sdk import CAPIFProviderConnector
import logging
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
from app.db.session import SessionLocal
from app.core.config import settings


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand All @@ -26,57 +25,13 @@ def init() -> None:
logger.error(e)
raise e

def capif_nef_connector():
"""
"""
try:
capif_connector = CAPIFProviderConnector(certificates_folder="app/core/certificates",
capif_host=settings.CAPIF_HOST,
capif_http_port=settings.CAPIF_HTTP_PORT,
capif_https_port=settings.CAPIF_HTTPS_PORT,
capif_netapp_username="test_nef01",
capif_netapp_password="test_netapp_password",
description= "test_app_description",
csr_common_name="apfExpapfoser1502", #TODO: ASK STAVROS. THIS SHOULD NOT BE HARDCODED, RIGHT?
csr_organizational_unit="test_app_ou",
csr_organization="test_app_o",
crs_locality="Madrid",
csr_state_or_province_name="Madrid",
csr_country_name="ES",
csr_email_address="[email protected]"
)


capif_connector.register_and_onboard_provider()

capif_connector.publish_services(service_api_description_json_full_path="app/core/capif_files/service_monitoring_event.json")
capif_connector.publish_services(service_api_description_json_full_path="app/core/capif_files/service_as_session_with_qos.json")
return True
except requests.exceptions.HTTPError as err:
if err.response.status_code == 409:
logger.error(f'"Http Error:", {err.response.json()}')
return False
except requests.exceptions.ConnectionError as err:
logger.error(f'"Error Connecting:", {err}')
return False
except requests.exceptions.Timeout as err:
logger.error(f'"Timeout Error:", {err}')
return False
except requests.exceptions.RequestException as err:
logger.error(f'"Error:", {err}')
return False


def main() -> None:
logger.info("Initializing service")
init()
logger.info("Service finished initializing")
logger.info("Trying to connect with CAPIF Core Function")
if capif_nef_connector():
logger.info("Successfully onboard NEF in the CAPIF Core Function")
else:
logger.info("Failed to onboard NEF in the CAPIF Core Function")


if __name__ == "__main__":
Expand Down
52 changes: 50 additions & 2 deletions backend/app/app/initial_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging, json, os

import logging, json, os, requests
from evolved5g.sdk import CAPIFProviderConnector
from app.db.init_db import init_db
from app.db.session import SessionLocal
from app.core.config import settings

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
Expand All @@ -11,6 +12,48 @@ def init() -> None:
db = SessionLocal()
init_db(db)


def capif_nef_connector():
"""
"""
try:
capif_connector = CAPIFProviderConnector(certificates_folder="app/core/certificates",
capif_host=settings.CAPIF_HOST,
capif_http_port=settings.CAPIF_HTTP_PORT,
capif_https_port=settings.CAPIF_HTTPS_PORT,
capif_netapp_username="test_nef01",
capif_netapp_password="test_netapp_password",
description= "test_app_description",
csr_common_name="apfExpapfoser1502", #TODO: ASK STAVROS. THIS SHOULD NOT BE HARDCODED, RIGHT?
csr_organizational_unit="test_app_ou",
csr_organization="test_app_o",
crs_locality="Madrid",
csr_state_or_province_name="Madrid",
csr_country_name="ES",
csr_email_address="[email protected]"
)


capif_connector.register_and_onboard_provider()

capif_connector.publish_services(service_api_description_json_full_path="app/core/capif_files/service_monitoring_event.json")
capif_connector.publish_services(service_api_description_json_full_path="app/core/capif_files/service_as_session_with_qos.json")
return True
except requests.exceptions.HTTPError as err:
if err.response.status_code == 409:
logger.error(f'"Http Error:", {err.response.json()}')
return False
except requests.exceptions.ConnectionError as err:
logger.error(f'"Error Connecting:", {err}')
return False
except requests.exceptions.Timeout as err:
logger.error(f'"Timeout Error:", {err}')
return False
except requests.exceptions.RequestException as err:
logger.error(f'"Error:", {err}')
return False

def capif_service_description() -> None:

try:
Expand Down Expand Up @@ -74,6 +117,11 @@ def main() -> None:
init()
capif_service_description()
logger.info("Initial data created")
logger.info("Trying to connect with CAPIF Core Function")
if capif_nef_connector():
logger.info("Successfully onboard NEF in the CAPIF Core Function")
else:
logger.info("Failed to onboard NEF in the CAPIF Core Function")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions backend/app/prestart.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env bash

# Create initial data in DB
python /app/app/initial_data.py

# Let the DB start
python /app/app/backend_pre_start.py

# Create initial data in DB
python /app/app/initial_data.py

# Run migrations
#alembic upgrade head
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ services:
INSTALL_JUPYTER: ${INSTALL_JUPYTER-true}
extra_hosts:
- "host.docker.internal:host-gateway"
restart: always
networks:
- services_default

Expand Down

0 comments on commit 1656a2f

Please sign in to comment.