Merge "Implement Building Blocks for CNF AAI update"
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
index 646861a..67e4b92 100644
--- 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
@@ -21,6 +21,7 @@
package org.onap.so.bpmn.infrastructure.scripts
import com.fasterxml.jackson.databind.ObjectMapper
+import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.json.JSONArray
import org.json.JSONObject
@@ -42,6 +43,7 @@
import org.slf4j.Logger
import org.slf4j.LoggerFactory
+import javax.ws.rs.NotFoundException
import javax.ws.rs.core.Response
import static org.apache.commons.lang3.StringUtils.isBlank
@@ -50,6 +52,8 @@
private final String PREFIX ="DoCommonCoreNSSI"
+ private static final String SLICE_PROFILE_TEMPLATE = "{\"sliceProfileId\": \"%s\"}"
+
private static final Logger LOGGER = LoggerFactory.getLogger( DoCommonCoreNSSI.class)
private JsonUtils jsonUtil = new JsonUtils()
@@ -58,7 +62,7 @@
@Override
void preProcessRequest(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start preProcessRequest")
+ LOGGER.debug("${getPrefix()} Start preProcessRequest")
def currentNSSI = execution.getVariable("currentNSSI")
if (!currentNSSI) {
@@ -89,19 +93,33 @@
// Slice Profile
- String sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile")
- if (isBlank(sliceProfile)) {
- String msg = "Slice Profile is null"
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
- } else {
- currentNSSI['sliceProfile'] = sliceProfile
+ String sliceProfile = execution.getVariable("sliceParams")
+
+ /* if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfile")) {
+ sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile")
}
+ else { // In case of Deallocate flow or Modify flow with deletion of Slice Profile Instance
+ if(jsonUtil.jsonValueExists(execution.getVariable("sliceParams"), "sliceProfileId")) {
+ sliceProfile = String.format(SLICE_PROFILE_TEMPLATE, jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfileId"))
+ }
+ else {
+ String msg = "Either Slice Profile or Slice Profile Id should be provided"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ } */
+
+ LOGGER.debug("sliceProfile=" + sliceProfile)
+ currentNSSI['sliceProfile'] = sliceProfile
// S-NSSAI
- def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList"))
+ String strList = jsonUtil.getJsonValue(sliceProfile, "snssaiList")
- String sNssai = snssaiList.get(0)
- currentNSSI['S-NSSAI'] = sNssai
+ if(strList != null) {
+ def snssaiList = jsonUtil.StringArrayToList(strList)
+
+ String sNssai = snssaiList.get(0)
+ currentNSSI['S-NSSAI'] = sNssai
+ }
// Slice Profile id
@@ -110,8 +128,7 @@
execution.setVariable("currentNSSI", currentNSSI)
-
- LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest")
+ LOGGER.debug("***** ${getPrefix()} Exit preProcessRequest")
}
@@ -120,7 +137,7 @@
* @param execution
*/
void getNetworkServiceInstance(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start getNetworkServiceInstance")
+ LOGGER.debug("${getPrefix()} Start getNetworkServiceInstance")
AAIResourcesClient client = getAAIClient()
@@ -144,7 +161,7 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
}
- LOGGER.trace("${getPrefix()} Exit getNetworkServiceInstance")
+ LOGGER.debug("${getPrefix()} Exit getNetworkServiceInstance")
}
@@ -156,6 +173,8 @@
* @return Network Service Instance
*/
private ServiceInstance handleNetworkInstance(DelegateExecution execution, String nssiId, AAIResourceUri nssiUri, AAIResourcesClient client ) {
+ LOGGER.debug("${getPrefix()} Start handleNetworkInstance")
+
ServiceInstance networkServiceInstance = null
def currentNSSI = execution.getVariable("currentNSSI")
@@ -169,7 +188,7 @@
if (networkServiceInstanceOpt.isPresent()) {
networkServiceInstance = networkServiceInstanceOpt.get()
- if (networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
+ if (networkServiceInstance.getServiceRole() == null /* WorkAround */ || networkServiceInstance.getServiceRole() == "Network Service") { // Network Service role
currentNSSI['networkServiceInstanceUri'] = networkServiceInstanceUri
break
}
@@ -180,6 +199,12 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
}
}
+
+ if (currentNSSI['networkServiceInstanceUri'] == null) {
+ String msg = String.format("Network Service Instance URI is null")
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
}
else {
String msg = String.format("No relationship presented for NSSI %s in AAI", nssiId)
@@ -193,6 +218,8 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
}
+ LOGGER.debug("${getPrefix()} Exit handleNetworkInstance")
+
return networkServiceInstance
}
@@ -202,7 +229,7 @@
* @param execution
*/
void getConstituteVNFFromNetworkServiceInst(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
+ LOGGER.debug("${getPrefix()} Start getConstituteVNFFromNetworkServiceInst")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -211,6 +238,7 @@
AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri']
AAIResultWrapper wrapper = client.get(networkServiceInstanceUri);
Optional<Relationships> relationships = wrapper.getRelationships()
+
if (relationships.isPresent()) {
for (AAIResourceUri constituteVnfUri : relationships.get().getRelatedUris(Types.GENERIC_VNF)) {
currentNSSI['constituteVnfUri'] = constituteVnfUri
@@ -234,135 +262,17 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
}
- LOGGER.trace("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
+ LOGGER.debug("${getPrefix()} Exit getConstituteVNFFromNetworkServiceInst")
}
/**
- * Retrieves NSSI associated profiles from AAI
- * @param execution
- */
- void getNSSIAssociatedProfiles(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles")
-
- List<SliceProfile> associatedProfiles = new ArrayList<>()
-
- AAIResourcesClient client = getAAIClient()
-
- def currentNSSI = execution.getVariable("currentNSSI")
-
- ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
-
- String nssiId = currentNSSI['nssiId']
-
- // NSSI
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
- AAIResultWrapper nssiWrapper = client.get(nssiUri)
- Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
-
- if (nssiRelationships.isPresent()) {
- // Allotted Resource
- for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
- AAIResultWrapper arWrapper = client.get(allottedResourceUri)
- Optional<Relationships> arRelationships = arWrapper.getRelationships()
-
- boolean isFound = false
- if(arRelationships.isPresent()) {
- // Slice Profile Instance
- for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
- Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
-
- if (sliceProfileInstanceOpt.isPresent()) {
- ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
- if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
- associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile()
-
- currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
-
- isFound = true
- break // Should be only one
- }
- }
- else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
- }
- }
- }
- else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
- }
-
- if(isFound) {
- break
- }
- }
- }
- else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for nssi id = " + nssiId)
- }
-
- 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" ) // Not exist in case of Deallocate
-
- 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")
+ LOGGER.debug("${getPrefix()} Start invokePUTServiceInstance")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -372,15 +282,18 @@
ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
+ GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
- currentNSSI['putServiceInstanceURL'] = url
+ // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
+ 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 basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
+
+ def authHeader = utils.getBasicAuth(basicAuth, msoKey) // ""
+ /* 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")
@@ -389,11 +302,15 @@
}
else {
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(responseAuthHeader, "errorMessage"))
- }
+ } */
def requestDetails = ""
+
String prepareRequestDetailsResponse = prepareRequestDetails(execution)
- errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
+ LOGGER.debug("invokePUTServiceInstance: prepareRequestDetailsResponse=" + prepareRequestDetailsResponse)
+
+ String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
+ LOGGER.debug("invokePUTServiceInstance: errorCode=" + errorCode)
if(errorCode == null || errorCode.isEmpty()) { // No error
requestDetails = prepareRequestDetailsResponse
}
@@ -402,15 +319,13 @@
}
String callPUTServiceInstanceResponse = callPUTServiceInstance(url, authHeader, requestDetails)
- String putServiceInstanceResponse = ""
- if(errorCode == null || errorCode.isEmpty()) { // No error
- putServiceInstanceResponse = callPUTServiceInstanceResponse
- }
- else {
- LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
- exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage"))
- }
+ String macroOperationId = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestId")
+ String requestSelfLink = jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "requestReferences.requestSelfLink")
+
+ execution.setVariable("macroOperationId", macroOperationId)
+ execution.setVariable("requestSelfLink", requestSelfLink)
+ currentNSSI['requestSelfLink'] = requestSelfLink
} catch (any) {
String msg = "Exception in ${getPrefix()}.invokePUTServiceInstance. " + any.getCause()
@@ -418,29 +333,36 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- LOGGER.trace("${getPrefix()} Exit invokePUTServiceInstance")
+ LOGGER.debug("${getPrefix()} Exit invokePUTServiceInstance")
}
String callPUTServiceInstance(String url, String authHeader, String requestDetailsStr) {
+ LOGGER.debug("${getPrefix()} Start callPUTServiceInstance")
+
String errorCode = ""
String errorMessage = ""
String response
+ LOGGER.debug("callPUTServiceInstance: url = " + url)
+ LOGGER.debug("callPUTServiceInstance: authHeader = " + authHeader)
+
try {
- HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.EXTERNAL)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
httpClient.addAdditionalHeader("Authorization", authHeader)
httpClient.addAdditionalHeader("Accept", "application/json")
- Response httpResponse = httpClient.put(requestDetailsStr) // check http code ???
+ Response httpResponse = httpClient.put(requestDetailsStr)
-
- if (httpResponse.hasEntity()) {
+ int soResponseCode = httpResponse.getStatus()
+ if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
response = httpResponse.readEntity(String.class)
+
+ LOGGER.debug("callPUTServiceInstance: response = " + response)
}
else {
errorCode = 500
- errorMessage = "No response received."
+ errorMessage = "Response code is " + soResponseCode
response = "{\n" +
" \"errorCode\": \"${errorCode}\",\n" +
@@ -461,6 +383,7 @@
return response
+ LOGGER.debug("${getPrefix()} Exit callPUTServiceInstance")
}
@@ -471,6 +394,7 @@
* @return ModelInfo
*/
ModelInfo prepareModelInfo(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareModelInfo")
def currentNSSI = execution.getVariable("currentNSSI")
ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
@@ -491,6 +415,8 @@
modelInfo.setModelVersion(modelVerOpt.get().getModelVersion())
}
+ LOGGER.debug("${getPrefix()} Exit prepareModelInfo")
+
return modelInfo
}
@@ -501,6 +427,8 @@
* @return SubscriberInfo
*/
SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareSubscriberInfo")
+
def currentNSSI = execution.getVariable("currentNSSI")
String globalSubscriberId = execution.getVariable("globalSubscriberId")
@@ -545,6 +473,8 @@
} */
+ LOGGER.debug("${getPrefix()} Exit prepareSubscriberInfo")
+
return subscriberInfo
}
@@ -555,6 +485,8 @@
* @return RequestInfo
*/
RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) {
+ LOGGER.debug("${getPrefix()} Start prepareRequestInfo")
+
def currentNSSI = execution.getVariable("currentNSSI")
String productFamilyId = execution.getVariable("productFamilyId")
@@ -566,6 +498,8 @@
requestInfo.setProductFamilyId(productFamilyId)
requestInfo.setRequestorId("NBI")
+ LOGGER.debug("${getPrefix()} Exit prepareRequestInfo")
+
return requestInfo
}
@@ -577,6 +511,7 @@
* @return ModelInfo
*/
ModelInfo prepareServiceModelInfo(ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+ LOGGER.debug("${getPrefix()} Start prepareServiceModelInfo")
ModelInfo serviceModelInfo = new ModelInfo()
serviceModelInfo.setModelType(ModelType.service)
@@ -586,6 +521,8 @@
serviceModelInfo.setModelName(modelInfo.getModelName())
serviceModelInfo.setModelVersion(modelInfo.getModelVersion())
+ LOGGER.debug("${getPrefix()} Exit prepareServiceModelInfo")
+
return serviceModelInfo
}
@@ -596,6 +533,8 @@
* @return CloudConfiguration
*/
CloudConfiguration prepareCloudConfiguration(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareCloudConfiguration")
+
def currentNSSI = execution.getVariable("currentNSSI")
CloudConfiguration cloudConfiguration = new CloudConfiguration()
@@ -603,6 +542,7 @@
AAIResourcesClient client = getAAIClient()
AAIResourceUri constituteVnfUri = currentNSSI['constituteVnfUri']
+
AAIResultWrapper wrapper = client.get(constituteVnfUri)
Optional<Relationships> cloudRegionRelationshipsOps = wrapper.getRelationships()
@@ -617,9 +557,29 @@
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
+
+ if(cloudRegion.getTenants() != null && cloudRegion.getTenants().getTenant() != null) {
+ for (Tenant tenant : cloudRegion.getTenants().getTenant()) {
+ cloudConfiguration.setTenantId(tenant.getTenantId())
+ cloudConfiguration.setTenantName(tenant.getTenantName())
+ break // only one is required
+ }
+ }
+ else {
+ List<AAIResourceUri> tenantRelatedAAIUris = cloudRegionRelationshipsOps.get().getRelatedUris(Types.TENANT)
+ if (!(tenantRelatedAAIUris == null || tenantRelatedAAIUris.isEmpty())) {
+ Optional<Tenant> tenantOpt = client.get(Tenant.class, tenantRelatedAAIUris.get(0))
+ Tenant tenant = null
+ if (tenantOpt.isPresent()) {
+ tenant = tenantOpt.get()
+
+ LOGGER.debug("prepareCloudConfiguration: tenantId=" + tenant.getTenantId())
+ LOGGER.debug("prepareCloudConfiguration: tenantName=" + tenant.getTenantName())
+
+ cloudConfiguration.setTenantId(tenant.getTenantId())
+ cloudConfiguration.setTenantName(tenant.getTenantName())
+ }
+ }
}
cloudConfiguration.setCloudOwner(cloudRegion.getCloudOwner())
@@ -627,6 +587,8 @@
}
}
+ LOGGER.debug("${getPrefix()} Exit prepareCloudConfiguration")
+
return cloudConfiguration
}
@@ -638,33 +600,100 @@
* @return List<VfModules>
*/
List<org.onap.so.serviceinstancebeans.VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) {
+ LOGGER.debug("${getPrefix()} Start prepareVfModules")
AAIResourcesClient client = getAAIClient()
+ def currentNSSI = execution.getVariable("currentNSSI")
+
List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
- for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
- org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
- ModelInfo vfModuleModelInfo = new ModelInfo()
- vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
- vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
+ ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
+ String networkServiceModelInvariantUuid = networkServiceInstance.getModelInvariantId()
- Optional<ModelVer> vfModuleModelVerOpt = client.get(ModelVer.class, vfModuleUrl)
+ String serviceVnfs="";
+ String msg=""
+ try{
+ CatalogDbUtils catalogDbUtils = getCatalogDbUtilsFactory().create()
- if (vfModuleModelVerOpt.isPresent()) {
- vfModuleModelInfo.setModelVersionId(vfModuleModelVerOpt.get().getModelVersionId())
- vfModuleModelInfo.setModelName(vfModuleModelVerOpt.get().getModelName())
- vfModuleModelInfo.setModelVersion(vfModuleModelVerOpt.get().getModelVersion())
+ String json = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidString(execution, networkServiceModelInvariantUuid)
+ LOGGER.debug("***** JSON IS: "+json)
+
+ serviceVnfs = jsonUtil.getJsonValue(json, "serviceResources.serviceVnfs") ?: ""
+
+ ObjectMapper mapper = new ObjectMapper()
+
+ List<Object> vnfList = mapper.readValue(serviceVnfs, List.class)
+ LOGGER.debug("vnfList: "+vnfList)
+
+ Map vnfMap = vnfList.get(0)
+ ModelInfo vnfModelInfo = vnfMap.get("modelInfo")
+ vnfModelInfo.setModelCustomizationId(vnfModelInfo.getModelCustomizationUuid())
+ vnfModelInfo.setModelVersionId(vnfModelInfo.getModelId())
+ LOGGER.debug("vnfModelInfo "+vnfModelInfo)
+
+ //List of VFModules
+ List<Map<String, Object>> vfModuleList = vnfMap.get("vfModules")
+ LOGGER.debug("vfModuleList "+vfModuleList)
+
+ //List of VfModules
+ List<ModelInfo> vfModelInfoList = new ArrayList<>()
+
+ //Traverse VFModules List and add in vfModelInfoList
+ for (vfModule in vfModuleList) {
+ ModelInfo vfModelInfo = vfModule.get("modelInfo")
+ vfModelInfo.setModelCustomizationId(vfModelInfo.getModelCustomizationUuid())
+ vfModelInfo.setModelVersionId(vfModelInfo.getModelId())
+ LOGGER.debug("vfModelInfo "+vfModelInfo)
+ vfModelInfoList.add(vfModelInfo)
}
- vfmodules.setModelInfo(vfModuleModelInfo)
- vfmodules.setInstanceName(vfModule.getVfModuleName())
+ for (ModelInfo vfModuleModelInfo : vfModelInfoList) {
+ org.onap.so.serviceinstancebeans.VfModules vfModules = new org.onap.so.serviceinstancebeans.VfModules()
+ vfModules.setModelInfo(vfModuleModelInfo)
+ vfModules.setInstanceName(vfModuleModelInfo.getModelName())
- vfModuless.add(vfmodules)
+ List<Map<String, Object>> vfModuleInstanceParams = new ArrayList<>()
+ vfModules.setInstanceParams(vfModuleInstanceParams)
+ vfModuless.add(vfModules)
+ }
+
+ } catch (Exception ex){
+ msg = "Exception in prepareVfModules " + ex.getMessage()
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
+ /*
+ List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>()
+ if(constituteVnf.getVfModules() != null && constituteVnf.getVfModules().getVfModule() != null) {
+ for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) {
+ org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules()
+
+ ModelInfo vfModuleModelInfo = new ModelInfo()
+ vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId())
+ vfModuleModelInfo.setModelCustomizationId(vfModule.getModelCustomizationId())
+
+ AAIResourceUri vfModuleUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(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)
+ }
+ } */
+
+ LOGGER.debug("${getPrefix()} Exit prepareVfModules")
+
return vfModuless
}
@@ -676,6 +705,8 @@
* @return ModelInfo
*/
ModelInfo prepareVNFModelInfo(DelegateExecution execution, GenericVnf constituteVnf) {
+ LOGGER.debug("${getPrefix()} Start prepareVNFModelInfo")
+
ModelInfo vnfModelInfo = new ModelInfo()
AAIResourcesClient client = getAAIClient()
@@ -694,11 +725,15 @@
vnfModelInfo.setModelVersion(vnfModelVerOpt.get().getModelVersion())
}
+ LOGGER.debug("${getPrefix()} Exit prepareVNFModelInfo")
+
return vnfModelInfo
}
List<Map<String, Object>> prepareInstanceParams(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareInstanceParams")
+
def currentNSSI = execution.getVariable("currentNSSI")
List<Map<String, Object>> instanceParams = new ArrayList<>()
@@ -734,6 +769,8 @@
instanceParamsMap.put("supportedNssai", supportedNssaiDetailsStr)
instanceParams.add(instanceParamsMap)
+ LOGGER.debug("${getPrefix()} Exit prepareInstanceParams")
+
return instanceParams
}
@@ -743,6 +780,8 @@
* @return Resources
*/
Resources prepareResources(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareResources")
+
def currentNSSI = execution.getVariable("currentNSSI")
Resources resources = new Resources()
@@ -781,6 +820,8 @@
vnfs.add(vnf)
resources.setVnfs(vnfs)
+ LOGGER.debug("${getPrefix()} Exit prepareResources")
+
return resources
}
@@ -790,6 +831,8 @@
* @return Service
*/
org.onap.so.serviceinstancebeans.Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+ LOGGER.debug("${getPrefix()} Start prepareService")
+
org.onap.so.serviceinstancebeans.Service service = new org.onap.so.serviceinstancebeans.Service()
// Model Info
@@ -800,6 +843,8 @@
// Resources
service.setResources(prepareResources(execution))
+ LOGGER.debug("${getPrefix()} Exit prepareService")
+
return service
}
@@ -811,6 +856,8 @@
* @return RequestParameters
*/
RequestParameters prepareRequestParameters(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) {
+ LOGGER.debug("${getPrefix()} Start prepareRequestParameters")
+
def currentNSSI = execution.getVariable("currentNSSI")
RequestParameters requestParameters = new RequestParameters()
@@ -834,6 +881,10 @@
userParams.add(serviceMap)
requestParameters.setUserParams(userParams)
+ requestParameters.setaLaCarte(false)
+
+ LOGGER.debug("${getPrefix()} Exit prepareRequestParameters")
+
return requestParameters
}
@@ -844,6 +895,8 @@
* @return OwningEntity
*/
org.onap.so.serviceinstancebeans.OwningEntity prepareOwningEntity(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareOwningEntity")
+
def currentNSSI = execution.getVariable("currentNSSI")
AAIResourcesClient client = getAAIClient()
@@ -866,6 +919,8 @@
}
}
+ LOGGER.debug("${getPrefix()} Exit prepareOwningEntity")
+
return owningEntity
}
@@ -876,6 +931,8 @@
* @return Project
*/
org.onap.so.serviceinstancebeans.Project prepareProject(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareProject")
+
def currentNSSI = execution.getVariable("currentNSSI")
AAIResourcesClient client = getAAIClient()
@@ -898,6 +955,8 @@
}
}
+ LOGGER.debug("${getPrefix()} Exit prepareProject")
+
return project
}
@@ -908,6 +967,8 @@
* @return
*/
String prepareRequestDetails(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start prepareRequestDetails")
+
String errorCode = ""
String errorMessage = ""
String response
@@ -941,9 +1002,12 @@
// Project
requestDetails.setProject(prepareProject(execution))
+ Map<String, Object> requestDetailsMap = new LinkedHashMap<>()
+ requestDetailsMap.put("requestDetails", requestDetails)
+
ObjectMapper mapper = new ObjectMapper()
- response = mapper.writeValueAsString(requestDetails)
+ response = mapper.writeValueAsString(requestDetailsMap)
}
catch (any) {
String msg = "Exception in ${getPrefix()}.prepareRequestDetails. " + any.getCause()
@@ -956,6 +1020,8 @@
}
+ LOGGER.debug("${getPrefix()} Exit prepareRequestDetails")
+
return response
}
@@ -990,11 +1056,108 @@
/**
+ * Retrieves NSSI associated profiles from AAI
+ * @param execution
+ */
+ void getNSSIAssociatedProfiles(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start getNSSIAssociatedProfiles")
+
+ List<SliceProfile> associatedProfiles = new ArrayList<>()
+
+ AAIResourcesClient client = getAAIClient()
+
+ def currentNSSI = execution.getVariable("currentNSSI")
+
+ ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi']
+
+ String nssiId = currentNSSI['nssiId']
+
+ String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+ // NSSI
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+ AAIResultWrapper nssiWrapper = client.get(nssiUri)
+ Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
+
+ if (nssiRelationships.isPresent()) {
+ // Allotted Resource
+ for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
+ AAIResultWrapper arWrapper = client.get(allottedResourceUri)
+ Optional<Relationships> arRelationships = arWrapper.getRelationships()
+
+ if(arRelationships.isPresent()) {
+ // Slice Profile Instance
+ for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
+ Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
+
+ if (sliceProfileInstanceOpt.isPresent()) {
+ ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+ if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance
+
+ String globalSubscriberId = execution.getVariable("globalSubscriberId")
+ String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+
+ org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
+ AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
+
+ def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
+ LOGGER.debug("client.exists(sliceProfilesUri = " + client.exists(sliceProfilesUri))
+ if (!client.exists(sliceProfilesUri)) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Slice Profiles URI doesn't exist")
+ }
+
+ AAIResultWrapper sliceProfilesWrapper = client.get(sliceProfilesUri)
+ Optional<SliceProfiles> sliceProfilesOpt = sliceProfilesWrapper.asBean(SliceProfiles.class)
+ if(sliceProfilesOpt.isPresent()) {
+ SliceProfiles sliceProfiles = sliceProfilesOpt.get()
+
+ LOGGER.debug("getNSSIAssociatedProfiles: sliceProfiles.getSliceProfile().size() = " + sliceProfiles.getSliceProfile().size())
+ LOGGER.debug("getNSSIAssociatedProfiles: givenSliceProfileId = " + givenSliceProfileId)
+ for(SliceProfile sliceProfile: sliceProfiles.getSliceProfile()) {
+ LOGGER.debug("getNSSIAssociatedProfiles: sliceProfile.getProfileId() = " + sliceProfile.getProfileId())
+ if(sliceProfile.getProfileId().equals(givenSliceProfileId)) { // Slice profile id equals to received slice profile id
+ currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri
+ }
+
+ }
+
+ associatedProfiles.addAll(sliceProfiles.getSliceProfile()) // Adds all slice profiles
+ }
+
+ }
+ }
+ else {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found")
+ }
+ }
+ }
+ else {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource")
+ }
+
+ }
+ }
+ else {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for nssi id = " + nssiId)
+ }
+
+ checkAssociatedProfiles(execution, associatedProfiles, nssi)
+
+ currentNSSI['associatedProfiles'] = associatedProfiles
+
+ LOGGER.debug("${getPrefix()} Exit getNSSIAssociatedProfiles")
+ }
+
+
+ void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {}
+
+
+ /**
* Removes Slice Profile association with NSSI
* @param execution
*/
void removeSPAssociationWithNSSI(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start removeSPAssociationWithNSSI")
+ LOGGER.debug("${getPrefix()} Start removeSPAssociationWithNSSI")
AAIResourcesClient client = getAAIClient()
@@ -1003,47 +1166,35 @@
String nssiId = currentNSSI['nssiId']
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
- AAIResourceUri sliceProfileInstanceUri = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri']
+ String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
- Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
- if (sliceProfileInstanceOpt.isPresent()) {
- ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+ boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
- List<SliceProfile> associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile()
-
- String currentSNSSAI = currentNSSI['S-NSSAI']
-
- if(!(associatedProfiles == null || associatedProfiles.isEmpty())) {
- // Removes slice profile which contains given S-NSSAI and updates Slice Profile Instance
- associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) })
-
- try {
- client.update(sliceProfileInstanceUri, sliceProfileInstance)
-
- currentNSSI['sliceProfileInstance'] = sliceProfileInstance
- } catch (Exception e) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage())
- }
+ AAIResourceUri sliceProfileInstanceUri = null
+ if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
+ def spURI = currentNSSI['sliceProfileInstanceUri']
+ if(spURI != null) {
+ sliceProfileInstanceUri = (AAIResourceUri)spURI
}
else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profiles found")
+ String msg = "Slice Profile URI not found"
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
-
- }
- else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found")
}
// Removes SLice Profile Instance association with NSSI
- try {
- client.disconnect(nssiUri, sliceProfileInstanceUri)
- }
- catch (Exception e) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
+ if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
+ try {
+ client.disconnect(nssiUri, sliceProfileInstanceUri)
+ }
+ catch (Exception e) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage())
+ }
}
- LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI")
+ LOGGER.debug("${getPrefix()} Exit removeSPAssociationWithNSSI")
}
@@ -1052,21 +1203,38 @@
* @param execution
*/
void deleteSliceProfileInstance(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start deleteSliceProfileInstance")
+ LOGGER.debug("${getPrefix()} Start deleteSliceProfileInstance")
AAIResourcesClient client = getAAIClient()
def currentNSSI = execution.getVariable("currentNSSI")
- AAIResourceUri sliceProfileInstanceURI = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri']
+ String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
- try {
- client.delete(sliceProfileInstanceURI)
- }catch(Exception e){
- exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
+ boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
+
+ AAIResourceUri sliceProfileInstanceUri = null
+ if(!isTerminateNSSI) { // In case of NSSI non-termination associated Slice Profile Instance should be presented
+ def spURI = currentNSSI['sliceProfileInstanceUri']
+ if(spURI != null) {
+ sliceProfileInstanceUri = (AAIResourceUri)spURI
+ }
+ else {
+ String msg = "Slice Profile URI not found"
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
}
- LOGGER.trace("${getPrefix()} Exit deleteSliceProfileInstance")
+ if(sliceProfileInstanceUri != null) { // NSSI should not be terminated
+ try {
+ client.delete(sliceProfileInstanceUri)
+ } catch (Exception e) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage())
+ }
+ }
+
+ LOGGER.debug("${getPrefix()} Exit deleteSliceProfileInstance")
}
@@ -1075,7 +1243,7 @@
* @param execution
*/
void prepareUpdateResourceOperationStatus(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus")
+ LOGGER.debug("${getPrefix()} Start updateServiceOperationStatus")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -1092,7 +1260,7 @@
setResourceOperationStatus(execution, "finished", "100", "Core NSSI ${getAction()} successful")
- LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus")
+ LOGGER.debug("${getPrefix()} Exit updateServiceOperationStatus")
}
@@ -1102,26 +1270,31 @@
* @param operationType
*/
void setResourceOperationStatus(DelegateExecution execution, String status, String progress, String statusDesc) {
- LOGGER.trace("${getPrefix()} Start setResourceOperationStatus")
+ LOGGER.debug("${getPrefix()} Start setResourceOperationStatus")
def currentNSSI = execution.getVariable("currentNSSI")
- String serviceId = currentNSSI['nssiId']
+ String serviceId = currentNSSI['nsiId']
String jobId = execution.getVariable("jobId")
String nsiId = currentNSSI['nsiId']
String operationType = execution.getVariable("operationType")
+ String resourceInstanceId = currentNSSI['nssiId']
+
+ ServiceInstance nssi = (ServiceInstance) currentNSSI['nssi']
+ String modelUuid = nssi.getModelVersionId()
ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus()
resourceOperationStatus.setServiceId(serviceId)
resourceOperationStatus.setOperationId(jobId)
- resourceOperationStatus.setResourceTemplateUUID(nsiId)
+ resourceOperationStatus.setResourceTemplateUUID(modelUuid)
resourceOperationStatus.setOperType(operationType)
+ resourceOperationStatus.setResourceInstanceID(resourceInstanceId)
resourceOperationStatus.setStatus(status)
resourceOperationStatus.setProgress(progress)
resourceOperationStatus.setStatusDescription(statusDesc)
requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus)
- LOGGER.trace("${getPrefix()} Exit setResourceOperationStatus")
+ LOGGER.debug("${getPrefix()} Exit setResourceOperationStatus")
}
@@ -1130,11 +1303,11 @@
* @param execution
*/
void prepareFailedOperationStatusUpdate(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start prepareFailedOperationStatusUpdate")
+ LOGGER.debug("${getPrefix()} Start prepareFailedOperationStatusUpdate")
setResourceOperationStatus(execution, "failed", "0", "Core NSSI ${getAction()} Failed")
- LOGGER.trace("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
+ LOGGER.debug("${getPrefix()} Exit prepareFailedOperationStatusUpdate")
}
@@ -1143,42 +1316,58 @@
* @param execution
*/
public void getPUTServiceInstanceProgress(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start getPUTServiceInstanceProgress")
+ LOGGER.debug("${getPrefix()} Start getPUTServiceInstanceProgress")
def currentNSSI = execution.getVariable("currentNSSI")
- String url = currentNSSI['putServiceInstanceURL']
+ ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- getProgress(execution, url, "putStatus")
+ String url = currentNSSI['requestSelfLink']
- LOGGER.trace("${getPrefix()} Exit getPUTServiceInstanceProgress")
+ String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
+
+ String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
+
+ def authHeader = ""
+ String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
+
+ getProgress(execution, url, basicAuthValue, "putStatus")
+
+ LOGGER.debug("${getPrefix()} Exit getPUTServiceInstanceProgress")
}
- void getProgress(DelegateExecution execution, String url, String statusVariableName) {
+ void getProgress(DelegateExecution execution, String url, String authHeader, String statusVariableName) {
+ LOGGER.debug("${getPrefix()} Start getProgress")
+
+ LOGGER.debug("getProgress: url = " + url)
+ LOGGER.debug("getProgress: authHeader = " + authHeader)
+
String msg=""
try {
- ExternalAPIUtil externalAPIUtil = getExternalAPIUtilFactory().create()
- Response response = externalAPIUtil.executeExternalAPIGetCall(execution, url)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
+ httpClient.addAdditionalHeader("Authorization", authHeader)
+ httpClient.addAdditionalHeader("Accept", "application/json")
+
+ Response response = httpClient.get()
int responseCode = response.getStatus()
- execution.setVariable("GetServiceOrderResponseCode", responseCode)
+ // execution.setVariable("GetServiceOrderResponseCode", responseCode)
LOGGER.debug("Get ServiceOrder response code is: " + responseCode)
- String extApiResponse = response.readEntity(String.class)
- JSONObject responseObj = new JSONObject(extApiResponse)
- execution.setVariable("GetServiceOrderResponse", extApiResponse)
- LOGGER.debug("Create response body is: " + extApiResponse)
- //Process Response //200 OK 201 CREATED 202 ACCEPTED
- if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
- {
- LOGGER.debug("Get Create ServiceOrder Received a Good Response")
- String orderState = responseObj.get("state")
- if("REJECTED".equalsIgnoreCase(orderState)) {
- prepareFailedOperationStatusUpdate(execution)
- return
- }
+ String soResponse = ""
+ if(response.hasEntity()) {
+ soResponse = response.readEntity(String.class)
+ // execution.setVariable("GetServiceOrderResponse", extApiResponse)
+ LOGGER.debug("Create response body is: " + soResponse)
+ }
+ //Process Response //200 OK 201 CREATED 202 ACCEPTED
+ if (responseCode >= 200 && responseCode < 204) {
+ LOGGER.debug("Get Create ServiceOrder Received a Good Response")
+ String requestState = jsonUtil.getJsonValue(soResponse, "request.requestStatus.requestState")
+
+ /*
JSONArray items = responseObj.getJSONArray("orderItem")
JSONObject item = items.get(0)
JSONObject service = item.get("service")
@@ -1190,21 +1379,25 @@
execution.setVariable("networkServiceId", networkServiceId)
String serviceOrderState = item.get("state")
- execution.setVariable("ServiceOrderState", serviceOrderState)
+ execution.setVariable("ServiceOrderState", serviceOrderState) */
+
// Get serviceOrder State and process progress
- if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
+ if("ACKNOWLEDGED".equalsIgnoreCase(requestState)) {
execution.setVariable(statusVariableName, "processing")
}
- else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
+ else if("IN_PROGRESS".equalsIgnoreCase(requestState)) {
execution.setVariable(statusVariableName, "processing")
}
- else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
+ else if("COMPLETE".equalsIgnoreCase(requestState)) {
execution.setVariable(statusVariableName, "completed")
}
- else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
+ else if("FAILED".equalsIgnoreCase(requestState)) {
msg = "ServiceOrder failed"
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
+ else if("REJECTED".equalsIgnoreCase(requestState)) {
+ prepareFailedOperationStatusUpdate(execution)
+ }
else {
msg = "ServiceOrder failed"
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
@@ -1219,6 +1412,7 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage())
}
+ LOGGER.debug("${getPrefix()} Exit getProgress")
}
@@ -1228,7 +1422,7 @@
* @param execution
*/
void timeDelay(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start timeDelay")
+ LOGGER.debug("${getPrefix()} Start timeDelay")
try {
LOGGER.debug("${getPrefix()} timeDelay going to sleep for 5 sec")
@@ -1240,10 +1434,20 @@
LOGGER.error("${getPrefix()} ::: timeDelay exception" + e)
}
- LOGGER.trace("${getPrefix()} Exit timeDelay")
+ LOGGER.debug("${getPrefix()} Exit timeDelay")
}
+ void postProcessRequest(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start postProcessRequest")
+
+ execution.removeVariable("currentNSSI")
+
+ LOGGER.debug("***** ${getPrefix()} Exit postProcessRequest")
+ }
+
+
+
/**
* Returns AAI client
* @return AAI client
@@ -1258,7 +1462,16 @@
}
- String getPrefix() {
+ /**
+ * Returns Catalog DB Util Factory
+ * @return ew CatalogDbUtilsFactory()
+ */
+ CatalogDbUtilsFactory getCatalogDbUtilsFactory() {
+ return new CatalogDbUtilsFactory()
+ }
+
+
+ private 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 fe881eb..c559845 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
@@ -20,10 +20,14 @@
package org.onap.so.bpmn.infrastructure.scripts
-
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.gson.JsonObject
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.v19.AllottedResource
+import org.onap.aai.domain.yang.v19.GenericVnf
import org.onap.aai.domain.yang.v19.ServiceInstance
+import org.onap.aai.domain.yang.v19.SliceProfile
+import org.onap.aai.domain.yang.v19.SliceProfiles
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.Relationships
@@ -34,16 +38,23 @@
import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.scripts.OofUtils
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.client.HttpClientFactory
+import org.onap.so.client.oof.adapter.beans.payload.OofRequest
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.ws.rs.core.Response
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
+import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
+
class DoDeallocateCoreNSSI extends DoCommonCoreNSSI {
private final String PREFIX ="DoDeallocateCoreNSSI"
private final String ACTION = "Deallocate"
@@ -55,54 +66,84 @@
private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateCoreNSSI.class)
+
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start preProcessRequest")
+
+ super.preProcessRequest(execution)
+
+ execution.setVariable("operationType", "DEALLOCATE")
+
+ LOGGER.debug("${getPrefix()} Exit preProcessRequest")
+ }
+
+
+
/**
* Queries OOF for NSSI termination
* @param execution
*/
void executeTerminateNSSIQuery(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start executeTerminateNSSIQuery")
+ LOGGER.debug("${PREFIX} Start executeTerminateNSSIQuery")
String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution)
+ // String urlString = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution)
+
+ //API Path
+ String apiPath = "/api/oof/terminate/nxi/v1"
+ LOGGER.debug("API path for DoAllocateCoreNSSI: "+apiPath)
+
+ urlString = urlString + apiPath
//Prepare auth for OOF
def authHeader = ""
String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution)
String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
- String basicAuthValue = encryptBasicAuth(basicAuth, msokey)
- 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"))
+ String basicAuthValue = utils.encrypt(basicAuth, msokey)
+ /* if (basicAuthValue != null) {
+ LOGGER.debug( "Obtained BasicAuth username and password for OOF Adapter: " + basicAuthValue)
+ try {
+ authHeader = utils.getBasicAuth(basicAuthValue, msokey)
+ execution.setVariable("BasicAuthHeaderValue", authHeader)
+ } catch (Exception ex) {
+ LOGGER.error( "Unable to encode username and password string: " + ex)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
}
} else {
LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
- exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
- "value null")
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth value null")
+ } */
+
+
+ try {
+ authHeader = utils.getBasicAuth(basicAuthValue, msokey)
+ execution.setVariable("BasicAuthHeaderValue", authHeader)
+ } catch (Exception ex) {
+ LOGGER.error( "Unable to encode username and password string: " + ex)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to encode username and password string")
}
//Prepare send request to OOF
String oofRequest = buildOOFRequest(execution)
String callOOFResponse = callOOF(urlString, authHeader, oofRequest)
+ LOGGER.debug("callOOFResponse=" + callOOFResponse)
+
String errorCode = jsonUtil.getJsonValue(callOOFResponse, "errorCode")
if(errorCode == null || errorCode.isEmpty()) { // No error
- String oofResponse = callOOFResponse
- String isTerminateNSSI = jsonUtil.getJsonValue(oofResponse, "terminateResponse")
+ String terminateNSSI = jsonUtil.getJsonValue(callOOFResponse, "terminateResponse")
+ LOGGER.debug("isTerminateNSSI=" + terminateNSSI)
- execution.setVariable("isTerminateNSSI", Boolean.parseBoolean(isTerminateNSSI))
+ execution.setVariable("isTerminateNSSI", terminateNSSI)
}
else {
LOGGER.error(jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(errorCode), jsonUtil.getJsonValue(callOOFResponse, "errorMessage"))
}
-
- LOGGER.trace("${PREFIX} Exit executeTerminateNSSIQuery")
+ LOGGER.debug("${PREFIX} Exit executeTerminateNSSIQuery")
}
@@ -111,15 +152,16 @@
* @return OOF response
*/
String callOOF(String urlString, String authHeader, String oofRequest) {
+ LOGGER.debug("${PREFIX} Start callOOF")
+
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)
+ URL url = new URL(urlString)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.OOF)
httpClient.addAdditionalHeader("Authorization", authHeader)
- httpClient.addAdditionalHeader("Accept", "application/json")
httpClient.addAdditionalHeader("Content-Type", "application/json")
Response httpResponse = httpClient.post(oofRequest)
@@ -127,7 +169,7 @@
int responseCode = httpResponse.getStatus()
LOGGER.debug("OOF sync response code is: " + responseCode)
- if (responseCode != 202) { // Accepted
+ if(responseCode < 200 || responseCode >= 300) { // Wrong code
errorCode = responseCode
errorMessage = "Received a Bad Sync Response from OOF."
@@ -161,6 +203,7 @@
"}"
}
+ LOGGER.debug("${PREFIX} Exit callOOF")
return response
}
@@ -172,23 +215,54 @@
* @return
*/
private String buildOOFRequest(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start buildOOFRequest")
def currentNSSI = execution.getVariable("currentNSSI")
String nssiId = currentNSSI['nssiId']
- String requestId = execution.getVariable("mso-request-id")
- String request = "{\n" +
- " \"type\": \"NSSI\",\n" +
- " \"NxIId\": \"${nssiId}\",\n" +
- " \"requestInfo\": {\n" +
- " \"transactionId\": \"${requestId}\",\n" +
- " \"requestId\": \"${requestId}\",\n" +
- " \"sourceId\": \"so\",\n" +
- " }\n" +
- "}"
+ ServiceInstance nssi = null
- return request
+ AAIResourcesClient client = getAAIClient()
+
+ // NSSI
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+ Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, nssiUri)
+
+ if (nssiOpt.isPresent()) {
+ nssi = nssiOpt.get()
+ }
+ else {
+ String msg = "NSSI service instance not found in AAI for nssi id " + nssiId
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ //Setting correlator as requestId
+ String requestId = execution.getVariable("msoRequestId")
+ execution.setVariable("NSSI_correlator", requestId)
+
+ //Setting messageType for all Core slice as cn
+ String messageType = "cn"
+ execution.setVariable("NSSI_messageType", messageType)
+
+ //Prepare Callback
+ String timeout = execution.getVariable("timeout")
+ if (isBlank(timeout)) {
+ timeout = UrnPropertiesReader.getVariable("mso.oof.timeout", execution);
+ if (isBlank(timeout)) {
+ timeout = "PT30M"
+ }
+ }
+
+ String nxlId = nssi.getServiceInstanceId()
+ String nxlType = "NSSI"
+ String oofRequest = getOofUtils().buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, nssi.getServiceInstanceId())
+ LOGGER.debug("**** Terminate Nxi Request: "+oofRequest)
+
+ LOGGER.debug("${PREFIX} Exit buildOOFRequest")
+
+ return oofRequest
}
@@ -198,24 +272,29 @@
* @param execution
*/
void deleteServiceOrder(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start deleteServiceOrder")
+ LOGGER.debug("${PREFIX} Start deleteServiceOrder")
def currentNSSI = execution.getVariable("currentNSSI")
try {
//url:/nbi/api/v4/serviceOrder/"
- def nbiEndpointUrl = UrnPropertiesReader.getVariable("nbi.endpoint.url", execution)
+ def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution)
ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance']
- String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+ //String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+
+ GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf']
+
+ // http://so.onap:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances/de6a0aa2-19f2-41fe-b313-a5a9f159acd7/vnfs/3abbb373-8d33-4977-aa4b-2bfee496b6d5
+ String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
currentNSSI['deleteServiceOrderURL'] = url
String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
- String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution)
+ String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
- String basicAuthValue = encryptBasicAuth(basicAuth, msoKey)
+ /*String basicAuthValue = encryptBasicAuth(basicAuth, msoKey)
def authHeader = ""
if (basicAuthValue != null) {
String responseAuthHeader = getAuthHeader(execution, basicAuthValue, msoKey)
@@ -230,14 +309,21 @@
LOGGER.error( "Unable to obtain BasicAuth - BasicAuth value null")
exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " +
"value null")
- }
+ } */
+
+ def authHeader = utils.getBasicAuth(basicAuth, msoKey)
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 ???
+ String macroOperationId = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestId")
+ String requestSelfLink = jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "requestReferences.requestSelfLink")
+
+ execution.setVariable("macroOperationId", macroOperationId)
+ execution.setVariable("requestSelfLink", requestSelfLink)
+
+ currentNSSI['requestSelfLink'] = requestSelfLink
}
else {
LOGGER.error(jsonUtil.getJsonValue(callDeleteServiceOrderResponse, "errorMessage"))
@@ -249,27 +335,34 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- LOGGER.trace("${PREFIX} Exit deleteServiceOrder")
+ LOGGER.debug("${PREFIX} Exit deleteServiceOrder")
}
- String callDeleteServiceOrder(DelegateExecution execution, String urlString, String authHeader) {
+ String callDeleteServiceOrder(DelegateExecution execution, String url, String authHeader) {
+ LOGGER.debug("${PREFIX} Start callDeleteServiceOrder")
+
String errorCode = ""
String errorMessage = ""
String response = ""
try {
- HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(urlString), ONAPComponents.EXTERNAL)
+ HttpClient httpClient = getHttpClientFactory().newJsonClient(new URL(url), ONAPComponents.SO)
httpClient.addAdditionalHeader("Authorization", authHeader)
httpClient.addAdditionalHeader("Accept", "application/json")
Response httpResponse = httpClient.delete()
- if (httpResponse.hasEntity()) {
+ int soResponseCode = httpResponse.getStatus()
+ LOGGER.debug("callDeleteServiceInstance: soResponseCode = " + soResponseCode)
+
+ if (soResponseCode >= 200 && soResponseCode < 204 && httpResponse.hasEntity()) {
response = httpResponse.readEntity(String.class)
+
+ LOGGER.debug("callDeleteServiceInstance: response = " + response)
}
else {
errorCode = 500
- errorMessage = "No response received."
+ errorMessage = "Response code is " + soResponseCode
response = "{\n" +
" \"errorCode\": \"${errorCode}\",\n" +
@@ -278,7 +371,7 @@
}
}
catch (any) {
- String msg = "Exception in DoDeallocateCoreNSSI.deleteServiceOrder. " + any.getCause()
+ String msg = "Exception in DoDeallocateCoreNSSI.callDeleteServiceOrder. " + any.getCause()
response = "{\n" +
" \"errorCode\": \"7000\",\n" +
@@ -286,6 +379,8 @@
"}"
}
+ LOGGER.debug("${PREFIX} Exit callDeleteServiceOrder")
+
return response
}
@@ -295,7 +390,7 @@
* @param execution
*/
void removeNSSIAssociationWithNSI(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start removeNSSIAssociationWithNSI")
+ LOGGER.debug("${PREFIX} Start removeNSSIAssociationWithNSI")
AAIResourcesClient client = getAAIClient()
@@ -308,38 +403,54 @@
// NSSI
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
- ServiceInstance nssi = currentNSSI['nssi']
+
String allottedResourceId = null
- // Removes Allotted resource
- List<AllottedResource> allottedResources = nssi.getAllottedResources()?.getAllottedResource()
- if(allottedResources != null && allottedResources.size() == 1) { // Shouldn contain one allotted resource
- allottedResourceId = allottedResources.get(0).getId()
- allottedResources.remove(0)
+
+ AAIResultWrapper nssiWrapper = client.get(nssiUri)
+ Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships()
+
+ if (nssiRelationships.isPresent()) {
+ // Allotted Resource
+ for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) {
+ AAIResultWrapper arWrapper = client.get(allottedResourceUri)
+ Optional<Relationships> arRelationships = arWrapper.getRelationships()
+
+ if(arRelationships.isPresent()) {
+ // NSI
+ for (AAIResourceUri nsiUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) {
+ Optional<ServiceInstance> nsiOpt = client.get(ServiceInstance.class, nsiUri)
+
+ if (nsiOpt.isPresent()) {
+ ServiceInstance nsi = nsiOpt.get()
+ if(nsi.getServiceRole().equals("nsi")) { // Service instance as NSI
+ // Removes NSSI association with NSI
+ try {
+ client.disconnect(nssiUri, nsiUri)
+ }
+ catch (Exception e) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI dosconnect call: " + e.getMessage())
+ }
+ }
+ }
+ else {
+ LOGGER.warn("No NSI found for NSSI id " + nssiId)
+ }
+ }
+ }
+ else {
+ LOGGER.warn("No relationships found for Allotted Resource for NSSI id " + nssiId)
+ }
+
+ }
}
else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No allotted resource found for NSSI id = " + nssiId)
- }
-
- try {
- client.update(nssiUri, nssi)
- }catch(Exception e){
- exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
+ LOGGER.warn("No relationships found for nssi id = " + nssiId)
}
- // Remove association between NSI and Allotted Resource
- AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId))
- AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResourceId))
-
- try {
- client.disconnect(nsiUri, allottedResourceUri)
- }catch(Exception e){
- exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage())
- }
-
- LOGGER.trace("${PREFIX} Exit removeNSSIAssociationWithNSI")
+ LOGGER.debug("${PREFIX} Exit removeNSSIAssociationWithNSI")
}
@@ -348,7 +459,7 @@
* @param execution
*/
void deleteNSSIServiceInstance(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start deleteNSSIServiceInstance")
+ LOGGER.debug("${PREFIX} Start deleteNSSIServiceInstance")
AAIResourcesClient client = getAAIClient()
@@ -358,12 +469,12 @@
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
try {
- getAAIClient().delete(nssiUri)
+ client.delete(nssiUri)
}catch(Exception e){
exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while NSSI Service Instance delete call: " + e.getMessage())
}
- LOGGER.trace("${PREFIX} Exit deleteNSSIServiceInstance")
+ LOGGER.debug("${PREFIX} Exit deleteNSSIServiceInstance")
}
@@ -372,19 +483,72 @@
* @param execution
*/
void getDeleteServiceOrderProgress(DelegateExecution execution) {
- LOGGER.trace("${getPrefix()} Start getDeleteServiceOrderProgress")
+ LOGGER.debug("${getPrefix()} Start getDeleteServiceOrderProgress")
def currentNSSI = execution.getVariable("currentNSSI")
- String url = currentNSSI['deleteServiceOrderURL']
+ String url = currentNSSI['requestSelfLink']
- getProgress(execution, url, "deleteStatus")
+ String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution)
+ String basicAuth = UrnPropertiesReader.getVariable("mso.adapters.po.auth", execution)
+
+ def authHeader = ""
+ String basicAuthValue = utils.getBasicAuth(basicAuth, msoKey)
+
+ getProgress(execution, url, basicAuthValue, "deleteStatus")
+
+ LOGGER.debug("${getPrefix()} Exit getDeleteServiceOrderProgress")
}
- @Override
- String getPrefix() {
+ /**
+ * Calculates a final list of S-NSSAI
+ * @param execution
+ */
+ void calculateSNSSAI(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start calculateSNSSAI")
+
+ def currentNSSI = execution.getVariable("currentNSSI")
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
+
+ String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+ List<String> snssais = new ArrayList<>()
+
+ String isTerminateNSSIVar = execution.getVariable("isTerminateNSSI" )
+
+ boolean isTerminateNSSI = Boolean.parseBoolean(isTerminateNSSIVar)
+
+ if(!isTerminateNSSI) { // NSSI should not be terminated
+ LOGGER.debug("calculateSNSSAI: associatedProfiles.size()" + associatedProfiles.size())
+ for (SliceProfile associatedProfile : associatedProfiles) {
+ if (!associatedProfile.getProfileId().equals(givenSliceProfileId)) { // not given profile id
+ LOGGER.debug("calculateSNSSAI: associatedProfile.getSNssai()" + associatedProfile.getSNssai())
+ snssais.add(associatedProfile.getSNssai())
+ } else {
+ currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
+ }
+ }
+ }
+
+ currentNSSI['S-NSSAIs'] = snssais
+
+ LOGGER.debug("${getPrefix()} Exit calculateSNSSAI")
+ }
+
+
+ /**
+ * OofUtils
+ * @return new OofUtils()
+ */
+ OofUtils getOofUtils() {
+ return new OofUtils()
+ }
+
+
+ private 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 ff16184..a52763f 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
@@ -29,6 +29,8 @@
import org.onap.aai.domain.yang.v19.SliceProfiles
import org.onap.aaiclient.client.aai.AAIResourcesClient
import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
+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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
@@ -56,15 +58,50 @@
private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class)
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start preProcessRequest")
+
+ super.preProcessRequest(execution)
+
+ String modifyAction = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "modifyAction")
+ if (isBlank(modifyAction)) {
+ String msg = "modifyAction is mandatory parameter"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ else {
+ String createSliceProfileInstance = ""
+ if(modifyAction.equals("allocate")) { // In case Slice Profile should be created
+ createSliceProfileInstance = "true"
+ }
+ else if(modifyAction.equals("deallocate")) { // In case Slice Profile should be created
+ createSliceProfileInstance = "false"
+ }
+ else {
+ String msg = "Value of modifyAction parameter should be either allocate or deallocate"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ execution.setVariable("isCreateSliceProfileInstance", createSliceProfileInstance)
+ }
+
+ execution.setVariable("operationType", "MODIFY")
+
+ LOGGER.debug("${getPrefix()} Exit preProcessRequest")
+ }
+
+
/**
* Prepares Slice Profile
* @param execution
* @return SLice Profile
*/
SliceProfile prepareSliceProfile(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start prepareSliceProfile")
+
def currentNSSI = execution.getVariable("currentNSSI")
- String sliceProfileID = currentNSSI['sliceProfileId']
+ String givenSliceProfileId = currentNSSI['sliceProfileId'] //UUID.randomUUID().toString()
Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class)
SliceProfile sliceProfile = new SliceProfile()
@@ -77,41 +114,43 @@
sliceProfile.setConnDensity(0)
sliceProfile.setSNssai(currentNSSI['S-NSSAI'])
- if(!isBlank(sliceProfileMap.get("expDataRateUL"))) {
+ if(sliceProfileMap.get("expDataRateUL") != null) {
sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString()))
}
- if(!isBlank(sliceProfileMap.get("expDataRateDL"))) {
+ if(sliceProfileMap.get("expDataRateDL") != null) {
sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString()))
}
- if(!isBlank(sliceProfileMap.get("activityFactor"))) {
+ if(sliceProfileMap.get("activityFactor") != null) {
sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString()))
}
- if(!isBlank(sliceProfileMap.get("resourceSharingLevel"))) {
+ if(sliceProfileMap.get("resourceSharingLevel") != null) {
sliceProfile.setResourceSharingLevel(sliceProfileMap.get("resourceSharingLevel").toString())
}
- if(!isBlank(sliceProfileMap.get("uEMobilityLevel"))) {
+ if(sliceProfileMap.get("uEMobilityLevel") != null) {
sliceProfile.setUeMobilityLevel(sliceProfileMap.get("uEMobilityLevel").toString())
}
- if(!isBlank(sliceProfileMap.get("coverageAreaTAList"))) {
+ if(sliceProfileMap.get("coverageAreaTAList") != null) {
sliceProfile.setCoverageAreaTAList(sliceProfileMap.get("coverageAreaTAList").toString())
}
- if(!isBlank(sliceProfileMap.get("maxNumberofUEs"))) {
- sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberofUEs").toString()))
+ if(sliceProfileMap.get("maxNumberOfUEs") != null) {
+ sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberOfUEs").toString()))
}
- if(!isBlank(sliceProfileMap.get("latency"))) {
+ if(sliceProfileMap.get("latency") != null) {
sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString()))
}
- sliceProfile.setProfileId(sliceProfileID)
+ sliceProfile.setProfileId(givenSliceProfileId)
sliceProfile.setE2ELatency(0)
+ LOGGER.debug("${PREFIX} Exit prepareSliceProfile")
+
return sliceProfile
}
@@ -122,6 +161,7 @@
* @return Slice Profile Instance
*/
ServiceInstance prepareSliceProfileInstance(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start prepareSliceProfileInstance")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -152,6 +192,8 @@
// TO DO: Model info
+ LOGGER.debug("${PREFIX} Exit prepareSliceProfileInstance")
+
return sliceProfileInstance
}
@@ -162,7 +204,7 @@
* @param execution
*/
void createSliceProfileInstance(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start createSliceProfileInstance")
+ LOGGER.debug("${PREFIX} Start createSliceProfileInstance")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -188,7 +230,7 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Slice Profile create call:" + ex.getMessage())
}
- LOGGER.trace("${PREFIX} Exit createSliceProfileInstance")
+ LOGGER.debug("${PREFIX} Exit createSliceProfileInstance")
}
@@ -198,6 +240,8 @@
* @return AllottedResource
*/
AllottedResource createAllottedResource(DelegateExecution execution) {
+ LOGGER.debug("${PREFIX} Start createAllottedResource")
+
def currentNSSI = execution.getVariable("currentNSSI")
String globalSubscriberId = execution.getVariable("globalSubscriberId")
@@ -223,6 +267,8 @@
exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Allotted Resource create call:" + ex.getMessage())
}
+ LOGGER.debug("${PREFIX} Exit createAllottedResource")
+
return allottedResource
}
@@ -233,7 +279,7 @@
* @param execution
*/
void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) {
- LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
+ LOGGER.debug("${PREFIX} Start associateSliceProfileInstanceWithNSSI")
def currentNSSI = execution.getVariable("currentNSSI")
@@ -247,12 +293,12 @@
AllottedResource allottedResource = createAllottedResource(execution)
AAIResourceUri allottedResourceUri = (AAIResourceUri)currentNSSI['allottedResourceUri']
- // Updates Slice Profile Instance with Allotted Resource
+ // Associates Allotted Resource with Slice Profile Instance
try {
AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId))
Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri)
if (sliceProfileInstanceOpt.isPresent()) {
- ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
+ /* ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get()
AllottedResources allottedResources = sliceProfileInstance.getAllottedResources()
if(allottedResources == null) {
@@ -262,7 +308,9 @@
allottedResources.getAllottedResource().add(allottedResource)
sliceProfileInstance.setAllottedResources(allottedResources)
- client.update(sliceProfileInstanceUri, sliceProfileInstance)
+ client.update(sliceProfileInstanceUri, sliceProfileInstance) */
+
+ client.connect(sliceProfileInstanceUri, allottedResourceUri)
}
else {
exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found with id = " + sliceProfileInstanceId)
@@ -276,17 +324,83 @@
// Associates NSSI with Allotted Resource
try {
AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
- client.connect(nssiUri, allottedResourceUri, AAIEdgeLabel.USES)
+ client.connect(allottedResourceUri, nssiUri)
} catch(Exception e){
exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI with Allotted Resource connect call: " + e.getMessage())
}
- LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
+ LOGGER.debug("${PREFIX} Exit associateSliceProfileInstanceWithNSSI")
}
@Override
- String getPrefix() {
+ void checkAssociatedProfiles(DelegateExecution execution, List<SliceProfile> associatedProfiles, ServiceInstance nssi) {
+ LOGGER.debug("${PREFIX} Start checkAssociatedProfiles")
+
+ LOGGER.debug("associatedProfiles == null = " + (associatedProfiles == null))
+ if(associatedProfiles == null || associatedProfiles.isEmpty()) {
+ String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" )
+ boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar)
+
+ if(!isCreateSliceProfileInstance) { // New Slice Profile Instance should not be created
+ String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId())
+ LOGGER.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+
+ LOGGER.debug("${PREFIX} Exit checkAssociatedProfiles")
+ }
+
+
+ /**
+ * Calculates a final list of S-NSSAI
+ * @param execution
+ */
+ void calculateSNSSAI(DelegateExecution execution) {
+ LOGGER.debug("${getPrefix()} Start calculateSNSSAI")
+
+ def currentNSSI = execution.getVariable("currentNSSI")
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI['associatedProfiles']
+
+ String currentSNSSAI = currentNSSI['S-NSSAI']
+
+ String givenSliceProfileId = currentNSSI['sliceProfileId']
+
+ 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
+ if(associatedProfiles != null) {
+ for (SliceProfile associatedProfile : associatedProfiles) {
+ if (!associatedProfile.getProfileId().equals(givenSliceProfileId)) { // not given profile id
+ LOGGER.debug("calculateSNSSAI: associatedProfile.getSNssai()" + associatedProfile.getSNssai())
+ snssais.add(associatedProfile.getSNssai())
+ } else {
+ currentNSSI['sliceProfileS-NSSAI'] = associatedProfile
+ }
+ }
+ }
+ }
+
+ currentNSSI['S-NSSAIs'] = snssais
+
+ LOGGER.debug("${getPrefix()} Exit calculateSNSSAI")
+ }
+
+
+ private 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
index 9707dd2..13edfee 100644
--- 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
@@ -33,16 +33,23 @@
import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
+import org.onap.logging.filter.base.ONAPComponents
+import org.onap.so.bpmn.common.scripts.CatalogDbUtils
+import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
import org.onap.so.serviceinstancebeans.RequestDetails
import javax.ws.rs.core.Response
import java.time.Instant
import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertNull
import static org.junit.Assert.assertTrue
import static org.mockito.Mockito.*
@@ -54,37 +61,6 @@
@Test
- void testPreProcessRequest() {
-
- String nssiId = "5G-999"
- when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
-
- String nsiId = "5G-777"
- when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
-
- String snssai = "S-NSSAI"
- String snssaiList = "[ \"${snssai}\" ]"
- String sliceProfileId = "slice-profile-id"
- String sliceParams = "{\n" +
- "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" +
- "}"
- when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
-
- DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
- dcnssi.preProcessRequest(mockExecution)
-
- def currentNSSI = [:]
- currentNSSI.put("nssiId", nssiId)
- currentNSSI.put("nsiId", nsiId)
- currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}")
- currentNSSI.put("S-NSSAI", snssai)
- currentNSSI.put("sliceProfileId", sliceProfileId)
- Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
-
- }
-
-
- @Test
void testGetNetworkServiceInstance() {
def currentNSSI = [:]
currentNSSI.put("nssiId","5G-999")
@@ -182,69 +158,6 @@
@Test
- void testGetNSSIAssociatedProfiles() {
- def currentNSSI = [:]
- when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
-
- String nssiId = "5G-999"
- ServiceInstance nssi = new ServiceInstance()
- nssi.setServiceInstanceId(nssiId)
- currentNSSI.put("nssiId", nssiId)
-
- 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 spy = spy(DoCommonCoreNSSI.class)
- when(spy.getAAIClient()).thenReturn(client)
-
- AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
-
- AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
- Relationships rsMock = mock(Relationships.class)
- Optional<Relationships> orsMock = Optional.of(rsMock)
- List<AAIResourceUri> allottedUris = new ArrayList<>()
- AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
- allottedUris.add(allottedUri)
-
- when(client.get(nssiUri)).thenReturn(wrapperMock)
- when(wrapperMock.getRelationships()).thenReturn(orsMock)
- when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
-
- String sliceProfileInstanceId = "slice-profile-instance-id"
- ServiceInstance sliceProfileInstance = new ServiceInstance()
- sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
- sliceProfileInstance.setServiceRole("slice-profile-instance")
-
- List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>()
- AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId()))
- sliceProfileInstanceUris.add(sliceProfileInstanceUri)
-
- Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
-
- when(client.get(allottedUri)).thenReturn(wrapperMock)
- when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris)
- when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
-
-
- SliceProfiles sps = new SliceProfiles()
- sps.getSliceProfile().addAll(slProfiles)
- sliceProfileInstance.setSliceProfiles(sps)
-
- spy.getNSSIAssociatedProfiles(mockExecution)
-
- List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
- assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null)
- assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
- }
-
-
- @Test
void testInvokePUTServiceInstance() {
def currentNSSI = [:]
@@ -263,13 +176,18 @@
DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
when(spy.getAAIClient()).thenReturn(client)
- when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
+ 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")
- String authHeaderResponse = "auth-header"
+ currentNSSI.put("constituteVnf", genericVnf)
- when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
- String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
+ String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
String callPUTServiceInstanceResponse = "put"
@@ -279,13 +197,36 @@
when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
- when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
+ MsoUtils msoUtilsMock = mock(MsoUtils.class)
+ String basicAuth = "basicAuth"
+ when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+ HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+ when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+ Response responseMock = mock(Response.class)
+
+ HttpClient httpClientMock = mock(HttpClient.class)
+
+ when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+ when(httpClientMock.put(requestDetailsStr)).thenReturn(responseMock)
+
+ when(responseMock.getStatus()).thenReturn(200)
+ when(responseMock.hasEntity()).thenReturn(true)
+
+ String macroOperationId = "request-id"
+ String requestSelfLink = "request-self-link"
+ String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
+ when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.invokePUTServiceInstance(mockExecution)
+
+ Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
+ Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
}
- @Test
+ @Test(expected = Test.None.class)
void testRemoveSPAssociationWithNSSI() {
def currentNSSI = [:]
@@ -349,7 +290,7 @@
spy.removeSPAssociationWithNSSI(mockExecution)
- assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
+ // assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
}
@@ -471,6 +412,15 @@
prepareProject(cloudRegionAAIUri)
+ CatalogDbUtilsFactory catalogDbUtilsFactoryMock = mock(CatalogDbUtilsFactory.class)
+ when(spy.getCatalogDbUtilsFactory()).thenReturn(catalogDbUtilsFactoryMock)
+
+ CatalogDbUtils catalogDbUtilsMock = mock(CatalogDbUtils.class)
+ when(catalogDbUtilsFactoryMock.create()).thenReturn(catalogDbUtilsMock)
+
+ String json = "{\"serviceResources\":{\"serviceVnfs\": [{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"},\"vfModules\":[{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"}}]}]}}"
+ when(catalogDbUtilsMock.getServiceResourcesByServiceModelInvariantUuidString(mockExecution, networkServiceInstance.getModelInvariantId())).thenReturn(json)
+
String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution)
JsonUtils jsonUtil = new JsonUtils()
@@ -492,11 +442,16 @@
String nssiId = "5G-999"
String nsiId = "5G-777"
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ nssi.setModelVersionId(UUID.randomUUID().toString())
+
currentNSSI.put("nssiId", nssiId)
currentNSSI.put("nsiId", nsiId)
currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
currentNSSI.put("operationId", "operationId")
currentNSSI.put("operationType", "operationType")
+ currentNSSI.put("nssi", nssi)
DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
@@ -515,11 +470,16 @@
String nssiId = "5G-999"
String nsiId = "5G-777"
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ nssi.setModelVersionId(UUID.randomUUID().toString())
+
currentNSSI.put("nssiId", nssiId)
currentNSSI.put("nsiId", nsiId)
currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
currentNSSI.put("operationId", "operationId")
currentNSSI.put("operationType", "operationType")
+ currentNSSI.put("nssi", nssi)
DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
@@ -539,7 +499,7 @@
@Test
void testGetPUTServiceInstanceProgressInProgress() {
- executePUTServiceInstanceProgress("INPROGRESS")
+ executePUTServiceInstanceProgress("IN_PROGRESS")
Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
}
@@ -547,7 +507,7 @@
@Test
void testGetPUTServiceInstanceProgressCompleted() {
- executePUTServiceInstanceProgress("COMPLETED")
+ executePUTServiceInstanceProgress("COMPLETE")
Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed")
}
@@ -567,6 +527,21 @@
}
+ @Test
+ void testPostProcessRequest() {
+
+ def currentNSSI = [:]
+ mockExecution.setVariable("currentNSSI", currentNSSI)
+
+ DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
+ dcnssi.postProcessRequest(mockExecution)
+
+ currentNSSI = mockExecution.getVariable("currentNSSI")
+ assertNull("currentNSSI is not null", currentNSSI)
+
+ }
+
+
void executePUTServiceInstanceProgress(String state) {
def currentNSSI = [:]
@@ -575,23 +550,37 @@
String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777"
- currentNSSI.put("putServiceInstanceURL", url)
+ currentNSSI['requestSelfLink'] = url
DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
- ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
+ // ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
- when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
+ // when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
+ MsoUtils msoUtilsMock = mock(MsoUtils.class)
+ String basicAuth = "basicAuth"
+ when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+ HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+ when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
Response responseMock = mock(Response.class)
- when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
+
+ HttpClient httpClientMock = mock(HttpClient.class)
+
+
+ when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+ when(httpClientMock.get()).thenReturn(responseMock)
+// when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
when(responseMock.getStatus()).thenReturn(200)
+ when(responseMock.hasEntity()).thenReturn(true)
- String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
+ String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.getPUTServiceInstanceProgress(mockExecution)
@@ -750,4 +739,5 @@
AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(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 26b96a0..5bf4f40 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
@@ -20,17 +20,26 @@
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.v19.*
+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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
+import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.scripts.OofUtils
+import org.onap.so.client.HttpClient
+import org.onap.so.client.HttpClientFactory
+import org.onap.so.serviceinstancebeans.RequestDetails
import javax.ws.rs.core.Response
@@ -47,10 +56,44 @@
@Test
+ void testPreProcessRequest() {
+
+ String nssiId = "5G-999"
+ when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
+
+ String nsiId = "5G-777"
+ when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
+
+ String snssai = "S-NSSAI"
+ String snssaiList = "[ \"${snssai}\" ]"
+ String sliceProfileId = "slice-profile-id"
+ String modifyAction = "allocate"
+ String sliceParams = "{\n" +
+ "\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}\n" +
+ "}"
+ when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
+
+ DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
+ obj.preProcessRequest(mockExecution)
+
+ def currentNSSI = [:]
+ currentNSSI.put("nssiId", nssiId)
+ currentNSSI.put("nsiId", nsiId)
+ currentNSSI.put("sliceProfile", sliceParams)
+ currentNSSI.put("S-NSSAI", snssai)
+ currentNSSI.put("sliceProfileId", sliceProfileId)
+ Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
+
+ }
+
+
+ @Test
void testExecuteTerminateNSSIQuery() {
def currentNSSI = [:]
- currentNSSI.put("nssiId","5G-999")
+
+ String nssiId = "5G-999"
+ currentNSSI.put("nssiId", nssiId)
when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
@@ -62,6 +105,9 @@
DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
when(spy.getAAIClient()).thenReturn(client)
+ OofUtils oofUtilsMock = mock(OofUtils.class)
+ when(spy.getOofUtils()).thenReturn(oofUtilsMock)
+
when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")
String authHeaderResponse = "auth-header"
@@ -73,6 +119,14 @@
when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId("5G-999")
+ Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
+
+ when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
+
String urlString = "http://oof.onap:8088"
String httpRequest = "{\n" +
@@ -85,7 +139,16 @@
" }\n" +
"}"
- boolean terminateResponse = true
+ String requestId = "request-id"
+ String nxlId = nssi.getServiceInstanceId()
+ String nxlType = "NSSI"
+ String messageType = "cn"
+ String serviceInstanceId = nssi.getServiceInstanceId()
+
+ when(mockExecution.getVariable("msoRequestId")).thenReturn(requestId)
+ when(oofUtilsMock.buildTerminateNxiRequest(requestId, nxlId, nxlType, messageType, serviceInstanceId)).thenReturn(httpRequest)
+
+ String terminateResponse = "false"
String oofResponse = "{\n" +
" \"requestId\": \"mso-request-id\",\n" +
@@ -96,18 +159,28 @@
" \"reason\": \"\"\n" +
" }\n"
- String oofCallResponse = oofResponse
+ String apiPath = "/api/oof/terminate/nxi/v1"
- /* String oofCallResponse = "{\n" +
- " \"errorCode\": \"401\",\n" +
- " \"errorMessage\": \"Exception during the call\"\n" +
- "}" */
+ urlString = urlString + apiPath
- when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)
+ HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+ when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+ Response responseMock = mock(Response.class)
+
+ HttpClient httpClientMock = mock(HttpClient.class)
+
+ when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+ when(httpClientMock.post(httpRequest)).thenReturn(responseMock)
+
+ when(responseMock.getStatus()).thenReturn(200)
+ when(responseMock.hasEntity()).thenReturn(true)
+
+ when(responseMock.readEntity(String.class)).thenReturn(oofResponse)
spy.executeTerminateNSSIQuery(mockExecution)
- verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)
+ Mockito.verify(mockExecution,times(1)).setVariable("isTerminateNSSI", terminateResponse)
}
@@ -125,56 +198,101 @@
currentNSSI.put("networkServiceInstance", networkServiceInstance)
- when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.onap:8088")
+ 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")
+ 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")
- String authHeaderResponse = "auth-header"
+ currentNSSI.put("constituteVnf", genericVnf)
- /* String authHeaderResponse = "{\n" +
- " \"errorCode\": \"401\",\n" +
- " \"errorMessage\": \"Bad request\"\n" +
- "}" */
+ String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
- when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
+ RequestDetails requestDetails = new RequestDetails()
+ ObjectMapper mapper = new ObjectMapper()
+ String requestDetailsStr = mapper.writeValueAsString(requestDetails)
- String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
+ when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
- String callDeleteServiceOrderResponse = "deleted"
+ MsoUtils msoUtilsMock = mock(MsoUtils.class)
+ String basicAuth = "basicAuth"
+ when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
- when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)
+ HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+ when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
+ Response responseMock = mock(Response.class)
+
+ HttpClient httpClientMock = mock(HttpClient.class)
+
+ when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+ when(httpClientMock.delete()).thenReturn(responseMock)
+
+ when(responseMock.getStatus()).thenReturn(200)
+ when(responseMock.hasEntity()).thenReturn(true)
+
+ String macroOperationId = "request-id"
+ String requestSelfLink = "request-self-link"
+ String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
+ when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.deleteServiceOrder(mockExecution)
+
+ Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
+ Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
+
+ assertTrue(currentNSSI['requestSelfLink'].equals(requestSelfLink))
}
@Test
- void testCalculateSNSSAI() {
+ void testCalculateSNSSAITerminateNSSI() {
+ invokeCalculateSNSSAI("true")
+ }
+
+ @Test
+ void testCalculateSNSSAINotTerminateNSSI() {
+ invokeCalculateSNSSAI("false")
+ }
+
+ void invokeCalculateSNSSAI(String isTerminateNSSI) {
def currentNSSI = [:]
when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+ when(mockExecution.getVariable("isTerminateNSSI")).thenReturn(isTerminateNSSI)
+
String theSNSSAI = "theS-NSSAI"
currentNSSI.put("S-NSSAI", theSNSSAI)
+ String theSliceProfileId = "the-slice-profile-id"
+ currentNSSI['sliceProfileId'] = theSliceProfileId
+
List<SliceProfile> associatedProfiles = new ArrayList<>()
SliceProfile sliceProfile1 = new SliceProfile()
- sliceProfile1.setSNssai("snssai1")
+ sliceProfile1.setProfileId(theSliceProfileId)
+ sliceProfile1.setSNssai(theSNSSAI)
SliceProfile sliceProfile2 = new SliceProfile()
- sliceProfile2.setSNssai(theSNSSAI)
+ sliceProfile2.setSNssai("snssai2")
SliceProfile sliceProfile3 = new SliceProfile()
sliceProfile3.setSNssai("snssai3")
- associatedProfiles.add(sliceProfile1)
- associatedProfiles.add(sliceProfile2)
- associatedProfiles.add(sliceProfile3)
+ if(isTerminateNSSI.equals("false")) {
+ associatedProfiles.add(sliceProfile1)
+ associatedProfiles.add(sliceProfile2)
+ associatedProfiles.add(sliceProfile3)
+ }
int sizeBefore = associatedProfiles.size()
@@ -186,9 +304,14 @@
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))
+ if(isTerminateNSSI.equals("false")) {
+ 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))
+ }
+ else {
+ assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == 0))
+ }
}
@@ -212,6 +335,10 @@
ServiceInstance nssi = new ServiceInstance()
nssi.setServiceInstanceId(nssiId)
+ ServiceInstance nsi = new ServiceInstance()
+ nsi.setServiceInstanceId(nsiId)
+ nsi.setServiceRole("nsi")
+
AllottedResources allottedResources = new AllottedResources()
AllottedResource allottedResource = new AllottedResource()
allottedResource.setId(UUID.randomUUID().toString())
@@ -222,7 +349,26 @@
AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId))
- doNothing().when(client).update(nssiUri, nssi)
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
+ when(client.get(nssiUri)).thenReturn(wrapperMock)
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+
+ List<AAIResourceUri> allottedUris = new ArrayList<>()
+ AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
+ allottedUris.add(allottedUri)
+
+ when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
+
+ List<AAIResourceUri> nsiUris = new ArrayList<>()
+ nsiUris.add(nsiUri)
+
+ Optional<ServiceInstance> nsiOpt = Optional.of(nsi)
+
+ when(client.get(allottedUri)).thenReturn(wrapperMock)
+ when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(nsiUris)
+ when(client.get(ServiceInstance.class, nsiUri)).thenReturn(nsiOpt)
String globalSubscriberId = "globalSubscriberId"
String subscriptionServiceType = "subscription-service-type"
@@ -231,7 +377,7 @@
AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResource.getId()))
- doNothing().when(client).disconnect(nsiUri, allottedResourceUri)
+ doNothing().when(client).disconnect(nssiUri, nsiUri)
spy.removeNSSIAssociationWithNSI(mockExecution)
@@ -270,7 +416,7 @@
@Test
void testDeleteServiceOrderProgressInProgress() {
- executeDeleteServiceOrderProgress("INPROGRESS")
+ executeDeleteServiceOrderProgress("IN_PROGRESS")
Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing")
}
@@ -278,7 +424,7 @@
@Test
void testDeleteServiceOrderProgressCompleted() {
- executeDeleteServiceOrderProgress("COMPLETED")
+ executeDeleteServiceOrderProgress("COMPLETE")
Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed")
}
@@ -290,23 +436,37 @@
String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777"
- currentNSSI.put("deleteServiceOrderURL", url)
+ currentNSSI['requestSelfLink'] = url
DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
- ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
+ /*ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
- when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
+ when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) */
+ MsoUtils msoUtilsMock = mock(MsoUtils.class)
+ String basicAuth = "basicAuth"
+ when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
+
+ HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
+ when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
Response responseMock = mock(Response.class)
- when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
+
+ HttpClient httpClientMock = mock(HttpClient.class)
+
+
+ when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
+
+ when(httpClientMock.get()).thenReturn(responseMock)
+// when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
when(responseMock.getStatus()).thenReturn(200)
+ when(responseMock.hasEntity()).thenReturn(true)
- String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
+ String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
when(responseMock.readEntity(String.class)).thenReturn(entity)
spy.getDeleteServiceOrderProgress(mockExecution)
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
index ac6f897..7293a23 100644
--- 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
@@ -29,11 +29,14 @@
import org.onap.aai.domain.yang.v19.SliceProfile
import org.onap.aai.domain.yang.v19.SliceProfiles
import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
+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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
import org.onap.so.bpmn.common.scripts.MsoGroovyTest
+import org.springframework.data.domain.Slice
import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertTrue
@@ -48,6 +51,40 @@
@Test
+ void testPreProcessRequest() {
+
+ String nssiId = "5G-999"
+ when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
+
+ String nsiId = "5G-777"
+ when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
+
+ String snssai = "S-NSSAI"
+ String snssaiList = "[ \"${snssai}\" ]"
+ String sliceProfileId = "slice-profile-id"
+ String modifyAction = "allocate"
+ String sliceParams = "{\n" +
+ "\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}\n" +
+ ",\"modifyAction\":\"${modifyAction}\"\n" +
+ "}"
+ when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
+
+ DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
+ obj.preProcessRequest(mockExecution)
+
+ def currentNSSI = [:]
+ currentNSSI.put("nssiId", nssiId)
+ currentNSSI.put("nsiId", nsiId)
+ currentNSSI.put("sliceProfile", sliceParams)
+ currentNSSI.put("S-NSSAI", snssai)
+ currentNSSI.put("sliceProfileId", sliceProfileId)
+
+ Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
+
+ }
+
+
+ @Test
void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
def currentNSSI = [:]
when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
@@ -58,31 +95,37 @@
currentNSSI.put("S-NSSAI", theSNSSAI)
+ String sliceProfileId = "the-slice-profile-id"
+ currentNSSI['sliceProfileId'] = sliceProfileId
+
List<SliceProfile> associatedProfiles = new ArrayList<>()
SliceProfile sliceProfile1 = new SliceProfile()
- sliceProfile1.setSNssai("snssai1")
+ sliceProfile1.setProfileId(sliceProfileId)
+ sliceProfile1.setSNssai(theSNSSAI)
SliceProfile sliceProfile2 = new SliceProfile()
+ sliceProfile2.setProfileId("sp-2")
sliceProfile2.setSNssai(theSNSSAI)
SliceProfile sliceProfile3 = new SliceProfile()
+ sliceProfile3.setProfileId("sp-3")
sliceProfile3.setSNssai("snssai2")
associatedProfiles.add(sliceProfile1)
associatedProfiles.add(sliceProfile2)
associatedProfiles.add(sliceProfile3)
- int sizeBefore = associatedProfiles.size()
-
currentNSSI.put("associatedProfiles", associatedProfiles)
+ when(mockExecution.getVariable("isCreateSliceProfileInstance" )).thenReturn(false)
+
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)))
+ assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (associatedProfiles.size() - 1)))
assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
}
@@ -233,4 +276,114 @@
}
+
+ @Test
+ void testGetNSSIAssociatedProfilesCreateSLiceProfileEmptySLiceProfiles() {
+ invokeGetNSSIAssociatedProfiles("true", true)
+ }
+
+ @Test
+ void testGetNSSIAssociatedProfilesCreateSLiceProfileNonEmptySliceProfiles() {
+ invokeGetNSSIAssociatedProfiles("true", false)
+ }
+
+ @Test
+ void testGetNSSIAssociatedProfilesDeleteSLiceProfile() {
+ invokeGetNSSIAssociatedProfiles("false", false)
+ }
+
+ void invokeGetNSSIAssociatedProfiles(String isCreateSliceProfileInstance, boolean isEmptySliceProfiles) {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String globalSubscriberId = "5GCustomer"
+ String subscriptionServiceType = "5G"
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
+ when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
+
+ when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn(isCreateSliceProfileInstance)
+
+ String nssiId = "5G-999"
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ currentNSSI.put("nssiId", nssiId)
+
+ String theSLiceProfileId = "slice-profile-id"
+ currentNSSI.put("sliceProfileId", theSLiceProfileId)
+
+ SliceProfiles sliceProfiles = new SliceProfiles()
+
+ List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
+
+ if(!isEmptySliceProfiles) {
+ SliceProfile sp1 = new SliceProfile()
+ sp1.setProfileId(theSLiceProfileId)
+ slProfiles.add(sp1)
+ slProfiles.add(new SliceProfile())
+ }
+
+ //nssi.setSliceProfiles(sliceProfiles)
+ currentNSSI.put("nssi", nssi)
+
+ DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
+ when(spy.getAAIClient()).thenReturn(client)
+
+ AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
+
+ AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
+ Relationships rsMock = mock(Relationships.class)
+ Optional<Relationships> orsMock = Optional.of(rsMock)
+ List<AAIResourceUri> allottedUris = new ArrayList<>()
+ AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
+ allottedUris.add(allottedUri)
+
+ when(client.get(nssiUri)).thenReturn(wrapperMock)
+ when(wrapperMock.getRelationships()).thenReturn(orsMock)
+ when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
+
+ String sliceProfileInstanceId = "slice-profile-instance-id"
+ ServiceInstance sliceProfileInstance = new ServiceInstance()
+ sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
+ sliceProfileInstance.setServiceRole("slice-profile-instance")
+
+ List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>()
+ AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId()))
+ sliceProfileInstanceUris.add(sliceProfileInstanceUri)
+
+ Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
+
+ when(client.get(allottedUri)).thenReturn(wrapperMock)
+ when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris)
+ when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
+
+
+ SliceProfiles sps = new SliceProfiles()
+ sps.getSliceProfile().addAll(slProfiles)
+ sliceProfileInstance.setSliceProfiles(sps)
+
+ Optional<SliceProfiles> sliceProfilesOpt = Optional.of(sps)
+
+ org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
+ AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
+
+ def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
+ when(client.exists(sliceProfilesUri)).thenReturn(true)
+
+ when(client.get(sliceProfilesUri)).thenReturn(wrapperMock)
+
+ when(wrapperMock.asBean(SliceProfiles.class)).thenReturn(sliceProfilesOpt)
+
+ spy.getNSSIAssociatedProfiles(mockExecution)
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
+ int expectedSize = sps.getSliceProfile().size()
+
+ if(!isEmptySliceProfiles) {
+ assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null)
+ }
+
+ assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == expectedSize))
+ }
+
+
}
diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn
index b55b7c4..bfc45f2 100644
--- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn
+++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeallocateCoreNSSI.bpmn
Binary files differ
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 e0c0b9a..80e154c 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
Binary files differ