summaryrefslogtreecommitdiffstats
path: root/components/pm-subscription-handler/pmsh_service/mod/api
diff options
context:
space:
mode:
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/api')
-rwxr-xr-xcomponents/pm-subscription-handler/pmsh_service/mod/api/db_models.py16
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py9
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/nf_service.py8
-rw-r--r--components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py46
4 files changed, 53 insertions, 26 deletions
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
index 2b340e24..49ca0581 100755
--- a/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/db_models.py
@@ -26,6 +26,8 @@ class SubscriptionModel(db.Model):
__tablename__ = 'subscriptions'
id = Column(Integer, primary_key=True, autoincrement=True)
subscription_name = Column(String(100), unique=True, nullable=False)
+ operational_policy_name = Column(String(80), nullable=False)
+ control_loop_name = Column(String(80))
status = Column(String(20))
nfs = relationship(
@@ -43,12 +45,17 @@ class SubscriptionModel(db.Model):
cascade='all, delete-orphan',
backref='subscription')
- def __init__(self, subscription_name, status):
+ def __init__(self, subscription_name, operational_policy_name, control_loop_name, status):
self.subscription_name = subscription_name
+ self.operational_policy_name = operational_policy_name
+ self.control_loop_name = control_loop_name
self.status = status
def __repr__(self):
- return f'subscription_name: {self.subscription_name}, status: {self.status}'
+ return f'subscription_name: {self.subscription_name},' \
+ f'operational_policy_name: {self.operational_policy_name},' \
+ f'control_loop_name: {self.control_loop_name},' \
+ f'status: {self.status}'
def __eq__(self, other):
if isinstance(self, other.__class__):
@@ -59,7 +66,10 @@ class SubscriptionModel(db.Model):
sub_nfs = NfSubRelationalModel.query.filter(
NfSubRelationalModel.subscription_name == self.subscription_name).all()
db.session.remove()
- return {'subscription_name': self.subscription_name, 'subscription_status': self.status,
+ return {'subscription_name': self.subscription_name,
+ 'operational_policy_name': self.operational_policy_name,
+ 'control_loop_name': self.control_loop_name,
+ 'subscription_status': self.status,
'network_functions': [sub_nf.serialize_nf() for sub_nf in sub_nfs]}
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
index 329dc857..733d803e 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/measurement_group_service.py
@@ -63,19 +63,19 @@ def apply_nf_to_measgroup(nf_name, measurement_group_name):
db.session.add(new_nf_measure_grp_rel)
-def publish_measurement_group(subscription_name, measurement_group, nf):
+def publish_measurement_group(sub_model, measurement_group, nf):
"""
Publishes an event for measurement group against nfs to MR
Args:
- subscription_name (string): Subscription name to publish against nf
+ sub_model(SubscriptionModel): Subscription model object
measurement_group (MeasurementGroupModel): Measurement group to publish
nf (NetworkFunction): Network function to publish.
"""
- event_body = nf_service.create_nf_event_body(nf, 'CREATE')
+ event_body = nf_service.create_nf_event_body(nf, 'CREATE', sub_model)
event_body['subscription'] = {
"administrativeState": measurement_group.administrative_state,
- "subscriptionName": subscription_name,
+ "subscriptionName": sub_model.subscription_name,
"fileBasedGP": measurement_group.file_based_gp,
"fileLocation": measurement_group.file_location,
"measurementGroup": {
@@ -84,4 +84,5 @@ def publish_measurement_group(subscription_name, measurement_group, nf):
"managedObjectDNsBasic": measurement_group.managed_object_dns_basic
}
}
+ logger.debug(f'Event Body: {event_body}')
AppConfig.get_instance().publish_to_topic(MRTopic.POLICY_PM_PUBLISHER.value, event_body)
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/nf_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/nf_service.py
index 1fca766a..6d431473 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/nf_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/nf_service.py
@@ -37,25 +37,25 @@ def capture_filtered_nfs(sub_name):
return aai_client.get_pmsh_nfs_from_aai(AppConfig.get_instance(), nf_filter)
-def create_nf_event_body(nf, change_type):
+def create_nf_event_body(nf, change_type, sub_model):
"""
Creates a network function event body to publish on MR
Args:
nf (NetworkFunction): the Network function to include in the event.
change_type (string): define the change type to be applied on node
+ sub_model(SubscriptionModel): Subscription model object
Returns:
dict: network function event body to publish on MR.
"""
- app_conf = AppConfig.get_instance()
return {'nfName': nf.nf_name,
'ipAddress': nf.ipv4_address if nf.ipv6_address in (None, '')
else nf.ipv6_address,
'blueprintName': nf.sdnc_model_name,
'blueprintVersion': nf.sdnc_model_version,
- 'policyName': app_conf.operational_policy_name,
+ 'operationalPolicyName': sub_model.operational_policy_name,
'changeType': change_type,
- 'closedLoopControlName': app_conf.control_loop_name}
+ 'controlLoopName': sub_model.control_loop_name}
def save_nf(nf):
diff --git a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
index 1485bebe..ea1640c2 100644
--- a/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
+++ b/components/pm-subscription-handler/pmsh_service/mod/api/services/subscription_service.py
@@ -39,24 +39,28 @@ def create_subscription(subscription):
logger.info(f'Initiating create subscription for: {subscription["subscriptionName"]}')
perform_validation(subscription)
try:
- sub_name, measurement_groups = save_subscription_request(subscription)
+ sub_model, measurement_groups = save_subscription_request(subscription)
db.session.commit()
logger.info(f'Successfully saved subscription request for: '
f'{subscription["subscriptionName"]}')
- filtered_nfs = nf_service.capture_filtered_nfs(sub_name)
+ filtered_nfs = nf_service.capture_filtered_nfs(sub_model.subscription_name)
if filtered_nfs:
- logger.info(f'Applying the filtered nfs for subscription: {sub_name}')
+ logger.info(f'Applying the filtered nfs for subscription: '
+ f'{sub_model.subscription_name}')
save_filtered_nfs(filtered_nfs)
- apply_subscription_to_nfs(filtered_nfs, sub_name)
+ apply_subscription_to_nfs(filtered_nfs, sub_model.subscription_name)
unlocked_msmt_groups = apply_measurement_grp_to_nfs(filtered_nfs, measurement_groups)
db.session.commit()
if unlocked_msmt_groups:
- publish_measurement_grp_to_nfs(sub_name, filtered_nfs, unlocked_msmt_groups)
+ publish_measurement_grp_to_nfs(sub_model, filtered_nfs,
+ unlocked_msmt_groups)
else:
- logger.error(f'All measurement groups are locked for subscription: {sub_name}, '
+ logger.error(f'All measurement groups are locked for subscription: '
+ f'{sub_model.subscription_name}, '
f'please verify/check measurement groups.')
else:
- logger.error(f'No network functions found for subscription: {sub_name}, '
+ logger.error(f'No network functions found for subscription: '
+ f'{sub_model.subscription_name}, '
f'please verify/check NetworkFunctionFilter.')
except IntegrityError as e:
db.session.rollback()
@@ -68,12 +72,13 @@ def create_subscription(subscription):
db.session.remove()
-def publish_measurement_grp_to_nfs(subscription_name, filtered_nfs, measurement_groups):
+def publish_measurement_grp_to_nfs(sub_model, filtered_nfs,
+ measurement_groups):
"""
Publishes an event for measurement groups against nfs
Args:
- subscription_name (string): subscription name against nfs
+ sub_model(SubscriptionModel): Subscription model object
filtered_nfs (list[NetworkFunction])): list of filtered network functions
measurement_groups (list[MeasurementGroupModel]): list of unlocked measurement group
"""
@@ -83,11 +88,11 @@ def publish_measurement_grp_to_nfs(subscription_name, filtered_nfs, measurement_
logger.info(f'Publishing event for nf name, measure_grp_name: {nf.nf_name},'
f'{measurement_group.measurement_group_name}')
measurement_group_service.publish_measurement_group(
- subscription_name, measurement_group, nf)
+ sub_model, measurement_group, nf)
except Exception as ex:
logger.error(f'Publish event failed for nf name, measure_grp_name, sub_name: '
f'{nf.nf_name},{measurement_group.measurement_group_name}, '
- f'{subscription_name} with error: {ex}')
+ f'{sub_model.subscription_name} with error: {ex}')
def save_filtered_nfs(filtered_nfs):
@@ -157,6 +162,8 @@ def check_missing_data(subscription):
"""
if subscription['subscriptionName'].strip() in (None, ''):
raise InvalidDataException("No value provided in subscription name")
+ if subscription['operationalPolicyName'].strip() in (None, ''):
+ raise InvalidDataException("Value required for operational Policy Name")
for measurement_group in subscription.get('measurementGroups'):
measurement_group_details = measurement_group['measurementGroup']
@@ -200,7 +207,7 @@ def save_subscription_request(subscription):
list[MeasurementGroupModel]: list of measurement groups
"""
logger.info(f'Saving subscription request for: {subscription["subscriptionName"]}')
- sub_name = save_subscription(subscription).subscription_name
+ sub_model = save_subscription(subscription)
save_nf_filter(subscription["nfFilter"], subscription["subscriptionName"])
measurement_groups = []
for measurement_group in subscription['measurementGroups']:
@@ -208,7 +215,7 @@ def save_subscription_request(subscription):
measurement_group_service.save_measurement_group(
measurement_group['measurementGroup'],
subscription["subscriptionName"]))
- return sub_name, measurement_groups
+ return sub_model, measurement_groups
def check_duplicate_fields(subscription_name):
@@ -235,9 +242,18 @@ def save_subscription(subscription):
Args:
subscription (dict): subscription model to be saved.
+ Returns:
+ subscription_model(SubscriptionModel): subscription model
+ which is added to the session
"""
- subscription_model = SubscriptionModel(subscription_name=subscription["subscriptionName"],
- status=AdministrativeState.LOCKED.value)
+ control_loop_name = ""
+ if 'controlLoopName' in subscription:
+ control_loop_name = subscription['controlLoopName']
+ subscription_model = \
+ SubscriptionModel(subscription_name=subscription["subscriptionName"],
+ operational_policy_name=subscription["operationalPolicyName"],
+ control_loop_name=control_loop_name,
+ status=AdministrativeState.LOCKED.value)
db.session.add(subscription_model)
return subscription_model