aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByung-Woo Jun <byung-woo.jun@est.tech>2020-09-21 16:15:41 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-21 16:15:41 +0000
commitd44f91ab7716796904d4dd34fbb3c7a79337999a (patch)
treebf2135953ee5da798a5069816e8027d94e7dc85d
parent9a8013406748df6d23386ea514b2407c3ffc56a5 (diff)
parentac3261cf76c1b4809d7e076a26edf21e9ca3901a (diff)
Merge "Adding more unit tests in Deallocate Core NSSMF workflow"
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy794
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy829
2 files changed, 1453 insertions, 170 deletions
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 fcb3b52322..49aeec8ee3 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
@@ -1,3 +1,23 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 TIM
+ * ================================================================================
+ * 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
@@ -12,6 +32,7 @@ import org.onap.aai.domain.yang.GenericVnf
import org.onap.aai.domain.yang.ServiceInstance
import org.onap.aai.domain.yang.Tenant
import org.onap.aai.domain.yang.VfModule
+import org.onap.aaiclient.client.aai.AAIClient
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
@@ -30,6 +51,7 @@ import org.onap.so.client.HttpClientFactory
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
@@ -89,19 +111,18 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution)
String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
- String basicAuthValue = utils.encrypt(basicAuth, msokey)
+ String basicAuthValue = encryptBasicAuth(basicAuth, msokey)
if (basicAuthValue != null) {
- logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue)
- try {
- authHeader = utils.getBasicAuth(basicAuthValue, msokey)
- execution.setVariable("BasicAuthHeaderValue", authHeader)
- } catch (Exception ex) {
- logger.debug( "Unable to encode username and password string: " + ex)
- exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " +
- "encode username and password string")
+ String responseAuthHeader = getAuthHeader(execution, 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"))
}
} else {
- logger.debug( "Unable to obtain BasicAuth - BasicAuth value null")
+ LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
"value null")
}
@@ -109,32 +130,114 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
//Prepare send request to OOF
String oofRequest = buildOOFRequest(execution)
- URL url = new URL(urlString+"/api/oof/terminate/nxi/v1")
- HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
- httpClient.addAdditionalHeader("Authorization", authHeader)
- httpClient.addAdditionalHeader("Accept", "application/json")
- httpClient.addAdditionalHeader("Content-Type", "application/json")
+ String callOOFResponse = callOOF(urlString, authHeader, oofRequest)
+ String errorCode = jsonUtil.getJsonValue(callOOFResponse, "errorCode")
+ if(errorCode == null || errorCode.isEmpty()) { // No error
+ String oofResponse = callOOFResponse
+ String isTerminateNSSI = jsonUtil.getJsonValue(oofResponse, "terminateResponse")
+
+ execution.setVariable("isTerminateNSSI", Boolean.parseBoolean(isTerminateNSSI))
+ }
+ else {
+ LOGGER.error(jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
+ exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
+ }
+
+
+ LOGGER.trace("${PREFIX} Exit executeTerminateNSSIQuery")
+ }
+
+
+ /**
+ * Executes sync call to OOF
+ * @return OOF response
+ */
+ String callOOF(String urlString, String authHeader, String oofRequest) {
+ String errorCode = ""
+ String errorMessage = ""
+ String response = ""
+
+ try {
+ URL url = new URL(urlString + "/api/oof/terminate/nxi/v1")
+ HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
+ httpClient.addAdditionalHeader("Authorization", authHeader)
+ httpClient.addAdditionalHeader("Accept", "application/json")
+ httpClient.addAdditionalHeader("Content-Type", "application/json")
+
+ Response httpResponse = httpClient.post(oofRequest)
+
+ int responseCode = httpResponse.getStatus()
+ LOGGER.debug("OOF sync response code is: " + responseCode)
- Response httpResponse = httpClient.post(oofRequest)
+ if (responseCode != 202) { // Accepted
+ errorCode = responseCode
+ errorMessage = "Received a Bad Sync Response from OOF."
- int responseCode = httpResponse.getStatus()
- logger.debug("OOF sync response code is: " + responseCode)
+ response = "{\n" +
+ " \"errorCode\": \"${errorCode}\",\n" +
+ " \"errorMessage\": \"${errorMessage}\"\n" +
+ "}"
+ //exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
+ }
- if(responseCode != 202){ // Accepted
- exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.")
+ if (httpResponse.hasEntity()) {
+ response = httpResponse.readEntity(String.class)
+ }
+ else {
+ errorCode = 500
+ errorMessage = "No response received from OOF."
+
+ response = "{\n" +
+ " \"errorCode\": \"${errorCode}\",\n" +
+ " \"errorMessage\": \"${errorMessage}\"\n" +
+ "}"
+ }
+ }
+ catch(Exception e) {
+ errorCode = 400
+ errorMessage = e.getMessage()
+
+ response = "{\n" +
+ " \"errorCode\": \"${errorCode}\",\n" +
+ " \"errorMessage\": \"${errorMessage}\"\n" +
+ "}"
}
- if(httpResponse.hasEntity()){
- String OOFResponse = httpResponse.readEntity(Boolean.class)
- String isTerminateNSSI = jsonUtil.getJsonValue(OOFResponse, "terminateResponse")
- execution.setVariable("isTerminateNSSI", Boolean.parseBoolean(isTerminateNSSI))
+ return response
+ }
+
+
+ String encryptBasicAuth(String basicAuth, String msoKey) {
+ return utils.encrypt(basicAuth, msoKey)
+ }
+
+
+ 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" +
+ "}"
}
- LOGGER.trace("${PREFIX} Exit executeTerminateNSSIQuery")
+ return response
}
+
/**
* Builds OOF request
* @param execution
@@ -177,7 +280,7 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
String serviceType = currentNSSI['serviceType']
String nssiId = currentNSSI['nssiId']
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId) //AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, nssiId)
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
if (nssiOpt.isPresent()) {
@@ -251,28 +354,49 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
* @param execution
*/
void deleteServiceOrder(DelegateExecution execution) {
- // TO DO: Unit test
LOGGER.trace("${PREFIX} Start deleteServiceOrder")
def currentNSSI = execution.getVariable("currentNSSI")
try {
//url:/nbi/api/v4/serviceOrder/"
- def nbiEndpointUrl = UrnPropertiesReader.getVariable("nbi.endpoint.url", execution) // ???
+ def nbiEndpointUrl = UrnPropertiesReader.getVariable("nbi.endpoint.url", execution)
ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId()) // Service Order ID = Network Service Instance ID ???
+ String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId()) // Service Order ID = Network Service Instance ID
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")
- Response httpResponse = httpClient.delete() // check http code ???
+ String basicAuthValue = encryptBasicAuth(basicAuth, msoKey)
+ def authHeader = ""
+ if (basicAuthValue != null) {
+ String responseAuthHeader = getAuthHeader(execution, 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"))
+ }
+ } else {
+ LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
+ "value null")
+ }
+
+ String callDeleteServiceOrderResponse = callDeleteServiceOrder(execution, url, authHeader)
+ String errorCode = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorCode")
+ String deleteServcieResponse = ""
+
+ if(errorCode == null || errorCode.isEmpty()) { // No error
+ deleteServcieResponse = callDeleteServiceOrderResponse // check the response ???
+ }
+ else {
+ LOGGER.error(jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
+ exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
+ }
} catch (any) {
String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
LOGGER.error(msg)
@@ -283,6 +407,43 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
}
+ String callDeleteServiceOrder(DelegateExecution execution, String urlString, String authHeader) {
+ String errorCode = ""
+ String errorMessage = ""
+ String response = ""
+
+ try {
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(urlString), ONAPComponents.EXTERNAL)
+ httpClient.addAdditionalHeader("Authorization", authHeader)
+ httpClient.addAdditionalHeader("Accept", "application/json")
+ Response httpResponse = httpClient.delete()
+
+ 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.deleteServiceOrder. " + any.getCause()
+
+ response = "{\n" +
+ " \"errorCode\": \"7000\",\n" +
+ " \"errorMessage\": \"${msg}\"\n" +
+ "}"
+ }
+
+ return response
+ }
+
+
/**
* Queries constitute VNF from Network Service Instance
* @param execution
@@ -298,12 +459,12 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
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)
+ 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()
- execution.setVariable("constituteVnf", constituteVnf)
+ currentNSSI['constituteVnf'] = constituteVnf
}
else {
String msg = String.format("No constitute VNF found for Network Service Instance %s in AAI", ((ServiceInstance)currentNSSI['networkServiceInstance']).getServiceInstanceId())
@@ -344,7 +505,7 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
}
else {
- execution.setVariable("associatedProfiles", associatedProfiles)
+ currentNSSI['associatedProfiles'] = associatedProfiles
}
LOGGER.trace("${PREFIX} Exit getNSSIAssociatedProfiles")
@@ -358,21 +519,24 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
void calculateSNSSAI(DelegateExecution execution) {
LOGGER.trace("${PREFIX} Start calculateSNSSAI")
- List<SliceProfile> associatedProfiles = (List<SliceProfile>)execution.getVariable("associatedProfiles")
-
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(currentNSSI)) { // not current S-NSSAI
+ if(!associatedProfile.getSNssai().equals(currentSNSSAI)) { // not current S-NSSAI
snssais.add(associatedProfile.getSNssai())
}
+ else {
+ currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
+ }
}
- execution.setVariable("S-NSSAIs", snssais)
+ currentNSSI['S-NSSAIs'] = snssais
LOGGER.trace("${PREFIX} Exit calculateSNSSAI")
}
@@ -393,26 +557,48 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- GenericVnf constituteVnf = (GenericVnf)execution.getVariable("constituteVnf")
+ GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
- String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) // ???
+ 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")
+ def authHeader = ""
+ String basicAuthValue = encryptBasicAuth(basicAuth, msoKey) //utils.encrypt(basicAuth, msoKey)
+ String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey) //utils.getBasicAuth(basicAuthValue, msoKey)
- RequestDetails requestDetails = prepareRequestDetails(execution)
- ObjectMapper mapper = new ObjectMapper()
- String requestDetailsStr = mapper.writeValueAsString(requestDetails)
+ 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"))
+ }
- Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
} catch (any) {
- String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
+ String msg = "Exception in DoDeallocateCoreNSSI.invokePUTServiceInstance. " + any.getCause()
LOGGER.error(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
@@ -421,19 +607,67 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
}
+ 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
+ * @return ModelInfo
*/
- private ModelInfo prepareModelInfo(DelegateExecution execution) {
+ 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())
- AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId()) // model of Network Service Instance ???
+ 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()) {
@@ -442,37 +676,30 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
}
-
return modelInfo
}
/**
- * Prepares RequestDetails object
+ * Prepares subscriber info
* @param execution
- * @return
+ * @return SubscriberInfo
*/
- private RequestDetails prepareRequestDetails(DelegateExecution execution) {
- RequestDetails requestDetails = new RequestDetails()
-
+ SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
def currentNSSI = execution.getVariable("currentNSSI")
String globalSubscriberId = currentNSSI['globalSubscriberId']
- ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
-
-
- AAIResourcesClient client = getAAIClient()
-
- // Model Info
- requestDetails.setModelInfo(prepareModelInfo(execution))
+ String subscriberName = currentNSSI['subscriberName']
- // Subscriber Info
SubscriberInfo subscriberInfo = new SubscriberInfo()
subscriberInfo.setGlobalSubscriberId(globalSubscriberId)
+ subscriberInfo.setSubscriberName(subscriberName)
+
+ /*
+ AAIResourcesClient client = getAAIClient()
Customer customer = null
- ServiceSubscription serviceSubscription = null
AAIResourceUri networkServiceInstanceUri = currentNSSI['networkServiceInstanceUri']
AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
@@ -482,8 +709,9 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
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()
+ currentNSSI['serviceSubscription'] = serviceSubscriptionOpt.get()
}
wrapper = client.get(serviceSubscriptionUri)
@@ -500,69 +728,81 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
}
}
- }
- requestDetails.setSubscriberInfo(subscriberInfo)
+ } */
- // Request Info
- RequestInfo requestInfo = new RequestInfo()
- requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName())
+ return subscriberInfo
+ }
- /* No found data to provide ???
- requestInfo.setSource()
- requestInfo.setSuppressRollback()
- requestInfo.setRequestorId()
- requestInfo.setProductFamilyId()
- */
- requestDetails.setRequestInfo(requestInfo)
+ /**
+ * Prepares Request Info
+ * @param execution
+ * @return RequestInfo
+ */
+ RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
+ def currentNSSI = execution.getVariable("currentNSSI")
+ String serviceId = currentNSSI['serviceId']
- // Request Parameters
- RequestParameters requestParameters = new RequestParameters()
+ RequestInfo requestInfo = new RequestInfo()
- // No found data to provide ??? requestParameters.setaLaCarte()
- requestParameters.setSubscriptionServiceType(serviceSubscription.getServiceType())
+ 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) {
- // 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())
+ serviceModelInfo.setModelVersionId(modelInfo.getModelVersionId())
+ serviceModelInfo.setModelName(modelInfo.getModelName())
+ serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
- service.setModelInfo(serviceModelInfo)
+ return serviceModelInfo
+ }
- // Resources
- Resources resources = new Resources()
- CloudRegion cloudRegion = null
- AAIResourceUri cloudRegionRelatedAAIUri = null
- // VNFs
- List<Vnfs> vnfs = new ArrayList<>()
- // VNF
- Vnfs vnf = new Vnfs()
+ /**
+ * Prepares Cloud configuration
+ * @param execution
+ * @return CloudConfiguration
+ */
+ CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
+ def currentNSSI = execution.getVariable("currentNSSI")
- // 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)
+ 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))
- if(cloudRegionrOpt.isPresent()) {
+ CloudRegion cloudRegion = null
+ if (cloudRegionrOpt.isPresent()) {
cloudRegion = cloudRegionrOpt.get()
cloudConfiguration.setLcpCloudRegionId(cloudRegion.getCloudRegionId())
- for(Tenant tenant:cloudRegion.getTenants()) {
+ for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
cloudConfiguration.setTenantId(tenant.getTenantId())
break // only one is required
}
@@ -572,18 +812,30 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
}
}
- vnf.setCloudConfiguration(cloudConfiguration)
+ 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()
- // VF Modules
- GenericVnf constituteVnf = execution.getVariable("constituteVnf")
List<VfModules> vfModuless = new ArrayList<>()
- for(VfModule vfModule:constituteVnf.getVfModules()) {
+ 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())
- AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId()) // ???
Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
if (vfModuleModelVerOpt.isPresent()) {
@@ -599,12 +851,28 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
vfModuless.add(vfmodules)
}
- vnf.setVfModules(vfModuless)
- // Model Info
+ 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())
- AAIResourceUri vnfModelUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, 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()) {
@@ -612,84 +880,276 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
vnfModelInfo.setModelName(vnfModelVerOpt.get().getModelName())
vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
- // No model customization ID
// No model instance name
}
- vnf.setModelInfo(vnfModelInfo)
+ return vnfModelInfo
+ }
- // Instance name
- vnf.setInstanceName(constituteVnf.getVnfInstanceId())
- // Instance params
+ List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
+ def currentNSSI = execution.getVariable("currentNSSI")
+
List<Map<String, Object>> instanceParams = new ArrayList<>()
- Map<String, Object> supporrtedNSSAIMap = new HashMap<>()
+ Map<String, Object> instanceParamsMap = 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)
+ 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
- vnf.setInstanceParams(instanceParams)
+ 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)
- service.setResources(resources)
+ 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", service)
+ serviceMap.put("service", prepareService(execution, networkServiceInstance, modelInfo))
userParams.add(serviceMap)
requestParameters.setUserParams(userParams)
// No other user params
- requestDetails.setRequestParameters(requestParameters)
+ return requestParameters
+ }
- // No other request params
- // Cloud configuration
- requestDetails.setCloudConfiguration(cloudConfiguration)
+ /**
+ * Prepare Owning Entity
+ * @param execution
+ * @return OwningEntity
+ */
+ OwningEntity prepareOwningEntity(DelegateExecution execution) {
+ def currentNSSI = execution.getVariable("currentNSSI")
+
+ AAIResourcesClient client = getAAIClient()
+
+ AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
- // Owning entity
OwningEntity owningEntity = new OwningEntity()
- wrapper = client.get(networkServiceInstanceUri)
+ AAIResultWrapper wrapper = client.get(networkServiceInstanceUri)
Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships()
- if(owningEntityRelationshipsOps.isPresent()) {
+ if (owningEntityRelationshipsOps.isPresent()) {
List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)
- if(!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) {
+ 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()) {
+ if (owningEntityOpt.isPresent()) {
owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId())
owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName())
- requestDetails.setOwningEntity(owningEntity)
+
}
}
}
- // Project
+ return owningEntity
+ }
+
+
+ /**
+ * Prepares Project
+ * @param execution
+ * @return Project
+ */
+ Project prepareProject(DelegateExecution execution) {
+ def currentNSSI = execution.getVariable("currentNSSI")
+
+ AAIResourcesClient client = getAAIClient()
+
Project project = new Project()
- if(cloudRegionRelatedAAIUri != null) {
- wrapper = client.get(cloudRegionRelatedAAIUri)
+
+ AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri']
+
+ if (cloudRegionRelatedAAIUri != null) {
+ AAIResultWrapper wrapper = client.get(cloudRegionRelatedAAIUri)
Optional<Relationships> cloudRegionOps = wrapper.getRelationships()
- if(cloudRegionOps.isPresent()) {
+ 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()) {
+ if (projectOpt.isPresent()) {
project.setProjectName(projectOpt.get().getProjectName())
}
}
}
}
- requestDetails.setProject(project)
- return requestDetails
+ 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
}
@@ -704,14 +1164,14 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
def currentNSSI = execution.getVariable("currentNSSI")
- String nssiId = currentNSSI['nssiServiceInstanceId']
+ String nssiId = currentNSSI['nssiId']
String nsiId = currentNSSI['nsiId']
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)
try {
- getAAIClient().disconnect(nssiUri, nsiUri)
+ client.disconnect(nssiUri, nsiUri)
}catch(Exception e){
exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
}
@@ -733,7 +1193,7 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
- String nssiId = currentNSSI['nssiServiceInstanceId']
+ String nssiId = currentNSSI['nssiId']
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
@@ -763,20 +1223,14 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
def currentNSSI = execution.getVariable("currentNSSI")
- ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
-
- List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
+ SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI']
- String currentSNSSAI = currentNSSI['S-NSSAI']
+ String globalSubscriberId = currentNSSI['globalSubscriberId']
+ String serviceType = currentNSSI['serviceType']
+ String nssiId = currentNSSI['nssiId']
- 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
- }
- }
+ // 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)
@@ -799,7 +1253,7 @@ class DoDeallocateCoreNSSI extends AbstractServiceTaskProcessor {
def currentNSSI = execution.getVariable("currentNSSI")
- String nssiId = currentNSSI['nssiServiceInstanceId']
+ String nssiId = currentNSSI['nssiId']
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
try {
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
new file mode 100644
index 0000000000..48b96fb60e
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
@@ -0,0 +1,829 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 TIM
+ * ================================================================================
+ * 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.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.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
+
+class DoDeallocateCoreNSSITest extends MsoGroovyTest {
+
+ @Before
+ void init() throws IOException {
+ super.init("DoDeallocateNSSITest")
+ }
+
+
+ @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")
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ when(mockExecution.getVariable("mso.oof.endpoint")).thenReturn("http://oof.onap:8088")
+ when(mockExecution.getVariable("mso.oof.auth")).thenReturn("mso.oof.auth")
+ when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
+ when(mockExecution.getVariable("mso-request-id")).thenReturn("mso-request-id")
+
+ DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")
+
+ String authHeaderResponse = "auth-header"
+
+ /* String authHeaderResponse = "{\n" +
+ " \"errorCode\": \"401\",\n" +
+ " \"errorMessage\": \"Bad request\"\n" +
+ "}" */
+
+ when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+
+ String urlString = "http://oof.onap:8088"
+
+ String httpRequest = "{\n" +
+ " \"type\": \"NSSI\",\n" +
+ " \"NxIId\": \"5G-999\",\n" +
+ " \"requestInfo\": {\n" +
+ " \"transactionId\": \"mso-request-id\",\n" +
+ " \"requestId\": \"mso-request-id\",\n" +
+ " \"sourceId\": \"so\",\n" +
+ " }\n" +
+ "}"
+
+ boolean terminateResponse = true
+
+ String oofResponse = "{\n" +
+ " \"requestId\": \"mso-request-id\",\n" +
+ " \"transactionId\": \"mso-request-id\",\n" +
+ " \"statusMessage\": \"\",\n" +
+ " \"requestStatus\": \"accepted\",\n" +
+ " \"terminateResponse\": \"${terminateResponse}\",\n" +
+ " \"reason\": \"\"\n" +
+ " }\n"
+
+ String oofCallResponse = oofResponse
+
+ /* String oofCallResponse = "{\n" +
+ " \"errorCode\": \"401\",\n" +
+ " \"errorMessage\": \"Exception during the call\"\n" +
+ "}" */
+
+ when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)
+
+ spy.executeTerminateNSSIQuery(mockExecution)
+
+ verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)
+
+ }
+
+
+ @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")
+
+ ServiceInstance networkServiceInstance = new ServiceInstance()
+ networkServiceInstance.setServiceInstanceId("NS-777")
+ networkServiceInstance.setServiceRole("Network Service")
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ currentNSSI.put("networkServiceInstance", networkServiceInstance)
+
+ when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.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"
+
+ /* String authHeaderResponse = "{\n" +
+ " \"errorCode\": \"401\",\n" +
+ " \"errorMessage\": \"Bad request\"\n" +
+ "}" */
+
+ when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+
+ String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+
+ String callDeleteServiceOrderResponse = "deleted"
+
+ when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)
+
+ spy.deleteServiceOrder(mockExecution)
+ }
+
+
+
+ @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 = [:]
+ 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)
+
+ DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
+ 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 testCalculateSNSSAI() {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ 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("snssai3")
+
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+ associatedProfiles.add(sliceProfile3)
+
+ int sizeBefore = associatedProfiles.size()
+
+ currentNSSI.put("associatedProfiles", associatedProfiles)
+
+ DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
+ 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 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 = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
+
+ when(spy.getAAIClient()).thenReturn(client)
+
+ String nssiId = "5G-999"
+ String nsiId = "5G-99"
+ currentNSSI.put("nssiId", nssiId)
+ currentNSSI.put("nsiId", nsiId)
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
+ AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)
+
+ doNothing().when(client).disconnect(nssiUri, nsiUri)
+
+ spy.removeNSSIAssociationWithNSI(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)
+
+ 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 = [:]
+
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String nssiId = "5G-999"
+
+ currentNSSI.put("nssiId", nssiId)
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
+
+ DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
+
+ when(spy.getAAIClient()).thenReturn(client)
+
+ doNothing().when(client).delete(nssiUri)
+
+ spy.deleteNSSIServiceInstance(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")
+
+ 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)
+ }
+
+}