aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy1012
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy908
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy637
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy583
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy579
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy242
-rw-r--r--bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn72
7 files changed, 1925 insertions, 2108 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
}
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy
new file mode 100644
index 0000000000..5d29a72341
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy
@@ -0,0 +1,583 @@
+/*-
+ * ============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.junit.Before
+import org.junit.Test
+import org.mockito.Mockito
+import org.onap.aai.domain.yang.*
+import org.onap.aaiclient.client.aai.AAIObjectType
+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.AAISimpleUri
+import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
+import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
+import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.serviceinstancebeans.RequestDetails
+
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+import static org.mockito.Mockito.*
+
+class DoCommonCoreNSSITest extends MsoGroovyTest {
+ @Before
+ void init() throws IOException {
+ super.init("DoCommonCoreNSSITest")
+ }
+
+
+ @Test
+ void testPreProcessRequest() {
+ def currentNSSI = [:]
+ currentNSSI.put("nssiId","5G-999")
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
+ dcnssi.preProcessRequest(mockExecution)
+ Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI")
+ }
+
+
+ @Test
+ void testGetNetworkServiceInstance() {
+ def currentNSSI = [:]
+ currentNSSI.put("nssiId","5G-999")
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5G-999")
+ AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "NS-777")
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId("5G-999")
+
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
+
+ Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
+ Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
+
+ //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+ List<AAIResourceUri> arus = new ArrayList<>()
+ AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri)
+ arus.add(aru)
+
+ when(client.get(nssiUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)).thenReturn(arus)
+ when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
+
+ spy.getNetworkServiceInstance(mockExecution)
+
+ assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
+ currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
+
+ assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
+ currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
+
+ assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
+ }
+
+
+ @Test
+ void getConstituteVNFFromNetworkServiceInst() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
+
+ GenericVnf genericVNF = new GenericVnf()
+ genericVNF.setVnfId("VNF-1")
+
+ AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkServiceInstance.getServiceInstanceId())
+
+ Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
+ AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVNF.getVnfId())
+
+ currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
+ currentNSSI.put("networkServiceInstance", networkServiceInstance)
+
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+ List<AAIResourceUri> arus = new ArrayList<>()
+ AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
+ arus.add(aru)
+
+ when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.GENERIC_VNF)).thenReturn(arus)
+ when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
+
+ spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
+
+ assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
+
+ assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
+ currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
+ }
+
+
+ @Test
+ void testGetNSSIAssociatedProfiles() {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId("5G-999")
+
+ SliceProfiles sliceProfiles = new SliceProfiles()
+
+ List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
+ slProfiles.add(new SliceProfile())
+ slProfiles.add(new SliceProfile())
+
+ nssi.setSliceProfiles(sliceProfiles)
+ currentNSSI.put("nssi", nssi)
+
+ DoCommonCoreNSSI obj = new DoCommonCoreNSSI()
+ obj.getNSSIAssociatedProfiles(mockExecution)
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
+ assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
+ }
+
+
+ @Test
+ void testInvokePUTServiceInstance() {
+ def currentNSSI = [:]
+
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
+
+ GenericVnf constituteVnf = new GenericVnf()
+ constituteVnf.setVnfId("VNF-1")
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ currentNSSI.put("networkServiceInstance", networkServiceInstance)
+ currentNSSI.put("constituteVnf", constituteVnf)
+
+ when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
+ when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
+ when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
+
+ String authHeaderResponse = "auth-header"
+
+ when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+
+ String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
+
+ String callPUTServiceInstanceResponse = "put"
+
+ RequestDetails requestDetails = new RequestDetails()
+ ObjectMapper mapper = new ObjectMapper()
+ String requestDetailsStr = mapper.writeValueAsString(requestDetails)
+
+ when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
+
+ when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
+
+ spy.invokePUTServiceInstance(mockExecution)
+ }
+
+
+ @Test
+ void testRemoveSPAssociationWithNSSI() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String nssiId = "5G-999"
+ currentNSSI.put("nssiId", nssiId)
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ nssi.setSliceProfiles(new SliceProfiles())
+
+ currentNSSI.put("nssi", nssi)
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+
+ when(spy.getAAIClient()).thenReturn(client)
+
+ String theSNSSAI = "theS-NSSAI"
+ currentNSSI.put("S-NSSAI", theSNSSAI)
+
+ List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
+
+ SliceProfile sliceProfile1 = new SliceProfile()
+ sliceProfile1.setSNssai("snssai1")
+
+ SliceProfile sliceProfile2 = new SliceProfile()
+ sliceProfile2.setSNssai(theSNSSAI)
+
+ SliceProfile sliceProfile3 = new SliceProfile()
+ sliceProfile3.setSNssai("snssai3")
+
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+ associatedProfiles.add(sliceProfile3)
+
+ int sizeBefore = associatedProfiles.size()
+
+ doNothing().when(client).update(nssiUri, nssi)
+
+ spy.removeSPAssociationWithNSSI(mockExecution)
+
+ assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
+ }
+
+
+ @Test
+ void testDeleteSliceProfileInstance() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String globalSubscriberId = "global-id"
+ String serviceType = "service"
+ String nssiId = "5G-999"
+
+ currentNSSI.put("globalSubscriberId", globalSubscriberId)
+ currentNSSI.put("serviceType", serviceType)
+ currentNSSI.put("nssiId", nssiId)
+
+ String theSNSSAI = "theS-NSSAI"
+
+ SliceProfile sliceProfile = new SliceProfile()
+ sliceProfile.setSNssai(theSNSSAI)
+ sliceProfile.setProfileId("prof-id")
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
+
+ currentNSSI.put("sliceProfileS-NSSAI", sliceProfile)
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+
+ when(spy.getAAIClient()).thenReturn(client)
+
+ doNothing().when(client).delete(nssiUri)
+
+ spy.deleteSliceProfileInstance(mockExecution)
+
+ }
+
+
+ @Test
+ void testUpdateServiceOperationStatus() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String nssiId = "5G-999"
+
+ currentNSSI.put("nssiId", nssiId)
+ currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
+ currentNSSI.put("operationId", "operationId")
+ currentNSSI.put("operationType", "operationType")
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+
+ spy.updateServiceOperationStatus(mockExecution)
+
+ }
+
+
+ @Test
+ void testPrepareRequestDetails() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
+ networkServiceInstance.setModelInvariantId("model-invariant-id")
+ networkServiceInstance.setServiceInstanceName("service-instance-name")
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId("5G-999")
+ nssi.setOrchestrationStatus("orchestration-status")
+
+ AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "networkServiceInstance.getServiceInstanceId()")
+
+ AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "cloud-owner", "cloud-region-id")
+
+ currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
+
+ currentNSSI.put("networkServiceInstance", networkServiceInstance)
+
+ currentNSSI.put("globalSubscriberId", "globalSubscriberId")
+
+ currentNSSI.put("subscriberName", "subscriber-name")
+
+ currentNSSI.put("serviceId", "service-id")
+
+ currentNSSI.put("nssi", nssi)
+
+ List<SliceProfile> associatedProfiles = new ArrayList<>()
+ SliceProfile sliceProfile1 = new SliceProfile()
+ sliceProfile1.setSNssai("snssai1")
+
+ SliceProfile sliceProfile2 = new SliceProfile()
+ sliceProfile2.setSNssai("snssai2")
+
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+
+ List<String> snssais = new ArrayList<>()
+ snssais.add(sliceProfile1.getSNssai())
+ snssais.add(sliceProfile2.getSNssai())
+
+ currentNSSI.put("S-NSSAIs", snssais)
+
+
+ ServiceSubscription serviceSubscription = new ServiceSubscription()
+ serviceSubscription.setServiceType("service-type")
+
+ currentNSSI.put("serviceSubscription", serviceSubscription)
+
+ GenericVnf genericVnf = new GenericVnf()
+ genericVnf.setServiceId("service-id")
+ genericVnf.setVnfName("vnf-name")
+ genericVnf.setModelInvariantId("model-invariant-id")
+ genericVnf.setModelCustomizationId("model-customization-id")
+ genericVnf.setVnfName("vnf-name")
+ genericVnf.setVnfId("vnf-id")
+
+ VfModule vfModule = new VfModule()
+ vfModule.setModelInvariantId("model-invariant-id")
+ vfModule.setModelCustomizationId("model-customization-id")
+ vfModule.setModelVersionId("model-version-id")
+ vfModule.setVfModuleName("vf-module-name")
+
+ VfModules vfModules = new VfModules()
+ vfModules.getVfModule().add(vfModule)
+ genericVnf.setVfModules(vfModules)
+
+ currentNSSI.put("constituteVnf", genericVnf)
+
+ AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId())
+
+ currentNSSI.put("constituteVnfUri", constituteVNFURI)
+
+ DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
+
+ when(spy.getAAIClient()).thenReturn(client)
+
+ prepareModelVer(networkServiceInstance)
+
+ //prepareSubscriberInfo(networkServiceInstanceUri)
+
+ prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
+
+ prepareModelVer(genericVnf)
+
+ prepareModelVer(vfModule)
+
+ prepareOwningEntity(networkServiceInstanceUri)
+
+ prepareProject(cloudRegionAAIUri)
+
+ String requestDetails = spy.prepareRequestDetails(mockExecution)
+
+ }
+
+
+ void prepareProject(AAIResourceUri cloudRegionAAIUri) {
+ Project project = new Project()
+ project.setProjectName("project-name")
+
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+
+ when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ List<AAIResourceUri> arus = new ArrayList<>()
+ AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
+ arus.add(aru)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.PROJECT)).thenReturn(arus)
+
+ Optional<Project> projectOpt = Optional.of(project)
+
+ when(client.get(Project.class, aru)).thenReturn(projectOpt)
+ }
+
+
+ void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
+ OwningEntity owningEntity = new OwningEntity()
+
+ owningEntity.setOwningEntityId("owning-entity-id")
+ owningEntity.setOwningEntityName("owning-entity-name")
+
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+
+ when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ List<AAIResourceUri> arus = new ArrayList<>()
+ AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
+ arus.add(aru)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)).thenReturn(arus)
+
+ Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
+
+ when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
+ }
+
+
+
+ void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+
+ when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ List<AAIResourceUri> arus = new ArrayList<>()
+ AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
+ arus.add(aru)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.CLOUD_REGION)).thenReturn(arus)
+
+ CloudRegion cloudRegion = new CloudRegion()
+ cloudRegion.setCloudRegionId("cloud-region-id")
+ cloudRegion.setCloudOwner("cloud-owner")
+ Tenant tenant = new Tenant()
+ tenant.setTenantId("tenant-id")
+
+ Tenants tenants = new Tenants()
+ tenants.getTenant().add(tenant)
+ cloudRegion.setTenants(tenants)
+ Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
+
+ when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
+ }
+
+
+ void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+
+ when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, "global-customer-id", "service-type")
+
+ AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, "global-customer-id")
+ List<AAIResourceUri> arus = new ArrayList<>()
+
+ arus.add(serviceSubscriptionUri)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)).thenReturn(arus)
+
+ ServiceSubscription serviceSubscription = new ServiceSubscription()
+ serviceSubscription.setServiceType("service-type")
+ Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
+
+ when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
+
+ when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
+
+ when(rsMock.getRelatedAAIUris(AAIObjectType.CUSTOMER)).thenReturn(arus)
+
+ Customer customer = new Customer()
+ customer.setSubscriberName("subscriber-name")
+ Optional<Customer> customerOpt = Optional.of(customer)
+
+ when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
+ }
+
+
+ void prepareModelVer(ServiceInstance networkServiceInstance) {
+ ModelVer modelVer = new ModelVer()
+ modelVer.setModelVersionId("model-version-id")
+ modelVer.setModelName("model-name")
+ modelVer.setModelVersion("model-version")
+
+ Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
+
+ AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId())
+ when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
+ }
+
+ void prepareModelVer(GenericVnf genericVnf) {
+ ModelVer modelVer = new ModelVer()
+ modelVer.setModelVersionId("model-version-id")
+ modelVer.setModelName("model-name")
+ modelVer.setModelVersion("model-version")
+
+ Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
+
+ AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, genericVnf.getModelInvariantId(), genericVnf.getModelVersionId())
+ when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
+ }
+
+ void prepareModelVer(VfModule vfModule) {
+ ModelVer modelVer = new ModelVer()
+ modelVer.setModelVersionId("model-version-id")
+ modelVer.setModelName("model-name")
+ modelVer.setModelVersion("model-version")
+
+ Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
+
+ AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId())
+ when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
index 48b96fb60e..4a23e80feb 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.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.
@@ -20,72 +20,20 @@
package org.onap.so.bpmn.infrastructure.scripts
-import com.fasterxml.jackson.databind.ObjectMapper
-import org.camunda.bpm.engine.ProcessEngineServices
-import org.camunda.bpm.engine.RepositoryService
-import org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl
-import org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope
-import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
-import org.camunda.bpm.engine.repository.ProcessDefinition
-import org.junit.Rule
-import org.junit.rules.ExpectedException
-import org.mockito.invocation.InvocationOnMock
-import org.mockito.stubbing.Answer
-import org.onap.aai.domain.yang.CloudRegion
-import org.onap.aai.domain.yang.Customer
-import org.onap.aai.domain.yang.GenericVnf
-import org.onap.aai.domain.yang.ModelVer
-import org.onap.aai.domain.yang.OwningEntity
-import org.onap.aai.domain.yang.Project
-import org.onap.aai.domain.yang.Relationship
-import org.onap.aai.domain.yang.RelationshipList
-import org.onap.aai.domain.yang.ServiceSubscription
-import org.onap.aai.domain.yang.SliceProfile
-import org.onap.aai.domain.yang.SliceProfiles
-import org.onap.aai.domain.yang.Tenant
-import org.onap.aai.domain.yang.Tenants
-import org.onap.aai.domain.yang.VfModule
-import org.onap.aai.domain.yang.VfModules
-import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
-import org.onap.aaiclient.client.aai.entities.Relationships
-import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri
-import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
-import org.onap.logging.filter.base.ONAPComponents
-import org.onap.so.beans.nsmf.NssiResponse
-import org.onap.so.bpmn.common.scripts.ExceptionUtil
-import org.onap.so.bpmn.common.scripts.MsoUtils
-import org.onap.so.bpmn.mock.FileUtil
-import org.onap.so.client.HttpClient
-import org.onap.so.client.HttpClientFactory
-import org.onap.so.serviceinstancebeans.RequestDetails
-import org.onap.so.utils.CryptoUtils
-
-import javax.ws.rs.core.Response
-
-import static org.junit.Assert.*;
+
import org.junit.Before
import org.junit.Test
-import org.mockito.Mockito
import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aai.domain.yang.SliceProfile
+import org.onap.aai.domain.yang.SliceProfiles
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.so.bpmn.common.scripts.MsoGroovyTest
-import static org.mockito.ArgumentMatchers.anyDouble
-import static org.mockito.ArgumentMatchers.anyInt
-import static org.mockito.ArgumentMatchers.anyString
-import static org.mockito.ArgumentMatchers.eq
-import static org.mockito.Mockito.doNothing
-import static org.mockito.Mockito.doReturn
-import static org.mockito.Mockito.doThrow
-import static org.mockito.Mockito.mock
-import static org.mockito.Mockito.mock
-import static org.mockito.Mockito.mock
-import static org.mockito.Mockito.spy
-import static org.mockito.Mockito.times
-import static org.mockito.Mockito.verify
-import static org.mockito.Mockito.when
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+import static org.mockito.Mockito.*
class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@@ -96,21 +44,7 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@Test
- void testPreProcessRequest() {
- def currentNSSI = [:]
- currentNSSI.put("nssiId","5G-999")
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- DoDeallocateCoreNSSI dcnssi = new DoDeallocateCoreNSSI()
- dcnssi.preProcessRequest(mockExecution)
- Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI")
- }
-
-
- @Test
void testExecuteTerminateNSSIQuery() {
- HttpClientFactory httpClientFactoryMock
- HttpClient httpClientMock
def currentNSSI = [:]
currentNSSI.put("nssiId","5G-999")
@@ -176,57 +110,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@Test
- void testGetNetworkServiceInstance() {
- def currentNSSI = [:]
- currentNSSI.put("nssiId","5G-999")
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5G-999")
- AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "NS-777")
-
- ServiceInstance nssi = new ServiceInstance()
- nssi.setServiceInstanceId("5G-999")
-
- ServiceInstance networkServiceInstance = new ServiceInstance()
- networkServiceInstance.setServiceInstanceId("NS-777")
- networkServiceInstance.setServiceRole("Network Service")
-
- Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
- Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
- when(spy.getAAIClient()).thenReturn(client)
-
- when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
-
- //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
- List<AAIResourceUri> arus = new ArrayList<>()
- AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri)
- arus.add(aru)
-
- when(client.get(nssiUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)).thenReturn(arus)
- when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
-
- spy.getNetworkServiceInstance(mockExecution)
-
- assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
- currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
-
- assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
- currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
-
- assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
- }
-
-
- @Test
void testDeleteServiceOrder() {
def currentNSSI = [:]
currentNSSI.put("nssiId","5G-999")
@@ -267,53 +150,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
}
-
- @Test
- void getConstituteVNFFromNetworkServiceInst() {
- def currentNSSI = [:]
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
- when(spy.getAAIClient()).thenReturn(client)
-
- ServiceInstance networkServiceInstance = new ServiceInstance()
- networkServiceInstance.setServiceInstanceId("NS-777")
- networkServiceInstance.setServiceRole("Network Service")
-
- GenericVnf genericVNF = new GenericVnf()
- genericVNF.setVnfId("VNF-1")
-
- AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkServiceInstance.getServiceInstanceId())
-
- Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
- AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVNF.getVnfId())
-
- currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
- currentNSSI.put("networkServiceInstance", networkServiceInstance)
-
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
- List<AAIResourceUri> arus = new ArrayList<>()
- AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
- arus.add(aru)
-
- when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.GENERIC_VNF)).thenReturn(arus)
- when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
-
- spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
-
- assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
-
- assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
- currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
- }
-
-
@Test
void testGetNSSIAssociatedProfiles() {
def currentNSSI = [:]
@@ -379,51 +215,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@Test
- void testInvokePUTServiceInstance() {
- def currentNSSI = [:]
-
- ServiceInstance networkServiceInstance = new ServiceInstance()
- networkServiceInstance.setServiceInstanceId("NS-777")
- networkServiceInstance.setServiceRole("Network Service")
-
- GenericVnf constituteVnf = new GenericVnf()
- constituteVnf.setVnfId("VNF-1")
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- currentNSSI.put("networkServiceInstance", networkServiceInstance)
- currentNSSI.put("constituteVnf", constituteVnf)
-
- when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
- when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
- when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
- when(spy.getAAIClient()).thenReturn(client)
-
- when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
-
- String authHeaderResponse = "auth-header"
-
- when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
-
- String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
-
- String callPUTServiceInstanceResponse = "put"
-
- RequestDetails requestDetails = new RequestDetails()
- ObjectMapper mapper = new ObjectMapper()
- String requestDetailsStr = mapper.writeValueAsString(requestDetails)
-
- when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
-
- when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
-
- spy.invokePUTServiceInstance(mockExecution)
- }
-
-
- @Test
void testRemoveNSSIAssociationWithNSI() {
def currentNSSI = [:]
@@ -449,89 +240,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
@Test
- void testRemoveSPAssociationWithNSSI() {
- def currentNSSI = [:]
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- String nssiId = "5G-999"
- currentNSSI.put("nssiId", nssiId)
- ServiceInstance nssi = new ServiceInstance()
- nssi.setServiceInstanceId(nssiId)
- nssi.setSliceProfiles(new SliceProfiles())
-
- currentNSSI.put("nssi", nssi)
-
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
-
- when(spy.getAAIClient()).thenReturn(client)
-
- String theSNSSAI = "theS-NSSAI"
- currentNSSI.put("S-NSSAI", theSNSSAI)
-
- List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
-
- SliceProfile sliceProfile1 = new SliceProfile()
- sliceProfile1.setSNssai("snssai1")
-
- SliceProfile sliceProfile2 = new SliceProfile()
- sliceProfile2.setSNssai(theSNSSAI)
-
- SliceProfile sliceProfile3 = new SliceProfile()
- sliceProfile3.setSNssai("snssai3")
-
- associatedProfiles.add(sliceProfile1)
- associatedProfiles.add(sliceProfile2)
- associatedProfiles.add(sliceProfile3)
-
- int sizeBefore = associatedProfiles.size()
-
- doNothing().when(client).update(nssiUri, nssi)
-
- spy.removeSPAssociationWithNSSI(mockExecution)
-
- assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
- }
-
-
- @Test
- void testDeleteSliceProfileInstance() {
- def currentNSSI = [:]
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- String globalSubscriberId = "global-id"
- String serviceType = "service"
- String nssiId = "5G-999"
-
- currentNSSI.put("globalSubscriberId", nssiId)
- currentNSSI.put("serviceType", nssiId)
- currentNSSI.put("nssiId", nssiId)
-
- String theSNSSAI = "theS-NSSAI"
-
- SliceProfile sliceProfile = new SliceProfile()
- sliceProfile.setSNssai(theSNSSAI)
- sliceProfile.setProfileId("prof-id")
-
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
-
- currentNSSI.put("sliceProfileS-NSSAI", sliceProfile)
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
-
- when(spy.getAAIClient()).thenReturn(client)
-
- doNothing().when(client).delete(nssiUri)
-
- spy.deleteSliceProfileInstance(mockExecution)
-
- }
-
-
- @Test
void testDeleteNSSIServiceInstance() {
def currentNSSI = [:]
@@ -553,277 +261,4 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest {
}
- @Test
- void testUpdateServiceOperationStatus() {
- def currentNSSI = [:]
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- String nssiId = "5G-999"
-
- currentNSSI.put("nssiId", nssiId)
- currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
- currentNSSI.put("operationId", "operationId")
- currentNSSI.put("operationType", "operationType")
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
-
- spy.updateServiceOperationStatus(mockExecution)
-
- }
-
-
- @Test
- void testPrepareRequestDetails() {
- def currentNSSI = [:]
-
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- ServiceInstance networkServiceInstance = new ServiceInstance()
- networkServiceInstance.setServiceInstanceId("NS-777")
- networkServiceInstance.setServiceRole("Network Service")
- networkServiceInstance.setModelInvariantId("model-invariant-id")
- networkServiceInstance.setServiceInstanceName("service-instance-name")
-
- ServiceInstance nssi = new ServiceInstance()
- nssi.setServiceInstanceId("5G-999")
- nssi.setOrchestrationStatus("orchestration-status")
-
- AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "networkServiceInstance.getServiceInstanceId()")
-
- AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "cloud-owner", "cloud-region-id")
-
- currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
-
- currentNSSI.put("networkServiceInstance", networkServiceInstance)
-
- currentNSSI.put("globalSubscriberId", "globalSubscriberId")
-
- currentNSSI.put("subscriberName", "subscriber-name")
-
- currentNSSI.put("serviceId", "service-id")
-
- currentNSSI.put("nssi", nssi)
-
- List<SliceProfile> associatedProfiles = new ArrayList<>()
- SliceProfile sliceProfile1 = new SliceProfile()
- sliceProfile1.setSNssai("snssai1")
-
- SliceProfile sliceProfile2 = new SliceProfile()
- sliceProfile2.setSNssai("snssai2")
-
- associatedProfiles.add(sliceProfile1)
- associatedProfiles.add(sliceProfile2)
-
- List<String> snssais = new ArrayList<>()
- snssais.add(sliceProfile1.getSNssai())
- snssais.add(sliceProfile2.getSNssai())
-
- currentNSSI.put("S-NSSAIs", snssais)
-
-
- ServiceSubscription serviceSubscription = new ServiceSubscription()
- serviceSubscription.setServiceType("service-type")
-
- currentNSSI.put("serviceSubscription", serviceSubscription)
-
- GenericVnf genericVnf = new GenericVnf()
- genericVnf.setServiceId("service-id")
- genericVnf.setVnfName("vnf-name")
- genericVnf.setModelInvariantId("model-invariant-id")
- genericVnf.setModelCustomizationId("model-customization-id")
- genericVnf.setVnfName("vnf-name")
- genericVnf.setVnfId("vnf-id")
-
- VfModule vfModule = new VfModule()
- vfModule.setModelInvariantId("model-invariant-id")
- vfModule.setModelCustomizationId("model-customization-id")
- vfModule.setModelVersionId("model-version-id")
- vfModule.setVfModuleName("vf-module-name")
-
- VfModules vfModules = new VfModules()
- vfModules.getVfModule().add(vfModule)
- genericVnf.setVfModules(vfModules)
-
- currentNSSI.put("constituteVnf", genericVnf)
-
- AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId())
-
- currentNSSI.put("constituteVnfUri", constituteVNFURI)
-
- DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
-
- when(spy.getAAIClient()).thenReturn(client)
-
- prepareModelVer(networkServiceInstance)
-
- //prepareSubscriberInfo(networkServiceInstanceUri)
-
- prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
-
- prepareModelVer(genericVnf)
-
- prepareModelVer(vfModule)
-
- prepareOwningEntity(networkServiceInstanceUri)
-
- prepareProject(cloudRegionAAIUri)
-
- String requestDetails = spy.prepareRequestDetails(mockExecution)
-
- }
-
-
- void prepareProject(AAIResourceUri cloudRegionAAIUri) {
- Project project = new Project()
- project.setProjectName("project-name")
-
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
-
- when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- List<AAIResourceUri> arus = new ArrayList<>()
- AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
- arus.add(aru)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.PROJECT)).thenReturn(arus)
-
- Optional<Project> projectOpt = Optional.of(project)
-
- when(client.get(Project.class, aru)).thenReturn(projectOpt)
- }
-
-
- void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
- OwningEntity owningEntity = new OwningEntity()
-
- owningEntity.setOwningEntityId("owning-entity-id")
- owningEntity.setOwningEntityName("owning-entity-name")
-
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
-
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
-
- when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- List<AAIResourceUri> arus = new ArrayList<>()
- AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
- arus.add(aru)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)).thenReturn(arus)
-
- Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
-
- when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
- }
-
-
-
- void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
-
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
-
- when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- List<AAIResourceUri> arus = new ArrayList<>()
- AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
- arus.add(aru)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.CLOUD_REGION)).thenReturn(arus)
-
- CloudRegion cloudRegion = new CloudRegion()
- cloudRegion.setCloudRegionId("cloud-region-id")
- cloudRegion.setCloudOwner("cloud-owner")
- Tenant tenant = new Tenant()
- tenant.setTenantId("tenant-id")
-
- Tenants tenants = new Tenants()
- tenants.getTenant().add(tenant)
- cloudRegion.setTenants(tenants)
- Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
-
- when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
- }
-
-
- void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
-
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
-
- when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
-
- AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, "global-customer-id", "service-type")
-
- AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, "global-customer-id")
- List<AAIResourceUri> arus = new ArrayList<>()
-
- arus.add(serviceSubscriptionUri)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)).thenReturn(arus)
-
- ServiceSubscription serviceSubscription = new ServiceSubscription()
- serviceSubscription.setServiceType("service-type")
- Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
-
- when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
-
- when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
-
- when(rsMock.getRelatedAAIUris(AAIObjectType.CUSTOMER)).thenReturn(arus)
-
- Customer customer = new Customer()
- customer.setSubscriberName("subscriber-name")
- Optional<Customer> customerOpt = Optional.of(customer)
-
- when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
- }
-
-
- void prepareModelVer(ServiceInstance networkServiceInstance) {
- ModelVer modelVer = new ModelVer()
- modelVer.setModelVersionId("model-version-id")
- modelVer.setModelName("model-name")
- modelVer.setModelVersion("model-version")
-
- Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
-
- AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId())
- when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
- }
-
- void prepareModelVer(GenericVnf genericVnf) {
- ModelVer modelVer = new ModelVer()
- modelVer.setModelVersionId("model-version-id")
- modelVer.setModelName("model-name")
- modelVer.setModelVersion("model-version")
-
- Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
-
- AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, genericVnf.getModelInvariantId(), genericVnf.getModelVersionId())
- when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
- }
-
- void prepareModelVer(VfModule vfModule) {
- ModelVer modelVer = new ModelVer()
- modelVer.setModelVersionId("model-version-id")
- modelVer.setModelName("model-name")
- modelVer.setModelVersion("model-version")
-
- Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
-
- AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId())
- when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
- }
-
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy
new file mode 100644
index 0000000000..a3c2b46fe6
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy
@@ -0,0 +1,242 @@
+/*-
+ * ============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 org.junit.Before
+import org.junit.Test
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aai.domain.yang.SliceProfile
+import org.onap.aai.domain.yang.SliceProfiles
+import org.onap.aaiclient.client.aai.AAIObjectType
+import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
+import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
+import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
+import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+import static org.mockito.Mockito.*
+
+class DoModifyCoreNSSITest extends MsoGroovyTest {
+
+ @Before
+ void init() throws IOException {
+ super.init("DoModifyCoreNSSITest")
+ }
+
+
+ @Test
+ void testGetNSSIAssociatedProfiles() {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId("5G-999")
+
+ SliceProfiles sliceProfiles = new SliceProfiles()
+
+ List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
+ slProfiles.add(new SliceProfile())
+ slProfiles.add(new SliceProfile())
+
+ nssi.setSliceProfiles(sliceProfiles)
+ currentNSSI.put("nssi", nssi)
+
+ DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
+ obj.getNSSIAssociatedProfiles(mockExecution)
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
+ assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
+ }
+
+
+ @Test
+ void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
+
+ String theSNSSAI = "theS-NSSAI"
+
+ currentNSSI.put("S-NSSAI", theSNSSAI)
+
+ List<SliceProfile> associatedProfiles = new ArrayList<>()
+ SliceProfile sliceProfile1 = new SliceProfile()
+ sliceProfile1.setSNssai("snssai1")
+
+ SliceProfile sliceProfile2 = new SliceProfile()
+ sliceProfile2.setSNssai(theSNSSAI)
+
+ SliceProfile sliceProfile3 = new SliceProfile()
+ sliceProfile3.setSNssai("snssai2")
+
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+ associatedProfiles.add(sliceProfile3)
+
+ int sizeBefore = associatedProfiles.size()
+
+ currentNSSI.put("associatedProfiles", associatedProfiles)
+
+ DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
+ obj.calculateSNSSAI(mockExecution)
+
+ List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
+ SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
+
+ assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
+ assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
+ assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
+ }
+
+
+ @Test
+ void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
+
+ String theSNSSAI = "theS-NSSAI"
+
+ currentNSSI.put("S-NSSAI", theSNSSAI)
+
+ List<SliceProfile> associatedProfiles = new ArrayList<>()
+ SliceProfile sliceProfile1 = new SliceProfile()
+ sliceProfile1.setSNssai("snssai1")
+
+ SliceProfile sliceProfile2 = new SliceProfile()
+ sliceProfile2.setSNssai("snssai2")
+
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+
+ int sizeBefore = associatedProfiles.size()
+
+ currentNSSI.put("associatedProfiles", associatedProfiles)
+
+ DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
+ obj.calculateSNSSAI(mockExecution)
+
+ List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
+
+ assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
+
+ }
+
+
+ @Test
+ void testCreateSliceProfileInstance() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String sliceProfileId = "sliceProfileId"
+
+ when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
+
+ Map<String, Object> sliceProfileMap = new HashMap<>()
+ sliceProfileMap.put("expDataRateUL", "12")
+ sliceProfileMap.put("expDataRateDL", 5)
+ sliceProfileMap.put("activityFactor", 2)
+ sliceProfileMap.put("latency", 10)
+
+ when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap)
+
+
+ Map<String, Object> serviceProfileMap = new HashMap<>()
+ when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap)
+
+
+ DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ String globalSubscriberId = "globalSubscriberId"
+ String serviceType = "serviceType"
+ String nssiId = "nssiId"
+
+ currentNSSI.put("globalSubscriberId", globalSubscriberId)
+ currentNSSI.put("serviceType", serviceType)
+ currentNSSI.put("nssiId", nssiId)
+ currentNSSI.put("sliceProfileId", sliceProfileId)
+
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
+
+ SliceProfile sliceProfile = new SliceProfile()
+ sliceProfile.setProfileId(sliceProfileId)
+
+ doNothing().when(client).create(uri, sliceProfile)
+
+ spy.createSliceProfileInstance(mockExecution)
+
+ assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile"))
+ assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId()))
+ }
+
+
+ @Test
+ void testAssociateSliceProfileInstanceWithNSSI() {
+ def currentNSSI = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ String sliceProfileId = "sliceProfileId"
+
+ when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
+
+ String nssiId = "5G-999"
+ currentNSSI.put("nssiId", nssiId)
+
+ String globalSubscriberId = "globalSubscriberId"
+ String serviceType = "serviceType"
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
+ AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
+
+ currentNSSI.put("globalSubscriberId", globalSubscriberId)
+ currentNSSI.put("serviceType", serviceType)
+ currentNSSI.put("sliceProfileId", sliceProfileId)
+
+ SliceProfile sliceProfile = new SliceProfile()
+ currentNSSI.put("createdSliceProfile", sliceProfile)
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ nssi.setSliceProfiles(new SliceProfiles())
+ currentNSSI.put("nssi", nssi)
+
+ int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size()
+
+ doNothing().when(client).update(nssiUri, nssi)
+ doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
+
+ spy.associateSliceProfileInstanceWithNSSI(mockExecution)
+
+ assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1))
+ }
+
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn
index fa167d4515..1f1fe4e735 100644
--- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn
+++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoModifyCoreNSSI.bpmn
@@ -118,7 +118,7 @@ def mcnssi= new ModifyCoreNSSI()
<bpmn:outgoing>Flow_1wtv1zj</bpmn:outgoing>
<bpmn:script>import org.onap.so.bpmn.infrastructure.scripts.*
def mcnssi= new ModifyCoreNSSI()
- mcnssi.removeNSSIToSliceInstanceAssociation(execution)</bpmn:script>
+ mcnssi.removeSPAssociationWithNSSI(execution)</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_15fi92t" sourceRef="Activity_0c4wmiz" targetRef="Activity_1iegufd" />
<bpmn:scriptTask id="Activity_010nkjp" name="Delete the slice profile instance " scriptFormat="groovy">
@@ -143,6 +143,14 @@ def mcnssi= new ModifyCoreNSSI()
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1nmtzzp">
+ <bpmndi:BPMNEdge id="Flow_06j2avj_di" bpmnElement="Flow_06j2avj">
+ <di:waypoint x="380" y="150" />
+ <di:waypoint x="440" y="150" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_0e007rx_di" bpmnElement="Flow_0e007rx">
+ <di:waypoint x="218" y="150" />
+ <di:waypoint x="280" y="150" />
+ </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0lrenyo_di" bpmnElement="Flow_0lrenyo">
<di:waypoint x="890" y="600" />
<di:waypoint x="930" y="600" />
@@ -217,20 +225,39 @@ def mcnssi= new ModifyCoreNSSI()
<di:waypoint x="540" y="150" />
<di:waypoint x="620" y="150" />
</bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="Flow_0e007rx_di" bpmnElement="Flow_0e007rx">
- <di:waypoint x="218" y="150" />
- <di:waypoint x="280" y="150" />
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="Flow_06j2avj_di" bpmnElement="Flow_06j2avj">
- <di:waypoint x="380" y="150" />
- <di:waypoint x="440" y="150" />
- </bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_0fbqt56_di" bpmnElement="Event_0fbqt56">
<dc:Bounds x="182" y="132" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="158" y="175" width="89" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_0tf735w_di" bpmnElement="Activity_0tf735w">
+ <dc:Bounds x="440" y="110" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_1ce41n6_di" bpmnElement="Activity_1ce41n6">
+ <dc:Bounds x="620" y="110" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_02skgkj_di" bpmnElement="Activity_02skgkj">
+ <dc:Bounds x="810" y="110" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Gateway_1hadnun_di" bpmnElement="Gateway_1hadnun" isMarkerVisible="true">
+ <dc:Bounds x="985" y="125" width="50" height="50" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="974" y="86" width="75" height="40" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Event_1243wg1_di" bpmnElement="Event_1243wg1">
+ <dc:Bounds x="1132" y="132" width="36" height="36" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="1113" y="173" width="90" height="40" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Event_1gjhrcq_di" bpmnElement="Event_1gjhrcq">
+ <dc:Bounds x="992" y="252" width="36" height="36" />
+ <bpmndi:BPMNLabel>
+ <dc:Bounds x="973" y="293" width="90" height="40" />
+ </bpmndi:BPMNLabel>
+ </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0oph5am_di" bpmnElement="Activity_0oph5am">
<dc:Bounds x="970" y="480" width="100" height="80" />
</bpmndi:BPMNShape>
@@ -276,33 +303,6 @@ def mcnssi= new ModifyCoreNSSI()
<bpmndi:BPMNShape id="Activity_010nkjp_di" bpmnElement="Activity_010nkjp">
<dc:Bounds x="790" y="560" width="100" height="80" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Event_1243wg1_di" bpmnElement="Event_1243wg1">
- <dc:Bounds x="1132" y="132" width="36" height="36" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="1113" y="173" width="90" height="40" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Gateway_1hadnun_di" bpmnElement="Gateway_1hadnun" isMarkerVisible="true">
- <dc:Bounds x="985" y="125" width="50" height="50" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="974" y="86" width="75" height="40" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Event_1gjhrcq_di" bpmnElement="Event_1gjhrcq">
- <dc:Bounds x="992" y="252" width="36" height="36" />
- <bpmndi:BPMNLabel>
- <dc:Bounds x="973" y="293" width="90" height="40" />
- </bpmndi:BPMNLabel>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Activity_02skgkj_di" bpmnElement="Activity_02skgkj">
- <dc:Bounds x="810" y="110" width="100" height="80" />
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Activity_1ce41n6_di" bpmnElement="Activity_1ce41n6">
- <dc:Bounds x="620" y="110" width="100" height="80" />
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Activity_0tf735w_di" bpmnElement="Activity_0tf735w">
- <dc:Bounds x="440" y="110" width="100" height="80" />
- </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0klj7y1_di" bpmnElement="Activity_0klj7y1">
<dc:Bounds x="280" y="110" width="100" height="80" />
</bpmndi:BPMNShape>