+from apps.pci.optimizers.config import configdb
+from apps.pci.optimizers.config import cps
--- /dev/null
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+
+
+class ConfigClient(object):
+
+ subclasses = {}
+
+ @classmethod
+ def register_subclass(cls, type):
+ def decorator(subclass):
+ cls.subclasses[type] = subclass
+ return subclass
+
+ return decorator
+
+ @classmethod
+ def create(cls, type):
+ if type not in cls.subclasses:
+ raise ValueError('Bad config client type {}'.format(type))
+
+ return cls.subclasses[type]()
--- /dev/null
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# 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.
+#
+# -------------------------------------------------------------------------
+#
+
+from datetime import datetime as dt
+import uuid
+
+from apps.pci.optimizers.config.config_client import ConfigClient
+from osdf.config.base import osdf_config
+from osdf.logging.osdf_logging import debug_log
+from osdf.utils.interfaces import RestClient
+
+
+@ConfigClient.register_subclass('configdb')
+class ConfigDb(ConfigClient):
+
+ def __init__(self):
+ self.config = osdf_config.deployment
+ uid, passwd = self.config['configDbUserName'], self.config['configDbPassword']
+ headers = dict(transaction_id=str(uuid.uuid4()))
+ self.rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers)
+
+ def get_cell_list(self, network_id):
+ ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
+ cell_list_url = '{}/{}/{}/{}'.format(self.config['configDbUrl'],
+ self.config['configDbGetCellListUrl'], network_id, ts)
+ return self.rc.request(raw_response=True, url=cell_list_url).json()
+
+ def get_nbr_list(self, network_id, cell_id):
+ ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
+ nbr_list_url = '{}/{}/{}/{}'.format(self.config['configDbUrl'],
+ self.config['configDbGetNbrListUrl'], cell_id, ts)
+ response = self.rc.request(url=nbr_list_url, raw_response=True).json()
+
+ debug_log.debug("cell_id {} nbr_list {}".format(cell_id, response.get('nbrList')))
+
+ return response.get('nbrList', [])
--- /dev/null
+# -------------------------------------------------------------------------
+# Copyright (C) 2021 Wipro Limited.
+#
+# 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 json
+
+from apps.pci.optimizers.config.config_client import ConfigClient
+from osdf.config.base import osdf_config
+from osdf.logging.osdf_logging import debug_log
+from osdf.utils.interfaces import RestClient
+
+
+@ConfigClient.register_subclass('cps')
+class Cps(ConfigClient):
+
+ def __init__(self):
+ self.config = osdf_config.deployment
+ username, password = self.config['cpsUsername'], self.config['cpsPassword']
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json"
+ }
+ self.rc = RestClient(userid=username, passwd=password, method="POST",
+ log_func=debug_log.debug, headers=headers)
+
+ def get_cell_list(self, network_id):
+ cell_list_url = '{}/{}'.format(self.config['cpsUrl'], self.config['cpsCellListUrl'])
+ data = {
+ 'inputParameters': {
+ 'regionId': network_id
+ }
+ }
+ response = self.rc.request(url=cell_list_url, data=json.dumps(data))
+ debug_log.debug("cell list response {}".format(response))
+ return sorted([x['idNRCellCU'] for x in response.get('NRCellCU')])
+
+ def get_nbr_list(self, network_id, cell_id):
+ nbr_list_url = '{}/{}'.format(self.config['cpsUrl'], self.config['cpsNbrListUrl'])
+ data = {
+ 'inputParameters': {
+ 'regionId': network_id,
+ 'idNRCellCU': cell_id
+ }
+ }
+ response = self.rc.request(url=nbr_list_url, data=json.dumps(data))
+ debug_log.debug("nbr list response {}".format(response))
+ nbr_list = []
+ for cell_relation in response.get('NRCellRelation'):
+ nbr = {
+ 'targetCellId': cell_relation['attributes']['nRTCI'],
+ 'pciValue': int(cell_relation['attributes']['nRPCI']),
+ 'ho': cell_relation['attributes']['isHOAllowed']
+ }
+ nbr_list.append(nbr)
+
+ debug_log.debug("cell_id {} nbr_list {}".format(cell_id, nbr_list))
+
+ return nbr_list
# -------------------------------------------------------------------------
#
-from datetime import datetime as dt
-
-from osdf.logging.osdf_logging import debug_log
-from osdf.utils.interfaces import RestClient
+from apps.pci.optimizers.config.config_client import ConfigClient
def request(req_object, osdf_config, flat_policies):
- """
- Process a configdb request from a Client (build Conductor API call, make the call, return result)
+ """Process a configdb request from a Client (build Conductor API call, make the call, return result)
+
:param req_object: Request parameters from the client
:param osdf_config: Configuration specific to OSDF application (core + deployment)
:param flat_policies: policies related to PCI Opt (fetched based on request)
:return: response from ConfigDB (accounting for redirects from Conductor service
"""
cell_list_response = {}
- config = osdf_config.deployment
- local_config = osdf_config.core
- uid, passwd = config['configDbUserName'], config['configDbPassword']
- req_id = req_object['requestInfo']['requestId']
- transaction_id = req_object['requestInfo']['transactionId']
- headers = dict(transaction_id=transaction_id)
network_id = req_object['cellInfo']['networkId']
cell_list_response['network_id'] = network_id
- ts = dt.strftime(dt.now(), '%Y-%m-%d %H:%M:%S%z')
-
- rc = RestClient(userid=uid, passwd=passwd, method="GET", log_func=debug_log.debug, headers=headers)
+ config = osdf_config.deployment
- cell_list_url = '{}/{}/{}/{}'.format(config['configDbUrl'], config['configDbGetCellListUrl'], network_id, ts)
+ config_client = ConfigClient.create(config['configClientType'])
- cell_list_resp = rc.request(raw_response=True, url=cell_list_url)
- cell_resp = cell_list_resp.json()
+ cell_resp = config_client.get_cell_list(network_id)
cell_list = []
count = 0
for cell_id in cell_resp:
- cell_info = {'cell_id': cell_id, 'id': count}
- nbr_list_url = '{}/{}/{}/{}'.format(config['configDbUrl'], config['configDbGetNbrListUrl'], cell_id, ts)
- nbr_list_raw = rc.request(url=nbr_list_url, raw_response=True)
- cell_info['nbr_list'] = get_neighbor_list(nbr_list_raw.json())
+ cell_info = {
+ 'cell_id': cell_id,
+ 'id': count,
+ 'nbr_list': config_client.get_nbr_list(network_id, cell_id)
+ }
cell_list.append(cell_info)
count += 1
cell_list_response['cell_list'] = cell_list
- return cell_resp, cell_list_response
-
-def get_neighbor_list(nbr_list_response):
- return nbr_list_response.get('nbrList', [])
+ return cell_resp, cell_list_response
from onaplogging.mdcContext import MDC
from requests import RequestException
-from osdf.logging.osdf_logging import metrics_log, MH, error_log
+from apps.pci.optimizers.config_request import request as config_request
+from apps.pci.optimizers.solver.optimizer import pci_optimize as optimize
+from apps.pci.optimizers.solver.pci_utils import get_cell_id
+from apps.pci.optimizers.solver.pci_utils import get_pci_value
+from osdf.logging.osdf_logging import error_log
+from osdf.logging.osdf_logging import metrics_log
+from osdf.logging.osdf_logging import MH
from osdf.operation.error_handling import build_json_error_body
from osdf.utils.interfaces import get_rest_client
-from .configdb import request as config_request
-from .solver.optimizer import pci_optimize as optimize
-from .solver.pci_utils import get_cell_id, get_pci_value
from osdf.utils.mdc_utils import mdc_from_json
"""
def process_pci_optimation(request_json, osdf_config, flat_policies):
- """
- Process a PCI request from a Client (build config-db, policy and API call, make the call, return result)
+ """Process a PCI request from a Client (build config-db, policy and API call, make the call, return result)
+
:param req_object: Request parameters from the client
:param osdf_config: Configuration specific to OSDF application (core + deployment)
:param flat_policies: policies related to pci (fetched based on request)
body = build_json_error_body(err)
metrics_log.info(MH.sending_response(req_id, "ERROR"))
rc.request(json=body, noresponse=True)
- except RequestException as err:
- MDC.put('requestID',req_id)
+ except RequestException:
+ MDC.put('requestID', req_id)
error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
raise err
-
try:
metrics_log.info(MH.calling_back_with_body(req_id, rc.url, pci_response))
+ error_log.error("pci response: {}".format(str(pci_response)))
rc.request(json=pci_response, noresponse=True)
except RequestException: # can't do much here but log it and move on
error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
def build_solution_list(cell_info_list, network_cell_info, request_json):
status = "success"
req_id = request_json["requestInfo"]["requestId"]
- pci_solutions =[]
- anr_solutions=[]
+ pci_solutions = []
+ anr_solutions = []
try:
opt_solution = optimize(network_cell_info, cell_info_list, request_json)
- if opt_solution == 'UNSATISFIABLE':
+ if opt_solution == 'UNSATISFIABLE':
status = 'inconsistent input'
return status, pci_solutions, anr_solutions
else:
secret_domain: osdf
aaf_ca_certs: ssl_certs/aaf_root_ca.cer
+configClientType: configdb
+
# config db api
configDbUrl: http://config.db.url:8080
configDbGetCellListUrl: 'SDNCConfigDBAPI/getCellList'
configDbGetNbrListUrl: 'SDNCConfigDBAPI/getNbrList'
+configDbUserName: ''
+configDbPassword: ''
+
+# cps api
+cpsUrl: http://cps-tbdmt:8000/execute
+cpsCellListUrl: 'ran-network/getCellList'
+cpsNbrListUrl: 'ran-network/getNbrList'
+cpsUsername: ''
+cpsPassword: ''
#aai api
aaiUrl: "https://aai.url:30233"
secret_domain: osdf
aaf_ca_certs: /opt/aaf_root_ca.cer
+configClientType: configdb
+
# config db api
configDbUrl: http://127.0.0.1:5000/simulated/configdb
configDbGetCellListUrl: 'getCellList'
configDbGetNbrListUrl: 'getNbrList'
+# cps api
+cpsUrl: http://localhost:8080/execute
+cpsCellListUrl: 'e2e-cavsta-schemaset/get-cell-list'
+cpsNbrListUrl: 'e2e-cavsta-schemaset/get-nbr-list'
+cpsUsername: ''
+cpsPassword: ''
+
#aai api
aaiUrl: "http://127.0.0.1:5000"
aaiGetLinksUrl: "/aai/v16/network/logical-links"
"timeout": 600
},
"cellInfo": {
- "networkId": "1000",
+ "networkId": "netw1000",
"cellIdList": [
"cell0"
]
pciHMSUsername: "" # pcihandler username for call back.
pciHMSPassword: "" # pcihandler password for call back.
+configClientType: configdb
+
+# config db api
+configDbUrl: http://127.0.0.1:5000/simulated/configdb
+configDbUserName: osdf
+configDbPassword: passwd
+configDbGetCellListUrl: 'getCellList'
+configDbGetNbrListUrl: 'getNbrList'
+
# Credentials for the OOF PCI Opt service
osdfPCIOptUsername: PCI-OSDF-USER
osdfPCIOptPassword: PCI-OSDF-PASSWD
# -------------------------------------------------------------------------
#
-from apps.pci.optimizers.configdb import request
+from apps.pci.optimizers.config_request import request
import osdf.config.loader as config_loader
from osdf.utils.interfaces import json_from_file
from osdf.utils.programming_utils import DotDict
secret_domain: osdf
aaf_ca_certs: ssl_certs/aaf_root_ca.cer
+configClientType: configdb
+
# config db api
configDbUrl: http://127.0.0.1:5000/simulated/configdb
configDbUserName: osdf
"cellInfo": {
- "networkId": "2000",
+ "networkId": "netw2000",
"cellIdList": [
"timeout": 600
},
"cellInfo": {
- "networkId": "2000",
+ "networkId": "netw2000",
"cellIdList": [
"cell20"
]
"timeout": 600
},
"cellInfo": {
- "networkId": "1000",
+ "networkId": "netw1000",
"cellIdList": [
"cell0"
]
}
-}
\ No newline at end of file
+}
def setUp(self):
mock_req_accept_message = Response("Accepted Request", content_type='application/json; charset=utf-8')
- self.patcher_req = patch('apps.pci.optimizers.configdb.request',
+ self.patcher_req = patch('apps.pci.optimizers.config_request.request',
return_value={"solutionInfo": {"placementInfo": "dummy"}})
self.patcher_req_accept = patch('osdf.operation.responses.osdf_response_for_request_accept',
return_value=mock_req_accept_message)
def setUp(self):
mock_req_accept_message = Response("Accepted Request", content_type='application/json; charset=utf-8')
- self.patcher_req = patch('apps.pci.optimizers.configdb.request',
+ self.patcher_req = patch('apps.pci.optimizers.config_request.request',
return_value={"solutionInfo": {"placementInfo": "dummy"}})
self.patcher_req_accept = patch('osdf.operation.responses.osdf_response_for_request_accept',
return_value=mock_req_accept_message)
def setUp(self):
mock_req_accept_message = Response("Accepted Request", content_type='application/json; charset=utf-8')
- self.patcher_req = patch('apps.pci.optimizers.configdb.request',
+ self.patcher_req = patch('apps.pci.optimizers.config_request.request',
return_value={"solutionInfo": {"placementInfo": "dummy"}})
self.patcher_req_accept = patch('osdf.operation.responses.osdf_response_for_request_accept',
return_value=mock_req_accept_message)
select = E,H,W,F
max-line-length = 119
ignore = W503 #conflict with W504
-per-file-ignores=
+per-file-ignores= apps/pci/optimizers/__init__.py:F401