diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src')
5 files changed, 3126 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AnNssmfutils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AnNssmfutils.groovy new file mode 100644 index 0000000000..d59f865b01 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AnNssmfutils.groovy @@ -0,0 +1,448 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2020, 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import com.google.gson.JsonArray +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils +import org.onap.so.bpmn.common.scripts.OofUtils +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import java.sql.Timestamp +import java.util.List +import static org.apache.commons.lang3.StringUtils.isBlank +import com.google.gson.JsonObject +import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import javax.ws.rs.NotFoundException +import org.onap.so.beans.nsmf.AllocateTnNssi +import org.onap.so.beans.nsmf.DeAllocateNssi +import org.onap.so.beans.nsmf.EsrInfo +import org.onap.so.beans.nsmf.ServiceInfo +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aai.domain.yang.SliceProfile +import org.onap.aai.domain.yang.SliceProfiles +import org.onap.aai.domain.yang.Relationship + +class AnNssmfUtils { + + private static final Logger logger = LoggerFactory.getLogger(AnNssmfUtils.class) + ObjectMapper objectMapper = new ObjectMapper(); + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + public String buildSelectRANNSSIRequest(String requestId, String messageType, String UUID,String invariantUUID, + String name, Map<String, Object> profileInfo, List<String> nsstInfoList, JsonArray capabilitiesList, Boolean preferReuse){ + + def transactionId = requestId + logger.debug( "transactionId is: " + transactionId) + String correlator = requestId + String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator + ObjectMapper objectMapper = new ObjectMapper(); + String profileJson = objectMapper.writeValueAsString(profileInfo); + String nsstInfoListString = objectMapper.writeValueAsString(nsstInfoList); + //Prepare requestInfo object + JsonObject requestInfo = new JsonObject() + requestInfo.addProperty("transactionId", transactionId) + requestInfo.addProperty("requestId", requestId) + requestInfo.addProperty("callbackUrl", callbackUrl) + requestInfo.addProperty("sourceId","SO" ) + requestInfo.addProperty("timeout", 600) + requestInfo.addProperty("numSolutions", 1) + + //Prepare serviceInfo object + JsonObject ranNsstInfo = new JsonObject() + ranNsstInfo.addProperty("UUID", UUID) + ranNsstInfo.addProperty("invariantUUID", invariantUUID) + ranNsstInfo.addProperty("name", name) + + JsonObject json = new JsonObject() + json.add("requestInfo", requestInfo) + json.add("NSTInfo", ranNsstInfo) + json.addProperty("serviceProfile", profileJson) + json.addProperty("NSSTInfo", nsstInfoListString) + json.add("subnetCapabilities", capabilitiesList) + json.addProperty("preferReuse", preferReuse) + + return json.toString() +} + +public String buildCreateTNNSSMFSubnetCapabilityRequest() { + EsrInfo esrInfo = new EsrInfo() + esrInfo.setNetworkType("TN") + esrInfo.setVendor("ONAP") + + JsonArray subnetTypes = new JsonArray() + subnetTypes.add("TN_FH") + subnetTypes.add("TN_MH") + JsonObject response = new JsonObject() + response.add("subnetCapabilityQuery", subnetTypes) + response.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo)) + return response.toString() +} + +public String buildCreateANNFNSSMFSubnetCapabilityRequest() { + EsrInfo esrInfo = new EsrInfo() + esrInfo.setNetworkType("AN") + esrInfo.setVendor("ONAP") + + JsonArray subnetTypes = new JsonArray() + subnetTypes.add("AN_NF") + JsonObject response = new JsonObject() + response.add("subnetCapabilityQuery", subnetTypes) + response.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo)) + return response.toString() +} +public void createDomainWiseSliceProfiles(List<String> ranConstituentSliceProfiles, DelegateExecution execution) { + + for(String profile : ranConstituentSliceProfiles) { + String domainType = jsonUtil.getJsonValue(profile, "domainType") + switch(domainType) { + case "AN_NF": + execution.setVariable("ranNfSliceProfile", profile) + break + case "TN_FH": + execution.setVariable("tnFhSliceProfile", profile) + break + case "TN_MH": + execution.setVariable("tnMhSliceProfile", profile) + break + default: + logger.debug("No expected match found for current domainType") + logger.error("No expected match found for current domainType "+ domainType) + exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current domainType "+ domainType) + } + + } +} + +public void createSliceProfilesInAai(DelegateExecution execution) { + + org.onap.aai.domain.yang.ServiceInstance ANNF_sliceProfileInstance = new ServiceInstance(); + org.onap.aai.domain.yang.ServiceInstance TNFH_sliceProfileInstance = new ServiceInstance(); + org.onap.aai.domain.yang.ServiceInstance TNMH_sliceProfileInstance = new ServiceInstance(); + //generate slice profile ids and slice profile instance ids + String ANNF_sliceProfileInstanceId = UUID.randomUUID().toString() + String ANNF_sliceProfileId = UUID.randomUUID().toString() + String TNFH_sliceProfileInstanceId = UUID.randomUUID().toString() + String TNFH_sliceProfileId = UUID.randomUUID().toString() + String TNMH_sliceProfileInstanceId = UUID.randomUUID().toString() + String TNMH_sliceProfileId = UUID.randomUUID().toString() + execution.setVariable("ANNF_sliceProfileInstanceId",ANNF_sliceProfileInstanceId) + execution.setVariable("ANNF_sliceProfileId",ANNF_sliceProfileId) + execution.setVariable("TNFH_sliceProfileInstanceId",TNFH_sliceProfileInstanceId) + execution.setVariable("TNFH_sliceProfileId",TNFH_sliceProfileId) + execution.setVariable("TNMH_sliceProfileInstanceId",TNMH_sliceProfileInstanceId) + execution.setVariable("TNMH_sliceProfileId",TNMH_sliceProfileId) + //slice profiles assignment + org.onap.aai.domain.yang.SliceProfiles ANNF_SliceProfiles = new SliceProfiles() + org.onap.aai.domain.yang.SliceProfiles TNFH_SliceProfiles = new SliceProfiles() + org.onap.aai.domain.yang.SliceProfiles TNMH_SliceProfiles = new SliceProfiles() + org.onap.aai.domain.yang.SliceProfile ANNF_SliceProfile = new SliceProfile() + org.onap.aai.domain.yang.SliceProfile TNFH_SliceProfile = new SliceProfile() + org.onap.aai.domain.yang.SliceProfile TNMH_SliceProfile = new SliceProfile() + ANNF_SliceProfile = createSliceProfile("AN-NF", execution) + TNFH_SliceProfile = createSliceProfile("TN-FH",execution) + TNMH_SliceProfile = createSliceProfile("TN-MH",execution) + + ANNF_SliceProfiles.getSliceProfile().add(ANNF_SliceProfile) + TNFH_SliceProfiles.getSliceProfile().add(TNFH_SliceProfile) + TNMH_SliceProfiles.getSliceProfile().add(TNMH_SliceProfile) + + logger.debug("sliceProfiles : 1. "+ANNF_SliceProfiles.toString()+"\n 2. "+TNFH_SliceProfiles.toString()+"\n 3. "+TNMH_SliceProfiles.toString()) + //ANNF slice profile instance creation + ANNF_sliceProfileInstance.setServiceInstanceId(ANNF_sliceProfileInstanceId) + String sliceInstanceName = "sliceprofile_"+ANNF_sliceProfileId + ANNF_sliceProfileInstance.setServiceInstanceName(sliceInstanceName) + String serviceType = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "sST") + ANNF_sliceProfileInstance.setServiceType(serviceType) + String serviceStatus = "deactivated" + ANNF_sliceProfileInstance.setOrchestrationStatus(serviceStatus) + String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "plmnIdList") + ANNF_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + String serviceRole = "slice-profile-instance" + ANNF_sliceProfileInstance.setServiceRole(serviceRole) + List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class) + String snssai = snssaiList.get(0) + ANNF_sliceProfileInstance.setEnvironmentContext(snssai) + ANNF_sliceProfileInstance.setWorkloadContext("AN-NF") + ANNF_sliceProfileInstance.setSliceProfiles(ANNF_SliceProfiles) + logger.debug("completed ANNF sliceprofileinstance build "+ ANNF_sliceProfileInstance.toString()) + //TNFH slice profile instance creation + TNFH_sliceProfileInstance.setServiceInstanceId(TNFH_sliceProfileInstanceId) + sliceInstanceName = "sliceprofile_"+TNFH_sliceProfileId + TNFH_sliceProfileInstance.setServiceInstanceName(sliceInstanceName) + serviceType = jsonUtil.getJsonValue(execution.getVariable("tnFhSliceProfile"), "sST") + TNFH_sliceProfileInstance.setServiceType(serviceType) + TNFH_sliceProfileInstance.setOrchestrationStatus(serviceStatus) + serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("tnFhSliceProfile"), "plmnIdList") + TNFH_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + TNFH_sliceProfileInstance.setServiceRole(serviceRole) + TNFH_sliceProfileInstance.setEnvironmentContext(snssai) + TNFH_sliceProfileInstance.setWorkloadContext("TN-FH") + TNFH_sliceProfileInstance.setSliceProfiles(TNFH_SliceProfiles) + logger.debug("completed TNFH sliceprofileinstance build "+TNFH_sliceProfileInstance) + //TNMH slice profile instance creation + TNMH_sliceProfileInstance.setServiceInstanceId(TNMH_sliceProfileInstanceId) + sliceInstanceName = "sliceprofile_"+TNMH_sliceProfileId + TNMH_sliceProfileInstance.setServiceInstanceName(sliceInstanceName) + serviceType = jsonUtil.getJsonValue(execution.getVariable("tnMhSliceProfile"), "sST") + TNMH_sliceProfileInstance.setServiceType(serviceType) + TNMH_sliceProfileInstance.setOrchestrationStatus(serviceStatus) + serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("tnMhSliceProfile"), "plmnIdList") + TNMH_sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + TNMH_sliceProfileInstance.setServiceRole(serviceRole) + TNMH_sliceProfileInstance.setEnvironmentContext(snssai) + TNMH_sliceProfileInstance.setWorkloadContext("TN-MH") + TNMH_sliceProfileInstance.setSliceProfiles(TNMH_SliceProfiles) + logger.debug("completed TNMH sliceprofileinstance build "+TNMH_sliceProfileInstance) + String msg = "" + try { + + AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), ANNF_sliceProfileInstanceId) + client.create(sliceProfileUri, ANNF_sliceProfileInstance) + + AAIResourceUri sliceProfileUri1 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), TNFH_sliceProfileInstanceId) + client.create(sliceProfileUri1, TNFH_sliceProfileInstance) + + AAIResourceUri sliceProfileUri2 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), TNMH_sliceProfileInstanceId) + client.create(sliceProfileUri2, TNMH_sliceProfileInstance) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + +} +private SliceProfile createSliceProfile(String domainType, DelegateExecution execution) { + + SliceProfile result = new SliceProfile() + Map<String,Object> profile + switch(domainType) { + case "AN-NF": + profile = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class)//pending fields - maxBandwidth, sST, pLMNIdList, cSReliabilityMeanTime, + //msgSizeByte, maxNumberofPDUSessions,overallUserDensity,transferIntervalTarget + result.setJitter(profile.get("jitter")) + result.setLatency(profile.get("latency")) + result.setResourceSharingLevel(profile.get("resourceSharingLevel")) + result.setSNssai(profile.get("sNSSAI")) + result.setUeMobilityLevel(profile.get("uEMobilityLevel")) + result.setMaxNumberOfUEs(profile.get("maxNumberofUEs")) + result.setActivityFactor(profile.get("activityFactor")) + result.setCoverageAreaTAList(profile.get("coverageAreaTAList")) + result.setCsAvailability(profile.get("cSAvailabilityTarget")) + result.setExpDataRateDL(profile.get("expDataRateDL")) + result.setExpDataRateUL(profile.get("expDataRateUL")) + result.setSurvivalTime(profile.get("survivalTime")) + result.setAreaTrafficCapDL(profile.get("areaTrafficCapDL")) + result.setAreaTrafficCapUL(profile.get("areaTrafficCapUL")) + result.setExpDataRate(profile.get("expDataRate")) + result.setProfileId(execution.getVariable("ANNF_sliceProfileId")) + break + case "TN-FH": + profile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class) //pending fields - maxBandwidth, sST, pLMNIdList + result.setJitter(profile.get("jitter")) + result.setLatency(profile.get("latency")) + result.setResourceSharingLevel(profile.get("resourceSharingLevel")) + result.setSNssai(profile.get("sNSSAI")) + result.setProfileId(execution.getVariable("TNFH_sliceProfileId")) + break + case "TN-MH": + profile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class)//pending fields - maxBandwidth, sST, pLMNIdList + result.setJitter(profile.get("jitter")) + result.setLatency(profile.get("latency")) + result.setResourceSharingLevel(profile.get("resourceSharingLevel")) + result.setSNssai(profile.get("sNSSAI")) + result.setProfileId(execution.getVariable("TNMH_sliceProfileId")) + break + default: + logger.debug("No expected match found for current domainType") + logger.error("No expected match found for current domainType "+ domainType) + exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current domainType "+ domainType) + } + return result +} + + /** + * create relationship in AAI + */ + public createRelationShipInAAI = { DelegateExecution execution, final Relationship relationship, String instanceId -> + logger.debug("createRelationShipInAAI Start") + String msg + AAIResourcesClient client = new AAIResourcesClient() + try { + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + instanceId).relationshipAPI() + client.create(uri, relationship) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in CreateCommunicationService.createRelationShipInAAI. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("createRelationShipInAAI Exit") + + } + + public void processRanNfModifyRsp(DelegateExecution execution) { + String status = execution.getVariable("ranNfStatus") + if(status.equals("success")) { + logger.debug("completed Ran NF NSSI modification ... proceeding with the flow") + } + else { + logger.error("failed to modify ran Nf nssi") + exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "modify ran nf nssi not successfull") + } + } + + public String buildCreateNSSMFRequest(DelegateExecution execution, String domainType, String action) { + EsrInfo esrInfo = new EsrInfo() + esrInfo.setNetworkType("TN") + esrInfo.setVendor("ONAP") + String esrInfoString = objectMapper.writeValueAsString(esrInfo) + JsonObject response = new JsonObject() + JsonObject allocateTnNssi = new JsonObject() + JsonObject serviceInfo = new JsonObject() + JsonArray transportSliceNetworksList = new JsonArray() + JsonArray connectionLinksList = new JsonArray() + JsonObject connectionLinks = new JsonObject() + if(action.equals("allocate")){ + Map<String, String> endpoints + if(domainType.equals("TN_FH")) { + serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid")) + serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid")) + allocateTnNssi.addProperty("nsstId", execution.getVariable("TNFH_modelUuid")) + allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_modelName")) + Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnFhSliceProfile"), Map.class) + sliceProfile.put("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId")) + String sliceProfileString = objectMapper.writeValueAsString(sliceProfile) + allocateTnNssi.addProperty("sliceProfile", sliceProfileString) + endpoints.put("transportEndpointA", execution.getVariable("tranportEp_ID_RU")) + endpoints.put("transportEndpointB", execution.getVariable("tranportEp_ID_DUIN")) + String endpointsString = objectMapper.writeValueAsString(endpoints) + connectionLinksList.add(endpointsString) + }else if(domainType.equals("TN_MH")) { + serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid")) + serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid")) + allocateTnNssi.addProperty("nsstId", execution.getVariable("TNMH_modelUuid")) + allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_modelName")) + Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("tnMhSliceProfile"), Map.class) + sliceProfile.put("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId")) + String sliceProfileString = objectMapper.writeValueAsString(sliceProfile) + allocateTnNssi.addProperty("sliceProfile", sliceProfileString) + endpoints.put("transportEndpointA", execution.getVariable("tranportEp_ID_DUEG")) + endpoints.put("transportEndpointB", execution.getVariable("tranportEp_ID_CUIN")) + String endpointsString = objectMapper.writeValueAsString(endpoints) + connectionLinksList.add(endpointsString) + } + + //Connection links + connectionLinks.add("connectionLinks", connectionLinksList) + transportSliceNetworksList.add(connectionLinks) + allocateTnNssi.add("transportSliceNetworks", transportSliceNetworksList) + allocateTnNssi.addProperty("nssiId", null) + serviceInfo.addProperty("nssiId", null) + }else if(action.equals("modify-allocate")) { + if(domainType.equals("TN_FH")) { + serviceInfo.addProperty("serviceInvariantUuid", null) + serviceInfo.addProperty("serviceUuid", null) + allocateTnNssi.addProperty("nsstId", null) + allocateTnNssi.addProperty("nssiName", execution.getVariable("TNFH_nssiName")) + allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId")) + allocateTnNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI")) + serviceInfo.addProperty("nssiId", execution.getVariable("TNFH_NSSI")) + }else if(domainType.equals("TN_MH")) { + serviceInfo.addProperty("serviceInvariantUuid", null) + serviceInfo.addProperty("serviceUuid", null) + allocateTnNssi.addProperty("nsstId", null) + allocateTnNssi.addProperty("nssiName", execution.getVariable("TNMH_nssiName")) + allocateTnNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId")) + allocateTnNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI")) + serviceInfo.addProperty("nssiId", execution.getVariable("TNMH_NSSI")) + } + } + String nsiInfo = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "nsiInfo") + allocateTnNssi.addProperty("nsiInfo", nsiInfo) + allocateTnNssi.addProperty("scriptName", "TN1") + serviceInfo.addProperty("nsiId", execution.getVariable("nsiId")) + serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId")) + serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType")) + response.addProperty("esrInfo", esrInfoString) + response.add("serviceInfo", serviceInfo) + response.add("allocateTnNssi", allocateTnNssi) + return response.toString() + } + + public String buildDeallocateNssiRequest(DelegateExecution execution,String domainType) { + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + JsonObject deAllocateNssi = new JsonObject() + deAllocateNssi.addProperty("snssaiList", execution.getVariable("snssaiList")) + deAllocateNssi.addProperty("nsiId", execution.getVariable("nsiId")) + deAllocateNssi.addProperty("modifyAction", true) + deAllocateNssi.addProperty("terminateNssiOption", 0) + deAllocateNssi.addProperty("scriptName", "TN1") + + if(domainType.equals("TN_FH")) { + deAllocateNssi.addProperty("nssiId", execution.getVariable("TNFH_NSSI")) + deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNFH_sliceProfileInstanceId")) + }else if(domainType.equals("TN_MH")) { + deAllocateNssi.addProperty("nssiId", execution.getVariable("TNMH_NSSI")) + deAllocateNssi.addProperty("sliceProfileId", execution.getVariable("TNMH_sliceProfileInstanceId")) + } + + EsrInfo esrInfo = new EsrInfo() + esrInfo.setVendor("ONAP") + esrInfo.setNetworkType("TN") + + JsonObject serviceInfo = new JsonObject() + serviceInfo.addProperty("serviceInvariantUuid", null) + serviceInfo.addProperty("serviceUuid", null) + serviceInfo.addProperty("globalSubscriberId", globalSubscriberId) + serviceInfo.addProperty("subscriptionServiceType", subscriptionServiceType) + + JsonObject json = new JsonObject() + json.add("deAllocateNssi", deAllocateNssi) + json.addProperty("esrInfo", objectMapper.writeValueAsString(esrInfo)) + json.add("serviceInfo", serviceInfo) + return json.toString() + + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateAccessNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateAccessNSSI.groovy new file mode 100644 index 0000000000..3df0d3d6f0 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateAccessNSSI.groovy @@ -0,0 +1,1041 @@ +/* + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2020, 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils +import org.onap.so.bpmn.common.scripts.OofUtils +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import java.sql.Timestamp +import java.util.List +import static org.apache.commons.lang3.StringUtils.isBlank +import com.google.gson.JsonObject +import com.fasterxml.jackson.databind.ObjectMapper +import com.google.gson.JsonArray +import org.onap.aai.domain.yang.Relationship +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.so.beans.nsmf.AllocateTnNssi +import org.onap.so.beans.nsmf.EsrInfo +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.domain.ServiceDecomposition +import org.onap.so.bpmn.core.domain.ServiceInstance +import org.onap.so.bpmn.core.domain.ServiceProxy +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.aai.AAINamespaceConstants +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aai.domain.yang.NetworkPolicy +import org.onap.aai.domain.yang.NetworkRoute + +class DoAllocateAccessNSSI extends AbstractServiceTaskProcessor { + + String Prefix="AASS_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + RequestDBUtil requestDBUtil = new RequestDBUtil() + JsonUtils jsonUtil = new JsonUtils() + OofUtils oofUtils = new OofUtils() + AnNssmfUtils anNssmfUtils = new AnNssmfUtils() + ObjectMapper objectMapper = new ObjectMapper(); + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + + private static final Logger logger = LoggerFactory.getLogger(DoAllocateAccessNSSI.class) + + @Override + void preProcessRequest(DelegateExecution execution) { + logger.debug(Prefix + "preProcessRequest Start") + execution.setVariable("prefix", Prefix) + execution.setVariable("startTime", System.currentTimeMillis()) + def msg + try { + + logger.debug("input variables : msoRequestId - "+execution.getVariable("msoRequestId") + +" modelInvariantUuid - "+execution.getVariable("modelInvariantUuid")+ + " modelUuid - "+execution.getVariable("modelUuid")+ + " globalSubscriberId - "+execution.getVariable("globalSubscriberId")+ + " dummyServiceId - "+ execution.getVariable("dummyServiceId")+ + " nsiId - "+execution.getVariable("nsiId")+ + " networkType - "+execution.getVariable("networkType")+ + " subscriptionServiceType - "+execution.getVariable("subscriptionServiceType")+ + " jobId - "+execution.getVariable("jobId")+ + " sliceParams - "+execution.getVariable("sliceParams")+ + " servicename - "+ execution.getVariable("servicename")) + + //validate slice subnet inputs + + String sliceParams = execution.getVariable("sliceParams") + String sliceProfile = jsonUtil.getJsonValue(sliceParams, "sliceProfile") + if (isBlank(sliceProfile)) { + msg = "Input sliceProfile is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("sliceProfile", sliceProfile) + } + String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId") + def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList")) + def plmnIdList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "plmnIdList")) + def coverageAreaTAList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "coverageAreaTAList")) + + if (isBlank(sliceProfileId) || (snssaiList.empty) || (plmnIdList.empty) + || (coverageAreaTAList.empty)) { + + msg = "Mandatory slice profile fields are empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("sliceProfileId", sliceProfileId) + execution.setVariable("snssaiList", snssaiList) + execution.setVariable("plmnIdList", plmnIdList) + execution.setVariable("coverageAreaTAList", coverageAreaTAList) + } + String nsiName = jsonUtil.getJsonValue(sliceParams, "nsiInfo.nsiName") + String scriptName = jsonUtil.getJsonValue(sliceParams, "scriptName") + execution.setVariable("nsiName", nsiName) + execution.setVariable("scriptName", scriptName) + //generate RAN,RAN NF NSSIs - will be re assigned if oof returns existing NSSI + String RANServiceInstanceId = UUID.randomUUID().toString() + String RANNFServiceInstanceId = UUID.randomUUID().toString() + logger.debug("RAN serviceInstance Id "+RANServiceInstanceId) + logger.debug("RAN NF serviceInstance Id "+RANNFServiceInstanceId) + execution.setVariable("RANServiceInstanceId", RANServiceInstanceId) + execution.setVariable("RANNFServiceInstanceId", RANNFServiceInstanceId) + execution.setVariable("ranNssiPreferReuse", true) + execution.setVariable("ranNfNssiPreferReuse", true) + execution.setVariable("job_timeout", 10) + + //set BH end point + List<String> BH_endPoints = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceParams, "endPoints")) + logger.debug("BH end points list : "+BH_endPoints) + if(BH_endPoints.empty) { + msg = "End point info is empty" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + }else { + execution.setVariable("bh_endpoint", BH_endPoints.get(0)) + } + + } catch(BpmnError e) { + throw e + } catch(Exception ex) { + msg = "Exception in DoAllocateAccessNSSI.preProcessRequest " + ex.getMessage() + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug(Prefix + "preProcessRequest Exit") + } + + /* + * Prepare request params for decomposing RAN NSST + */ + + def prepareDecomposeService = { DelegateExecution execution -> + logger.debug(Prefix+"prepareDecomposeService method start") + String RANServiceInstanceId = execution.getVariable("RANServiceInstanceId") + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelUuid = execution.getVariable("modelUuid") + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + execution.setVariable("serviceInstanceId", RANServiceInstanceId) + logger.debug("serviceModelInfo : "+serviceModelInfo) + logger.debug("Finish RAN NSST prepareDecomposeService") + } + + /* process the decompose service(RAN NSST) response + * + */ + def processDecomposition = { DelegateExecution execution -> + logger.debug(Prefix+"processDecomposition method start") + ServiceDecomposition ranNsstServiceDecomposition = execution.getVariable("ranNsstServiceDecomposition") + logger.debug("ranNsstServiceDecomposition : "+ranNsstServiceDecomposition.toString()) + //RAN NSST decomposition + String ranModelVersion = ranNsstServiceDecomposition.getModelInfo().getModelVersion() + String ranModelName = ranNsstServiceDecomposition.getModelInfo().getModelName() + List<ServiceProxy> serviceProxyList = ranNsstServiceDecomposition.getServiceProxy() + List<String> nsstInfoList = new ArrayList<>() + for(ServiceProxy serviceProxy : serviceProxyList) + { + String nsstModelUuid = serviceProxy.getModelInfo().getModelUuid() + String nsstModelInvariantUuid = serviceProxy.getModelInfo().getModelInvariantUuid() + String name = serviceProxy.getModelInfo().getModelName() + String nsstServiceModelInfo = """{ + "UUID":"${nsstModelUuid}", + "invariantUUID":"${nsstModelInvariantUuid}", + "name":"${name}" + }""" + nsstInfoList.add(nsstServiceModelInfo) + } + int currentIndex=0 + int maxIndex=nsstInfoList.size() + if(maxIndex < 1) + { + String msg = "Exception in RAN NSST processDecomposition. There is no NSST associated with RAN NSST " + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + execution.setVariable("ranNsstInfoList",nsstInfoList) + execution.setVariable("ranModelVersion", ranModelVersion) + execution.setVariable("ranModelName", ranModelName) + execution.setVariable("currentIndex",currentIndex) + execution.setVariable("maxIndex",maxIndex) + logger.debug(Prefix+"processDecomposition maxIndex value - "+maxIndex) + } + + /* + * Function to subnet capabilities from nssmf adapter + */ + def getSubnetCapabilities = { DelegateExecution execution -> + logger.debug(Prefix+"getSubnetCapabilities method start") + + String tnNssmfRequest = anNssmfUtils.buildCreateTNNSSMFSubnetCapabilityRequest() + + String urlString = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery" + + String tnNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, tnNssmfRequest) + + if (tnNssmfResponse != null) { + String FHCapabilities= jsonUtil.getJsonValue(tnNssmfResponse, "TN_FH") + String MHCapabilities = jsonUtil.getJsonValue(tnNssmfResponse, "TN_MH") + execution.setVariable("FHCapabilities",FHCapabilities) + execution.setVariable("MHCapabilities",MHCapabilities) + + } else { + logger.error("received error message from NSSMF : "+ tnNssmfResponse) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.") + } + String anNssmfRequest = anNssmfUtils.buildCreateANNFNSSMFSubnetCapabilityRequest() + + String anNssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, anNssmfRequest) + + if (anNssmfResponse != null) { + String ANNFCapabilities = jsonUtil.getJsonValue(anNssmfResponse, "AN_NF") + execution.setVariable("ANNFCapabilities",ANNFCapabilities) + + } else { + logger.error("received error message from NSSMF : "+ anNssmfResponse) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.") + } + } + + /* + * prepare OOF request for RAN NSSI selection + */ + def prepareOofRequestForRanNSS = { DelegateExecution execution -> + logger.debug(Prefix+"prepareOofRequestForRanNSS method start") + + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + logger.debug( "get NSSI option OOF Url: " + urlString) + + //build oof request body + boolean ranNssiPreferReuse = execution.getVariable("ranNssiPreferReuse"); + String requestId = execution.getVariable("msoRequestId") + String messageType = "NSISelectionResponse" + Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("sliceProfile"), Map.class) + String modelUuid = execution.getVariable("modelUuid") + String modelInvariantUuid = execution.getVariable("modelInvariantUuid") + String modelName = execution.getVariable("ranModelName") + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + List<String> nsstInfoList = objectMapper.readValue(execution.getVariable("nsstInfoList"), List.class) + JsonArray capabilitiesList = new JsonArray() + String FHCapabilities = execution.getVariable("FHCapabilities") + String MHCapabilities = execution.getVariable("MHCapabilities") + String ANNFCapabilities = execution.getVariable("ANNFCapabilities") + JsonObject FH = new JsonObject() + JsonObject MH = new JsonObject() + JsonObject ANNF = new JsonObject() + FH.addProperty("domainType", "TN_FH") + FH.addProperty("capabilityDetails", FHCapabilities) + MH.addProperty("domainType", "TN_MH") + MH.addProperty("capabilityDetails", MHCapabilities) + ANNF.addProperty("domainType", "AN_NF") + ANNF.addProperty("capabilityDetails", FHCapabilities) + capabilitiesList.add(FH) + capabilitiesList.add(MH) + capabilitiesList.add(ANNF) + + execution.setVariable("nssiSelection_Url", "/api/oof/selection/nsi/v1") + execution.setVariable("nssiSelection_messageType",messageType) + execution.setVariable("nssiSelection_correlator",requestId) + execution.setVariable("nssiSelection_timeout",timeout) + + String oofRequest = anNssmfUtils.buildSelectRANNSSIRequest(requestId, messageType, modelUuid,modelInvariantUuid, + modelName, profileInfo, nsstInfoList, capabilitiesList, ranNssiPreferReuse) + + execution.setVariable("nssiSelection_oofRequest",oofRequest) + logger.debug("Sending request to OOF: " + oofRequest) + } + /* + * process OOF response for RAN NSSI selection + */ + def processOofResponseForRanNSS = { DelegateExecution execution -> + logger.debug(Prefix+"processOofResponseForRanNSS method start") + String oofResponse = execution.getVariable("nssiSelection_asyncCallbackResponse") + String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus") + if(requestStatus.equals("completed")) { + List<String> solution = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(oofResponse, "solutions")) + boolean existingNSI = jsonUtil.getJsonValue(solution.get(0), "existingNSI") + if(existingNSI) { + def sharedNSISolution = jsonUtil.getJsonValue(solution.get(0), "sharedNSISolution") + execution.setVariable("sharedRanNSSISolution", sharedNSISolution) + logger.debug("sharedRanNSSISolution from OOF "+sharedNSISolution) + String RANServiceInstanceId = jsonUtil.getJsonValue(solution.get(0), "sharedNSISolution.NSIId") + execution.setVariable("RANServiceInstanceId", RANServiceInstanceId) + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setInstanceId(RANServiceInstanceId); + ServiceDecomposition serviceDecomposition = execution.getVariable("ranNsstServiceDecomposition") + serviceDecomposition.setServiceInstance(serviceInstance); + execution.setVariable("ranNsstServiceDecomposition", serviceDecomposition) + execution.setVariable("isRspRanNssi", true) + }else { + def sliceProfiles = jsonUtil.getJsonValue(solution.get(0), "newNSISolution.sliceProfiles") + execution.setVariable("RanConstituentSliceProfiles", sliceProfiles) + logger.debug("RanConstituentSliceProfiles list from OOF "+sliceProfiles) + } + }else { + String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage") + logger.error("received failed status from oof "+ statusMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage) + } + + } + + def prepareModifyAccessNssiInputs = { DelegateExecution execution -> + logger.debug(Prefix+"prepareModifyAccessNssiInputs method start") + String jobId = UUID.randomUUID().toString() + execution.setVariable("modifyRanNssiJobId", jobId) + String snssaiList = execution.getVariable("snssaiList") + String sliceParams = execution.getVariable("sliceParams") + String sliceProfileId = execution.getVariable("sliceProfileId") + String nsiInfo = jsonUtil.getJsonValue(sliceParams, "nsiInfo") + String scriptName = execution.getVariable("scriptName") + + JsonObject modifySliceParams = new JsonObject() + modifySliceParams.addProperty("modifyAction", "allocate") + modifySliceParams.addProperty("snssaiList", snssaiList) + modifySliceParams.addProperty("sliceProfileId", sliceProfileId) + modifySliceParams.addProperty("nsiInfo", nsiInfo) + modifySliceParams.addProperty("scriptName", scriptName) + + execution.setVariable("modifySliceParams", modifySliceParams.toString()) + //create operation status in request db + String serviceId = execution.getVariable("RANServiceInstanceId") + String nsiId = execution.getVariable("nsiId") + logger.debug("Generated new job for Service Instance serviceId:" + serviceId + "jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(serviceId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(nsiId) + initStatus.setOperType("Modify") + requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus) + } + + def createModifyNssiQueryJobStatus = { DelegateExecution execution -> + logger.debug(Prefix+"createModifyNssiQueryJobStatus method start") + EsrInfo esrInfo = new EsrInfo() + esrInfo.setNetworkType("AN") + esrInfo.setVendor("ONAP") + String esrInfoString = objectMapper.writeValueAsString(esrInfo) + execution.setVariable("esrInfo", esrInfoString) + JsonObject serviceInfo = new JsonObject() + serviceInfo.addProperty("nssiId", execution.getVariable("RANServiceInstanceId")) + serviceInfo.addProperty("nsiId", execution.getVariable("nsiId")) + serviceInfo.addProperty("nssiName", execution.getVariable("servicename")) + String sST = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST") + serviceInfo.addProperty("sST", sST) + serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("plmnIdList"))) + serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId")) + serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType")) + serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("modelInvariantUuid")) + serviceInfo.addProperty("serviceUuid", execution.getVariable("modelUuid")) + execution.setVariable("serviceInfo", serviceInfo.toString()) + execution.setVariable("responseId", "") + } + def prepareNsstDecomposeService = { DelegateExecution execution -> + logger.debug(Prefix+"prepareNsstDecomposeService method start") + List<String> nsstInfoList = objectMapper.readValue(execution.getVariable("ranNsstInfoList"), List.class) + int currentIndex = execution.getVariable("currentIndex") + int maxIndex = execution.getVariable("maxIndex") + logger.debug(Prefix+"prepareNsstDecomposeService : currentIndex value - "+currentIndex+" maxIndex : "+maxIndex) + if(currentIndex<maxIndex) { + String nsstInfo = nsstInfoList.get(currentIndex) + String modelInvariantUuid = jsonUtil.getJsonValue(nsstInfo, "invariantUUID") + String modelUuid = jsonUtil.getJsonValue(nsstInfo, "UUID") + + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + execution.setVariable("serviceInstanceId", "") + logger.debug("serviceModelInfo : "+serviceModelInfo) + currentIndex++ + execution.setVariable("currentIndex", currentIndex) + }else { + logger.error("nsstList decomposition error ") + exceptionUtil.buildAndThrowWorkflowException(execution, 1000, "nsstList decomposition error ") + } + + } + def processNsstDecomposition = { DelegateExecution execution -> + logger.debug(Prefix+"processNsstDecomposition method start") + ServiceDecomposition decomposedNsst = execution.getVariable("nsstServiceDecomposition") + logger.debug("decomposedNsst : "+decomposedNsst.toString()) + + String nsstType = decomposedNsst.getServiceRole() //domainType + String modelVersion = decomposedNsst.getModelInfo().getModelVersion() + String modelName = decomposedNsst.getModelInfo().getModelName() + String modelUuid = decomposedNsst.getModelInfo().getModelUuid() + String modelInvariantUuid = decomposedNsst.getModelInfo().getModelInvariantUuid() + + switch(nsstType) { + case "AN_NF": + execution.setVariable("ANNF_modelInvariantUuid", modelInvariantUuid) + execution.setVariable("ANNF_modelUuid", modelUuid) + execution.setVariable("ANNF_modelVersion", modelVersion) + execution.setVariable("ANNF_modelName", modelName) + execution.setVariable("ANNF_ServiceDecomposition", decomposedNsst) + break + case "TN_FH": + execution.setVariable("TNFH_modelInvariantUuid", modelInvariantUuid) + execution.setVariable("TNFH_modelUuid", modelUuid) + execution.setVariable("TNFH_modelVersion", modelVersion) + execution.setVariable("TNFH_modelName", modelName) + execution.setVariable("TNFH_ServiceDecomposition", decomposedNsst) + break + case "TN_MH": + execution.setVariable("TNMH_modelInvariantUuid", modelInvariantUuid) + execution.setVariable("TNMH_modelUuid", modelUuid) + execution.setVariable("TNMH_modelVersion", modelVersion) + execution.setVariable("TNMH_modelName", modelName) + execution.setVariable("TNMH_ServiceDecomposition", decomposedNsst) + break + default: + logger.debug("No expected match found for current nsstType") + logger.error("No expected match found for current nsstType "+ nsstType) + exceptionUtil.buildAndThrowWorkflowException(execution, 1000,"No expected match found for current nsstType "+ nsstType) + } + boolean isAllNsstsDecomposed = false + int currentIndex = execution.getVariable("currentIndex") + int maxIndex = execution.getVariable("maxIndex") + if(currentIndex == maxIndex) { + isAllNsstsDecomposed = true + } + execution.setVariable("isAllNsstsDecomposed", isAllNsstsDecomposed) + } + /* + * prepare OOF request for NF RAN NSSI selection + */ + def prepareOofRequestForRanNfNSS = { DelegateExecution execution -> + logger.debug(Prefix+"prepareOofRequestForRanNfNSS method start") + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + logger.debug( "get NSSI option OOF Url: " + urlString) + + //build oof request body + boolean ranNfNssiPreferReuse = execution.getVariable("ranNfNssiPreferReuse"); + String requestId = execution.getVariable("msoRequestId") + String messageType = "NSSISelectionResponse" + List<String> ranConstituentSliceProfiles = jsonUtil.StringArrayToList(execution.getVariable("RanConstituentSliceProfiles")) + anNssmfUtils.createDomainWiseSliceProfiles(ranConstituentSliceProfiles, execution) + Map<String, Object> profileInfo = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class) + String modelUuid = execution.getVariable("ANNF_modelUuid") + String modelInvariantUuid = execution.getVariable("ANNF_modelInvariantUuid") + String modelName = execution.getVariable("ANNF_modelName") + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + + execution.setVariable("nssiSelection_Url", "/api/oof/selection/nssi/v1") + execution.setVariable("nssiSelection_messageType",messageType) + execution.setVariable("nssiSelection_correlator",requestId) + execution.setVariable("nssiSelection_timeout",timeout) + + String oofRequest = oofUtils.buildSelectNSSIRequest(requestId, messageType, modelUuid, modelInvariantUuid, modelName, profileInfo) + + execution.setVariable("nssiSelection_oofRequest",oofRequest) + } + /* + * process OOF response for RAN NF NSSI selection + */ + def processOofResponseForRanNfNSS = { DelegateExecution execution -> + logger.debug(Prefix+"processOofResponseForRanNfNSS method start") + String oofResponse = execution.getVariable("nfNssiSelection_asyncCallbackResponse") + String requestStatus = jsonUtil.getJsonValue(oofResponse, "requestStatus") + if(requestStatus.equals("completed")) { + List<String> solution = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(oofResponse, "solutions")) + if(solution.size()>=1) { + String ranNfNssiId = jsonUtil.getJsonValue(solution.get(0), "NSSIId") + String invariantUuid = jsonUtil.getJsonValue(solution.get(0), "invariantUUID") + String uuid = jsonUtil.getJsonValue(solution.get(0), "UUID") + String nssiName = jsonUtil.getJsonValue(solution.get(0), "NSSIName") + execution.setVariable("RANNFServiceInstanceId", ranNfNssiId) + execution.setVariable("RANNFInvariantUUID", invariantUuid) + execution.setVariable("RANNFUUID", uuid) + execution.setVariable("RANNFNssiName", nssiName) + logger.debug("RANNFServiceInstanceId from OOF "+ranNfNssiId) + + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setInstanceId(ranNfNssiId); + ServiceDecomposition serviceDecomposition = execution.getVariable("ANNF_ServiceDecomposition") + serviceDecomposition.setServiceInstance(serviceInstance); + execution.setVariable("ANNF_ServiceDecomposition", serviceDecomposition) + execution.setVariable("isRspRanNfNssi", true) + }else { + logger.debug("No solutions returned from OOF .. Create new RAN NF NSSI") + } + }else { + String statusMessage = jsonUtil.getJsonValue(oofResponse, "statusMessage") + logger.error("received failed status from oof "+ statusMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a failed Async Response from OOF : "+statusMessage) + } + } + + def createSliceProfilesInAai = { DelegateExecution execution -> + logger.debug(Prefix+"createSliceProfilesInAai method start") + anNssmfUtils.createSliceProfilesInAai(execution) + } + + def processRanNfModifyRsp = { DelegateExecution execution -> + logger.debug(Prefix+"processRanNfModifyRsp method start") + anNssmfUtils.processRanNfModifyRsp(execution) + //create RAN NSSI + org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new ServiceInstance(); + //AN instance creation + ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId")) + String sliceInstanceName = execution.getVariable("servicename") + ANServiceInstance.setServiceInstanceName(sliceInstanceName) + String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST") + ANServiceInstance.setServiceType(serviceType) + String serviceStatus = "deactivated" + ANServiceInstance.setOrchestrationStatus(serviceStatus) + String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "plmnIdList") + ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + String serviceRole = "nssi" + ANServiceInstance.setServiceRole(serviceRole) + List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class) + String snssai = snssaiList.get(0) + ANServiceInstance.setEnvironmentContext(snssai) + ANServiceInstance.setWorkloadContext("AN") + + logger.debug("completed AN service instance build "+ ANServiceInstance.toString()) + String msg = "" + try { + + AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), execution.getVariable("RANServiceInstanceId")) + client.create(nssiServiceUri, ANServiceInstance) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + //end point update + createEndPointsInAai(execution) + } + + def createSdnrRequest = { DelegateExecution execution -> + logger.debug(Prefix+"createSdnrRequest method start") + String callbackUrl = UrnPropertiesReader.getVariable("mso.workflow.message.endpoint") + "/AsyncSdnrResponse/"+execution.getVariable("msoRequestId") + String sdnrRequest = buildSdnrAllocateRequest(execution, "allocate", "InstantiateRANSlice", callbackUrl) + execution.setVariable("createNSSI_sdnrRequest", sdnrRequest) + execution.setVariable("createNSSI_timeout", "PT10M") + execution.setVariable("createNSSI_correlator", execution.getVariable("msoRequestId")) + execution.setVariable("createNSSI_messageType", "AsyncSdnrResponse"); + } + + def processSdnrResponse = { DelegateExecution execution -> + logger.debug(Prefix+"processSdnrResponse method start") + String SDNRResponse = execution.getVariable("SDNR_asyncCallbackResponse") + String status = jsonUtil.getJsonValue(SDNRResponse, "status") + if(status.equalsIgnoreCase("success")) { + String nfIds = jsonUtil.getJsonValue(SDNRResponse, "nfIds") + execution.setVariable("ranNfIdsJson", nfIds) + }else { + String reason = jsonUtil.getJsonValue(SDNRResponse, "reason") + logger.error("received failed status from SDNR "+ reason) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from SDNR "+ reason) + } + logger.debug("response from SDNR "+SDNRResponse) + } + + def updateAaiWithRANInstances = { DelegateExecution execution -> + logger.debug(Prefix+"updateAaiWithRANInstances method start") + //create RAN NSSI + org.onap.aai.domain.yang.ServiceInstance ANServiceInstance = new ServiceInstance(); + org.onap.aai.domain.yang.ServiceInstance ANNFServiceInstance = new ServiceInstance(); + //AN instance creation + ANServiceInstance.setServiceInstanceId(execution.getVariable("RANServiceInstanceId")) + String sliceInstanceName = execution.getVariable("servicename") + ANServiceInstance.setServiceInstanceName(sliceInstanceName) + String serviceType = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST") + ANServiceInstance.setServiceType(serviceType) + String serviceStatus = "deactivated" + ANServiceInstance.setOrchestrationStatus(serviceStatus) + String serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "plmnIdList") + ANServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + String serviceRole = "nssi" + ANServiceInstance.setServiceRole(serviceRole) + List<String> snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class) + String snssai = snssaiList.get(0) + ANServiceInstance.setEnvironmentContext(snssai) + ANServiceInstance.setWorkloadContext("AN") + + logger.debug("completed AN service instance build "+ ANServiceInstance.toString()) + //create RAN NF NSSI + ANNFServiceInstance.setServiceInstanceId(execution.getVariable("RANNFServiceInstanceId")) + sliceInstanceName = execution.getVariable("ANNF_modelName") + ANNFServiceInstance.setServiceInstanceName(sliceInstanceName) + ANNFServiceInstance.setServiceType(serviceType) + ANNFServiceInstance.setOrchestrationStatus(serviceStatus) + serviceInstanceLocationid = jsonUtil.getJsonValue(execution.getVariable("ranNfSliceProfile"), "plmnIdList") + ANNFServiceInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + ANNFServiceInstance.setServiceRole(serviceRole) + snssaiList = objectMapper.readValue(execution.getVariable("snssaiList"), List.class) + snssai = snssaiList.get(0) + ANNFServiceInstance.setEnvironmentContext(snssai) + ANNFServiceInstance.setWorkloadContext("AN-NF") + logger.debug("completed AN service instance build "+ ANNFServiceInstance.toString()) + + String msg = "" + try { + + AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri nssiServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), execution.getVariable("RANServiceInstanceId")) + client.create(nssiServiceUri, ANServiceInstance) + + AAIResourceUri nssiServiceUri1 = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), execution.getVariable("RANNFServiceInstanceId")) + client.create(nssiServiceUri1, ANNFServiceInstance) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in AnNssmfUtils.createSliceProfilesInAai " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + //end point update + createEndPointsInAai(execution) + } + def prepareTnFhRequest = { DelegateExecution execution -> + logger.debug(Prefix+"prepareTnFhRequest method start") + + String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_FH", "allocate") + String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles" + String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest) + + if (nssmfResponse != null) { + execution.setVariable("nssmfResponse", nssmfResponse) + String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId") + execution.setVariable("TNFH_jobId",jobId) + } else { + logger.error("received error message from NSSMF : "+ nssmfResponse) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.") + } + logger.debug("Exit prepareTnFhRequest") + + } + def prepareTnMhRequest = { DelegateExecution execution -> + logger.debug(Prefix+"prepareTnMhRequest method start") + + String nssmfRequest = anNssmfUtils.buildCreateNSSMFRequest(execution, "TN_MH", "allocate") + String urlString = "/api/rest/provMns/v1/NSS/SliceProfiles" + String nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest) + + if (nssmfResponse != null) { + execution.setVariable("nssmfResponse", nssmfResponse) + String jobId = jsonUtil.getJsonValue(nssmfResponse, "jobId") + execution.setVariable("TNMH_jobId",jobId) + } else { + logger.error("received error message from NSSMF : "+ nssmfResponse) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"Received a Bad Sync Response from NSSMF.") + } + logger.debug("Exit prepareTnMhRequest") + } + + def createFhAllocateNssiJobQuery = { DelegateExecution execution -> + logger.debug(Prefix+"createModifyNssiQueryJobStatus method start") + createTnAllocateNssiJobQuery(execution, "TN_FH") + } + + def createMhAllocateNssiJobQuery = { DelegateExecution execution -> + logger.debug(Prefix+"createModifyNssiQueryJobStatus method start") + createTnAllocateNssiJobQuery(execution, "TN_MH") + } + + private void createTnAllocateNssiJobQuery(DelegateExecution execution, String domainType) { + EsrInfo esrInfo = new EsrInfo() + esrInfo.setNetworkType("TN") + esrInfo.setVendor("ONAP") + String esrInfoString = objectMapper.writeValueAsString(esrInfo) + execution.setVariable("esrInfo", esrInfoString) + JsonObject serviceInfo = new JsonObject() + serviceInfo.addProperty("nssiId", null) + serviceInfo.addProperty("nsiId", execution.getVariable("nsiId")) + String sST = jsonUtil.getJsonValue(execution.getVariable("sliceProfile"), "sST") + serviceInfo.addProperty("sST", sST) + serviceInfo.addProperty("PLMNIdList", objectMapper.writeValueAsString(execution.getVariable("plmnIdList"))) + serviceInfo.addProperty("globalSubscriberId", execution.getVariable("globalSubscriberId")) + serviceInfo.addProperty("subscriptionServiceType", execution.getVariable("subscriptionServiceType")) + if(domainType.equals("TN_FH")) { + serviceInfo.addProperty("nssiName", execution.getVariable("TNFH_modelName")) + serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNFH_modelInvariantUuid")) + serviceInfo.addProperty("serviceUuid", execution.getVariable("TNFH_modelUuid")) + }else if(domainType.equals("TN_MH")) { + serviceInfo.addProperty("nssiName", execution.getVariable("TNMH_modelName")) + serviceInfo.addProperty("serviceInvariantUuid", execution.getVariable("TNMH_modelInvariantUuid")) + serviceInfo.addProperty("serviceUuid", execution.getVariable("TNMH_modelUuid")) + } + execution.setVariable("serviceInfo", serviceInfo.toString()) + execution.setVariable("responseId", "") + } + + def processFhAllocateNssiJobStatusRsp = { DelegateExecution execution -> + logger.debug(Prefix+"processJobStatusRsp method start") + String jobResponse = execution.getVariable("TNFH_jobResponse") + logger.debug("Job status response "+jobResponse) + String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status") + String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi") + if(status.equalsIgnoreCase("finished")) { + execution.setVariable("TNFH_NSSI", nssi) + logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi) + } + else { + String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription") + logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + } + } + + def processMhAllocateNssiJobStatusRsp = { DelegateExecution execution -> + logger.debug(Prefix+"processJobStatusRsp method start") + String jobResponse = execution.getVariable("TNMH_jobResponse") + logger.debug("Job status response "+jobResponse) + String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status") + String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi") + if(status.equalsIgnoreCase("finished")) { + execution.setVariable("TNMH_NSSI", nssi) + logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi) + } + else { + String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription") + logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + } + } + + def processModifyJobStatusRsp = { DelegateExecution execution -> + logger.debug(Prefix+"processJobStatusRsp method start") + String jobResponse = execution.getVariable("jobResponse") + logger.debug("Job status response "+jobResponse) + String status = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.status") + String nssi = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.nssi") + if(status.equalsIgnoreCase("finished")) { + logger.debug("Job successfully completed ... proceeding with flow for nssi : "+nssi) + } + else { + String statusDescription = jsonUtil.getJsonValue(jobResponse, "responseDescriptor.statusDescription") + logger.error("received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000,"received failed status from job status query for nssi : "+nssi+" with status description : "+ statusDescription) + } + } + + def updateAairelationships = { DelegateExecution execution -> + logger.debug(Prefix + "updateAairelationships Start") + String msg = "" + try { + def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId") + def TNFH_serviceInstanceId = execution.getVariable("TNFH_NSSI") + def TNMH_serviceInstanceId = execution.getVariable("TNMH_NSSI") + def AN_profileInstanceId = execution.getVariable("sliceProfileId") + def AN_NSSI = execution.getVariable("RANServiceInstanceId") + def ANNF_profileInstanceId = execution.getVariable("ANNF_sliceProfileInstanceId") + def TNFH_profileInstanceId = execution.getVariable("TNFH_sliceProfileInstanceId") + def TNMH_profileInstanceId = execution.getVariable("TNMH_sliceProfileInstanceId") + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + Relationship ANNF_relationship = new Relationship() + Relationship TNFH_relationship = new Relationship() + Relationship TNMH_relationship = new Relationship() + + String ANNF_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_profileInstanceId}" + String TNFH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_profileInstanceId}" + String TNMH_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_profileInstanceId}" + + String ANNF_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${ANNF_serviceInstanceId}" + String TNFH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNFH_serviceInstanceId}" + String TNMH_NSSI_relatedLink = "aai/v21/business/customers/customer/${globalSubscriberId}/service-subscriptions/service-subscription/${subscriptionServiceType}/service-instances/service-instance/${TNMH_serviceInstanceId}" + + ANNF_relationship.setRelatedLink(ANNF_relatedLink) + ANNF_relationship.setRelatedTo("service-instance") + ANNF_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + TNFH_relationship.setRelatedLink(TNFH_relatedLink) + TNFH_relationship.setRelatedTo("service-instance") + TNFH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + TNMH_relationship.setRelatedLink(TNMH_relatedLink) + TNMH_relationship.setRelatedTo("service-instance") + TNMH_relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + + // create SliceProfile and NSSI relationship in AAI + anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,ANNF_serviceInstanceId) + anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,TNFH_serviceInstanceId) + anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,TNMH_serviceInstanceId) + anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_profileInstanceId) + anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_profileInstanceId) + anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_profileInstanceId) + + //create AN NSSI and ANNF,TNFH,TNMH relationship in AAI + ANNF_relationship.setRelatedLink(ANNF_NSSI_relatedLink) + TNFH_relationship.setRelatedLink(TNFH_NSSI_relatedLink) + TNMH_relationship.setRelatedLink(TNMH_NSSI_relatedLink) + anNssmfUtils.createRelationShipInAAI(execution, ANNF_relationship,AN_NSSI) + anNssmfUtils.createRelationShipInAAI(execution, TNFH_relationship,AN_NSSI) + anNssmfUtils.createRelationShipInAAI(execution, TNMH_relationship,AN_NSSI) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + + msg = "Exception in DoCreateE2EServiceInstance.createCustomRelationship. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + + /** + * update operation status in request db + * + */ + def prepareOperationStatusUpdate = { DelegateExecution execution -> + logger.debug(Prefix + "prepareOperationStatusUpdate Start") + + String serviceId = execution.getVariable("dummyServiceId") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + String nssiId = execution.getVariable("RANServiceInstanceId") + logger.debug("Service Instance serviceId:" + serviceId + " jobId:" + jobId) + + ResourceOperationStatus updateStatus = new ResourceOperationStatus() + updateStatus.setServiceId(serviceId) + updateStatus.setOperationId(jobId) + updateStatus.setResourceTemplateUUID(nsiId) + updateStatus.setResourceInstanceID(nssiId) + updateStatus.setOperType("Allocate") + updateStatus.setProgress(100) + updateStatus.setStatus("finished") + requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus) + + logger.debug(Prefix + "prepareOperationStatusUpdate Exit") + } + + def prepareFailedOperationStatusUpdate = { DelegateExecution execution -> + logger.debug(Prefix + "prepareFailedOperationStatusUpdate Start") + + String serviceId = execution.getVariable("dummyServiceId") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + String nssiId = execution.getVariable("RANServiceInstanceId") + logger.debug("Service Instance serviceId:" + serviceId + " jobId:" + jobId) + + ResourceOperationStatus updateStatus = new ResourceOperationStatus() + updateStatus.setServiceId(serviceId) + updateStatus.setOperationId(jobId) + updateStatus.setResourceTemplateUUID(nsiId) + updateStatus.setResourceInstanceID(nssiId) + updateStatus.setOperType("Allocate") + updateStatus.setProgress(0) + updateStatus.setStatus("failed") + requestDBUtil.prepareUpdateResourceOperationStatus(execution, updateStatus) + } + + private String buildSdnrAllocateRequest(DelegateExecution execution, String action, String rpcName, String callbackUrl) { + + String requestId = execution.getVariable("msoRequestId") + Date date = new Date().getTime() + Timestamp time = new Timestamp(date) + Map<String,Object> sliceProfile = objectMapper.readValue(execution.getVariable("ranNfSliceProfile"), Map.class) + sliceProfile.put("sliceProfileId", execution.getVariable("ANNF_sliceProfileInstanceId")) + sliceProfile.put("maxNumberofConns", sliceProfile.get("maxNumberofPDUSessions")) + sliceProfile.put("uLThptPerSlice", sliceProfile.get("expDataRateUL")) + sliceProfile.put("dLThptPerSlice", sliceProfile.get("expDataRateDL")) + String sliceProfileString = objectMapper.writeValueAsString(sliceProfile) + JsonObject response = new JsonObject() + JsonObject body = new JsonObject() + JsonObject input = new JsonObject() + JsonObject commonHeader = new JsonObject() + JsonObject payload = new JsonObject() + JsonObject payloadInput = new JsonObject() + commonHeader.addProperty("TimeStamp", time.toString()) + commonHeader.addProperty("APIver", "1.0") + commonHeader.addProperty("RequestID", requestId) + commonHeader.addProperty("SubRequestID", "1") + commonHeader.add("RequestTrack", new JsonObject()) + commonHeader.add("Flags", new JsonObject()) + payloadInput.addProperty("sliceProfile", sliceProfileString) + payloadInput.addProperty("RANNSSIId", execution.getVariable("RANServiceInstanceId")) + payloadInput.addProperty("NSIID", execution.getVariable("nsiId")) + payloadInput.addProperty("RANNFNSSIId", execution.getVariable("RANNFServiceInstanceId")) + payloadInput.addProperty("callbackURL", callbackUrl) + payloadInput.add("additionalproperties", new JsonObject()) + payload.add("input", payloadInput) + input.add("CommonHeader", commonHeader) + input.addProperty("Action", action) + input.add("Payload", payload) + body.add("input", input) + response.add("body", body) + response.addProperty("version", "1.0") + response.addProperty("rpc-name", rpcName) + response.addProperty("correlation-id", requestId+"-1") + response.addProperty("type", "request") + return response.toString() + } + + private void createEndPointsInAai(DelegateExecution execution) { + String type = "endpoint" + String function = "transport_EP" + int prefixLength = 24 + String addressFamily = "ipv4" + //BH RAN end point update + String bh_endpoint = execution.getVariable("bh_endpoint") + String bh_routeId = UUID.randomUUID().toString() + execution.setVariable("tranportEp_ID_bh", bh_routeId) + String role = "CU" + String CU_IpAddress = 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(CU_IpAddress) + bh_ep.setLogicalInterfaceId(LogicalLinkId) + bh_ep.setNextHop(nextHopInfo) + bh_ep.setPrefixLength(prefixLength) + bh_ep.setAddressFamily(addressFamily) + //FH RAN end points update + //RU + String RU_routeId = UUID.randomUUID().toString() + execution.setVariable("tranportEp_ID_RU", RU_routeId) + role = "RU" + NetworkRoute RU_ep = new NetworkRoute() + RU_ep.setRouteId(RU_routeId) + RU_ep.setFunction(function) + RU_ep.setRole(role) + RU_ep.setType(type) + RU_ep.setIpAddress("192.168.100.4") + RU_ep.setLogicalInterfaceId("1234") + RU_ep.setNextHop("Host1") + RU_ep.setPrefixLength(prefixLength) + RU_ep.setAddressFamily(addressFamily) + //DU Ingress + String DUIN_routeId = UUID.randomUUID().toString() + execution.setVariable("tranportEp_ID_DUIN", DUIN_routeId) + role = "DU" + NetworkRoute DU_ep = new NetworkRoute() + DU_ep.setRouteId(DUIN_routeId) + DU_ep.setFunction(function) + DU_ep.setRole(role) + DU_ep.setType(type) + DU_ep.setIpAddress("192.168.100.5") + DU_ep.setLogicalInterfaceId("1234") + DU_ep.setNextHop("Host2") + DU_ep.setPrefixLength(prefixLength) + DU_ep.setAddressFamily(addressFamily) + //MH RAN end point update + //DUEG + String DUEG_routeId = UUID.randomUUID().toString() + execution.setVariable("tranportEp_ID_DUEG", DUEG_routeId) + NetworkRoute DUEG_ep = new NetworkRoute() + DU_ep.setRouteId(DUEG_routeId) + DU_ep.setNextHop("Host3") + //CUIN + String CUIN_routeId = UUID.randomUUID().toString() + execution.setVariable("tranportEp_ID_CUIN", CUIN_routeId) + NetworkRoute CUIN_ep = new NetworkRoute() + CUIN_ep.setRouteId(CUIN_routeId) + CUIN_ep.setFunction(function) + CUIN_ep.setRole(role) + CUIN_ep.setType(type) + CUIN_ep.setIpAddress("192.168.100.6") + CUIN_ep.setLogicalInterfaceId("1234") + CUIN_ep.setNextHop("Host4") + CUIN_ep.setPrefixLength(prefixLength) + CUIN_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) + logger.debug("creating RU endpoint . ID : "+RU_routeId+" node details : "+RU_ep.toString()) + networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), RU_routeId) + client.create(networkRouteUri, RU_ep) + logger.debug("creating DUIN endpoint . ID : "+DUIN_routeId+" node details : "+DU_ep.toString()) + networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUIN_routeId) + client.create(networkRouteUri, DU_ep) + logger.debug("creating DUEG endpoint . ID : "+DUEG_routeId+" node details : "+DU_ep.toString()) + networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), DUEG_routeId) + client.create(networkRouteUri, DU_ep) + logger.debug("creating CUIN endpoint . ID : "+CUIN_routeId+" node details : "+CUIN_ep.toString()) + networkRouteUri = AAIUriFactory.createResourceUri( new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkRoute.class), CUIN_routeId) + client.create(networkRouteUri, CUIN_ep) + //relationship b/w bh_ep and RAN NSSI + def AN_NSSI = execution.getVariable("RANServiceInstanceId") + 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") + anNssmfUtils.createRelationShipInAAI(execution, relationship, AN_NSSI) + def ANNF_serviceInstanceId = execution.getVariable("RANNFServiceInstanceId") + relatedLink = "aai/v21/network/network-routes/network-route/${RU_routeId}" + relationship.setRelatedLink(relatedLink) + anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId) + relatedLink = "aai/v21/network/network-routes/network-route/${DUIN_routeId}" + relationship.setRelatedLink(relatedLink) + anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId) + relatedLink = "aai/v21/network/network-routes/network-route/${DUEG_routeId}" + relationship.setRelatedLink(relatedLink) + anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId) + relatedLink = "aai/v21/network/network-routes/network-route/${CUIN_routeId}" + relationship.setRelatedLink(relatedLink) + anNssmfUtils.createRelationShipInAAI(execution, relationship, ANNF_serviceInstanceId) + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + String msg = "Exception in createEndPointsInAai " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSIV2.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSIV2.groovy new file mode 100644 index 0000000000..924b42fe9f --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSIV2.groovy @@ -0,0 +1,613 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.BpmnError +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.Relationship +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aai.domain.yang.SliceProfile +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.so.beans.nsmf.* +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils +import org.onap.so.bpmn.core.json.JsonUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import javax.ws.rs.NotFoundException + +class DoAllocateNSIandNSSIV2 extends AbstractServiceTaskProcessor{ + + private static final Logger logger = LoggerFactory.getLogger( DoAllocateNSIandNSSIV2.class); + + ExceptionUtil exceptionUtil = new ExceptionUtil() + + JsonUtils jsonUtil = new JsonUtils() + + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + + AAIResourcesClient client = getAAIClient() + + /** + * Pre Process the BPMN Flow Request + * Inclouds: + * generate the nsOperationKey + * generate the nsParameters + */ + + void preProcessRequest (DelegateExecution execution) { + String msg = "" + logger.trace("Enter preProcessRequest()") + Map<String, Object> nssiMap = new HashMap<>() + execution.setVariable("nssiMap", nssiMap) + boolean isMoreNSSTtoProcess = true + execution.setVariable("isMoreNSSTtoProcess", isMoreNSSTtoProcess) + List<String> nsstSequence = new ArrayList<>(Arrays.asList("cn")) + execution.setVariable("nsstSequence", nsstSequence) + logger.trace("Exit preProcessRequest") + } + + /** + * Process NSI options + * @param execution + */ + void retriveSliceOption(DelegateExecution execution) { + logger.trace("Enter retriveSliceOption() of DoAllocateNSIandNSSI") + + boolean isNSIOptionAvailable + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter +// try +// { +// Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map +// String modelUuid = nstSolution.get("UUID") +// String modelInvariantUuid = nstSolution.get("invariantUUID") +// String serviceModelInfo = """{ +// "modelInvariantUuid":"${modelInvariantUuid}", +// "modelUuid":"${modelUuid}", +// "modelVersion":"" +// }""" +// execution.setVariable("serviceModelInfo", serviceModelInfo) +// +// execution.setVariable("sliceParams", sliceParams) +// }catch (Exception ex) { +// logger.debug( "Unable to get the task information from request DB: " + ex) +// exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Unable to get task information from request DB.") +// } + + if(StringUtils.isBlank(sliceParams.getSuggestNsiId())) { + isNSIOptionAvailable = false + } + else { + isNSIOptionAvailable = true + execution.setVariable('nsiServiceInstanceId', sliceParams.getSuggestNsiId()) + execution.setVariable('nsiServiceInstanceName', sliceParams.getSuggestNsiName()) + } + execution.setVariable("isNSIOptionAvailable", isNSIOptionAvailable) + logger.trace("Exit retriveSliceOption() of DoAllocateNSIandNSSI") + } + + + /** + * create nsi instance in aai + * @param execution + */ + void createNSIinAAI(DelegateExecution execution) { + logger.debug("Enter CreateNSIinAAI in DoAllocateNSIandNSSI()") + + String sliceInstanceId = UUID.randomUUID().toString() + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter + + sliceParams.setServiceId(sliceInstanceId) + + ServiceInstance nsi = new ServiceInstance() + + + String sliceInstanceName = "nsi_"+execution.getVariable("sliceServiceInstanceName") + String serviceType = execution.getVariable("serviceType") + String serviceStatus = "deactivated" + String modelInvariantUuid = sliceParams.getNSTInfo().invariantUUID + String modelUuid = sliceParams.getNSTInfo().UUID + + String uuiRequest = execution.getVariable("uuiRequest") + String serviceInstanceLocationid = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.plmnIdList") + String serviceRole = "nsi" + + execution.setVariable("sliceInstanceId", sliceInstanceId) + nsi.setServiceInstanceId(sliceInstanceId) + nsi.setServiceInstanceName(sliceInstanceName) + nsi.setServiceType(serviceType) + nsi.setOrchestrationStatus(serviceStatus) + nsi.setModelInvariantId(modelInvariantUuid) + nsi.setModelVersionId(modelUuid) + nsi.setServiceInstanceLocationId(serviceInstanceLocationid) + nsi.setServiceRole(serviceRole) + String msg + try { + + AAIResourceUri nsiServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + sliceInstanceId) + client.create(nsiServiceUri, nsi) + + execution.setVariable("nsiServiceUri", nsiServiceUri.build().toString()) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + logger.debug("Exit CreateNSIinAAI in DoAllocateNSIandNSSI()") + } + + + /** + * create relationship between nsi and service profile instance + * @param execution + */ + void createRelationship(DelegateExecution execution) { + //relation ship + Relationship relationship = new Relationship() + String nsiServiceUri = execution.getVariable("nsiServiceUri") as String + logger.info("Creating Allotted resource relationship, nsiServiceUri: " + nsiServiceUri) + + relationship.setRelatedLink(nsiServiceUri) + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri( + AAIObjectType.ALLOTTED_RESOURCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + execution.getVariable("sliceServiceInstanceId"), + execution.getVariable("allottedResourceId")) + .relationshipAPI() + client.create(allottedResourceUri, relationship) + } + + /** + * + * @param execution + */ + void updateRelationship(DelegateExecution execution) { + logger.debug("Enter update relationship in DoAllocateNSIandNSSI()") + String allottedResourceId = execution.getVariable("allottedResourceId") + //Need to check whether nsi exist : Begin + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + + String nsiServiceInstanceID = sliceParams.getSuggestNsiId() + sliceParams.setServiceId(nsiServiceInstanceID) + + AAIResourceUri nsiServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + nsiServiceInstanceID) + + try { + AAIResultWrapper wrapper = client.get(nsiServiceUri, NotFoundException.class) + Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class) + //todo: if exists + if (!si.ifPresent()) { + String msg = "NSI suggested in the option doesn't exist. " + nsiServiceInstanceID + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE, + execution.getVariable("globalSubscriberId"), + execution.getVariable("subscriptionServiceType"), + execution.getVariable("sliceServiceInstanceId"), + allottedResourceId) + + client.connect(allottedResourceUri, nsiServiceUri) + + execution.setVariable("sliceParams", sliceParams) + }catch(BpmnError e) { + throw e + }catch (Exception ex){ + String msg = "NSI suggested in the option doesn't exist. " + nsiServiceInstanceID + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("Exit update relationship in DoAllocateNSIandNSSI()") + } + + /** + * create RAN Slice Profile Instance + * @param execution + */ + void createAnSliceProfileInstance(DelegateExecution execution) { + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + String serviceInstanceId = UUID.randomUUID().toString() + execution.setVariable("ranSliceProfileInstanceId", serviceInstanceId) //todo: + + String serviceType = "" + String serviceRole = "slice-profile" + String oStatus = "deactivated" + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<AnSliceProfile> sliceTaskInfo = sliceParams.anSliceTaskInfo + sliceTaskInfo.setServiceInstanceId(serviceInstanceId) + + // create slice profile + ServiceInstance rspi = new ServiceInstance() + rspi.setServiceInstanceName(sliceTaskInfo.NSSTInfo.name) + rspi.setServiceType(serviceType) + rspi.setServiceRole(serviceRole) + rspi.setOrchestrationStatus(oStatus) + rspi.setModelInvariantId(sliceTaskInfo.NSSTInfo.invariantUUID) + rspi.setModelVersionId(sliceTaskInfo.NSSTInfo.UUID) + rspi.setInputParameters(uuiRequest) + rspi.setWorkloadContext(useInterval) + rspi.setEnvironmentContext(sNSSAI_id) + + //timestamp format YYYY-MM-DD hh:mm:ss + rspi.setCreatedAt(new Date(System.currentTimeMillis()).format("yyyy-MM-dd HH:mm:ss", TimeZone.getDefault())) + + execution.setVariable("communicationServiceInstance", rspi) + + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + globalSubscriberId, + subscriptionServiceType, + serviceInstanceId) + client.create(uri, rspi) + + execution.setVariable("sliceParams", sliceParams) + } + + /** + * create An Slice Profile + * @param execution + */ + void createAnSliceProfile(DelegateExecution execution) { + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + //String serviceInstanceId = execution.getVariable("ranSliceProfileInstanceId") + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<AnSliceProfile> sliceTaskInfo = sliceParams.anSliceTaskInfo + AnSliceProfile anSliceProfile = sliceTaskInfo.sliceProfile + + String profileId = UUID.randomUUID().toString() + anSliceProfile.setSliceProfileId(profileId) + + SliceProfile sliceProfile = new SliceProfile() + sliceProfile.setProfileId(profileId) + sliceProfile.setCoverageAreaTAList(anSliceProfile.coverageAreaTAList as String) + //todo:... + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, + globalSubscriberId, + subscriptionServiceType, + sliceTaskInfo.serviceInstanceId, + profileId + ) + client.create(uri, sliceProfile) + execution.setVariable("sliceParams", sliceParams) + } + + /** + * prepare AllocateAnNssi + * @param execution + */ + void prepareAllocateAnNssi(DelegateExecution execution) { + + //todo: + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<AnSliceProfile> sliceTaskInfo = sliceParams.anSliceTaskInfo + + NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest() + + AllocateAnNssi allocateAnNssi = new AllocateAnNssi() + allocateAnNssi.nsstId = sliceTaskInfo.NSSTInfo.UUID + allocateAnNssi.nssiId = sliceTaskInfo.NSSTInfo.UUID + allocateAnNssi.nssiName = sliceTaskInfo.NSSTInfo.name + allocateAnNssi.sliceProfile = sliceTaskInfo.sliceProfile + allocateAnNssi.nsiInfo.nsiId = sliceParams + + EsrInfo esrInfo = new EsrInfo() + //todo: vendor and network + esrInfo.setVendor(sliceTaskInfo.getVendor()) + esrInfo.setNetworkType(sliceTaskInfo.getNetworkType()) + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + //todo: service info + ServiceInfo serviceInfo = new ServiceInfo() + serviceInfo.globalSubscriberId = globalSubscriberId + serviceInfo.subscriptionServiceType = subscriptionServiceType + serviceInfo.nsiId = sliceParams.serviceId + serviceInfo.serviceInvariantUuid = sliceTaskInfo.NSSTInfo.invariantUUID + serviceInfo.serviceUuid = sliceTaskInfo.NSSTInfo.UUID + + nbiRequest.setServiceInfo(serviceInfo) + nbiRequest.setEsrInfo(esrInfo) + nbiRequest.setAllocateAnNssi(allocateAnNssi) + + execution.setVariable("AnAllocateNssiNbiRequest", nbiRequest) + execution.setVariable("anBHSliceTaskInfo", sliceTaskInfo) + } + + + /** + * create RAN Slice Profile Instance + * @param execution + */ + void createCnSliceProfileInstance(DelegateExecution execution) { + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + String serviceInstanceId = UUID.randomUUID().toString() + execution.setVariable("cnSliceProfileInstanceId", serviceInstanceId) //todo: + + String serviceType = "" + String serviceRole = "slice-profile" + String oStatus = "deactivated" + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<CnSliceProfile> sliceTaskInfo = sliceParams.cnSliceTaskInfo + sliceTaskInfo.setServiceInstanceId(serviceInstanceId) + + // create slice profile + ServiceInstance rspi = new ServiceInstance() + rspi.setServiceInstanceName(sliceTaskInfo.NSSTInfo.name) + rspi.setServiceType(serviceType) + rspi.setServiceRole(serviceRole) + rspi.setOrchestrationStatus(oStatus) + rspi.setModelInvariantId(sliceTaskInfo.NSSTInfo.invariantUUID) + rspi.setModelVersionId(sliceTaskInfo.NSSTInfo.UUID) + rspi.setInputParameters(uuiRequest) + rspi.setWorkloadContext(useInterval) + rspi.setEnvironmentContext(sNSSAI_id) + + //timestamp format YYYY-MM-DD hh:mm:ss + rspi.setCreatedAt(new Date(System.currentTimeMillis()).format("yyyy-MM-dd HH:mm:ss", TimeZone.getDefault())) + + execution.setVariable("communicationServiceInstance", rspi) + + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + globalSubscriberId, + subscriptionServiceType, + serviceInstanceId) + client.create(uri, rspi) + execution.setVariable("sliceParams", sliceParams) + } + + /** + * create An Slice Profile + * @param execution + */ + void createCnSliceProfile(DelegateExecution execution) { + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + //String serviceInstanceId = execution.getVariable("ranSliceProfileInstanceId") + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + + SliceTaskInfo<CnSliceProfile> sliceTaskInfo = sliceParams.cnSliceTaskInfo + CnSliceProfile cnSliceProfile = sliceTaskInfo.sliceProfile + + String profileId = UUID.randomUUID().toString() + cnSliceProfile.setSliceProfileId(profileId) + + SliceProfile sliceProfile = new SliceProfile() + sliceProfile.setProfileId(profileId) + sliceProfile.setCoverageAreaTAList(cnSliceProfile.coverageAreaTAList as String) + //todo:... + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, + globalSubscriberId, + subscriptionServiceType, + sliceTaskInfo.serviceInstanceId, + profileId + ) + client.create(uri, sliceProfile) + execution.setVariable("sliceParams", sliceParams) + } + + /** + * prepare AllocateCnNssi + * @param execution + */ + void prepareAllocateCnNssi(DelegateExecution execution) { + + //todo: + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<CnSliceProfile> sliceTaskInfo = sliceParams.cnSliceTaskInfo + + NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest() + + AllocateCnNssi allocateCnNssi = new AllocateCnNssi() + allocateCnNssi.nsstId = sliceTaskInfo.NSSTInfo.UUID + allocateCnNssi.nssiId = sliceTaskInfo.NSSTInfo.UUID + allocateCnNssi.nssiName = sliceTaskInfo.NSSTInfo.name + allocateCnNssi.sliceProfile = sliceTaskInfo.sliceProfile + allocateCnNssi.nsiInfo.nsiId = sliceParams + + EsrInfo esrInfo = new EsrInfo() + //todo: vendor and network + esrInfo.setVendor(sliceTaskInfo.getVendor()) + esrInfo.setNetworkType(sliceTaskInfo.getNetworkType()) + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + //todo: service info + ServiceInfo serviceInfo = new ServiceInfo() + serviceInfo.globalSubscriberId = globalSubscriberId + serviceInfo.subscriptionServiceType = subscriptionServiceType + serviceInfo.nsiId = sliceParams.serviceId + serviceInfo.serviceInvariantUuid = sliceTaskInfo.NSSTInfo.invariantUUID + serviceInfo.serviceUuid = sliceTaskInfo.NSSTInfo.UUID + + nbiRequest.setServiceInfo(serviceInfo) + nbiRequest.setEsrInfo(esrInfo) + nbiRequest.setAllocateCnNssi(allocateCnNssi) + + execution.setVariable("CnAllocateNssiNbiRequest", nbiRequest) + execution.setVariable("cnSliceTaskInfo", sliceTaskInfo) + } + + + /** + * create TN Slice Profile Instance + * @param execution + */ + void createTnBHSliceProfileInstance(DelegateExecution execution) { + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + String serviceType = "" + String serviceRole = "slice-profile" + String oStatus = "deactivated" + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + + SliceTaskInfo<TnSliceProfile> sliceTaskInfo = sliceParams.tnBHSliceTaskInfo + String serviceInstanceId = UUID.randomUUID().toString() + + sliceTaskInfo.setServiceInstanceId(serviceInstanceId) + //execution.setVariable("cnSliceProfileInstanceId", serviceInstanceId) //todo: + + // create slice profile + ServiceInstance rspi = new ServiceInstance() + rspi.setServiceInstanceName(sliceTaskInfo.NSSTInfo.name) + rspi.setServiceType(serviceType) + rspi.setServiceRole(serviceRole) + rspi.setOrchestrationStatus(oStatus) + rspi.setModelInvariantId(sliceTaskInfo.NSSTInfo.invariantUUID) + rspi.setModelVersionId(sliceTaskInfo.NSSTInfo.UUID) + rspi.setInputParameters(uuiRequest) + rspi.setWorkloadContext(useInterval) + rspi.setEnvironmentContext(sNSSAI_id) + + //timestamp format YYYY-MM-DD hh:mm:ss + rspi.setCreatedAt(new Date(System.currentTimeMillis()).format("yyyy-MM-dd HH:mm:ss", TimeZone.getDefault())) + + execution.setVariable("communicationServiceInstance", rspi) + + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + globalSubscriberId, + subscriptionServiceType, + serviceInstanceId) + client.create(uri, rspi) + + execution.setVariable("sliceParams", sliceParams) + } + + /** + * create An Slice Profile + * @param execution + */ + void createTnBHSliceProfile(DelegateExecution execution) { + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + String serviceInstanceId = execution.getVariable("ranSliceProfileInstanceId") + + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + + SliceTaskInfo<TnSliceProfile> sliceTaskInfo = sliceParams.tnBHSliceTaskInfo + + TnSliceProfile tnSliceProfile = sliceTaskInfo.sliceProfile + String profileId = UUID.randomUUID().toString() + tnSliceProfile.setSliceProfileId(profileId) + + SliceProfile sliceProfile = new SliceProfile() + sliceProfile.setProfileId(profileId) + //todo:... + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, + globalSubscriberId, + subscriptionServiceType, + serviceInstanceId, + profileId + ) + client.create(uri, sliceProfile) + + execution.setVariable("sliceParams", sliceParams) + } + + /** + * prepare AllocateCnNssi + * @param execution + */ + void prepareAllocateTnBHNssi(DelegateExecution execution) { + + //todo: + SliceTaskParamsAdapter sliceParams = + execution.getVariable("sliceParams") as SliceTaskParamsAdapter + SliceTaskInfo<TnSliceProfile> sliceTaskInfo = sliceParams.tnBHSliceTaskInfo + + NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest() + + AllocateTnNssi allocateTnNssi = new AllocateTnNssi() + //todo: AllocateTnNssi + //allocateTnNssi.networkSliceInfos + + EsrInfo esrInfo = new EsrInfo() + //todo: vendor and network + esrInfo.setVendor(sliceTaskInfo.getVendor()) + esrInfo.setNetworkType(sliceTaskInfo.getNetworkType()) + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + //todo: service info + ServiceInfo serviceInfo = new ServiceInfo() + serviceInfo.globalSubscriberId = globalSubscriberId + serviceInfo.subscriptionServiceType = subscriptionServiceType + serviceInfo.nsiId = sliceParams.serviceId + serviceInfo.serviceInvariantUuid = sliceTaskInfo.NSSTInfo.invariantUUID + serviceInfo.serviceUuid = sliceTaskInfo.NSSTInfo.UUID + + nbiRequest.setServiceInfo(serviceInfo) + nbiRequest.setEsrInfo(esrInfo) + nbiRequest.setAllocateTnNssi(allocateTnNssi) + + execution.setVariable("TnBHAllocateNssiNbiRequest", nbiRequest) + execution.setVariable("tnBHSliceTaskInfo", sliceTaskInfo) + } + +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSIV2.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSIV2.groovy new file mode 100644 index 0000000000..05bb53a61e --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSIV2.groovy @@ -0,0 +1,117 @@ +package org.onap.so.bpmn.infrastructure.scripts + +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.so.beans.nsmf.SliceTaskInfo +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils +import org.onap.so.bpmn.core.domain.ModelInfo +import org.onap.so.bpmn.core.domain.ServiceDecomposition +import org.onap.so.bpmn.core.json.JsonUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class DoAllocateNSSIV2 extends AbstractServiceTaskProcessor { + + private static final Logger logger = LoggerFactory.getLogger( DoAllocateNSSIV2.class); + private static final ObjectMapper MAPPER = new ObjectMapper(); + + ExceptionUtil exceptionUtil = new ExceptionUtil() + + JsonUtils jsonUtil = new JsonUtils() + + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + + @Override + void preProcessRequest(DelegateExecution execution) { + logger.trace("Enter preProcessRequest()") + +// String nssmfOperation +// +// String nsstInput = execution.getVariable("nsstInput") +// String modelUuid = jsonUtil.getJsonValue(nsstInput, "modelUuid") +// //modelUuid="2763777c-27bd-4df7-93b8-c690e23f4d3f" +// String nssiInstanceId = jsonUtil.getJsonValue(nsstInput, "serviceInstanceId") +// String serviceModelInfo = """{ +// "modelInvariantUuid":"", +// "modelUuid":"${modelUuid}", +// "modelVersion":"" +// }""" +// execution.setVariable("serviceModelInfo", serviceModelInfo) +// execution.setVariable("nssiInstanceId", nssiInstanceId) +// String nssiProfileID = UUID.randomUUID().toString() +// execution.setVariable("nssiProfileID", nssiProfileID) +// if(isBlank(nssiInstanceId)) +// { +// nssmfOperation="create" +// nssiInstanceId = UUID.randomUUID().toString() +// }else { +// nssmfOperation = "update" +// } +// execution.setVariable("nssmfOperation",nssmfOperation) +// execution.setVariable("nssiInstanceId",nssiInstanceId) +// +// def isNSSICreated = false +// execution.setVariable("isNSSICreated",isNSSICreated) +// +// int currentCycle = 0 +// execution.setVariable("currentCycle", currentCycle) + + + SliceTaskInfo sliceTaskInfo = execution.getVariable("sliceTaskInfo") as SliceTaskInfo + if (StringUtils.isBlank(sliceTaskInfo.suggestNssiId)) { + execution.setVariable("nssmfOperation", "create") + } else { + execution.setVariable("nssmfOperation", "update") + } + logger.trace("Exit preProcessRequest") + } + + /** + * prepare nssi request + * @param execution + */ + void prepareNSSIReq(DelegateExecution execution) { + + } + + void getNSSTInfo(DelegateExecution execution){ + logger.trace("Enter getNSSTInfo in DoAllocateNSSI()") + ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition") + ModelInfo modelInfo = serviceDecomposition.getModelInfo() + String serviceRole = "nssi" + String nssiServiceInvariantUuid = serviceDecomposition.modelInfo.getModelInvariantUuid() + String nssiServiceUuid = serviceDecomposition.modelInfo.getModelUuid() + String nssiServiceType = serviceDecomposition.getServiceType() + String uuiRequest = execution.getVariable("uuiRequest") + String nssiServiceName = "nssi_"+jsonUtil.getJsonValue(uuiRequest, "service.name") + execution.setVariable("nssiServiceName",nssiServiceName) + execution.setVariable("nssiServiceType",nssiServiceType) + execution.setVariable("nssiServiceInvariantUuid",nssiServiceInvariantUuid) + execution.setVariable("nssiServiceUuid",nssiServiceUuid) + execution.setVariable("serviceRole",serviceRole) + + String content = serviceDecomposition.getServiceInfo().getServiceArtifact().get(0).getContent() + String nsstID = jsonUtil.getJsonValue(content, "metadata.id") + String nsstVendor = jsonUtil.getJsonValue(content, "metadata.vendor") + String nsstDomain = jsonUtil.getJsonValue(content, "metadata.domainType") + String nsstType = jsonUtil.getJsonValue(content, "metadata.type") + + execution.setVariable("nsstID",nsstID) + execution.setVariable("nsstVendor",nsstVendor) + execution.setVariable("nsstDomain",nsstDomain) + execution.setVariable("nssiServiceUuid",nssiServiceUuid) + execution.setVariable("nsstType",nsstType) + + String nsstContentInfo = """{ + "NsstID":"${nsstID}", + "Vendor":"${nsstVendor}", + "type":"${nsstType}" + }""" + + logger.trace("Exit getNSSTInfo in DoAllocateNSSI()") + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOptionV2.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOptionV2.groovy new file mode 100644 index 0000000000..ca262172d0 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOptionV2.groovy @@ -0,0 +1,907 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + # Copyright (c) 2019, CMCC Technologies Co., Ltd. + # + # 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.scripts + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri +import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.logging.filter.base.ONAPComponents +import org.onap.so.beans.nsmf.* +import org.onap.so.beans.nsmf.oof.SubnetCapability +import org.onap.so.beans.nsmf.oof.TemplateInfo +import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils +import org.onap.so.bpmn.common.scripts.OofUtils +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.domain.ServiceDecomposition +import org.onap.so.bpmn.core.domain.ServiceProxy +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import javax.ws.rs.NotFoundException +import javax.ws.rs.core.Response + +class DoCreateSliceServiceOptionV2 extends AbstractServiceTaskProcessor{ + + private static final Logger logger = LoggerFactory.getLogger( DoCreateSliceServiceOptionV2.class) + + ExceptionUtil exceptionUtil = new ExceptionUtil() + + JsonUtils jsonUtil = new JsonUtils() + + OofUtils oofUtils = new OofUtils() + + ObjectMapper objectMapper = new ObjectMapper() + + void preProcessRequest (DelegateExecution execution) { + } + + + /** + * prepare select nsi request + * @param execution + */ + void prepareSelectNSIRequest(DelegateExecution execution) { + + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + logger.debug( "get NSI option OOF Url: " + urlString) + + boolean isNSISuggested = true + execution.setVariable("isNSISuggested",isNSISuggested) + String requestId = execution.getVariable("msoRequestId") + String messageType = "NSISelectionResponse" + + Map<String, Object> profileInfo = execution.getVariable("serviceProfile") + Map<String, Object> nstSolution = execution.getVariable("nstSolution") + logger.debug("Get NST selection from OOF: " + nstSolution.toString()) + String nstInfo = """{ + "modelInvariantId":"${nstSolution.invariantUUID}", + "modelVersionId":"${nstSolution.UUID}", + "modelName":"${nstSolution.NSTName}" + }""" + + execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1") + execution.setVariable("nsiSelection_messageType",messageType) + execution.setVariable("nsiSelection_correlator",requestId) + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + execution.setVariable("nsiSelection_timeout",timeout) + String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo,messageType, profileInfo) + execution.setVariable("nsiSelection_oofRequest",oofRequest) + logger.debug("Sending request to OOF: " + oofRequest) + } + + /** + * process select nsi response + * @param execution + */ + void processOOFResponse(DelegateExecution execution) { + + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams + String OOFResponse = execution.getVariable("nsiSelection_oofResponse") + logger.debug("NSI OOFResponse is: " + OOFResponse) + execution.setVariable("OOFResponse", OOFResponse) + //This needs to be changed to derive a value when we add policy to decide the solution options. + + Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class) + List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions") + Map<String, Object> solutions = nsiSolutions.get(0) + + String resourceSharingLevel = execution.getVariable("resourceSharingLevel") + Boolean isSharable = resourceSharingLevel == "shared" + + if (solutions != null) { + if (isSharable && solutions.get("existingNSI")) { + //sharedNSISolution + processSharedNSISolutions(solutions, execution) + } + else if(solutions.containsKey("newNSISolution")) { + processNewNSISolutions(solutions, execution) + } + } + execution.setVariable("sliceTaskParams", sliceTaskParams) + logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson()) + logger.debug("*** Completed options Call to OOF ***") + + logger.debug("start parseServiceProfile") + parseServiceProfile(execution) + logger.debug("end parseServiceProfile") + } + + + private void processNewNSISolutions(Map solutions, DelegateExecution execution) { + int index = 0 + List<Map> newNSISolutions = solutions.get("newNSISolution") + List<Map> NSSImap = new ArrayList<>() + if (newNSISolutions != null && newNSISolutions.size() > 0) { + NSSImap = newNSISolutions.get(index).get("NSSISolutions") as List<Map> + for (Map nssi : NSSImap) { + Map oofSliceProfile = nssi.get("sliceProfile") + String domain = oofSliceProfile.getOrDefault("domainType","") + logger.debug("OOF newNSISolutions SliceProfile: " +oofSliceProfile.toString()+",domain:${domain}") + if(null != domain){ + //TODO +// def nssiSolution = nssi.get("NSSISolution") as Map<String, ?> +// String nssiName = nssiSolution.getOrDefault("NSSIName", "") +// String nssiId = nssiSolution.getOrDefault("NSSIId", "") +// saveNSSIId(nssi, sliceTaskParams) + Map<String, Object> sliceProfile = getSliceProfile(domain, execution, oofSliceProfile) + saveSliceProfile(execution, domain, sliceProfile) + + } + } + } + } + + private void processSharedNSISolutions(Map solutions, DelegateExecution execution) { + String nsiName, nsiInstanceId, nssiId, nssiName + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + + Map sharedNSIsolution = ((List) solutions.get("sharedNSISolutions"))?.get(0) + nsiInstanceId = sharedNSIsolution.getOrDefault("NSIId", "") + nsiName = sharedNSIsolution.getOrDefault("NSIName", "") + sliceTaskParams.setSuggestNsiId(nsiInstanceId) + sliceTaskParams.setSuggestNsiName(nsiName) + + //Temporary modification + List NSSIs = sharedNSIsolution.get("NSSIs") + for(Map nssi : NSSIs){ + Map oofSliceProfile = ((List)nssi.get("sliceProfile"))?.get(0) + String domain = oofSliceProfile.getOrDefault("domainType","") + nssiId = nssi.getOrDefault("NSSIId","") + nssiName = nssi.getOrDefault("NSSIName","") + saveNSSIId(domain, nssiId, nssiName,execution) + Map<String, Object> sliceProfile = getSliceProfile(domain, execution, oofSliceProfile) + saveSliceProfile(execution, domain, sliceProfile) + logger.debug("OOF sharedNSISolution SliceProfile:"+oofSliceProfile.toString()+",domain:${domain}") + logger.debug("OOF sharedNSISolution nsiInstanceId:${nsiInstanceId}, nsiName:${nsiName}, nssiId:${nssiId}, nssiName:${nssiName}") + } + } + + private void parseServiceProfile(DelegateExecution execution) { + logger.debug("Start parseServiceProfile") + String serviceType = execution.getVariable("serviceType") + Map<String, Object> serviceProfile = execution.getVariable("serviceProfile") + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + // set sliceProfile for three domains + if(!sliceTaskParams.getSliceProfileAn()){ + Map<String, Object> sliceProfileAn = getSliceProfile( "AN", execution,null) + saveSliceProfile(execution,"AN",sliceProfileAn) + } + + if(!sliceTaskParams.getSliceProfileTn()){ + Map<String, Object> sliceProfileTn = getSliceProfile( "TN", execution,null) + saveSliceProfile(execution,"TN",sliceProfileTn) + } + + if(!sliceTaskParams.getSliceProfileCn()){ + Map<String, Object> sliceProfileCn = getSliceProfile( "CN", execution,null, ) + saveSliceProfile(execution,"CN",sliceProfileCn) + } + + logger.debug("Finish parseServiceProfile") + } + + private void saveSliceProfile(DelegateExecution execution, String domain, Map<String, Object> sliceProfile){ + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + if(domain.equalsIgnoreCase("AN")){ + execution.setVariable("sliceProfileAn", sliceProfile) + sliceTaskParams.setSliceProfileAn(sliceProfile) + logger.debug("sliceProfileAn: " + sliceProfile) + } + else if(domain.equalsIgnoreCase("TN")){ + execution.setVariable("sliceProfileTn", sliceProfile) + sliceTaskParams.setSliceProfileTn(sliceProfile) + logger.debug("sliceProfileTn: " + sliceProfile) + } + else if(domain.equalsIgnoreCase("CN")){ + execution.setVariable("sliceProfileCn", sliceProfile) + sliceTaskParams.setSliceProfileCn(sliceProfile) + logger.debug("sliceProfileCn: " + sliceProfile) + } + } + + private void saveNSSIId(String domain, String nssiId, String nssiName, DelegateExecution execution) { + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + if(domain.equalsIgnoreCase("AN")){ + sliceTaskParams.setAnSuggestNssiId(nssiId) + sliceTaskParams.setAnSuggestNssiName(nssiName) + } + else if(domain.equalsIgnoreCase("CN")){ + sliceTaskParams.setCnSuggestNssiId(nssiId) + sliceTaskParams.setCnSuggestNssiName(nssiName) + } + else if(domain.equalsIgnoreCase("TN")){ + sliceTaskParams.setTnSuggestNssiId(nssiId) + sliceTaskParams.setTnSuggestNssiName(nssiName) + } + } + + private Map getSliceProfile(String domain, DelegateExecution execution, Map<String, Object> oofSliceProfile) { + String profileMapStr + Map<String, Object> serviceProfile = execution.getVariable("serviceProfile") + Integer domainLatency = (Integer) serviceProfile.get("latency")/3 + + if(domain.equalsIgnoreCase("AN")){ + profileMapStr = """ { + "latency": ${domainLatency}, + "sNSSAI": "sNSSAI", + "uEMobilityLevel": "uEMobilityLevel", + "coverageAreaTAList": "coverageAreaTAList", + "5QI": 100 + }""" + } + else if(domain.equalsIgnoreCase("TN")){ + profileMapStr =""" { + "latency":${domainLatency}, + "sNSSAI":"sNSSAI", + "e2eLatency":"latency", + "bandwidth": 100 + }""" + } + else if(domain.equalsIgnoreCase("CN")){ + profileMapStr = """ { + "areaTrafficCapDL":"areaTrafficCapDL", + "maxNumberofUEs":"maxNumberofUEs", + "latency":${domainLatency}, + "expDataRateUL":"expDataRateUL", + "sNSSAI":"sNSSAI", + "areaTrafficCapUL":"areaTrafficCapUL", + "uEMobilityLevel":"uEMobilityLevel", + "expDataRateDL":"expDataRateDL", + "activityFactor":"activityFactor", + "resourceSharingLevel":"resourceSharingLevel" + }""" + } + + logger.debug("Profile map for " + domain + " : " + profileMapStr) + Map<String, Object> profileMaps = objectMapper.readValue(profileMapStr.trim().replaceAll(" ", ""), new TypeReference<Map<String, String>>(){}) + Map<String, Object> sliceProfile = [:] + for (Map.Entry<String, String> profileMap : profileMaps) { + String key = profileMap.key + String value = profileMaps.get(key) + if(null != oofSliceProfile && oofSliceProfile.keySet().contains(key)){ + sliceProfile.put(key, oofSliceProfile.get(key)) + logger.debug("Get from oof, key:${key}, value: ${oofSliceProfile.get(key)}") + } + else if(serviceProfile.keySet().contains(value)){ + sliceProfile.put(key, serviceProfile.get(value)) + } + else{ + sliceProfile.put(key, profileMaps.get(key)) + } + } + return sliceProfile + } + + void processDecomposition(DelegateExecution execution){ + logger.debug("Start processDecomposition") + + ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition") + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + String nstName = serviceDecomposition.getModelInfo().getModelName() + String nstId = serviceDecomposition.getModelInfo().getModelUuid() + sliceTaskParams.setNstName(nstName) + sliceTaskParams.setNstId(nstId) + + logger.debug("End processDecomposition") + } + + + void prepareNSTDecompose(DelegateExecution execution) { + + String modelUuid = execution.getVariable("nstModelUuid") + String modelInvariantUuid = execution.getVariable("nstModelInvariantUuid") + + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + } + + void prepareNSSTDecompose(DelegateExecution execution) { + Boolean isMoreNSSTtoProcess = false + Integer maxNSST = execution.getVariable("maxNSST") + Integer currentNSST=execution.getVariable("currentNSST") + List<String> nsstModelUUIDList = new ArrayList<>() + nsstModelUUIDList = execution.getVariable("nsstModelUUIDList") + String modelUuid = nsstModelUUIDList.get(currentNSST) + String serviceModelInfo = """{ + "modelInvariantUuid":"", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("serviceModelInfo", serviceModelInfo) + currentNSST=currentNSST+1 + if(currentNSST<maxNSST) + isMoreNSSTtoProcess=true + execution.setVariable("isMoreNSSTtoProcess",isMoreNSSTtoProcess) + execution.setVariable("maxNSST",maxNSST) + execution.setVariable("currentNSST",currentNSST) + } + + + void prepareNSSTlistfromNST(DelegateExecution execution) { + //Need to update this part from decomposition. + logger.trace("Enter prepareNSSTlistfromNST()") + Boolean isMoreNSSTtoProcess = false + ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition") + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + String nstName = serviceDecomposition.getModelInfo().getModelName() + sliceTaskParams.setNstName(nstName) + String nstId = serviceDecomposition.getModelInfo().getModelUuid() + sliceTaskParams.setNstId(nstId) + execution.setVariable("sliceTaskParams",sliceTaskParams) + + List<ServiceProxy> proxyList = serviceDecomposition.getServiceProxy() + List<String> nsstModelUUIDList = new ArrayList<>() + for(ServiceProxy serviceProxy:proxyList) + nsstModelUUIDList.add(serviceProxy.getSourceModelUuid()) + execution.setVariable("nsstModelUUIDList",nsstModelUUIDList) + Integer maxNSST = nsstModelUUIDList.size() + Integer currentNSST=0 + execution.setVariable("maxNSST",maxNSST) + execution.setVariable("currentNSST",currentNSST) + if(currentNSST<maxNSST) + isMoreNSSTtoProcess=true + execution.setVariable("isMoreNSSTtoProcess",isMoreNSSTtoProcess) + logger.trace("Exit prepareNSSTlistfromNST()") + + } + + void getNSSTOption(DelegateExecution execution) { + ServiceDecomposition serviceDecomposition= execution.getVariable("serviceDecomposition") + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String serviceType = execution.getVariable("subscriptionServiceType") + String nssiInstanceId ="" + String nssiName ="" + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + logger.debug( "get NSI option OOF Url: " + urlString) + boolean isNSISuggested = false + execution.setVariable("isNSISuggested",isNSISuggested) + + //Prepare auth for OOF - Begin + def authHeader = "" + String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution) + String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution) + + String basicAuthValue = utils.encrypt(basicAuth, msokey) + if (basicAuthValue != null) { + logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue) + try { + authHeader = utils.getBasicAuth(basicAuthValue, msokey) + execution.setVariable("BasicAuthHeaderValue", authHeader) + } catch (Exception ex) { + logger.debug( "Unable to encode username and password string: " + ex) + exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " + + "encode username and password string") + } + } else { + logger.debug( "Unable to obtain BasicAuth - BasicAuth value null") + exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " + + "value null") + } + //Prepare auth for OOF - End + //Prepare send request to OOF - Begin + String requestId = execution.getVariable("msoRequestId") + Map<String, Object> profileInfo = execution.getVariable("serviceProfile") + String nsstModelInvariantUuid = serviceDecomposition.getModelInfo().getModelInvariantUuid() + String nsstModelUuid = serviceDecomposition.getModelInfo().getModelUuid() + String nsstInfo = """"NSSTInfo": { + "invariantUUID":"${nsstModelInvariantUuid}", + "UUID":"${nsstModelUuid}" + }""" + String oofRequest = oofUtils.buildSelectNSSIRequest(execution, requestId, nsstInfo ,profileInfo) + + + URL url = new URL(urlString+"/api/oof/v1/selectnssi") + HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF) + httpClient.addAdditionalHeader("Authorization", authHeader) + Response httpResponse = httpClient.post(oofRequest) + + int responseCode = httpResponse.getStatus() + logger.debug("OOF sync response code is: " + responseCode) + + if(responseCode != 200){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") + } + + if(httpResponse.hasEntity()){ + String OOFResponse = httpResponse.readEntity(String.class) + execution.setVariable("OOFResponse", OOFResponse) + nssiInstanceId = jsonUtil.getJsonValue(OOFResponse, "NSSIIInfo.NSSIID") + nssiName = jsonUtil.getJsonValue(OOFResponse, "NSSIInfo.NSSIName") + execution.setVariable("nssiInstanceId",nssiInstanceId) + execution.setVariable("nssiName",nssiName) + } + if(StringUtils.isBlank(nssiInstanceId)){ + logger.debug( "There is no valid NSST suggested by OOF.") + }else + { + try { + AAIResourcesClient resourceClient = new AAIResourcesClient() + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiInstanceId) + AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) + Optional<ServiceInstance> si = wrapper.asBean(org.onap.aai.domain.yang.ServiceInstance.class) + org.onap.aai.domain.yang.ServiceInstance nssi = si.get() + + String domain = nssi.getEnvironmentContext().toString().toUpperCase() + switch (domain) { + case "AN": + sliceTaskParams.setAnSuggestNssiId(nssi.getServiceInstanceId()) + sliceTaskParams.setAnSuggestNssiName(nssi.getServiceInstanceName()) + break + case "CN": + sliceTaskParams.setCnSuggestNssiId(nssi.getServiceInstanceId()) + sliceTaskParams.setCnSuggestNssiName(nssi.getServiceInstanceName()) + break + case "TN": + sliceTaskParams.setTnSuggestNssiId(nssi.getServiceInstanceId()) + sliceTaskParams.setTnSuggestNssiName(nssi.getServiceInstanceName()) + break + default: + break + } + }catch(NotFoundException e) + { + logger.debug("NSSI Service Instance not found in AAI: " + nssiInstanceId) + }catch(Exception e) + { + logger.debug("NSSI Service Instance not found in AAI: " + nssiInstanceId) + } + } + logger.debug("Prepare NSSI option completed ") + } + + + /** + * new + */ + + private static final ObjectMapper MAPPER = new ObjectMapper() + + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + + private static final String QUERY_SUB_NET_CAPABILITY = "/api/rest/provMns/v1/NSS/subnetCapabilityQuery" + + private static final String QUERY_NSSI_SELECTION_CAPABILITY = "/api/rest/provMns/v1/NSS/NSSISelectionCapability" + + /** + * query Subnet Capability of TN + * @param execution + */ + public void queryTNSubnetCapability(DelegateExecution execution) { + + String vendor = execution.getVariable("vendor") + + List<String> subnetTypes = new ArrayList<>() + subnetTypes.add("TN_FH") + subnetTypes.add("TN_MH") + subnetTypes.add("TN_BH") + + String strRequest = MAPPER.writeValueAsString( + buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.TRANSPORT)) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest) + execution.setVariable("subnetCapabilityOfTN", response) + } + + /** + * query Subnet Capability of CN + * @param execution + */ + public void queryCNSubnetCapability(DelegateExecution execution) { + + String vendor = execution.getVariable("vendor") + + List<String> subnetTypes = new ArrayList<>() + subnetTypes.add("CN") + + String strRequest = MAPPER.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.CORE)) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest) + + execution.setVariable("subnetCapabilityOfCN", response) + } + + /** + * query Subnet Capability of AN + * @param execution + */ + public void queryANSubnetCapability(DelegateExecution execution) { + + String vendor = execution.getVariable("vendor") + + List<String> subnetTypes = new ArrayList<>() + subnetTypes.add("AN-NF") + + String strRequest = MAPPER.writeValueAsString(buildQuerySubnetCapRequest(vendor, subnetTypes, NetworkType.ACCESS)) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_SUB_NET_CAPABILITY, strRequest) + + execution.setVariable("subnetCapabilityOfAN", response) + } + + /** + * build request body for querying Subnet Capability + * @param vendor + * @param subnetTypes + * @param networkType + * @return + */ + private static String buildQuerySubnetCapRequest(String vendor, List<String> subnetTypes, NetworkType networkType) { + NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest() + + Map<String, Object> paramMap = new HashMap() + paramMap.put("subnetTypes", subnetTypes) + + request.setSubnetCapabilityQuery(MAPPER.writeValueAsString(paramMap)) + + EsrInfo esrInfo = new EsrInfo() + esrInfo.setVendor(vendor) + esrInfo.setNetworkType(networkType) + + request.setEsrInfo(esrInfo) + + String strRequest = MAPPER.writeValueAsString(request) + + return strRequest + } + + /** + * handle response of Subnet Capability, generate SubnetCapabilities Info for request to oof + * @param execution + */ + public void generateSubnetCapabilities(DelegateExecution execution) { + //todo: + execution.setVariable("subnetCapabilities", []) + } + + /** + * prepare the params for decompose nst + * @param execution + */ + public void prepareDecomposeNST(DelegateExecution execution) { + + String modelUuid = execution.getVariable("nstModelUuid") + String modelInvariantUuid = execution.getVariable("nstModelInvariantUuid") + + String serviceModelInfo = """{ + "modelInvariantUuid":"${modelInvariantUuid}", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("nstServiceModelInfo", serviceModelInfo) + } + + /** + * process the result of NST Decomposition + * @param execution + */ + public void processDecompositionNST(DelegateExecution execution) { + + ServiceDecomposition nstServiceDecomposition = execution.getVariable("nstServiceDecomposition") + //todo: + + } + + + /** + * prepare the params for decompose nsst + * @param execution + */ + public void prepareDecomposeNSST(DelegateExecution execution) { + Boolean isMoreNSSTtoProcess = false + def maxNSST = execution.getVariable("maxNSST") as Integer + def currentNSST = execution.getVariable("currentNSST") as Integer + def nsstModelUUIDList = execution.getVariable("nsstModelUUIDList") as List + String modelUuid = nsstModelUUIDList.get(currentNSST) + String serviceModelInfo = """{ + "modelInvariantUuid":"", + "modelUuid":"${modelUuid}", + "modelVersion":"" + }""" + execution.setVariable("nsstServiceModelInfo", serviceModelInfo) + currentNSST = currentNSST + 1 + + if(currentNSST < maxNSST) { + isMoreNSSTtoProcess = true + } + + execution.setVariable("isMoreNSSTtoProcess", isMoreNSSTtoProcess) + execution.setVariable("maxNSST", maxNSST) + execution.setVariable("currentNSST", currentNSST) + + //todo: + } + + /** + * process the result of NSST Decomposition + * @param execution + */ + public void processDecompositionNSST(DelegateExecution execution) { + ServiceDecomposition nsstServiceDecomposition = execution.getVariable("nsstServiceDecomposition") + //todo: + } + + /** + * todo: need rewrite + * prepare select nsi request + * @param execution + */ + public void preNSIRequest(DelegateExecution execution) { + + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + logger.debug( "get NSI option OOF Url: " + urlString) + + boolean isNSISuggested = true + execution.setVariable("isNSISuggested", isNSISuggested) + String requestId = execution.getVariable("msoRequestId") + String messageType = "NSISelectionResponse" + + ServiceProfile profileInfo = execution.getVariable("serviceProfile") as ServiceProfile + Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map + logger.debug("Get NST selection from OOF: " + nstSolution.toString()) + + execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1") + execution.setVariable("nsiSelection_messageType", messageType) + execution.setVariable("nsiSelection_correlator", requestId) + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution) + execution.setVariable("nsiSelection_timeout", timeout) + + + TemplateInfo nstInfo = new TemplateInfo() + nstInfo.setInvariantUUID(nstSolution.get("invariantUUID") as String) + nstInfo.setUUID(nstSolution.get("UUID") as String) + nstInfo.setName(nstSolution.get("NSTName") as String) + + execution.setVariable("NSTInfo", nstInfo) + + List<TemplateInfo> nsstInfos = execution.getVariable("NSSTInfos") as List<TemplateInfo> + + List<SubnetCapability> subnetCapabilities = execution.getVariable("subnetCapabilities") as List<SubnetCapability> + + String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, nsstInfos, + messageType, profileInfo, subnetCapabilities, timeout as Integer) + + execution.setVariable("nsiSelection_oofRequest", oofRequest) + logger.debug("Sending request to OOF: " + oofRequest) + } + + /** + * todo: need rewrite + * process select nsi response + * @param execution + */ + public void processNSIResp(DelegateExecution execution) { + + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams + String OOFResponse = execution.getVariable("nsiSelection_oofResponse") + logger.debug("NSI OOFResponse is: " + OOFResponse) + execution.setVariable("OOFResponse", OOFResponse) + //This needs to be changed to derive a value when we add policy to decide the solution options. + + Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class) + List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions") + Map<String, Object> solutions = nsiSolutions.get(0) + + String resourceSharingLevel = execution.getVariable("resourceSharingLevel") + Boolean isSharable = resourceSharingLevel == "shared" + + if (solutions != null) { + if (isSharable && solutions.get("existingNSI")) { + //sharedNSISolution + processSharedNSISolutions(solutions, execution) + } + else if(solutions.containsKey("newNSISolution")) { + processNewNSISolutions(solutions, execution) + } + } + execution.setVariable("sliceTaskParams", sliceTaskParams) + logger.debug("sliceTaskParams: " + sliceTaskParams.convertToJson()) + logger.debug("*** Completed options Call to OOF ***") + + logger.debug("start parseServiceProfile") + parseServiceProfile(execution) + logger.debug("end parseServiceProfile") + } + + /** + * get NSSI Selection Capability for AN + * @param execution + */ + public void getNSSISelectionCap4AN(DelegateExecution execution) { + + def vendor = execution.getVariable("vendor") as String + + String strRequest = buildNSSISelectionReq(vendor, NetworkType.ACCESS) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest) + + Map<String, Object> resMap = objectMapper.readValue(response, Map.class) + + String selection = resMap.get("selection") + + + if ("NSMF".equalsIgnoreCase(selection)) { + execution.setVariable("NEED_AN_NSSI_SELECTION", true) + } + } + + /** + * get NSSI Selection Capability for TN + * @param execution + */ + public void getNSSISelectionCap4TN(DelegateExecution execution) { + + def vendor = execution.getVariable("vendor") as String + + String strRequest = buildNSSISelectionReq(vendor, NetworkType.TRANSPORT) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest) + + Map<String, Object> resMap = objectMapper.readValue(response, Map.class) + + String selection = resMap.get("selection") + + if ("NSMF".equalsIgnoreCase(selection)) { + execution.setVariable("NEED_TN_NSSI_SELECTION", true) + } + } + + /** + * get NSSI Selection Capability for CN + * @param execution + */ + public void getNSSISelectionCap4CN(DelegateExecution execution) { + + def vendor = execution.getVariable("vendor") as String + + String strRequest = buildNSSISelectionReq(vendor, NetworkType.CORE) + + String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, QUERY_NSSI_SELECTION_CAPABILITY, strRequest) + + Map<String, Object> resMap = objectMapper.readValue(response, Map.class) + + String selection = resMap.get("selection") + + if ("NSMF".equalsIgnoreCase(selection)) { + execution.setVariable("NEED_CN_NSSI_SELECTION", true) + } + } + + /** + * build NSSI Selection Capability Request body to nssmf adapter + * @param vendor + * @param networkType + * @return + */ + private static String buildNSSISelectionReq(String vendor, NetworkType networkType) { + NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest() + EsrInfo esrInfo = new EsrInfo() + esrInfo.setVendor(vendor) + esrInfo.setNetworkType(networkType) + request.setEsrInfo(esrInfo) + + return MAPPER.writeValueAsString(request) + } + + /** + * if exist nssi need to select? + * @param execution + */ + public void handleNssiSelect(DelegateExecution execution) { + + SliceTaskParamsAdapter sliceTaskParams = + execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter + + execution.setVariable() + } + + /** + * todo: need rewrite + * prepare select nssi request + * @param execution + */ + public void preNSSIRequest(DelegateExecution execution) { + + String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) + logger.debug( "get NSI option OOF Url: " + urlString) + + boolean isNSISuggested = true + execution.setVariable("isNSISuggested", isNSISuggested) + String requestId = execution.getVariable("msoRequestId") + String messageType = "NSISelectionResponse" + + Map<String, Object> profileInfo = execution.getVariable("serviceProfile") as Map + Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map + logger.debug("Get NST selection from OOF: " + nstSolution.toString()) + String nstInfo = """{ + "modelInvariantId":"${nstSolution.invariantUUID}", + "modelVersionId":"${nstSolution.UUID}", + "modelName":"${nstSolution.NSTName}" + }""" + + execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1") + execution.setVariable("nsiSelection_messageType", messageType) + execution.setVariable("nsiSelection_correlator", requestId) + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution) + execution.setVariable("nsiSelection_timeout", timeout) + + //todo + String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, messageType, profileInfo) + + execution.setVariable("nsiSelection_oofRequest", oofRequest) + logger.debug("Sending request to OOF: " + oofRequest) + } + + /** + * process select nssi response + * @param execution + */ + public void processNSSIResp(DelegateExecution execution) { + + SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") as SliceTaskParams + String OOFResponse = execution.getVariable("nsiSelection_oofResponse") + logger.debug("NSI OOFResponse is: " + OOFResponse) + execution.setVariable("OOFResponse", OOFResponse) + //This needs to be changed to derive a value when we add policy to decide the solution options. + + Map<String, Object> resMap = objectMapper.readValue(OOFResponse, Map.class) + List<Map<String, Object>> nsiSolutions = (List<Map<String, Object>>) resMap.get("solutions") + Map<String, Object> solutions = nsiSolutions.get(0) + + String resourceSharingLevel = execution.getVariable("resourceSharingLevel") + Boolean isSharable = resourceSharingLevel == "shared" + + if (solutions != null) { + if (isSharable && solutions.get("existingNSI")) { + //sharedNSISolution + processSharedNSISolutions(solutions, execution) + } + else if(solutions.containsKey("newNSISolution")) { + processNewNSISolutions(solutions, execution) + } + } + execution.setVariable("sliceTaskParams", sliceTaskParams) + logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson()) + logger.debug("*** Completed options Call to OOF ***") + + logger.debug("start parseServiceProfile") + parseServiceProfile(execution) + logger.debug("end parseServiceProfile") + } + + +} |