diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/groovy')
3 files changed, 1057 insertions, 1500 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy new file mode 100644 index 0000000000..00746d4e65 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy @@ -0,0 +1,1012 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Telecom Italia + * ================================================================================ + * 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.databind.ObjectMapper +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.CloudRegion +import org.onap.aai.domain.yang.GenericVnf +import org.onap.aai.domain.yang.ModelVer +import org.onap.aai.domain.yang.ServiceInstance +import org.onap.aai.domain.yang.ServiceSubscription +import org.onap.aai.domain.yang.SliceProfile +import org.onap.aai.domain.yang.Tenant +import org.onap.aai.domain.yang.VfModule +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.Relationships +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.bpmn.common.scripts.AbstractServiceTaskProcessor +import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClient +import org.onap.so.db.request.beans.OperationStatus +import org.onap.so.requestsdb.RequestsDbConstant +import org.onap.so.serviceinstancebeans.CloudConfiguration +import org.onap.so.serviceinstancebeans.LineOfBusiness +import org.onap.so.serviceinstancebeans.ModelInfo +import org.onap.so.serviceinstancebeans.ModelType +import org.onap.so.serviceinstancebeans.OwningEntity +import org.onap.so.serviceinstancebeans.Project +import org.onap.so.serviceinstancebeans.RequestDetails +import org.onap.so.serviceinstancebeans.RequestInfo +import org.onap.so.serviceinstancebeans.RequestParameters +import org.onap.so.serviceinstancebeans.Resources +import org.onap.so.serviceinstancebeans.Service +import org.onap.so.serviceinstancebeans.SubscriberInfo +import org.onap.so.serviceinstancebeans.VfModules +import org.onap.so.serviceinstancebeans.Vnfs +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +import javax.ws.rs.core.Response + + + class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { + + private final String PREFIX ="DoCommonCoreNSSI" + + private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class) + + private JsonUtils jsonUtil = new JsonUtils() + private ExceptionUtil exceptionUtil = new ExceptionUtil() + private RequestDBUtil requestDBUtil = new RequestDBUtil() + + @Override + void preProcessRequest(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start preProcessRequest") + + def currentNSSI = execution.getVariable("currentNSSI") + if (!currentNSSI) { + String msg = "currentNSSI is null" + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest") + } + + + /** + * Queries Network Service Instance in AAI + * @param execution + */ + void getNetworkServiceInstance(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start getNetworkServiceInstance") + + AAIResourcesClient client = getAAIClient() + + def currentNSSI = execution.getVariable("currentNSSI") + + String nssiId = currentNSSI['nssiId'] + + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) + Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri) + + if (nssiOpt.isPresent()) { + ServiceInstance nssi = nssiOpt.get() + currentNSSI['nssi'] = nssi + + ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client) + currentNSSI['networkServiceInstance'] = networkServiceInstance + } + else { + String msg = String.format("NSSI %s not found in AAI", nssiId) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + + LOGGER.trace("${getPrefix()} Exit getNetworkServiceInstance") + } + + + /** + * Handles Network Service + * @param nssiId + * @param nssiUri + * @param client + * @return Network Service Instance + */ + private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) { + ServiceInstance networkServiceInstance = null + + def currentNSSI = execution.getVariable("currentNSSI") + + AAIResultWrapper wrapper = client.get(nssiUri) + Optional<Relationships> relationships = wrapper.getRelationships() + + if (relationships.isPresent()) { + for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)) { + Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri) + if (networkServiceInstanceOpt.isPresent()) { + networkServiceInstance = networkServiceInstanceOpt.get() + + if (networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role + currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri + break + } + } + else { + String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + } + } + else { + String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + + if(networkServiceInstance == null) { + String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + + return networkServiceInstance + } + + + /** + * Queries constitute VNF from Network Service Instance + * @param execution + */ + void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst") + + def currentNSSI = execution.getVariable("currentNSSI") + + AAIResourcesClient client = getAAIClient() + + AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri'] + AAIResultWrapper wrapper = client.get(networkServiceInstanceUri); + Optional<Relationships> relationships = wrapper.getRelationships() + if (relationships.isPresent()) { + for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) { + currentNSSI['constituteVnfUri'] = constituteVnfUri + Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri) + if(constituteVnfOpt.isPresent()) { + GenericVnf constituteVnf = constituteVnfOpt.get() + currentNSSI['constituteVnf'] = constituteVnf + } + else { + String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId()) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + + break // Should be only one constitute VNF + } + } + else { + String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId()) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + + LOGGER.trace("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst") + + } + + + /** + * Retrieves NSSI associated profiles from AAI + * @param execution + */ + void getNSSIAssociatedProfiles(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles") + + def currentNSSI = execution.getVariable("currentNSSI") + + ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] + + List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() + + if(associatedProfiles.isEmpty()) { + String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId()) + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) + } + else { + currentNSSI['associatedProfiles'] = associatedProfiles + } + + LOGGER.trace("${getPrefix()} Exit getNSSIAssociatedProfiles") + } + + + /** + * Calculates a final list of S-NSSAI + * @param execution + */ + void calculateSNSSAI(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start calculateSNSSAI") + + def currentNSSI = execution.getVariable("currentNSSI") + + List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles'] + + String currentSNSSAI = currentNSSI['S-NSSAI'] + + List<String> snssais = new ArrayList<>() + + String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" ) + + boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar) + + if(isCreateSliceProfileInstance) { // Slice Profile Instance has to be created + for (SliceProfile associatedProfile : associatedProfiles) { + snssais.add(associatedProfile.getSNssai()) + } + + snssais.add(currentSNSSAI) + } + else { // Slice profile instance has to be deleted + for (SliceProfile associatedProfile : associatedProfiles) { + if (!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI + snssais.add(associatedProfile.getSNssai()) + } else { + currentNSSI['sliceProfileS-NSSAI'] = associatedProfile + } + } + } + + currentNSSI['S-NSSAIs'] = snssais + + LOGGER.trace("${getPrefix()} Exit calculateSNSSAI") + } + + + /** + * Invoke PUT Service Instance API + * @param execution + */ + void invokePUTServiceInstance(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start invokePUTServiceInstance") + + def currentNSSI = execution.getVariable("currentNSSI") + + try { + //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}" + def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ??? + + ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] + + GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf'] + + String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) + + String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) + String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) + + def authHeader = "" + String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey) + String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey) + + String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode") + if(errorCode == null || errorCode.isEmpty()) { // No error + authHeader = responseAuthHeader + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage")) + } + + def requestDetails = "" + String prepareRequestDetailsResponse = prepareRequestDetails(execution) + errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode") + if(errorCode == null || errorCode.isEmpty()) { // No error + requestDetails = prepareRequestDetailsResponse + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage")) + } + + String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails) + String putServiceInstanceResponse = "" + + if(errorCode == null || errorCode.isEmpty()) { // No error + putServiceInstanceResponse = callPUTServiceInstanceResponse // check the response ??? + } + else { + LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage")) + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage")) + } + + } catch (any) { + String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause() + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + + LOGGER.trace("${getPrefix()} Exit invokePUTServiceInstance") + } + + + String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) { + String errorCode = "" + String errorMessage = "" + String response + + try { + HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL) + httpClient.addAdditionalHeader("Authorization", authHeader) + httpClient.addAdditionalHeader("Accept", "application/json") + + Response httpResponse = httpClient.put(requestDetailsStr) // check http code ??? + + + if (httpResponse.hasEntity()) { + response = httpResponse.readEntity(String.class) + } + else { + errorCode = 500 + errorMessage = "No response received." + + response = "{\n" + + " \"errorCode\": \"${errorCode}\",\n" + + " \"errorMessage\": \"${errorMessage}\"\n" + + "}" + } + } + catch (any) { + String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause() + LOGGER.error(msg) + + response = "{\n" + + " \"errorCode\": \"7000\",\n" + + " \"errorMessage\": \"${msg}\"\n" + + "}" + + } + + return response + + } + + + /** + * Prepare model info + * @param execution + * @param requestDetails + * @return ModelInfo + */ + ModelInfo prepareModelInfo(DelegateExecution execution) { + + def currentNSSI = execution.getVariable("currentNSSI") + ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] + + ModelInfo modelInfo = new ModelInfo() + + modelInfo.setModelType(ModelType.service) + modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) + + AAIResourcesClient client = getAAIClient() + + AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId()) + Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl) + + if (modelVerOpt.isPresent()) { + modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId()) + modelInfo.setModelName(modelVerOpt.get().getModelName()) + modelInfo.setModelVersion(modelVerOpt.get().getModelVersion()) + } + + return modelInfo + } + + + /** + * Prepares subscriber info + * @param execution + * @return SubscriberInfo + */ + SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + String globalSubscriberId = currentNSSI['globalSubscriberId'] + + String subscriberName = currentNSSI['subscriberName'] + + SubscriberInfo subscriberInfo = new SubscriberInfo() + subscriberInfo.setGlobalSubscriberId(globalSubscriberId) + subscriberInfo.setSubscriberName(subscriberName) + + /* + AAIResourcesClient client = getAAIClient() + + Customer customer = null + + AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri'] + AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) + Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships() + if(serviceSubscriptionRelationshipsOps.isPresent()) { + List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION) + if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) { + AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation + Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri) + + if(serviceSubscriptionOpt.isPresent()) { + currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get() + } + + wrapper = client.get(serviceSubscriptionUri) + Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships() + if(customerRelationshipsOps.isPresent()) { + List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER) + if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) { + Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation + if(customerOpt.isPresent()) { + customer = customerOpt.get() + subscriberInfo.setSubscriberName(customer.getSubscriberName()) + } + } + } + } + + } */ + + return subscriberInfo + } + + + /** + * Prepares Request Info + * @param execution + * @return RequestInfo + */ + RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) { + def currentNSSI = execution.getVariable("currentNSSI") + + String serviceId = currentNSSI['serviceId'] + + RequestInfo requestInfo = new RequestInfo() + + requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName()) + requestInfo.setSource("VID") + requestInfo.setProductFamilyId(serviceId) + requestInfo.setRequestorId("NBI") + + return requestInfo + } + + + /** + * Prepares Model Info + * @param networkServiceInstance + * @param modelInfo + * @return ModelInfo + */ + ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) { + + ModelInfo serviceModelInfo = new ModelInfo() + serviceModelInfo.setModelType(ModelType.service) + serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) + + serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId()) + serviceModelInfo.setModelName(modelInfo.getModelName()) + serviceModelInfo.setModelVersion(modelInfo.getModelVersion()) + + return serviceModelInfo + } + + + /** + * Prepares Cloud configuration + * @param execution + * @return CloudConfiguration + */ + CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + CloudConfiguration cloudConfiguration = new CloudConfiguration() + + AAIResourcesClient client = getAAIClient() + + AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri'] + AAIResultWrapper wrapper = client.get(constituteVnfUri) + Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships() + + if(cloudRegionRelationshipsOps.isPresent()) { + List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION) + if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) { + AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0) + currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri + + Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0)) + CloudRegion cloudRegion = null + if (cloudRegionrOpt.isPresent()) { + cloudRegion = cloudRegionrOpt.get() + cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId()) + for (Tenant tenant : cloudRegion.getTenants().getTenant()) { + cloudConfiguration.setTenantId(tenant.getTenantId()) + break // only one is required + } + + cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner()) + } + } + } + + return cloudConfiguration + } + + + /** + * Prepares a list of VF Modules + * @param execution + * @param constituteVnf + * @return List<VfModules> + */ + List<VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) { + + AAIResourcesClient client = getAAIClient() + + List<VfModules> vfModuless = new ArrayList<>() + for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) { + VfModules vfmodules = new VfModules() + + ModelInfo vfModuleModelInfo = new ModelInfo() + vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId()) + vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId()) + + AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId()) + + Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl) + + if (vfModuleModelVerOpt.isPresent()) { + vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId()) + vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName()) + vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion()) + } + vfmodules.setModelInfo(vfModuleModelInfo) + + vfmodules.setInstanceName(vfModule.getVfModuleName()) + + vfModuless.add(vfmodules) + } + + return vfModuless + } + + + /** + * prepares VNF Model Info + * @param execution + * @param constituteVnf + * @return ModelInfo + */ + ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) { + ModelInfo vnfModelInfo = new ModelInfo() + + AAIResourcesClient client = getAAIClient() + + vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId()) + vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId()) + vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName()) + + AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId(), constituteVnf.getModelVersionId()) + + Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl) + + if (vnfModelVerOpt.isPresent()) { + vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId()) + vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName()) + vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion()) + } + + return vnfModelInfo + } + + + List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + List<Map<String, Object>> instanceParams = new ArrayList<>() + Map<String, Object> instanceParamsMap = new HashMap<>() + + // Supported S-NSSAI + List<String> snssais = (List<String>) currentNSSI['S-NSSAIs'] + + ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi'] + + String orchStatus = nssi.getOrchestrationStatus() + + + List<Map<String, String>> snssaiList = new ArrayList<>() + + for(String snssai:snssais) { + Map<String, String> snssaisMap = new HashMap<>() + snssaisMap.put("snssai", snssai) + snssaisMap.put("status", orchStatus) + snssaiList.add(snssaisMap) + } + + // Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>() + // supportedNssaiDetails.put("sNssai", supportedNssaiDetails) + + ObjectMapper mapper = new ObjectMapper() + + String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList) + + + instanceParamsMap.put("k8s-rb-profile-name", "default") // ??? + instanceParamsMap.put("config-type", "day2") // ??? + instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr) + instanceParams.add(instanceParamsMap) + + return instanceParams + } + + /** + * Prepares Resources + * @param execution + * @return Resources + */ + Resources prepareResources(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + Resources resources = new Resources() + + // VNFs + List<Vnfs> vnfs = new ArrayList<>() + // VNF + Vnfs vnf = new Vnfs() + + // Line of Business + LineOfBusiness lob = new LineOfBusiness() + lob.setLineOfBusinessName("VNF") + vnf.setLineOfBusiness(lob) + + // Product family ID + GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf'] + vnf.setProductFamilyId(constituteVnf.getServiceId()) + + // Cloud configuration + vnf.setCloudConfiguration(prepareCloudConfiguration(execution)) + + // VF Modules + vnf.setVfModules(prepareVfModules(execution, constituteVnf)) + + // Model Info + vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf)) + + // Instance name + vnf.setInstanceName(constituteVnf.getVnfName()) + + // Instance params + vnf.setInstanceParams(prepareInstanceParams(execution)) + + // No platform data + + vnfs.add(vnf) + resources.setVnfs(vnfs) + + return resources + } + + + /** + * Prepare Service + * @return Service + */ + Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { + Service service = new Service() + + // Model Info + service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo)) + + service.setInstanceName(networkServiceInstance.getServiceInstanceName()) + + // Resources + service.setResources(prepareResources(execution)) + + return service + + } + + + /** + * Prepares request parameters + * @param execution + * @return RequestParameters + */ + RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { + def currentNSSI = execution.getVariable("currentNSSI") + + RequestParameters requestParameters = new RequestParameters() + + ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription'] + + if(serviceSubscription != null) { + requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType()) + } + + // User params + List<Map<String, Object>> userParams = new ArrayList<>() + + Map<String, Object> userParam = new HashMap<>() + userParam.put("Homing_Solution", "none") + userParams.add(userParam) + + // Service + Map<String, Object> serviceMap = new HashMap<>() + serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo)) + userParams.add(serviceMap) + requestParameters.setUserParams(userParams) + + return requestParameters + } + + + /** + * Prepare Owning Entity + * @param execution + * @return OwningEntity + */ + OwningEntity prepareOwningEntity(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + AAIResourcesClient client = getAAIClient() + + AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri'] + + OwningEntity owningEntity = new OwningEntity() + AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) + Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships() + if (owningEntityRelationshipsOps.isPresent()) { + List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY) + + if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) { + Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation + if (owningEntityOpt.isPresent()) { + owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId()) + owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName()) + + } + } + } + + return owningEntity + } + + + /** + * Prepares Project + * @param execution + * @return Project + */ + Project prepareProject(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + AAIResourcesClient client = getAAIClient() + + Project project = new Project() + + AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri'] + + if (cloudRegionRelatedAAIUri != null) { + AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri) + Optional<Relationships> cloudRegionOps = wrapper.getRelationships() + if (cloudRegionOps.isPresent()) { + List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT) + if (!(projectAAIUris == null || projectAAIUris.isEmpty())) { + Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0)) + if (projectOpt.isPresent()) { + project.setProjectName(projectOpt.get().getProjectName()) + } + } + } + } + + return project + } + + + /** + * Prepares RequestDetails object + * @param execution + * @return + */ + String prepareRequestDetails(DelegateExecution execution) { + String errorCode = "" + String errorMessage = "" + String response + + RequestDetails requestDetails = new RequestDetails() + + def currentNSSI = execution.getVariable("currentNSSI") + + ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] + + try { + // Model Info + ModelInfo modelInfo = prepareModelInfo(execution) + requestDetails.setModelInfo(modelInfo) + + // Subscriber Info + requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution)) + + // Request Info + requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance)) + + // Request Parameters + requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo)) + + // Cloud configuration + requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution)) + + // Owning entity + requestDetails.setOwningEntity(prepareOwningEntity(execution)) + + // Project + requestDetails.setProject(prepareProject(execution)) + + ObjectMapper mapper = new ObjectMapper() + + response = mapper.writeValueAsString(requestDetails) + } + catch (any) { + String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause() + LOGGER.error(msg) + + response = "{\n" + + " \"errorCode\": \"7000\",\n" + + " \"errorMessage\": \"${msg}\"\n" + + "}" + + } + + return response + } + + + String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) { + String response = "" + String errorCode = "" + String errorMessage = "" + + LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue) + try { + response = utils.getBasicAuth(basicAuthValue, msokey) + } catch (Exception ex) { + LOGGER.error("Unable to encode username and password string: ", ex) + + errorCode = "401" + errorMessage = "Internal Error - Unable to encode username and password string" + + response = "{\n" + + " \"errorCode\": \"${errorCode}\",\n" + + " \"errorMessage\": \"${errorMessage}\"\n" + + "}" + } + + return response + } + + + String encryptBasicAuth(String basicAuth, String msoKey) { + return utils.encrypt(basicAuth, msoKey) + } + + + /** + * Removes Slice Profile association with NSSI + * @param execution + */ + void removeSPAssociationWithNSSI(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start removeSPAssociationWithNSSI") + + AAIResourcesClient client = getAAIClient() + + def currentNSSI = execution.getVariable("currentNSSI") + + ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] + + String nssiId = currentNSSI['nssiId'] + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) + + List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() + + String currentSNSSAI = currentNSSI['S-NSSAI'] + + associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) }) + + try { + getAAIClient().update(nssiUri, nssi) + }catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage()) + } + + LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI") + } + + + /** + * Deletes Slice Profile Instance + * @param execution + */ + void deleteSliceProfileInstance(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start deleteSliceProfileInstance") + + AAIResourcesClient client = getAAIClient() + + def currentNSSI = execution.getVariable("currentNSSI") + + SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI'] + + String globalSubscriberId = currentNSSI['globalSubscriberId'] + String serviceType = currentNSSI['serviceType'] + String nssiId = currentNSSI['nssiId'] + + // global-customer-id, service-type, service-instance-id, profile-id + AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileContainsSNSSAI.getProfileId()) + + try { + getAAIClient().delete(sliceProfileUri) + }catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage()) + } + + LOGGER.trace("${getPrefix()} Exit deleteSliceProfileInstance") + } + + + /** + * Updates operation status + * @param execution + */ + void updateServiceOperationStatus(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus") + + def currentNSSI = execution.getVariable("currentNSSI") + + OperationStatus operationStatus = new OperationStatus() + operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String) + operationStatus.setOperationId(currentNSSI['operationId'] as String) + operationStatus.setOperation(currentNSSI['operationType'] as String) + operationStatus.setResult(RequestsDbConstant.Status.FINISHED) + + requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus) + + LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus") + } + + + /** + * Returns AAI client + * @return AAI client + */ + AAIResourcesClient getAAIClient() { + return new AAIResourcesClient() + } + + + String getPrefix() { + return PREFIX + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy index 49aeec8ee3..5dd70a0ab9 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2020 TIM + * Copyright (C) 2020 Telecom Italia * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ import org.slf4j.LoggerFactory import javax.ws.rs.core.Response -class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { +class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { private final String PREFIX ="DoDeallocateCoreNSSI" private ExceptionUtil exceptionUtil = new ExceptionUtil() @@ -79,31 +79,13 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateCoreNSSI.class) - @Override - void preProcessRequest(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start preProcessRequest") - - def currentNSSI = execution.getVariable("currentNSSI") - if (!currentNSSI) { - String msg = "currentNSSI is null" - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - - LOGGER.trace("***** ${PREFIX} Exit preProcessRequest") - } - - - /** +/** * Queries OOF for NSSI termination * @param execution */ void executeTerminateNSSIQuery(DelegateExecution execution) { - // TO DO: Unit test LOGGER.trace("${PREFIX} Start executeTerminateNSSIQuery") - def currentNSSI = execution.getVariable("currentNSSI") - String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) //Prepare auth for OOF @@ -266,90 +248,6 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { /** - * Queries Network Service Instance in AAI - * @param execution - */ - void getNetworkServiceInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getNetworkServiceInstance") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] - String nssiId = currentNSSI['nssiId'] - - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) - Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri) - - if (nssiOpt.isPresent()) { - ServiceInstance nssi = nssiOpt.get() - currentNSSI['nssi'] = nssi - - ServiceInstance networkServiceInstance = handleNetworkInstance(execution, nssiId, nssiUri, client) - currentNSSI['networkServiceInstance'] = networkServiceInstance - } - else { - String msg = String.format("NSSI %s not found in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - LOGGER.trace("${PREFIX} Exit getNetworkServiceInstance") - } - - - /** - * Handles Network Service - * @param nssiId - * @param nssiUri - * @param client - * @return Network Service Instance - */ - private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) { - ServiceInstance networkServiceInstance = null - - def currentNSSI = execution.getVariable("currentNSSI") - - AAIResultWrapper wrapper = client.get(nssiUri) - Optional<Relationships> relationships = wrapper.getRelationships() - - if (relationships.isPresent()) { - for (AAIResourceUri networkServiceInstanceUri : relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)) { - Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri) - if (networkServiceInstanceOpt.isPresent()) { - networkServiceInstance = networkServiceInstanceOpt.get() - - if (networkServiceInstance.getServiceRole().equals("Network Service")) { // Network Service role - currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri - break - } - } - else { - String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - } - else { - String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - if(networkServiceInstance == null) { - String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - return networkServiceInstance - } - - - /** * Invokes deleteServiceOrder external API * @param execution */ @@ -445,715 +343,6 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { /** - * Queries constitute VNF from Network Service Instance - * @param execution - */ - void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getConstituteVNFFromNetworkServiceInst") - - def currentNSSI = execution.getVariable("currentNSSI") - - AAIResourcesClient client = getAAIClient() - - AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri'] - AAIResultWrapper wrapper = client.get(networkServiceInstanceUri); - Optional<Relationships> relationships = wrapper.getRelationships() - if (relationships.isPresent()) { - for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) { - currentNSSI['constituteVnfUri'] = constituteVnfUri - Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri) - if(constituteVnfOpt.isPresent()) { - GenericVnf constituteVnf = constituteVnfOpt.get() - currentNSSI['constituteVnf'] = constituteVnf - } - else { - String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - break // Should be only one constitute VNF - } - } - else { - String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - LOGGER.trace("${PREFIX} Exit getConstituteVNFFromNetworkServiceInst") - - } - - - /** - * Retrieves NSSI associated profiles from AAI - * @param execution - */ - void getNSSIAssociatedProfiles(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getNSSIAssociatedProfiles") - - def currentNSSI = execution.getVariable("currentNSSI") - - ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] - - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - - if(associatedProfiles.isEmpty()) { - String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - else { - currentNSSI['associatedProfiles'] = associatedProfiles - } - - LOGGER.trace("${PREFIX} Exit getNSSIAssociatedProfiles") - } - - - /** - * Calculates a final list of S-NSSAI - * @param execution - */ - void calculateSNSSAI(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start calculateSNSSAI") - - def currentNSSI = execution.getVariable("currentNSSI") - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles'] - - String currentSNSSAI = currentNSSI['S-NSSAI'] - - List<String> snssais = new ArrayList<>() - - for(SliceProfile associatedProfile:associatedProfiles) { - if(!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI - snssais.add(associatedProfile.getSNssai()) - } - else { - currentNSSI['sliceProfileS-NSSAI'] = associatedProfile - } - } - - currentNSSI['S-NSSAIs'] = snssais - - LOGGER.trace("${PREFIX} Exit calculateSNSSAI") - } - - - /** - * Invoke PUT Service Instance API - * @param execution - */ - void invokePUTServiceInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start invokePUTServiceInstance") - - def currentNSSI = execution.getVariable("currentNSSI") - - try { - //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}" - def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ??? - - ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] - - GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf'] - - String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) - - String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) - - def authHeader = "" - String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey) - String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey) - - String errorCode = jsonUtil.getJsonValue(responseAuthHeader, "errorCode") - if(errorCode == null || errorCode.isEmpty()) { // No error - authHeader = responseAuthHeader - } - else { - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage")) - } - - def requestDetails = "" - String prepareRequestDetailsResponse = prepareRequestDetails(execution) - errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode") - if(errorCode == null || errorCode.isEmpty()) { // No error - requestDetails = prepareRequestDetailsResponse - } - else { - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage")) - } - - String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails) - String putServiceInstanceResponse = "" - - if(errorCode == null || errorCode.isEmpty()) { // No error - putServiceInstanceResponse = callPUTServiceInstanceResponse // check the response ??? - } - else { - LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage")) - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage")) - } - - } catch (any) { - String msg = "Exception in DoDeallocateCoreNSSI.invokePUTServiceInstance. " + any.getCause() - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - - LOGGER.trace("${PREFIX} Exit invokePUTServiceInstance") - } - - - String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) { - String errorCode = "" - String errorMessage = "" - String response - - try { - HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL) - httpClient.addAdditionalHeader("Authorization", authHeader) - httpClient.addAdditionalHeader("Accept", "application/json") - - Response httpResponse = httpClient.put(requestDetailsStr) // check http code ??? - - - if (httpResponse.hasEntity()) { - response = httpResponse.readEntity(String.class) - } - else { - errorCode = 500 - errorMessage = "No response received." - - response = "{\n" + - " \"errorCode\": \"${errorCode}\",\n" + - " \"errorMessage\": \"${errorMessage}\"\n" + - "}" - } - } - catch (any) { - String msg = "Exception in DoDeallocateCoreNSSI.invokePUTServiceInstance. " + any.getCause() - LOGGER.error(msg) - - response = "{\n" + - " \"errorCode\": \"7000\",\n" + - " \"errorMessage\": \"${msg}\"\n" + - "}" - - } - - return response - - } - - - /** - * Prepare model info - * @param execution - * @param requestDetails - * @return ModelInfo - */ - ModelInfo prepareModelInfo(DelegateExecution execution) { - - def currentNSSI = execution.getVariable("currentNSSI") - ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] - - ModelInfo modelInfo = new ModelInfo() - - modelInfo.setModelType(ModelType.service) - modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) - - AAIResourcesClient client = getAAIClient() - - AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId()) - Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl) - - if (modelVerOpt.isPresent()) { - modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId()) - modelInfo.setModelName(modelVerOpt.get().getModelName()) - modelInfo.setModelVersion(modelVerOpt.get().getModelVersion()) - } - - return modelInfo - } - - - /** - * Prepares subscriber info - * @param execution - * @return SubscriberInfo - */ - SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - - String subscriberName = currentNSSI['subscriberName'] - - SubscriberInfo subscriberInfo = new SubscriberInfo() - subscriberInfo.setGlobalSubscriberId(globalSubscriberId) - subscriberInfo.setSubscriberName(subscriberName) - - /* - AAIResourcesClient client = getAAIClient() - - Customer customer = null - - AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri'] - AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) - Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships() - if(serviceSubscriptionRelationshipsOps.isPresent()) { - List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION) - if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) { - AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation - Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri) - - if(serviceSubscriptionOpt.isPresent()) { - currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get() - } - - wrapper = client.get(serviceSubscriptionUri) - Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships() - if(customerRelationshipsOps.isPresent()) { - List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER) - if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) { - Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation - if(customerOpt.isPresent()) { - customer = customerOpt.get() - subscriberInfo.setSubscriberName(customer.getSubscriberName()) - } - } - } - } - - } */ - - return subscriberInfo - } - - - /** - * Prepares Request Info - * @param execution - * @return RequestInfo - */ - RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) { - def currentNSSI = execution.getVariable("currentNSSI") - - String serviceId = currentNSSI['serviceId'] - - RequestInfo requestInfo = new RequestInfo() - - requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName()) - requestInfo.setSource("VID") - requestInfo.setProductFamilyId(serviceId) - requestInfo.setRequestorId("NBI") - - return requestInfo - } - - - /** - * Prepares Model Info - * @param networkServiceInstance - * @param modelInfo - * @return ModelInfo - */ - ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) { - - ModelInfo serviceModelInfo = new ModelInfo() - serviceModelInfo.setModelType(ModelType.service) - serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) - - serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId()) - serviceModelInfo.setModelName(modelInfo.getModelName()) - serviceModelInfo.setModelVersion(modelInfo.getModelVersion()) - - return serviceModelInfo - } - - - /** - * Prepares Cloud configuration - * @param execution - * @return CloudConfiguration - */ - CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - CloudConfiguration cloudConfiguration = new CloudConfiguration() - - AAIResourcesClient client = getAAIClient() - - AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri'] - AAIResultWrapper wrapper = client.get(constituteVnfUri) - Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships() - - if(cloudRegionRelationshipsOps.isPresent()) { - List<AAIResourceUri> cloudRegionRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION) - if (!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) { - AAIResourceUri cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0) - currentNSSI['cloudRegionRelatedAAIUri'] = cloudRegionRelatedAAIUri - - Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0)) - CloudRegion cloudRegion = null - if (cloudRegionrOpt.isPresent()) { - cloudRegion = cloudRegionrOpt.get() - cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId()) - for (Tenant tenant : cloudRegion.getTenants().getTenant()) { - cloudConfiguration.setTenantId(tenant.getTenantId()) - break // only one is required - } - - cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner()) - } - } - } - - return cloudConfiguration - } - - - /** - * Prepares a list of VF Modules - * @param execution - * @param constituteVnf - * @return List<VfModules> - */ - List<VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) { - - AAIResourcesClient client = getAAIClient() - - List<VfModules> vfModuless = new ArrayList<>() - for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) { - VfModules vfmodules = new VfModules() - - ModelInfo vfModuleModelInfo = new ModelInfo() - vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId()) - vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId()) - - AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId()) - - Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl) - - if (vfModuleModelVerOpt.isPresent()) { - vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId()) - vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName()) - vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion()) - - // No model customization ID - } - vfmodules.setModelInfo(vfModuleModelInfo) - - vfmodules.setInstanceName(vfModule.getVfModuleName()) // ??? - - vfModuless.add(vfmodules) - } - - return vfModuless - } - - - /** - * prepares VNF Model Info - * @param execution - * @param constituteVnf - * @return ModelInfo - */ - ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) { - ModelInfo vnfModelInfo = new ModelInfo() - - AAIResourcesClient client = getAAIClient() - - vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId()) - vnfModelInfo.setModelCustomizationId(constituteVnf.getModelCustomizationId()) - vnfModelInfo.setModelInstanceName(constituteVnf.getVnfName()) - - AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId(), constituteVnf.getModelVersionId()) - - Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl) - - if (vnfModelVerOpt.isPresent()) { - vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId()) - vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName()) - vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion()) - - // No model instance name - } - - return vnfModelInfo - } - - - List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - List<Map<String, Object>> instanceParams = new ArrayList<>() - Map<String, Object> instanceParamsMap = new HashMap<>() - - // Supported S-NSSAI - List<String> snssais = (List<String>) currentNSSI['S-NSSAIs'] - - ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi'] - - String orchStatus = nssi.getOrchestrationStatus() - - - List<Map<String, String>> snssaiList = new ArrayList<>() - - for(String snssai:snssais) { - Map<String, String> snssaisMap = new HashMap<>() - snssaisMap.put("snssai", snssai) - snssaisMap.put("status", orchStatus) - snssaiList.add(snssaisMap) - } - - // Map<String, List<Map<String, String>>> supportedNssaiDetails = new HashMap<>() - // supportedNssaiDetails.put("sNssai", supportedNssaiDetails) - - ObjectMapper mapper = new ObjectMapper() - - String supportedNssaiDetailsStr = mapper.writeValueAsString(snssaiList) - - - instanceParamsMap.put("k8s-rb-profile-name", "default") // ??? - instanceParamsMap.put("config-type", "day2") // ??? - instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr) - instanceParams.add(instanceParamsMap) - - // No other instance params, e.g. config-type - - return instanceParams - } - - /** - * Prepares Resources - * @param execution - * @return Resources - */ - Resources prepareResources(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - Resources resources = new Resources() - - // VNFs - List<Vnfs> vnfs = new ArrayList<>() - // VNF - Vnfs vnf = new Vnfs() - - // Line of Business - LineOfBusiness lob = new LineOfBusiness() - lob.setLineOfBusinessName("VNF") - vnf.setLineOfBusiness(lob) - - // Product family ID - GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf'] - vnf.setProductFamilyId(constituteVnf.getServiceId()) - - // Cloud configuration - vnf.setCloudConfiguration(prepareCloudConfiguration(execution)) - - // VF Modules - vnf.setVfModules(prepareVfModules(execution, constituteVnf)) - - // Model Info - vnf.setModelInfo(prepareVNFModelInfo(execution, constituteVnf)) - - // Instance name - vnf.setInstanceName(constituteVnf.getVnfName()) - - // Instance params - vnf.setInstanceParams(prepareInstanceParams(execution)) - - // No platform data - - vnfs.add(vnf) - resources.setVnfs(vnfs) - - return resources - } - - - /** - * Prepare Service - * @return Service - */ - Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { - Service service = new Service() - - // Model Info - service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo)) - - service.setInstanceName(networkServiceInstance.getServiceInstanceName()) - - // Resources - service.setResources(prepareResources(execution)) - - return service - - } - - - /** - * Prepares request parameters - * @param execution - * @return RequestParameters - */ - RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { - def currentNSSI = execution.getVariable("currentNSSI") - - RequestParameters requestParameters = new RequestParameters() - - ServiceSubscription serviceSubscription = (ServiceSubscription)currentNSSI['serviceSubscription'] - - if(serviceSubscription != null) { - requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType()) - } - - // User params - List<Map<String, Object>> userParams = new ArrayList<>() - - Map<String, Object> userParam = new HashMap<>() - userParam.put("Homing_Solution", "none") - userParams.add(userParam) - - // Service - Map<String, Object> serviceMap = new HashMap<>() - serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo)) - userParams.add(serviceMap) - requestParameters.setUserParams(userParams) - - // No other user params - - return requestParameters - } - - - /** - * Prepare Owning Entity - * @param execution - * @return OwningEntity - */ - OwningEntity prepareOwningEntity(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - AAIResourcesClient client = getAAIClient() - - AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri'] - - OwningEntity owningEntity = new OwningEntity() - AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) - Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships() - if (owningEntityRelationshipsOps.isPresent()) { - List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY) - - if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation - if (owningEntityOpt.isPresent()) { - owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId()) - owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName()) - - } - } - } - - return owningEntity - } - - - /** - * Prepares Project - * @param execution - * @return Project - */ - Project prepareProject(DelegateExecution execution) { - def currentNSSI = execution.getVariable("currentNSSI") - - AAIResourcesClient client = getAAIClient() - - Project project = new Project() - - AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri'] - - if (cloudRegionRelatedAAIUri != null) { - AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri) - Optional<Relationships> cloudRegionOps = wrapper.getRelationships() - if (cloudRegionOps.isPresent()) { - List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT) - if (!(projectAAIUris == null || projectAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0)) - if (projectOpt.isPresent()) { - project.setProjectName(projectOpt.get().getProjectName()) - } - } - } - } - - return project - } - - - /** - * Prepares RequestDetails object - * @param execution - * @return - */ - String prepareRequestDetails(DelegateExecution execution) { - String errorCode = "" - String errorMessage = "" - String response - - RequestDetails requestDetails = new RequestDetails() - - def currentNSSI = execution.getVariable("currentNSSI") - - ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] - - try { - // Model Info - ModelInfo modelInfo = prepareModelInfo(execution) - requestDetails.setModelInfo(modelInfo) - - // Subscriber Info - requestDetails.setSubscriberInfo(prepareSubscriberInfo(execution)) - - // Request Info - requestDetails.setRequestInfo(prepareRequestInfo(execution, networkServiceInstance)) - - // Request Parameters - requestDetails.setRequestParameters(prepareRequestParameters(execution, networkServiceInstance, modelInfo)) - - // Cloud configuration - requestDetails.setCloudConfiguration(prepareCloudConfiguration(execution)) - - // Owning entity - requestDetails.setOwningEntity(prepareOwningEntity(execution)) - - // Project - requestDetails.setProject(prepareProject(execution)) - - ObjectMapper mapper = new ObjectMapper() - - response = mapper.writeValueAsString(requestDetails) - } - catch (any) { - String msg = "Exception in DoDeallocateCoreNSSI.prepareRequestDetails. " + any.getCause() - LOGGER.error(msg) - - response = "{\n" + - " \"errorCode\": \"7000\",\n" + - " \"errorMessage\": \"${msg}\"\n" + - "}" - - } - - return response - } - - - /** * Removes NSSI association with NSI * @param execution */ @@ -1181,68 +370,6 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { /** - * Removes Slice Profile association with NSSI - * @param execution - */ - void removeSPAssociationWithNSSI(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start removeSPAssociationWithNSSI") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] - - String nssiId = currentNSSI['nssiId'] - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) - - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - - String currentSNSSAI = currentNSSI['S-NSSAI'] - - associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) }) - - try { - getAAIClient().update(nssiUri, nssi) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage()) - } - - LOGGER.trace("${PREFIX} Exit removeSPAssociationWithNSSI") - } - - - /** - * Deletes Slice Profile Instance - * @param execution - */ - void deleteSliceProfileInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start deleteSliceProfileInstance") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI'] - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] - String nssiId = currentNSSI['nssiId'] - - // global-customer-id, service-type, service-instance-id, profile-id - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileContainsSNSSAI.getProfileId()) - - try { - getAAIClient().delete(sliceProfileUri) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage()) - } - - LOGGER.trace("${PREFIX} Exit deleteSliceProfileInstance") - } - - - /** * Delets NSSI Service Instance * @param execution */ @@ -1266,33 +393,10 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor { } - /** - * Updates operation status - * @param execution - */ - void updateServiceOperationStatus(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start updateServiceOperationStatus") - - def currentNSSI = execution.getVariable("currentNSSI") - - OperationStatus operationStatus = new OperationStatus() - operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String) - operationStatus.setOperationId(currentNSSI['operationId'] as String) - operationStatus.setOperation(currentNSSI['operationType'] as String) - operationStatus.setResult(RequestsDbConstant.Status.FINISHED) - - requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus) - - LOGGER.trace("${PREFIX} Exit updateServiceOperationStatus") - } - - /** - * Returns AAI client - * @return AAI client - */ - AAIResourcesClient getAAIClient() { - return new AAIResourcesClient() + @Override + String getPrefix() { + return PREFIX } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy index 6c12a656f4..1f25c733cd 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Telecom Italia + * ================================================================================ + * 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.databind.ObjectMapper @@ -47,7 +67,7 @@ import org.slf4j.LoggerFactory import javax.ws.rs.core.Response -class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { +class DoModifyCoreNSSI extends DoCommonCoreNSSI { private final String PREFIX ="DoModifyCoreNSSI" @@ -58,501 +78,6 @@ class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class) - @Override - void preProcessRequest(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start preProcessRequest") - - def currentNSSI = execution.getVariable("currentNSSI") - if (!currentNSSI) { - String msg = "currentNSSI is null" - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) - } - - LOGGER.trace("***** ${PREFIX} Exit preProcessRequest") - } - - - /** - * Queries Network Service Instance in AAI - * @param execution - */ - void getNetworkServiceInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getNetworkServiceInstance") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] - String nssiId = currentNSSI['nssiServiceInstanceId'] - - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) //AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiId) - Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri) - - if (nssiOpt.isPresent()) { - ServiceInstance nssi = nssiOpt.get() - execution.setVariable("nssi", nssi) - - execution.setVariable("nssiUri", nssiUrl) - - // Network Service Instance - AAIResultWrapper wrapper = client.get(nssiUri); - Optional<Relationships> relationships = wrapper.getRelationships() - if (relationships.isPresent()) { - for(AAIResourceUri networkServiceInstanceUri: relationships.get().getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)){ // ??? - Optional<ServiceInstance> networkServiceInstanceOpt = client.get(ServiceInstance.class, networkServiceInstanceUri) - if(networkServiceInstanceOpt.isPresent()) { - ServiceInstance networkServiceInstance = networkServiceInstanceOpt.get() - - if(networkServiceInstance.getServiceRole().equals("Network Service")) { // Network Service - execution.setVariable("networkServiceInstance", networkServiceInstance) - - execution.setVariable("networkServiceInstanceUri", networkServiceInstanceUri) - break // Should be only one Network Service Instance - } - } - else { - String msg = String.format("No Network Service Instance found for NSSI %s in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - } - } - else { - String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - } - else { - String msg = String.format("NSSI %s not found in AAI", nssiId) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - - LOGGER.trace("***** ${PREFIX} Exit getNetworkServiceInstance") - } - - - /** - * Queries constitute VNF from Network Service Instance - * @param execution - */ - void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getConstituteVNFFromNetworkServiceInst") - - AAIResourcesClient client = getAAIClient() - - AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)execution.getVariable("networkServiceInstanceUri") - AAIResultWrapper wrapper = client.get(networkServiceInstanceUri); - Optional<Relationships> relationships = wrapper.getRelationships() - if (relationships.isPresent()) { - for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedAAIUris(AAIObjectType.GENERIC_VNF)) { // ??? - execution.setVariable("constituteVnfUri", constituteVnfUri) - Optional<GenericVnf> constituteVnfOpt = client.get(GenericVnf.class, constituteVnfUri) - if(constituteVnfOpt.isPresent()) { - GenericVnf constituteVnf = constituteVnfOpt.get() - execution.setVariable("constituteVnf", constituteVnf) - } - else { - String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)execution.getVariable("networkServiceInstance")).getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - execution.setVariable("networkServiceInstanceUri", networkServiceInstanceUri) - break // Should be only one constitute VNF - } - } - else { - String msg = String.format("No relationship presented for Network Service Instance %s in AAI", ((ServiceInstance)execution.getVariable("networkServiceInstance")).getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - - LOGGER.trace("${PREFIX} Exit getConstituteVNFFromNetworkServiceInst") - - } - - - /** - * Retrieves NSSI associated profiles from AAI - * @param execution - */ - void getNSSIAssociatedProfiles(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start getNSSIAssociatedProfiles") - - AAIResourcesClient client = getAAIClient() - - ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi") - - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - - if(associatedProfiles.isEmpty()) { - String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId()) - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg) - } - else { - execution.setVariable("associatedProfiles", associatedProfiles) - } - - LOGGER.trace("${PREFIX} Exit getNSSIAssociatedProfiles") - } - - - /** - * Calculates a final list of S-NSSAI - * @param execution - */ - void calculateSNSSAI(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start calculateSNSSAI") - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)execution.getVariable("associatedProfiles") - - def currentNSSI = execution.getVariable("currentNSSI") - - String currentSNSSAI = currentNSSI['S-NSSAI'] - - List<String> snssais = new ArrayList<>() - - if((Boolean)execution.getVariable("isCreateSliceProfileInstance" ).equals(Boolean.TRUE)) { // Slice Profile Instance has to be created - for (SliceProfile associatedProfile : associatedProfiles) { - snssais.add(associatedProfile.getSNssai()) - } - - snssais.add(currentSNSSAI) - } - else { // Slice profile instance has to be deleted - for (SliceProfile associatedProfile : associatedProfiles) { - if (!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI - snssais.add(associatedProfile.getSNssai()) - } - } - } - - execution.setVariable("S-NSSAIs", snssais) - - LOGGER.trace("${PREFIX} Exit calculateSNSSAI") - } - - - /** - * Invoke PUT Service Instance API - * @param execution - */ - void invokePUTServiceInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start invokePUTServiceInstance") - - try { - //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}" - def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ??? - - ServiceInstance networkServiceInstance = (ServiceInstance)execution.getVariable("networkServiceInstance") - - GenericVnf constituteVnf = (GenericVnf)execution.getVariable("constituteVnf") - - String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) // ??? - - String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) - String basicAuthValue = utils.encrypt(basicAuth, msoKey) - String encodeString = utils.getBasicAuth(basicAuthValue, msoKey) - - HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL) - httpClient.addAdditionalHeader("Authorization", encodeString) - httpClient.addAdditionalHeader("Accept", "application/json") - - RequestDetails requestDetails = prepareRequestDetails(execution) - ObjectMapper mapper = new ObjectMapper() - String requestDetailsStr = mapper.writeValueAsString(requestDetails) - - Response httpResponse = httpClient.put(requestDetailsStr) // check http code ??? - } catch (any) { - String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause() - LOGGER.error(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) - } - - LOGGER.trace("${PREFIX} Exit invokePUTServiceInstance") - } - - - /** - * Prepare model info - * @param execution - * @param requestDetails - * @return - */ - private ModelInfo prepareModelInfo(DelegateExecution execution) { - ModelInfo modelInfo = new ModelInfo() - - modelInfo.setModelType(ModelType.service) - modelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) - - AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId()) // model of Network Service Instance ??? - Optional<ModelVer> modelVerOpt = client.get(ModelVer.class, modelVerUrl) - - if (modelVerOpt.isPresent()) { - modelInfo.setModelVersionId(modelVerOpt.get().getModelVersionId()) - modelInfo.setModelName(modelVerOpt.get().getModelName()) - modelInfo.setModelVersion(modelVerOpt.get().getModelVersion()) - } - - - return modelInfo - } - - - /** - * Prepares RequestDetails object - * @param execution - * @return - */ - private RequestDetails prepareRequestDetails(DelegateExecution execution) { - RequestDetails requestDetails = new RequestDetails() - - def currentNSSI = execution.getVariable("currentNSSI") - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - - ServiceInstance networkServiceInstance = (ServiceInstance)execution.getVariable("networkServiceInstance") - - - AAIResourcesClient client = getAAIClient() - - // Model Info - requestDetails.setModelInfo(prepareModelInfo(execution)) - - // Subscriber Info - SubscriberInfo subscriberInfo = new SubscriberInfo() - subscriberInfo.setGlobalSubscriberId(globalSubscriberId) - - Customer customer = null - ServiceSubscription serviceSubscription = null - - AAIResourceUri networkServiceInstanceUri = execution.getVariable("networkServiceInstanceUri") - AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) - Optional<Relationships> serviceSubscriptionRelationshipsOps = wrapper.getRelationships() - if(serviceSubscriptionRelationshipsOps.isPresent()) { - List<AAIResourceUri> serviceSubscriptionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION) - if(!(serviceSubscriptionRelatedAAIUris == null || serviceSubscriptionRelatedAAIUris.isEmpty())) { - AAIResourceUri serviceSubscriptionUri = serviceSubscriptionRelatedAAIUris.get(0) // Many-To-One relation - Optional<ServiceSubscription> serviceSubscriptionOpt = client.get(ServiceSubscription.class, serviceSubscriptionUri) - if(serviceSubscriptionOpt.isPresent()) { - serviceSubscription = serviceSubscriptionOpt.get() - } - - wrapper = client.get(serviceSubscriptionUri) - Optional<Relationships> customerRelationshipsOps = wrapper.getRelationships() - if(customerRelationshipsOps.isPresent()) { - List<AAIResourceUri> customerRelatedAAIUris = customerRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CUSTOMER) - if(!(customerRelatedAAIUris == null || customerRelatedAAIUris.isEmpty())) { - Optional<Customer> customerOpt = client.get(Customer.class, customerRelatedAAIUris.get(0)) // Many-To-One relation - if(customerOpt.isPresent()) { - customer = customerOpt.get() - subscriberInfo.setSubscriberName(customer.getSubscriberName()) - } - } - } - } - - } - requestDetails.setSubscriberInfo(subscriberInfo) - - // Request Info - RequestInfo requestInfo = new RequestInfo() - requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName()) - - /* No found data to provide ??? - requestInfo.setSource() - requestInfo.setSuppressRollback() - requestInfo.setRequestorId() - requestInfo.setProductFamilyId() - */ - - requestDetails.setRequestInfo(requestInfo) - - - // Request Parameters - RequestParameters requestParameters = new RequestParameters() - - // No found data to provide ??? requestParameters.setaLaCarte() - requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType()) - - // User params - List<Map<String, Object>> userParams = new ArrayList<>() - // Service - Service service = new Service() - // Model Info - ModelInfo serviceModelInfo = new ModelInfo() - serviceModelInfo.setModelType(ModelType.service) - serviceModelInfo.setModelInvariantId(networkServiceInstance.getModelInvariantId()) - - serviceModelInfo.setModelVersionId(modelInfo.get().getModelVersionId()) - serviceModelInfo.setModelName(modelInfo.get().getModelName()) - serviceModelInfo.setModelVersion(modelInfo.get().getModelVersion()) - - service.setModelInfo(serviceModelInfo) - - // Resources - Resources resources = new Resources() - - CloudRegion cloudRegion = null - AAIResourceUri cloudRegionRelatedAAIUri = null - // VNFs - List<Vnfs> vnfs = new ArrayList<>() - // VNF - Vnfs vnf = new Vnfs() - - // Cloud configuration - CloudConfiguration cloudConfiguration = new CloudConfiguration() - - AAIResourceUri constituteVnfUri = (AAIResourceUri)execution.getVariable("constituteVnfUri") - wrapper = client.get(constituteVnfUri) - Optional<Relationships> constituteVnfOps = wrapper.getRelationships() - if(constituteVnfOps.isPresent()) { - List<AAIResourceUri> cloudRegionRelatedAAIUris = serviceSubscriptionRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.CLOUD_REGION) - if(!(cloudRegionRelatedAAIUris == null || cloudRegionRelatedAAIUris.isEmpty())) { - cloudRegionRelatedAAIUri = cloudRegionRelatedAAIUris.get(0) - Optional<CloudRegion> cloudRegionrOpt = client.get(CloudRegion.class, cloudRegionRelatedAAIUris.get(0)) - if(cloudRegionrOpt.isPresent()) { - cloudRegion = cloudRegionrOpt.get() - cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId()) - for(Tenant tenant:cloudRegion.getTenants()) { - cloudConfiguration.setTenantId(tenant.getTenantId()) - break // only one is required - } - - cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner()) - } - } - } - - vnf.setCloudConfiguration(cloudConfiguration) - - // VF Modules - GenericVnf constituteVnf = execution.getVariable("constituteVnf") - List<VfModules> vfModuless = new ArrayList<>() - for(VfModule vfModule:constituteVnf.getVfModules()) { - VfModules vfmodules = new VfModules() - - ModelInfo vfModuleModelInfo = new ModelInfo() - vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId()) - - AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId()) // ??? - Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl) - - if (vfModuleModelVerOpt.isPresent()) { - vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId()) - vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName()) - vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion()) - - // No model customization ID - } - vfmodules.setModelInfo(vfModuleModelInfo) - - vfmodules.setInstanceName(vfModule.getVfModuleName()) // ??? - - vfModuless.add(vfmodules) - } - vnf.setVfModules(vfModuless) - - // Model Info - ModelInfo vnfModelInfo = new ModelInfo() - vnfModelInfo.setModelInvariantUuid(constituteVnf.getModelInvariantId()) - AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, constituteVnf.getModelInvariantId()) // ??? - Optional<ModelVer> vnfModelVerOpt = client.get(ModelVer.class, vnfModelUrl) - - if (vnfModelVerOpt.isPresent()) { - vnfModelInfo.setModelVersionId(vnfModelVerOpt.get().getModelVersionId()) - vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName()) - vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion()) - - // No model customization ID - // No model instance name - } - - vnf.setModelInfo(vnfModelInfo) - - // Instance name - vnf.setInstanceName(constituteVnf.getVnfInstanceId()) - - // Instance params - List<Map<String, Object>> instanceParams = new ArrayList<>() - Map<String, Object> supporrtedNSSAIMap = new HashMap<>() - - // Supported S-NSSAI - List<String> snssais = ( List<String>)execution.getVariable("S-NSSAIs") - supporrtedNSSAIMap.put("supporrtedNSSAI", snssais) // remaining S-NSSAIs ??? there is no status for each s-nssai - instanceParams.add(supporrtedNSSAIMap) - - // No other instance params, e.g. config-type - - vnf.setInstanceParams(instanceParams) - - // No platform data - - vnfs.add(vnf) - resources.setVnfs(vnfs) - - service.setResources(resources) - - Map<String, Object> serviceMap = new HashMap<>() - serviceMap.put("service", service) - userParams.add(serviceMap) - requestParameters.setUserParams(userParams) - - // No other user params - - requestDetails.setRequestParameters(requestParameters) - - // No other request params - - // Cloud configuration - requestDetails.setCloudConfiguration(cloudConfiguration) - - // Owning entity - OwningEntity owningEntity = new OwningEntity() - wrapper = client.get(networkServiceInstanceUri) - Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships() - if(owningEntityRelationshipsOps.isPresent()) { - List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY) - - if(!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation - if(owningEntityOpt.isPresent()) { - owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId()) - owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName()) - requestDetails.setOwningEntity(owningEntity) - } - } - } - - // Project - Project project = new Project() - if(cloudRegionRelatedAAIUri != null) { - wrapper = client.get(cloudRegionRelatedAAIUri) - Optional<Relationships> cloudRegionOps = wrapper.getRelationships() - if(cloudRegionOps.isPresent()) { - List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedAAIUris(AAIObjectType.PROJECT) - if (!(projectAAIUris == null || projectAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0)) - if(projectOpt.isPresent()) { - project.setProjectName(projectOpt.get().getProjectName()) - } - } - } - } - requestDetails.setProject(project) - - return requestDetails - } - /** * Creates Slice Profile Instance @@ -561,10 +86,16 @@ class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { void createSliceProfileInstance(DelegateExecution execution) { LOGGER.trace("${PREFIX} Start createSliceProfileInstance") + def currentNSSI = execution.getVariable("currentNSSI") + String sliceProfileID = execution.getVariable("sliceProfileID") Map<String, Object> sliceProfileMap = execution.getVariable("sliceProfileCn") Map<String, Object> serviceProfileMap = execution.getVariable("serviceProfile") + String globalSubscriberId = currentNSSI['globalSubscriberId'] + String serviceType = currentNSSI['serviceType'] + String nssiId = currentNSSI['nssiId'] + SliceProfile sliceProfile = new SliceProfile() sliceProfile.setServiceAreaDimension("") sliceProfile.setPayloadSize(0) @@ -587,10 +118,10 @@ class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { try { AAIResourcesClient client = getAAIClient() - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, sliceProfileID) + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileID) client.create(uri, sliceProfile) - execution.setVariable("createdSliceProfile", sliceProfile) + currentNSSI['createdSliceProfile'] = sliceProfile } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile create call:" + ex.getMessage()) } @@ -610,20 +141,22 @@ class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { def currentNSSI = execution.getVariable("currentNSSI") - String nssiId = currentNSSI['nssiServiceInstanceId'] + String globalSubscriberId = currentNSSI['globalSubscriberId'] + String serviceType = currentNSSI['serviceType'] + String nssiId = currentNSSI['nssiId'] AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, sliceProfileID) + AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileID) try { - SliceProfile createdSliceProfile = (SliceProfile)execution.getVariable("createdSliceProfile") - ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi") + SliceProfile createdSliceProfile = (SliceProfile)currentNSSI['createdSliceProfile'] + ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() associatedProfiles.add(createdSliceProfile) getAAIClient().update(nssiUri, nssi) - getAAIClient().connect(sliceProfileUri, nsiUri, AAIEdgeLabel.BELONGS_TO) + getAAIClient().connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO) }catch(Exception e){ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI disconnect call: " + e.getMessage()) } @@ -632,101 +165,9 @@ class DoModifyCoreNSSI extends AbstractServiceTaskProcessor { } - /** - * Removes Slice Profile association with NSSI - * @param execution - */ - void removeSPAssociationWithNSSI(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start removeSPAssociationWithNSSI") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi") - - String nssiId = currentNSSI['nssiServiceInstanceId'] - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) - - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - - String currentSNSSAI = currentNSSI['S-NSSAI'] - - associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) }) - - try { - getAAIClient().update(nssiUri, nssi) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage()) - } - - LOGGER.trace("${PREFIX} Exit removeSPAssociationWithNSSI") - } - - - /** - * Deletes Slice Profile Instance - * @param execution - */ - void deleteSliceProfileInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start deleteSliceProfileInstance") - - AAIResourcesClient client = getAAIClient() - - def currentNSSI = execution.getVariable("currentNSSI") - - ServiceInstance nssi = (ServiceInstance)execution.getVariable("nssi") - - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - - String currentSNSSAI = currentNSSI['S-NSSAI'] - - AAIResourceUri sliceProfileUri = null - - for(SliceProfile associatedProfile:associatedProfiles) { - if(!associatedProfile.getSNssai().equals(currentNSSI)) { // not current S-NSSAI - sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, associatedProfile.getProfileId()) - break - } - } - - try { - getAAIClient().delete(sliceProfileUri) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage()) - } - - LOGGER.trace("${PREFIX} Exit deleteSliceProfileInstance") - } - - - /** - * Updates operation status - * @param execution - */ - void updateServiceOperationStatus(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start updateServiceOperationStatus") - - def currentNSSI = execution.getVariable("currentNSSI") - - OperationStatus operationStatus = new OperationStatus() - operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String) - operationStatus.setOperationId(currentNSSI['operationId'] as String) - operationStatus.setOperation(currentNSSI['operationType'] as String) - operationStatus.setResult(RequestsDbConstant.Status.FINISHED) - - requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus) - - LOGGER.trace("${PREFIX} Exit updateServiceOperationStatus") - } - - - /** - * Returns AAI client - * @return AAI client - */ - AAIResourcesClient getAAIClient() { - return new AAIResourcesClient() + @Override + String getPrefix() { + return PREFIX } } |