diff options
author | aleemraja <ar00500721@techmahindra.com> | 2020-12-18 17:59:03 +0530 |
---|---|---|
committer | Aleem Raja <ar00500721@techmahindra.com> | 2020-12-18 13:57:37 +0000 |
commit | 36cdaeb207619022fdb6098370a06f904d57b9a4 (patch) | |
tree | 20adb30b6fc969ec33a6e670f99fb41489b563ae /bpmn/so-bpmn-infrastructure-common/src/main/groovy/org | |
parent | 1cf3bdec6f48670b24fabf8ba751e7a50e0325cb (diff) |
5G core nssmf - Allocate api
Code changes to fix issues observed during testing for share/non-shared
nssmf Allocate api
Issue-ID: SO-3418
Signed-off-by: aleemraja <ar00500721@techmahindra.com>
Change-Id: I37ce7d21eaba8ea51a91a7034502323b2cf3a615
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/groovy/org')
3 files changed, 218 insertions, 200 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNSSI.groovy index 64c36e7026..ec97972e5d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNSSI.groovy @@ -68,10 +68,7 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { execution.setVariable("coreServiceInstanceId", coreServiceInstanceId) logger.debug(Prefix+" **** Exit DoAllocateCoreNSSI ::: preProcessRequest ****") } - /** - * Query NSST name from CatalogDB - * @param execution - */ + void getNSSTName(DelegateExecution execution){ logger.debug(Prefix+" **** Enter DoAllocateCoreNSSI ::: getNSSTName ****") String nsstModelInvariantUuid = execution.getVariable("modelInvariantUuid") @@ -79,8 +76,8 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution, nsstModelInvariantUuid) logger.debug("***** JSON Response is: "+json) String nsstName = jsonUtil.getJsonValue(json, "serviceResources.modelInfo.modelName") ?: "" - String networkServiceModelInfo = jsonUtil.getJsonValue(json, "serviceResources.serviceProxy.modelInfo") ?: "" - + List serviceProxyList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(json, "serviceResources.serviceProxy")) + String networkServiceModelInfo = serviceProxyList.get(0) execution.setVariable("networkServiceModelInfo", networkServiceModelInfo) logger.debug("***** nsstName is: "+ nsstName) execution.setVariable("nsstName",nsstName) @@ -93,6 +90,7 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { } logger.debug(Prefix+" **** Exit DoAllocateCoreNSSI ::: getNSSTName ****") } + void prepareOOFRequest(DelegateExecution execution){ logger.debug(Prefix+" **** Enter DoAllocateCoreNSSI ::: prepareOOFRequest ****") //API Path @@ -105,8 +103,6 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { //Setting messageType for all Core slice as cn String messageType = "cn" execution.setVariable("NSSI_messageType", messageType) - //Is there any specific timeout we have to set or else we don't need to send - //if blank will be set default value in DoHandleOofRequest String timeout = "PT30M" execution.setVariable("NSSI_timeout", timeout) Map<String, Object> profileInfo = mapper.readValue(execution.getVariable("sliceProfile"), Map.class) @@ -128,6 +124,10 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { String solutions ="" if(requestStatus.equals("completed")) { solutions = jsonUtil.getJsonValue(OOFResponse, "solutions") + List solutionsList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(OOFResponse, "solutions")) + if(solutionsList!=null && !solutionsList.isEmpty() ) { + solutions = solutionsList.get(0) + } } else { String statusMessage = jsonUtil.getJsonValue(OOFResponse, "statusMessage") logger.error("received failed status from oof "+ statusMessage) @@ -139,16 +139,20 @@ class DoAllocateCoreNSSI extends AbstractServiceTaskProcessor { void prepareFailedOperationStatusUpdate(DelegateExecution execution){ logger.debug(Prefix + " **** Enter DoAllocateCoreNSSI ::: prepareFailedOperationStatusUpdate ****") - String serviceId = execution.getVariable("nssiId") + String serviceId = execution.getVariable("nsiId") String jobId = execution.getVariable("jobId") String nsiId = execution.getVariable("nsiId") - String operationType = execution.getVariable("operationType") + String nssiId = execution.getVariable("nssiId") + String operationType = "ALLOCATE" + logger.debug("serviceId: "+serviceId+" jobId: "+jobId+" nsiId: "+nsiId+" operationType: "+operationType) + String modelUuid= execution.getVariable("modelUuid") ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() resourceOperationStatus.setServiceId(serviceId) + resourceOperationStatus.setJobId(jobId) resourceOperationStatus.setOperationId(jobId) - resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setResourceTemplateUUID(modelUuid) resourceOperationStatus.setOperType(operationType) - resourceOperationStatus.setProgress(0) + resourceOperationStatus.setProgress("0") resourceOperationStatus.setStatus("failed") resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed") requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy index c5a928aaf9..1ca0605ac8 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreNonSharedSlice.groovy @@ -64,6 +64,8 @@ import org.onap.so.bpmn.core.json.JsonUtils import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.HttpEntity +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aaiclient.client.aai.AAINamespaceConstants import javax.ws.rs.NotFoundException @@ -79,24 +81,26 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { public void preProcessRequest(DelegateExecution execution) { logger.debug(Prefix+ "**** Enter DoAllocateCoreNonSharedSlice::: preProcessRequest ****") String nssiServiceInstanceId= execution.getVariable("serviceInstanceId") + logger.debug("nssiServiceInstanceId: "+nssiServiceInstanceId) execution.setVariable("nssiServiceInstanceId", nssiServiceInstanceId) //Set orchestration-status as created execution.setVariable("orchestrationStatus", "created") //networkServiceName - String networkServiceName = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelName") ?: "" + String networkServiceName = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelInfo.modelName") ?: "" execution.setVariable("networkServiceName", networkServiceName.replaceAll(" Service Proxy", "")) //networkServiceModelUuid - String networkServiceModelUuid = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "modelUuid") ?: "" + logger.debug("networkServiceName: "+networkServiceName) + String networkServiceModelUuid = jsonUtil.getJsonValue(execution.getVariable("networkServiceModelInfo"), "sourceModelUuid") ?: "" execution.setVariable("networkServiceModelUuid", networkServiceModelUuid) - String sliceParams = execution.getVariable("sliceParams") - logger.debug("sliceParams "+sliceParams) - List<String> bhEndPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints")) - if(bhEndPoints.empty) { - logger.debug("End point info is empty") - exceptionUtil.buildAndThrowWorkflowException(execution, 500, "End point info is empty") - }else { - execution.setVariable("bh_endpoint", bhEndPoints.get(0)) - } + String sliceParams = execution.getVariable("sliceParams") + logger.debug("sliceParams "+sliceParams) + List<String> bhEndPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints")) + if(bhEndPoints.empty) { + logger.debug("End point info is empty") + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "End point info is empty") + }else { + execution.setVariable("bh_endpoint", bhEndPoints.get(0)) + } logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice::: preProcessRequest ****") } @@ -139,10 +143,8 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { si.setWorkloadContext(workloadContext) logger.debug("AAI service Instance Request Payload : "+si.toString()) AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(serviceType).serviceInstance(serviceInstanceId)) - Response response = getAAIClient().create(uri, si) - if(response.getStatus()!=200) { - exceptionUtil.buildAndThrowWorkflowException(execution, response.getStatus(), "AAI instance creation failed") - } + getAAIClient().create(uri, si) + execution.setVariable("nssiServiceInstance", si) } catch (BpmnError e) { throw e; @@ -151,12 +153,14 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { logger.debug(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } + getVnfInstanceName(execution) logger.debug(Prefix+ " Exit DoAllocateCoreNonSharedSlice ::: Enter createNSSIinAAI ****") } public void prepareServiceOrderRequest(DelegateExecution execution) { logger.debug("**** Enter DoAllocateCoreNonSharedSlice ::: prepareServiceOrderRequest ****") - String extAPIPath = UrnPropertiesReader.getVariable("extapi.endpoint", execution) + '/serviceOrder' + //extAPI path hardcoded for testing purposes, will be updated in next patch + String extAPIPath = "https://nbi.onap:8443/nbi/api/v4" + "/serviceOrder" execution.setVariable("ExternalAPIURL", extAPIPath) ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> serviceOrder = new LinkedHashMap() @@ -186,10 +190,10 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { // service Details Map<String, Object> service = new LinkedHashMap() //ServiceName - String serviceName= "nsi_"+execution.getVariable("networkServiceName") + String serviceName= "ns_"+execution.getVariable("networkServiceName")+"_"+execution.getVariable("serviceInstanceId") service.put("name", serviceName) // Service Type - service.put("serviceType", execution.getVariable("serviceType")) + service.put("serviceType", execution.getVariable("subscriptionServiceType")) //Service State service.put("serviceState", "active") Map<String, String> serviceSpecification = new LinkedHashMap() @@ -198,7 +202,7 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { //serviceCharacteristic List List serviceCharacteristicList = new ArrayList() Map<String, Object> serviceCharacteristic = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class); - List serviceCharacteristicListMap = retrieveServiceCharacteristicsAsKeyValue(serviceCharacteristic) + List serviceCharacteristicListMap = retrieveServiceCharacteristicsAsKeyValue(execution, serviceCharacteristic) logger.debug("serviceCharacteristicListMap "+serviceCharacteristicListMap) serviceCharacteristicList.add(serviceCharacteristic) //service.put("serviceCharacteristic", serviceCharacteristicList) @@ -213,10 +217,23 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: prepareServiceOrderRequest****") } - private List retrieveServiceCharacteristicsAsKeyValue(Map serviceCharacteristics) { + private void getVnfInstanceName(DelegateExecution execution) { + //Get NetworkService modelInvariantUuid + String networkServiceModelUuid = execution.getVariable("networkServiceModelUuid") + String json = catalogDbUtils.getServiceResourcesByServiceModelUuid(execution, networkServiceModelUuid, "v2") + logger.debug("json returned: "+json) + logger.debug(("Service Vnfs JSON: "+jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs"))) + List serviceVnfs = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs")) + String networkServiceVnfJson = serviceVnfs.get(0) + String vnfInstanceName = (jsonUtil.getJsonValue(networkServiceVnfJson, "modelInfo.modelInstanceName")).trim() ?: "" + execution.setVariable("vnfInstanceName", vnfInstanceName) + } + + private List retrieveServiceCharacteristicsAsKeyValue(DelegateExecution execution, Map serviceCharacteristics) { logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: retrieveServiceCharacteristicsAsKeyValue ****") List serviceCharacteristicsList = new ArrayList() ObjectMapper mapperObj = new ObjectMapper(); + String vnfInstanceName = execution.getVariable("vnfInstanceName") Map<String, Object> serviceCharacteristicsObject = new LinkedHashMap() for (Map.Entry<String, Integer> entry : serviceCharacteristics.entrySet()) { Map<String, Object> ServiceCharacteristicValueObject = new LinkedHashMap<>() @@ -224,7 +241,7 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { //For G Release we are sending single value from snssaiList if(entry.getKey().equals("snssaiList")) { List sNssaiValue = entry.getValue() - serviceCharacteristicsObject.put("name", "snssai") + serviceCharacteristicsObject.put("name", vnfInstanceName+"_snssai") ServiceCharacteristicValueObject.put("serviceCharacteristicValue", sNssaiValue.get(0)) serviceCharacteristicsObject.put("value", ServiceCharacteristicValueObject) } @@ -303,18 +320,12 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { JSONObject item = items.get(0) JSONObject service = item.get("service") String networkServiceId = service.get("id") - if (networkServiceId == null || networkServiceId.equals("null")) { - prepareFailedOperationStatusUpdate(execution) - return - } + execution.setVariable("networkServiceId", networkServiceId) String serviceOrderState = item.get("state") execution.setVariable("ServiceOrderState", serviceOrderState) // Get serviceOrder State and process progress - if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) { - execution.setVariable("status", "processing") - } - else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) { + if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState) || "INPROGRESS".equalsIgnoreCase(serviceOrderState)) { execution.setVariable("status", "processing") } else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) { @@ -328,6 +339,7 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { msg = "ServiceOrder failed" exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } + logger.debug("NBI serviceOrder state: "+serviceOrderState) } else{ msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode @@ -340,9 +352,6 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: getNBIServiceOrderProgress ****") } - /** - * delay 5 sec - */ public void timeDelay(DelegateExecution execution) { try { logger.debug(Prefix+ " **** DoAllocateCoreNonSharedSlice ::: timeDelay going to sleep for 5 sec") @@ -353,47 +362,42 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { } } - void updateRelationship(DelegateExecution execution) { logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: updateRelationship ****") - String networkServiceInstanceId = execution.getVariable("networkServiceId") String nssiId = execution.getVariable("nssiServiceInstanceId") String globalCustId = execution.getVariable("globalSubscriberId") - String serviceType = execution.getVariable("serviceType") + String serviceType = execution.getVariable("subscriptionServiceType") + logger.debug("networkServiceInstanceId: "+networkServiceInstanceId +" nssiId: "+nssiId +" globalCustId: "+globalCustId+ " serviceType: "+serviceType) try{ //Update NSSI orchestration status nssiServiceInstance ServiceInstance si = execution.getVariable("nssiServiceInstance") + logger.debug("nssiServiceInstance "+si) si.setOrchestrationStatus("activated") + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(nssiId)) + logger.debug("uri to call: "+uri) - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(networkServiceInstanceId)) try { getAAIClient().update(uri, si) } catch (Exception e) { logger.info("Update OrchestrationStatus in AAI failed") - String msg = "Update OrchestrationStatus in AAI failed, " + e.getMessage() + String msg = "Update OrchestrationStatus in AAI failed, " + e exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } - //URI for NSSI AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)); - + logger.debug("nssiUri to update RelationShip : "+nssiUri) //URI for Network Service Instance AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstanceId)) - + logger.debug("networkServiceInstanceUri to update RelationShip : "+networkServiceInstanceUri) // Update Relationship in AAI - Response response = getAAIClient().connect(nssiUri, networkServiceInstanceUri, AAIEdgeLabel.COMPOSED_OF); - - if(response.getStatus()!=200 || response.getStatus()!=201 || response.getStatus()!=202) { - exceptionUtil.buildAndThrowWorkflowException(execution, response.getStatus(), "Set association of NSSI and Network service instance has failed in AAI") - } else { - //end point update - createEndPointsInAai(execution) - execution.setVariable("progress", 100) - execution.setVariable("status", "finished") - execution.setVariable("statusDescription", "DoAllocateCoreNonSharedNSSI success") - setResourceOperationStatus(execution) - } + getAAIClient().connect(nssiUri, networkServiceInstanceUri, AAIEdgeLabel.COMPOSED_OF); + //end point update + createEndPointsInAai(execution) + execution.setVariable("progress", "100") + execution.setVariable("status", "finished") + execution.setVariable("statusDescription", "DoAllocateCoreNonSharedNSSI success") + setResourceOperationStatus(execution) }catch(Exception ex) { String msg = "Exception while creating relationship " + ex.getMessage() logger.info(msg) @@ -402,78 +406,81 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+ " **** Exit DoAllocateCoreNonSharedSlice ::: updateRelationship ****") } - private void createEndPointsInAai(DelegateExecution execution) { - String type = "endpoint" - String function = "core_EP" - int prefixLength = 24 - String addressFamily = "ipv4" - //BH RAN end point update - String bh_endpoint = execution.getVariable("bhEndPoints") - String bh_routeId = UUID.randomUUID().toString() - execution.setVariable("coreEp_ID_bh", bh_routeId) - String role = "CN" - String cnIpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress") - String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId") - String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo") - NetworkRoute bh_ep = new NetworkRoute() - bh_ep.setRouteId(bh_routeId) - bh_ep.setFunction(function) - bh_ep.setRole(role) - bh_ep.setType(type) - bh_ep.setIpAddress(cnIpAddress) - bh_ep.setLogicalInterfaceId(LogicalLinkId) - bh_ep.setNextHop(nextHopInfo) - bh_ep.setPrefixLength(prefixLength) - bh_ep.setAddressFamily(addressFamily) - try { - AAIResourcesClient client = new AAIResourcesClient() - logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString()) - AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId) - client.create(networkRouteUri, bh_ep) - //relationship b/w bh_ep and Core NSSI - def coreNssi = execution.getVariable("NSSIserviceInstanceId") - Relationship relationship = new Relationship() - String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}" - relationship.setRelatedLink(relatedLink) - relationship.setRelatedTo("network-route") - relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") - try { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, - execution.getVariable("globalSubscriberId"), - execution.getVariable("subscriptionServiceType"), - coreNssi).relationshipAPI() - client.create(uri, relationship) - } catch (BpmnError e) { - throw e - } catch (Exception ex) { - String msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage() - logger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - } catch (BpmnError e) { - throw e - } catch (Exception ex) { - String msg = "Exception in createEndPointsInAai " + ex.getMessage() - logger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - } - /** - * prepare ResourceOperation status + * creates EndPoints in AAI * @param execution - * @param operationType */ + private void createEndPointsInAai(DelegateExecution execution) { + String type = "endpoint" + String function = "core_EP" + int prefixLength = 24 + String addressFamily = "ipv4" + //BH end point update + String bh_endpoint = execution.getVariable("bh_endpoint") + String bh_routeId = UUID.randomUUID().toString() + execution.setVariable("coreEp_ID_bh", bh_routeId) + String role = "CN" + String cnIpAddress = jsonUtil.getJsonValue(bh_endpoint, "IpAddress") + String LogicalLinkId = jsonUtil.getJsonValue(bh_endpoint, "LogicalLinkId") + String nextHopInfo = jsonUtil.getJsonValue(bh_endpoint, "nextHopInfo") + NetworkRoute bh_ep = new NetworkRoute() + logger.debug("bh_endpoint: "+bh_endpoint +" "+ "bh_routeId: "+bh_routeId +" "+ "cnIpAddress: "+cnIpAddress +" "+ "role: "+role +" "+ "cnIpAddress: "+cnIpAddress +" "+ "LogicalLinkId: "+LogicalLinkId +" "+ "nextHopInfo: "+nextHopInfo +" "+ "bh_ep: "+bh_ep) + bh_ep.setRouteId(bh_routeId) + bh_ep.setFunction(function) + bh_ep.setRole(role) + bh_ep.setType(type) + bh_ep.setIpAddress(cnIpAddress) + bh_ep.setLogicalInterfaceId(LogicalLinkId) + bh_ep.setNextHop(nextHopInfo) + bh_ep.setPrefixLength(prefixLength) + bh_ep.setAddressFamily(addressFamily) + try { + AAIResourcesClient client = new AAIResourcesClient() + logger.debug("creating bh endpoint . ID : "+bh_routeId+" node details : "+bh_ep.toString()) + AAIResourceUri networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), bh_routeId) + client.create(networkRouteUri, bh_ep) + //relationship b/w bh_ep and Core NSSI + def coreNssi = execution.getVariable("nssiServiceInstanceId") + Relationship relationship = new Relationship() + String relatedLink = "aai/v21/network/network-routes/network-route/${bh_routeId}" + relationship.setRelatedLink(relatedLink) + relationship.setRelatedTo("network-route") + relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + logger.debug("networkRouteUri: "+networkRouteUri+"relationship: "+relationship) + try { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + coreNssi).relationshipAPI() + logger.debug("uri: "+uri) + client.create(uri, relationship) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in createRelationShipInAAI. " + ex.getMessage() + logger.debug(msg+": "+ex) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in createEndPointsInAai " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + private void setResourceOperationStatus(DelegateExecution execution) { logger.debug(Prefix+ " **** Enter DoAllocateCoreNonSharedSlice ::: setResourceOperationStatus ****") - String serviceId = execution.getVariable("nssiId") + String serviceId = execution.getVariable("nsiId") String jobId = execution.getVariable("jobId") String nsiId = execution.getVariable("nsiId") - String operationType = execution.getVariable("operationType") + String operationType = "ALLOCATE" ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() resourceOperationStatus.setServiceId(serviceId) resourceOperationStatus.setOperationId(jobId) resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setResourceInstanceID(nssiId) resourceOperationStatus.setOperType(operationType) resourceOperationStatus.setStatus(execution.getVariable("status")) resourceOperationStatus.setProgress(execution.getVariable("progress")) @@ -484,17 +491,21 @@ class DoAllocateCoreNonSharedSlice extends AbstractServiceTaskProcessor { void prepareFailedOperationStatusUpdate(DelegateExecution execution){ logger.debug(Prefix + " **** Enter DoAllocateCoreNonSharedSlice ::: prepareFailedOperationStatusUpdate ****") - String serviceId = execution.getVariable("nssiId") + String serviceId = execution.getVariable("nsiId") String jobId = execution.getVariable("jobId") String nsiId = execution.getVariable("nsiId") - String operationType = execution.getVariable("operationType") - + String nssiId = execution.getVariable("nssiId") + String operationType = "ALLOCATE" + //modelUuid + String modelUuid= execution.getVariable("modelUuid") + logger.debug("serviceId: "+serviceId +" "+ "jobId: "+jobId +" "+ "nsiId: "+nsiId +" "+ "operationType: "+operationType) ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() resourceOperationStatus.setServiceId(serviceId) + resourceOperationStatus.setJobId(jobId) resourceOperationStatus.setOperationId(jobId) - resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setResourceTemplateUUID(modelUuid) resourceOperationStatus.setOperType(operationType) - resourceOperationStatus.setProgress(0) + resourceOperationStatus.setProgress("0") resourceOperationStatus.setStatus("failed") resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed") requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreSharedSlice.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreSharedSlice.groovy index 5ecfc9a872..b3c99c6e9a 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreSharedSlice.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateCoreSharedSlice.groovy @@ -115,7 +115,7 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: getNetworkInstanceAssociatedWithNssiId ****") //NSSI Id as service Instance Id to get from Request - String serviceInstanceId = execution.getVariable("serviceInstanceID") + String serviceInstanceId = execution.getVariable("nssiId") String errorMsg = "query Network Service Instance from AAI failed" AAIResultWrapper wrapper = queryAAI(execution, Types.SERVICE_INSTANCE, serviceInstanceId, errorMsg) @@ -304,14 +304,6 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: getVnfRelationships ****") } - - /** - * query AAI - * @param execution - * @param aaiObjectName - * @param instanceId - * @return AAIResultWrapper - */ private AAIResultWrapper queryAAI(DelegateExecution execution, AAIObjectName aaiObjectName, String instanceId, String errorMsg) { logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: queryAAI ****") String globalSubscriberId = execution.getVariable("globalSubscriberId") @@ -368,6 +360,8 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { Map vnfMap = vnfList.get(0) ModelInfo vnfModelInfo = vnfMap.get("modelInfo") + vnfModelInfo.setModelCustomizationId(vnfModelInfo.getModelCustomizationUuid()) + vnfModelInfo.setModelVersionId(vnfModelInfo.getModelId()) logger.debug("vnfModelInfo "+vnfModelInfo) //List of VFModules @@ -380,6 +374,8 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { //Traverse VFModules List and add in vfModelInfoList for (vfModule in vfModuleList) { ModelInfo vfModelInfo = vfModule.get("modelInfo") + vfModelInfo.setModelCustomizationId(vfModelInfo.getModelCustomizationUuid()) + vfModelInfo.setModelVersionId(vfModelInfo.getModelId()) logger.debug("vfModelInfo "+vfModelInfo) vfModelInfoList.add(vfModelInfo) } @@ -410,25 +406,31 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { //Individual VFModule List Map<String, Object> vfModuleValues = new LinkedHashMap<>() vfModuleValues.put("modelInfo", vfModuleModelInfo) - vfModuleValues.put("instanceName", vfModuleModelInfo.getModelInstanceName()) + vfModuleValues.put("instanceName", vfModuleModelInfo.getModelName()) //VFModule InstanceParams should be empty or this field should not be there? List<Map<String, Object>> vfModuleInstanceParams = new ArrayList<>() vfModuleValues.put("instanceParams", vfModuleInstanceParams) + vfModules.add(vfModuleValues) } //Vnf intsanceParams Map<String, Object> sliceProfile = mapper.readValue(execution.getVariable("sliceProfile"), Map.class); - List vnfInstanceParamsList = new ArrayList<>() + List<Map<String, Object>> vnfInstanceParamsList = new ArrayList<>() String supportedsNssaiJson= prepareVnfInstanceParamsJson(execution) - vnfInstanceParamsList.add(supportedsNssaiJson) + + Map<String, Object> supportedNssai= new LinkedHashMap<>() + supportedNssai.put("supportedsNssai", supportedsNssaiJson) + vnfInstanceParamsList.add(supportedNssai) Platform platform = new Platform() - platform.setPlatformName(execution.getVariable("platform")) + String platformName = execution.getVariable("platformName") + platform.setPlatformName(platformName) LineOfBusiness lineOfbusiness = new LineOfBusiness() - lineOfbusiness.setLineOfBusinessName(execution.getVariable("lineOfBusiness")) + String lineOfBusinessName = execution.getVariable("lineOfBusinessName") + lineOfbusiness.setLineOfBusinessName(lineOfBusinessName) //Vnf Values Map<String, Object> vnfValues = new LinkedHashMap<>() @@ -438,7 +440,7 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { vnfValues.put("cloudConfiguration", cloudConfiguration) vnfValues.put("vfModules", vfModules) vnfValues.put("modelInfo", vnfModelInfo) - vnfValues.put("instanceName", execution.getVariable("vnfInstanceName")) + vnfValues.put("instanceName", vnfModelInfo.getModelInstanceName()) vnfValues.put("instanceParams",vnfInstanceParamsList) vnfModelInfoList.add(vnfValues) @@ -496,10 +498,8 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { Map<String, Object> requestDetailsMap = new LinkedHashMap<>() requestDetailsMap.put("requestDetails", requestDetails) String requestPayload = mapper.writeValueAsString(requestDetailsMap) - logger.debug("requestDetails "+requestPayload) execution.setVariable("requestPayload", requestPayload) - logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: prepareSOMacroRequestPayLoad ****") } @@ -508,14 +508,11 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { List instanceParamsvalues = execution.getVariable("snssaiAndOrchStatusList") Map<String, Object> nSsai= new LinkedHashMap<>() nSsai.put("sNssai", instanceParamsvalues) - String supportedsNssaiJson = mapper.writeValueAsString(nSsai) //SupportedNssai - Map<String, Object> supportedNssai= new LinkedHashMap<>() - supportedNssai.put("supportedNssai", supportedsNssaiJson) - logger.debug("**** supportedsNssaiJson**** "+supportedNssai) + logger.debug("**** supportedsNssaiJson**** "+supportedsNssaiJson) logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: prepareVnfInstanceParamsJson ****") - return supportedNssai + return supportedsNssaiJson } public void sendPutRequestToSOMacro(DelegateExecution execution) { @@ -523,14 +520,9 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { try { String msoEndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) String url = msoEndpoint+"/serviceInstantiation/v7/serviceInstances/"+execution.getVariable("networkServiceInstanceId")+"/vnfs/"+execution.getVariable("vnfId") - String requestBody = execution.getVariable("requestPayload") - - String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) - String basicAuthValue = utils.encrypt(basicAuth, msoKey) - String encodeString = utils.getBasicAuth(basicAuthValue, msoKey) - + String encodeString = "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==" + logger.debug("msoEndpoint: "+msoEndpoint +" "+ "url: "+url +" requestBody: "+requestBody +" "+ "encodeString: "+encodeString) HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO) httpClient.addAdditionalHeader("Authorization", encodeString) httpClient.addAdditionalHeader("Accept", "application/json") @@ -546,84 +538,93 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: sendPostRequestToSOMacro ****") } - /** - * Handle SO Response for PUT and prepare update operation status - * @param execution - */ private void handleSOResponse(Response httpResponse, DelegateExecution execution){ logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: handleSOResponse ****") - int soResponseCode = httpResponse.getStatus() logger.debug("soResponseCode : "+soResponseCode) if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) { String soResponse = httpResponse.readEntity(String.class) - String operationId = execution.getVariable("operationId") - def macroOperationId = jsonUtil.getJsonValue(soResponse, "operationId") + logger.debug("soResponse: "+soResponse) + logger.debug("soResponse JsonUtil: "+jsonUtil.getJsonValue(soResponse, "requestReferences.requestId")) + def macroOperationId = jsonUtil.getJsonValue(soResponse, "requestReferences.requestId") + def requestSelfLink = jsonUtil.getJsonValue(soResponse, "requestReferences.requestSelfLink") execution.setVariable("macroOperationId", macroOperationId) + execution.setVariable("requestSelfLink", requestSelfLink) execution.setVariable("isSOTimeOut", "no") execution.setVariable("isSOResponseSucceed","yes") } else { - String serviceName = execution.getVariable("serviceInstanceName") execution.setVariable("isSOResponseSucceed","no") prepareFailedOperationStatusUpdate(execution) } logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: handleSOResponse ****") } - /** - * prepare to call sub process CheckProcessStatus - * @param execution - */ - void prepareCallCheckProcessStatus(DelegateExecution execution){ - logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: prepareCallCheckProcessStatus ****") - def successConditions = new ArrayList<>() - successConditions.add("finished") - execution.setVariable("successConditions", successConditions) - def errorConditions = new ArrayList<>() - errorConditions.add("error") - execution.setVariable("errorConditions", errorConditions) - execution.setVariable("processServiceType", "Network service") - execution.setVariable("subOperationType", "PUT") - execution.setVariable("initProgress", 20) - execution.setVariable("endProgress",90) - execution.setVariable("timeOut", TIMEOUT) - logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: prepareCallCheckProcessStatus ****") + public void getSOPUTProgress(DelegateExecution execution) { + logger.debug(Prefix+ " **** Enter DoAllocateCoreSharedSlice ::: getSOPUTProgress ****") + String url= execution.getVariable("requestSelfLink") + logger.debug("url "+url) + HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO) + //Hardcoding for now, will be updated in next patch + httpClient.addAdditionalHeader("Authorization", "Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==") + httpClient.addAdditionalHeader("Accept", "application/json") + Response httpResponse = httpClient.get() + logger.debug("httpResponse "+httpResponse) + int soResponseCode = httpResponse.getStatus() + logger.debug("soResponseCode : "+soResponseCode) + if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) { + String soResponse = httpResponse.readEntity(String.class) + logger.debug("soResponse: "+soResponse) + String requestState= jsonUtil.getJsonValue(soResponse, "request.requestStatus.requestState") + logger.debug("requestState: "+requestState) + execution.setVariable("requestState", requestState) + } else { + execution.setVariable("isSOResponseSucceed","no") + prepareFailedOperationStatusUpdate(execution) + } + logger.debug(Prefix+ " **** Exit DoAllocateCoreSharedSlice ::: getSOPUTProgress ****") + } + + public void timeDelay(DelegateExecution execution) { + try { + logger.debug(Prefix+ " **** DoAllocateCoreSharedSlice ::: timeDelay going to sleep for 5 sec") + Thread.sleep(5000) + logger.debug("**** DoAllocateCoreNonSharedSlice ::: timeDelay wakeup after 5 sec") + } catch(InterruptedException e) { + logger.error(Prefix+ " **** DoAllocateCoreSharedSlice ::: timeDelay exception" + e) + } } void prepareUpdateResourceOperationStatus(DelegateExecution execution) { logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: prepareUpdateResourceOperationStatus ****") //Prepare Update Status for PUT failure and success - if(execution.getVariable("isTimeOut").equals("YES")) { - logger.debug("TIMEOUT - SO PUT Failure") - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SO PUT Failure") - } else { + if("COMPLETED".equals(execution.getVariable("requestState"))) { execution.setVariable("progress", "100") execution.setVariable("status", "finished") execution.setVariable("operationContent", "AllocteCoreNSSI successful.") - logger.debug("prepareFailureStatus,result:${execution.getVariable("result")}, reason: ${execution.getVariable("reason")}") + logger.debug("Success ,result:${execution.getVariable("result")}, reason: ${execution.getVariable("reason")}") + } else { + logger.debug("SO PUT Failure") + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SO PUT Failure") } setResourceOperationStatus(execution) logger.debug(Prefix+" **** Exit DoAllocateCoreSharedSlice ::: prepareUpdateResourceOperationStatus ****") } - /** - * prepare ResourceOperation status - * @param execution - * @param operationType - */ private void setResourceOperationStatus(DelegateExecution execution) { logger.debug(Prefix+" **** Enter DoAllocateCoreSharedSlice ::: setResourceOperationStatus ****") String serviceId = execution.getVariable("nssiId") String jobId = execution.getVariable("jobId") String nsiId = execution.getVariable("nsiId") String operationType = execution.getVariable("operationType") + logger.debug("serviceId: "+serviceId +" "+ " jobId: "+jobId +" "+ " nsiId: "+nsiId+" nssiId: "+nssiId+" operationType: "+operationType) ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() resourceOperationStatus.setServiceId(serviceId) resourceOperationStatus.setOperationId(jobId) resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setResourceInstanceID(nssiId) resourceOperationStatus.setOperType(operationType) resourceOperationStatus.setStatus("finished") resourceOperationStatus.setProgress("100") @@ -634,17 +635,19 @@ class DoAllocateCoreSharedSlice extends AbstractServiceTaskProcessor { void prepareFailedOperationStatusUpdate(DelegateExecution execution){ logger.debug(Prefix + " **** Enter DoAllocateCoreSharedSlice ::: prepareFailedOperationStatusUpdate ****") - String serviceId = execution.getVariable("nssiId") + String serviceId = execution.getVariable("nsiId") String jobId = execution.getVariable("jobId") String nsiId = execution.getVariable("nsiId") - String operationType = execution.getVariable("operationType") - + String operationType = "ALLOCATE" + logger.debug("serviceId: "+serviceId +" "+ " jobId: "+jobId +" "+ " nsiId: "+nsiId+" operationType: "+operationType) + String modelUuid= execution.getVariable("modelUuid") ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() resourceOperationStatus.setServiceId(serviceId) + resourceOperationStatus.setJobId(jobId) resourceOperationStatus.setOperationId(jobId) - resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setResourceTemplateUUID(modelUuid) resourceOperationStatus.setOperType(operationType) - resourceOperationStatus.setProgress(0) + resourceOperationStatus.setProgress("0") resourceOperationStatus.setStatus("failed") resourceOperationStatus.setStatusDescription("Core NSSI Allocate Failed") requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus) |