aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org
diff options
context:
space:
mode:
authorhetengjiao <hetengjiao@chinamobile.com>2021-01-18 09:16:38 +0800
committerhetengjiao <hetengjiao@chinamobile.com>2021-01-18 16:26:28 +0800
commitbcfee1b5b7bd91f21a6b7b2fd3be9484b10b542c (patch)
treee1e6087f90db1421a4fc1e1a695e98fdb2eda61c /bpmn/so-bpmn-infrastructure-common/src/main/groovy/org
parent5e9676e8319a1867976ce2a09c607681c3445887 (diff)
update nsmf workflow of active and deactive nssi
Issue-ID: SO-2963 Signed-off-by: hetengjiao <hetengjiao@chinamobile.com> Change-Id: Ic144713f9cf55ed8db679bd7c57052fcea2aadf9
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/groovy/org')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy648
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateSliceService.groovy273
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoSendCommandToNSSMF.groovy423
3 files changed, 565 insertions, 779 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy
index 36d579c7ab..5c030a9f86 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceService.groovy
@@ -20,9 +20,7 @@
package org.onap.so.bpmn.infrastructure.scripts
-import static org.apache.commons.lang3.StringUtils.isBlank
-import java.lang.reflect.Type
-import javax.ws.rs.NotFoundException
+
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.aai.domain.yang.*
@@ -32,9 +30,12 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri
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.ErrorCode
-import org.onap.so.beans.nsmf.NSSI
+import org.onap.so.beans.nsmf.CustomerInfo
+import org.onap.so.beans.nsmf.NetworkType
+import org.onap.so.beans.nsmf.NssInstance
+import org.onap.so.beans.nsmf.OperationType
+import org.onap.so.beans.nsmf.OrchestrationStatusEnum
import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
@@ -46,8 +47,11 @@ import org.onap.so.logger.LoggingAnchor
import org.onap.so.logger.MessageEnum
import org.slf4j.Logger
import org.slf4j.LoggerFactory
-import com.google.gson.Gson
-import com.google.gson.reflect.TypeToken
+
+import javax.ws.rs.NotFoundException
+import java.util.function.Consumer
+
+import static org.apache.commons.lang3.StringUtils.isBlank
/**
* This groovy class supports the <class>ActivateSliceService.bpmn</class> process.
@@ -66,6 +70,8 @@ class ActivateSliceService extends AbstractServiceTaskProcessor {
RequestDBUtil requestDBUtil = new RequestDBUtil()
+ AAIResourcesClient client = getAAIClient()
+
private static final Logger logger = LoggerFactory.getLogger(ActivateSliceService.class)
void preProcessRequest(DelegateExecution execution) {
@@ -75,7 +81,7 @@ class ActivateSliceService extends AbstractServiceTaskProcessor {
try {
// check for incoming json message/input
- String siRequest = execution.getVariable("bpmnRequest")
+ String siRequest = Objects.requireNonNull(execution.getVariable("bpmnRequest"))
logger.debug(siRequest)
String requestId = execution.getVariable("mso-request-id")
@@ -109,13 +115,20 @@ class ActivateSliceService extends AbstractServiceTaskProcessor {
} else {
execution.setVariable("subscriptionServiceType", subscriptionServiceType)
}
- String operationId = jsonUtil.getJsonValue(siRequest, "operationId")
+ String operationId = Objects.requireNonNull(jsonUtil.getJsonValue(siRequest, "operationId"))
execution.setVariable("operationId", operationId)
- String operationType = execution.getVariable("operationType")
- execution.setVariable("operationType", operationType.toUpperCase())
-
+ String operationType = Objects.requireNonNull(execution.getVariable("operationType"))
logger.info("operationType is " + execution.getVariable("operationType") )
+
+ CustomerInfo customerInfo = CustomerInfo.builder().operationId(operationId)
+ .operationType(Objects.requireNonNull(OperationType.getOperationType(operationType)))
+ .globalSubscriberId(globalSubscriberId).serviceInstanceId(serviceInstanceId)
+ .subscriptionServiceType(subscriptionServiceType)
+ .build()
+
+ execution.setVariable("customerInfo", customerInfo)
+
} catch (BpmnError e) {
throw e
} catch (Exception ex) {
@@ -126,14 +139,58 @@ class ActivateSliceService extends AbstractServiceTaskProcessor {
logger.debug(Prefix + "preProcessRequest Exit")
}
+ /**
+ * Init the service Operation Status
+ */
+ def prepareInitServiceOperationStatus = { DelegateExecution execution ->
+ logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
+ try {
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String serviceId = customerInfo.getServiceInstanceId()
+ String operationId = customerInfo.getOperationId()
+ String operationType = customerInfo.getOperationType().getType()
+ String userId = customerInfo.getGlobalSubscriberId()
+ String result = "processing"
+ String progress = "0"
+ String reason = ""
+ String operationContent = "Prepare service activation"
+
+ execution.setVariable("e2eserviceInstanceId", serviceId)
+ //execution.setVariable("operationType", operationType)
+
+ OperationStatus initStatus = new OperationStatus()
+ initStatus.setServiceId(serviceId)
+ initStatus.setOperationId(operationId)
+ initStatus.setOperation(operationType)
+ initStatus.setUserId(userId)
+ initStatus.setResult(result)
+ initStatus.setProgress(progress)
+ initStatus.setReason(reason)
+ initStatus.setOperationContent(operationContent)
+
+ requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
+
+ } catch (Exception e) {
+ logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
+ "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
+ ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
+ execution.setVariable("CVFMI_ErrorResponse",
+ "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
+ }
+ logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
+ }
+
def sendSyncResponse = { DelegateExecution execution ->
logger.debug(Prefix + "sendSyncResponse Start")
try {
- String operationId = execution.getVariable("operationId")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String operationId = customerInfo.getOperationId()
+
// RESTResponse for API Handler (APIH) Reply Task
String Activate5GsliceServiceRestRequest = """{"operationId":"${operationId}"}""".trim()
logger.debug(" sendSyncResponse to APIH:" + "\n" + Activate5GsliceServiceRestRequest)
+
sendWorkflowResponse(execution, 202, Activate5GsliceServiceRestRequest)
execution.setVariable("sentSyncResponse", true)
} catch (Exception ex) {
@@ -171,410 +228,289 @@ class ActivateSliceService extends AbstractServiceTaskProcessor {
logger.debug(Prefix + "sendSyncError Exit")
}
+ def checkAAIOrchStatusOfE2ESlice = { DelegateExecution execution ->
+ logger.debug(Prefix + "CheckAAIOrchStatus Start")
+ execution.setVariable("isContinue", "false")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String msg
+ String serviceInstanceId = customerInfo.serviceInstanceId
+ String globalSubscriberId = customerInfo.globalSubscriberId
+ String subscriptionServiceType = customerInfo.subscriptionServiceType
- def prepareCompletionRequest = { DelegateExecution execution ->
- logger.debug(Prefix + "prepareCompletionRequest Start")
- String serviceId = execution.getVariable("serviceInstanceId")
- String operationId = execution.getVariable("operationId")
- String userId = execution.getVariable("globalSubscriberId")
- //String result = execution.getVariable("result")
- String result = "finished"
- String progress = "100"
- String reason = ""
- String operationContent = execution.getVariable("operationContent")
- String operationType = execution.getVariable("operationType")
-
- OperationStatus initStatus = new OperationStatus()
- initStatus.setServiceId(serviceId)
- initStatus.setOperationId(operationId)
- initStatus.setOperation(operationType)
- initStatus.setUserId(userId)
- initStatus.setResult(result)
- initStatus.setProgress(progress)
- initStatus.setReason(reason)
- initStatus.setOperationContent(operationContent)
-
- requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
-
- logger.debug(Prefix + "prepareCompletionRequest Exit")
- }
-
+ logger.debug("serviceInstanceId: " + serviceInstanceId)
- /**
- * Init the service Operation Status
- */
- def prepareInitServiceOperationStatus = { DelegateExecution execution ->
- logger.debug(Prefix + "prepareActivateServiceOperationStatus Start")
+ //check the e2e slice status
try {
- String serviceId = execution.getVariable("serviceInstanceId")
- String operationId = execution.getVariable("operationId")
- String operationType = execution.getVariable("operationType")
- String userId = execution.getVariable("globalSubscriberId")
- String result = "processing"
- String progress = "0"
- String reason = ""
- String operationContent = "Prepare service activation"
-
- execution.setVariable("e2eserviceInstanceId", serviceId)
- execution.setVariable("operationType", operationType)
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId)
+ .serviceSubscription(subscriptionServiceType)
+ .serviceInstance(serviceInstanceId))
- OperationStatus initStatus = new OperationStatus()
- initStatus.setServiceId(serviceId)
- initStatus.setOperationId(operationId)
- initStatus.setOperation(operationType)
- initStatus.setUserId(userId)
- initStatus.setResult(result)
- initStatus.setProgress(progress)
- initStatus.setReason(reason)
- initStatus.setOperationContent(operationContent)
+ AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
+ Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
+ ServiceInstance serviceInstance = si.orElseThrow()
- requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
+ boolean isContinue = handleOperation(customerInfo, serviceInstance)
+ execution.setVariable("isContinue", isContinue)
+ customerInfo.setSnssai(serviceInstance.getEnvironmentContext())
- } catch (Exception e) {
- logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
- "Exception Occured Processing prepareInitServiceOperationStatus.", "BPMN",
- ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
- execution.setVariable("CVFMI_ErrorResponse",
- "Error Occurred during prepareInitServiceOperationStatus Method:\n" + e.getMessage())
+ execution.setVariable("customerInfo", customerInfo)
+ execution.setVariable("ssInstance", serviceInstance)
+ execution.setVariable("ssiUri", uri)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ execution.setVariable("isContinue", "false")
+ msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus, " +
+ "Requested e2eservice does not exist: " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- logger.debug(Prefix + "prepareInitServiceOperationStatus Exit")
- }
+ logger.debug(Prefix + "CheckAAIOrchStatus Exit")
+ }
- private getSNSSIStatusByNsi = { DelegateExecution execution, String NSIServiceId ->
+ static boolean handleOperation(CustomerInfo customerInfo, ServiceInstance serviceInstance) {
+ OperationType operationType = customerInfo.operationType
+ OrchestrationStatusEnum status = OrchestrationStatusEnum.getStatus(Objects.requireNonNull(
+ serviceInstance.getOrchestrationStatus()))
- logger.debug(Prefix + "getSNSSIStatusByNsi Start")
- String globalSubscriberId = execution.getVariable("globalSubscriberId")
- String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
+ return ((OrchestrationStatusEnum.ACTIVATED == status && OperationType.DEACTIVATE == operationType)
+ || (OrchestrationStatusEnum.DEACTIVATED == status && OperationType.ACTIVATE == operationType))
+ }
- AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIServiceId))
- if (!client.exists(uri)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
- Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
- if (si.isPresent()) {
+ void checkAAIOrchStatusOfAllocates(DelegateExecution execution) {
+ logger.debug(Prefix + "CheckAAIOrchStatus Start")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String msg
+ String serviceInstanceId = customerInfo.serviceInstanceId
+ String globalSubscriberId = customerInfo.globalSubscriberId
+ String subscriptionServiceType = customerInfo.subscriptionServiceType
- List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
- for (Relationship relationship : relatedList) {
- String relatedTo = relationship.getRelatedTo()
- if (relatedTo.toLowerCase() == "allotted-resource") {
- //get snssi from allotted resource in list by nsi
- List<String> SNSSIList = new ArrayList<>()
- List<RelationshipData> relationshipDataList = relationship.getRelationshipData()
- for (RelationshipData relationshipData : relationshipDataList) {
- if (relationshipData.getRelationshipKey() == "service-instance.service-instance-id") {
- SNSSIList.add(relationshipData.getRelationshipValue())
- }
- }
- for (String snssi : SNSSIList) {
- AAIResourcesClient client01 = new AAIResourcesClient()
- AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(snssi))
- if (!client.exists(uri01)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
- "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
- Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
- if (nssiSi.isPresent()) {
- return nssiSi.get().getOrchestrationStatus() == "deactivated"
- }
- }
+ logger.debug("serviceInstanceId: " + serviceInstanceId)
- }
- }
+ //check the NSI is exist or the status of NSI is active or de-active
+ try {
- }
- logger.debug(Prefix + "getSNSSIStatusByNsi Exit")
- }
+ //get the allotted-resources by e2e slice id
+ AAIPluralResourceUri uriAllotted = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId)
+ .serviceSubscription(subscriptionServiceType)
+ .serviceInstance(serviceInstanceId)
+ .allottedResources()
+ )
+ AAIResultWrapper wrapperAllotted = client.get(uriAllotted, NotFoundException.class)
+ Optional<AllottedResources> allAllotted = wrapperAllotted.asBean(AllottedResources.class)
- def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
- logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
- logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
- String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
- String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
-
- String globalCustId = execution.getVariable("globalSubscriberId")
- String serviceType = execution.getVariable("serviceType")
- String operationType = execution.getVariable("operationType")
-
- String nssiMap = execution.getVariable("nssiMap")
- Type type = new TypeToken<HashMap<String, NSSI>>() {}.getType()
- Map<String, NSSI> activateNssiMap = new Gson().fromJson(nssiMap, type)
- //update tn/cn/an nssi
- for (Map.Entry<String, NSSI> entry : activateNssiMap.entrySet()) {
- NSSI nssi = entry.getValue()
- String nssiid = nssi.getNssiId()
- updateStratus(execution, globalCustId, serviceType, nssiid, operationType)
- }
- if (operationType.equalsIgnoreCase("activation")) {
- //update the s-nssai
- updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
- //update the nsi
- updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
- } else {
- //update the s-nssai
- updateStratus(execution, globalCustId, serviceType, e2eserviceInstanceId, operationType)
- boolean flag = getSNSSIStatusByNsi(execution, NSIserviceInstanceId)
- if (flag) {
- //update the nsi
- updateStratus(execution, globalCustId, serviceType, NSIserviceInstanceId, operationType)
- } else {
- logger.error("Service's status update failed")
- String msg = "Service's status update failed"
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ AllottedResources allottedResources = allAllotted.get()
+ List<AllottedResource> AllottedResourceList = allottedResources.getAllottedResource()
+ if (AllottedResourceList.isEmpty()) {
+ execution.setVariable("isContinue", "false")
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
+ "allottedResources in aai is empty")
}
+ AllottedResource ar = AllottedResourceList.first()
+ String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
+ String nsiServiceId = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
+ customerInfo.setNsiId(nsiServiceId)
+ execution.setVariable("customerInfo", customerInfo)
+ logger.info("the NSI ID is:" + nsiServiceId)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ logger.info("NSI Service doesnt exist")
+ execution.setVariable("isContinue", "false")
+ msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
+ logger.debug(Prefix + "CheckAAIOrchStatus Exit")
}
+ void checkAAIOrchStatusOfNSI(DelegateExecution execution) {
- def updateStratus = { DelegateExecution execution, String globalCustId,
- String serviceType, String serviceId, String operationType ->
- logger.debug(Prefix + "updateStratus Start")
+ logger.debug(Prefix + "CheckAAIOrchStatus Start")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String msg = ""
+ String globalSubscriberId = customerInfo.globalSubscriberId
+ String subscriptionServiceType = customerInfo.subscriptionServiceType
+ String nsiServiceId = customerInfo.getNsiId()
+
+ logger.debug("network slice instance id: " + nsiServiceId)
+ //check the NSI is exist or the status of NSI is active or de-active
try {
- AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalCustId).serviceSubscription(serviceType).serviceInstance(serviceId))
- if (!client.exists(uri)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
- }
+ //Query nsi by nsi id
+
+ //get the NSI id by e2e slice id
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId)
+ .serviceSubscription(subscriptionServiceType)
+ .serviceInstance(nsiServiceId))
+
AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
- if (si.isPresent()) {
- if (operationType.equalsIgnoreCase("activation")) {
- if (si.get().getOrchestrationStatus() == "deactivated") {
- si.get().setOrchestrationStatus("activated")
- client.update(uri, si.get())
- }
- } else {
- if (si.get().getOrchestrationStatus() == "activated") {
- si.get().setOrchestrationStatus("deactivated")
- client.update(uri, si.get())
- }
- }
-
+ ServiceInstance nsInstance = si.get()
+ if (!"nsi".equalsIgnoreCase(nsInstance.getServiceRole().toLowerCase())) {
+ logger.info("the service id" + nsInstance.getServiceInstanceId() + "is " +
+ nsInstance.getServiceRole())
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- } catch (Exception e) {
- logger.info("Service is already in active state")
- String msg = "Service is already in active state, " + e.getMessage()
+ execution.setVariable("nsInstance", nsInstance)
+ execution.setVariable("nsiUri", uri)
+ boolean isContinue = handleOperation(customerInfo, nsInstance)
+ execution.setVariable("isContinue", isContinue)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ logger.info("NSI Service doesnt exist")
+ execution.setVariable("isActivate", "false")
+ execution.setVariable("isContinue", "false")
+ msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
+ logger.info(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
-
- logger.debug(Prefix + "updateStratus Exit")
+ logger.debug(Prefix + "CheckAAIOrchStatus Exit")
}
-
- def prepareActivation = { DelegateExecution execution ->
+ void prepareActivation(DelegateExecution execution) {
logger.debug(Prefix + "prepareActivation Start")
- logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
- String NSIserviceInstanceId = execution.getVariable("NSIserviceid")
-
- String globalSubscriberId = execution.getVariable("globalSubscriberId")
- String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
-
- Map<String, NSSI> nssiMap = new HashMap<>()
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String globalSubscriberId = customerInfo.globalSubscriberId
+ String subscriptionServiceType = customerInfo.subscriptionServiceType
- List<String> activationSequence = new ArrayList<>(Arrays.asList("an", "tn", "cn"))
-
- def activationCount = activationSequence.size()
-
- execution.setVariable("activationIndex", "0")
+ logger.debug(" ***** prepare active NSI/AN/CN/TN slice ***** ")
- execution.setVariable("activationCount", activationCount)
+ Queue<NssInstance> nssInstances = new LinkedList<>()
+ ServiceInstance nsInstance =
+ execution.getVariable("nsInstance") as ServiceInstance
try {
//get the TN NSSI id by NSI id, active NSSI TN slicing
- AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(NSIserviceInstanceId))
- if (!client.exists(uri)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
- Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
- if (si.isPresent()) {
-
- List<Relationship> relatedList = si.get().getRelationshipList().getRelationship()
- for (Relationship relationship : relatedList) {
- String relatedTo = relationship.getRelatedTo()
- if (relatedTo.toLowerCase() == "service-instance") {
- String relatioshipurl = relationship.getRelatedLink()
- String nssiserviceid =
- relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1, relatioshipurl.length())
-
- AAIResourcesClient client01 = new AAIResourcesClient()
- AAIResourceUri uri01 = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiserviceid))
- if (!client.exists(uri01)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
- "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper01 = client01.get(uri01, NotFoundException.class)
- Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
- if (nssiSi.isPresent()) {
- if (nssiSi.get().getEnvironmentContext().toLowerCase().contains("an")
- || nssiSi.get().getEnvironmentContext().toLowerCase().contains("cn")
- || nssiSi.get().getEnvironmentContext().toLowerCase().contains("tn")) {
- nssiMap.put(nssiSi.get().getEnvironmentContext(),
- new NSSI(nssiSi.get().getServiceInstanceId(),
- nssiSi.get().getModelInvariantId(), nssiSi.get().getModelVersionId()))
- }
- }
- }
+ List<Relationship> relatedList = nsInstance.getRelationshipList().getRelationship()
+ for (Relationship relationship : relatedList) {
+ String relatedTo = relationship.getRelatedTo()
+ if (!"service-instance".equalsIgnoreCase(relatedTo)) {
+ continue
}
-
-
+ String relatioshipurl = relationship.getRelatedLink()
+ String nssiserviceid = relatioshipurl.substring(relatioshipurl.lastIndexOf("/") + 1,
+ relatioshipurl.length())
+
+ AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(globalSubscriberId)
+ .serviceSubscription(subscriptionServiceType)
+ .serviceInstance(nssiserviceid))
+ if (!client.exists(nsiUri)) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
+ "Service Instance was not found in aai")
+ }
+ AAIResultWrapper wrapper01 = client.get(nsiUri, NotFoundException.class)
+ Optional<ServiceInstance> nssiSi = wrapper01.asBean(ServiceInstance.class)
+ nssiSi.ifPresent(new Consumer<ServiceInstance>() {
+ @Override
+ void accept(ServiceInstance instance) {
+ String env = Objects.requireNonNull(instance.getEnvironmentContext())
+ NssInstance nssi = NssInstance.builder().nssiId(instance.getServiceInstanceId())
+ .modelInvariantId(instance.getModelInvariantId())
+ .modelVersionId(instance.getModelVersionId())
+ .networkType(NetworkType.fromString(env))
+ .operationType(customerInfo.operationType)
+ .snssai(customerInfo.snssai)
+ .serviceType(instance.getServiceType())
+ .build()
+ nssInstances.offer(nssi)
+ }
+ })
}
+ execution.setVariable("nssInstances", nssInstances)
+ execution.setVariable("nssInstanceInfos", nssInstances)
} catch (Exception e) {
String msg = "Requested service does not exist:" + e.getMessage()
logger.info("Service doesnt exist")
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- if (nssiMap.size() > 0) {
- execution.setVariable("isNSSIActivate", "true")
- String nssiMap01 = mapToJsonStr(nssiMap)
- execution.setVariable("nssiMap", nssiMap01)
- execution.setVariable("operation_type", "activate")
- execution.setVariable("activationCount", nssiMap.size())
- logger.info("the nssiMap01 is :" + nssiMap01)
- } else {
- execution.setVariable("isNSSIActivate", "false")
- }
-
logger.debug(Prefix + "prepareActivation Exit")
}
-
- private mapToJsonStr = { HashMap<String, NSSI> stringNSSIHashMap ->
- HashMap<String, NSSI> map = new HashMap<String, NSSI>()
- for (Map.Entry<String, NSSI> child : stringNSSIHashMap.entrySet()) {
- map.put(child.getKey(), child.getValue())
+ void isOperationFinished(DelegateExecution execution) {
+ Queue<NssInstance> nssInstances = execution.getVariable("nssInstances") as Queue<NssInstance>
+ if (nssInstances.isEmpty()) {
+ execution.setVariable("isOperationFinished", "true")
}
- return new Gson().toJson(map)
}
+ def updateStatusSNSSAIandNSIandNSSI = { DelegateExecution execution ->
+ logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Start")
+ logger.debug(" ***** update SNSSAI NSI NSSI slicing ***** ")
+ ServiceInstance ssInstance = execution.getVariable("ssInstance") as ServiceInstance
+ AAIResourceUri ssUri = execution.getVariable("ssiUri") as AAIResourceUri
- def checkAAIOrchStatusofslice = { DelegateExecution execution ->
- logger.debug(Prefix + "CheckAAIOrchStatus Start")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ OperationType operationType = customerInfo.operationType
- String msg = ""
- String serviceInstanceId = execution.getVariable("serviceInstanceId")
- String globalSubscriberId = execution.getVariable("globalSubscriberId")
- String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
- String operationType = execution.getVariable("operationType")
+ updateStratus(execution, ssInstance, operationType, ssUri)
+ //update the nsi
+ ServiceInstance nsInstance = execution.getVariable("nsInstance") as ServiceInstance
+ AAIResourceUri nsiUri = execution.getVariable("nsiUri") as AAIResourceUri
- logger.debug("serviceInstanceId: " + serviceInstanceId)
+ updateStratus(execution, nsInstance, operationType, nsiUri)
- //check the e2e slice status
- try {
- try {
- AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId))
- if (!client.exists(uri)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
- "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
- Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
- if (si.isPresent()) {
- if (si.get().getOrchestrationStatus().toLowerCase() == "activated" &&
- operationType.equalsIgnoreCase("deactivation")) {
- logger.info("Service is in active state")
- execution.setVariable("e2eservicestatus", "activated")
- execution.setVariable("isContinue", "true")
- String snssai = si.get().getEnvironmentContext()
- execution.setVariable("snssai", snssai)
- } else if (si.get().getOrchestrationStatus().toLowerCase() == "deactivated" &&
- operationType.equalsIgnoreCase("activation")) {
- logger.info("Service is in de-activated state")
- execution.setVariable("e2eservicestatus", "deactivated")
- execution.setVariable("isContinue", "true")
- String snssai = si.get().getEnvironmentContext()
- execution.setVariable("snssai", snssai)
- } else {
- execution.setVariable("isContinue", "false")
- }
- }
- } catch (Exception e) {
- msg = "Requested e2eservice does not exist"
- logger.info("e2eservice doesnt exist")
- execution.setVariable("isContinue", "false")
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
- }
- //check the NSI is exist or the status of NSI is active or de-active
- try {
+ logger.debug(Prefix + "updateStatusSNSSAIandNSIandNSSI Exit")
+ }
- //get the allotted-resources by e2e slice id
- AAIResourcesClient client_allotted = new AAIResourcesClient()
- AAIPluralResourceUri uri_allotted = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(serviceInstanceId).allottedResources()
- )
- if (!client_allotted.exists(uri_allotted)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper_allotted = client_allotted.get(uri_allotted, NotFoundException.class)
- Optional<AllottedResources> all_allotted = wrapper_allotted.asBean(AllottedResources.class)
-
- if (all_allotted.isPresent() && all_allotted.get().getAllottedResource()) {
- List<AllottedResource> AllottedResourceList = all_allotted.get().getAllottedResource()
- AllottedResource ar = AllottedResourceList.first()
- String relatedLink = ar.getRelationshipList().getRelationship().first().getRelatedLink()
- String nsiserviceid = relatedLink.substring(relatedLink.lastIndexOf("/") + 1, relatedLink.length())
- execution.setVariable("NSIserviceid", nsiserviceid)
- logger.info("the NSI ID is:" + nsiserviceid)
-
- //Query nsi by nsi id
- try {
- //get the NSI id by e2e slice id
- AAIResourcesClient client = new AAIResourcesClient()
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nsiserviceid))
- if (!client.exists(uri)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500,
- "Service Instance was not found in aai")
- }
- AAIResultWrapper wrapper = client.get(uri, NotFoundException.class)
- Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
-
- if (si.isPresent()) {
- if (si.get().getServiceRole().toLowerCase() == "nsi") {
- if (si.get().getOrchestrationStatus() == "activated") {
- logger.info("NSI services is in activated state")
- execution.setVariable("NSIservicestatus", "activated")
- } else {
- logger.info("NSI services is in deactivated state")
- execution.setVariable("NSIservicestatus", "deactivated")
- }
- } else {
- logger.info("the service id" + si.get().getServiceInstanceId() + "is " +
- si.get().getServiceRole())
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
- }
- }
- } catch (Exception e) {
- msg = "Requested NSI service does not exist:" + e.getMessage()
- logger.info("NSI service doesnt exist")
- execution.setVariable("isContinue", "false")
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
- }
- }
- } catch (Exception e) {
- msg = "Requested service does not exist: " + e.getMessage()
- logger.info("NSI Service doesnt exist")
- execution.setVariable("isActivate", "false")
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ void updateStratus(DelegateExecution execution, ServiceInstance serviceInstance,
+ OperationType operationType, AAIResourceUri uri) {
+
+ logger.debug(Prefix + "updateStratus Start")
+
+ try {
+ serviceInstance.setOrchestrationStatus()
+ if (OperationType.ACTIVATE == operationType) {
+ serviceInstance.setOrchestrationStatus(OrchestrationStatusEnum.ACTIVATED.getValue())
+ } else {
+ serviceInstance.setOrchestrationStatus(OrchestrationStatusEnum.DEACTIVATED.getValue())
}
- } catch (BpmnError e) {
- throw e
- } catch (Exception ex) {
- msg = "Exception in org.onap.so.bpmn.common.scripts.CompleteMsoProcess.CheckAAIOrchStatus " + ex.getMessage()
- logger.info(msg)
+ client.update(uri, serviceInstance)
+ } catch (Exception e) {
+ logger.info("Service is already in active state")
+ String msg = "Service is already in active state, " + e.getMessage()
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
}
- logger.debug(Prefix + "CheckAAIOrchStatus Exit")
+ logger.debug(Prefix + "updateStratus Exit")
}
+ def prepareCompletionRequest = { DelegateExecution execution ->
+ logger.debug(Prefix + "prepareCompletionRequest Start")
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ String serviceId = customerInfo.getServiceInstanceId()
+ String operationId = customerInfo.getOperationId()
+ String userId = customerInfo.getGlobalSubscriberId()
+
+ String result = "finished"
+ String progress = "100"
+ String reason = ""
+ String operationContent = "action finished success"
+ String operationType = customerInfo.operationType.getType()
+
+ OperationStatus initStatus = new OperationStatus()
+ initStatus.setServiceId(serviceId)
+ initStatus.setOperationId(operationId)
+ initStatus.setOperation(operationType)
+ initStatus.setUserId(userId)
+ initStatus.setResult(result)
+ initStatus.setProgress(progress)
+ initStatus.setReason(reason)
+ initStatus.setOperationContent(operationContent)
+
+ requestDBUtil.prepareUpdateOperationStatus(execution, initStatus)
+
+ logger.debug(Prefix + "prepareCompletionRequest Exit")
+ }
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateSliceService.groovy
new file mode 100644
index 0000000000..3d9f67653b
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateSliceService.groovy
@@ -0,0 +1,273 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.gson.Gson
+import com.google.gson.reflect.TypeToken
+import org.apache.commons.lang3.StringUtils
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.logging.filter.base.ErrorCode
+import org.onap.so.beans.nsmf.*
+import org.onap.so.beans.nsmf.oof.SubnetType
+import org.onap.so.bpmn.common.scripts.*
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.bpmn.core.domain.ServiceArtifact
+import org.onap.so.bpmn.core.domain.ServiceDecomposition
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.logger.LoggingAnchor
+import org.onap.so.logger.MessageEnum
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.web.util.UriUtils
+
+import java.lang.reflect.Type
+
+/**
+ * This class supports the DoCreateVnf building block subflow
+ * with the creation of a generic vnf for
+ * infrastructure.
+ *
+ */
+class DoActivateSliceService extends AbstractServiceTaskProcessor {
+
+ private static final Logger logger = LoggerFactory.getLogger(DoActivateSliceService.class)
+
+ private static final NSSMF_ACTIVATION_URL = "/api/rest/provMns/v1/NSS/%s/activation"
+
+ private static final NSSMF_DEACTIVATION_URL = "/api/rest/provMns/v1/NSS/%s/deactivation"
+
+ private static final NSSMF_QUERY_JOB_STATUS_URL = "/api/rest/provMns/v1/NSS/jobs/%s"
+
+ String Prefix="DoCNSSMF_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+
+ JsonUtils jsonUtil = new JsonUtils()
+
+ ObjectMapper objectMapper = new ObjectMapper()
+
+ SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
+
+ private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
+
+ /**
+ * This method gets and validates the incoming
+ * request.
+ *
+ * @param - execution
+ *
+ */
+ public void preProcessRequest(DelegateExecution execution) {
+
+ execution.setVariable("prefix",Prefix)
+ logger.debug("STARTED Do sendcommandtoNssmf PreProcessRequest Process")
+
+ /*******************/
+ try{
+ Queue<NssInstance> nssInstances = execution.getVariable("nssInstances") as Queue<NssInstance>
+ NssInstance nssInstance = nssInstances.poll()
+ execution.setVariable("nssInstances", nssInstances)
+ execution.setVariable("nssInstance", nssInstance)
+
+ logger.info("the end !!")
+ }catch(BpmnError b){
+ logger.debug("Rethrowing MSOWorkflowException")
+ throw b
+ }catch(Exception e){
+ logger.info("the end of catch !!")
+ logger.debug(" Error Occured in DoSendCommandToNSSMF PreProcessRequest method!" + e.getMessage())
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoSendCommandToNSSMF PreProcessRequest")
+
+ }
+ logger.trace("COMPLETED DoSendCommandToNSSMF PreProcessRequest Process")
+ }
+
+ void prepareCompose(DelegateExecution execution) {
+ NssInstance nssInstance = execution.getVariable("nssInstance") as NssInstance
+ execution.setVariable("nssInstanceId", nssInstance.nssiId)
+ String serviceModelInfo = """{
+ "modelInvariantUuid":"${nssInstance.modelInvariantId}",
+ "modelUuid":"${nssInstance.modelVersionId}",
+ "modelVersion":""
+ }"""
+ execution.setVariable("serviceModelInfo", serviceModelInfo)
+ }
+
+ /**
+ * get vendor Info
+ * @param execution
+ */
+ void processDecomposition(DelegateExecution execution) {
+ logger.debug("***** processDecomposition *****")
+
+ try {
+ ServiceDecomposition serviceDecomposition =
+ execution.getVariable("serviceDecomposition") as ServiceDecomposition
+
+ String vendor = serviceDecomposition.getServiceRole()
+ CustomerInfo customerInfo = execution.getVariable("customerInfo") as CustomerInfo
+ NssInstance nssInstance = execution.getVariable("nssInstance") as NssInstance
+ String reqUrl
+ String actionType
+ if (OperationType.ACTIVATE == nssInstance.operationType) {
+ reqUrl = String.format(NSSMF_ACTIVATION_URL, nssInstance.snssai)
+ actionType = "activate"
+ } else {
+ reqUrl = String.format(NSSMF_DEACTIVATION_URL, nssInstance.snssai)
+ actionType = "deactivate"
+ }
+ execution.setVariable("reqUrl", reqUrl)
+
+ NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest()
+
+ EsrInfo esrInfo = new EsrInfo()
+ esrInfo.setVendor(vendor)
+ esrInfo.setNetworkType(nssInstance.networkType)
+
+ ServiceInfo serviceInfo = ServiceInfo.builder()
+ .nssiId(nssInstance.nssiId)
+ .subscriptionServiceType(customerInfo.subscriptionServiceType)
+ .globalSubscriberId(customerInfo.globalSubscriberId)
+ .nsiId(customerInfo.nsiId)
+ .serviceInvariantUuid(nssInstance.modelInvariantId)
+ .serviceUuid(nssInstance.modelVersionId)
+ .serviceType(nssInstance.serviceType)
+ .actionType(actionType)
+ .build()
+
+ ActDeActNssi actDeActNssi = new ActDeActNssi()
+ actDeActNssi.setNsiId(customerInfo.nsiId)
+ actDeActNssi.setNssiId(nssInstance.nssiId)
+
+ nbiRequest.setEsrInfo(esrInfo)
+ nbiRequest.setServiceInfo(serviceInfo)
+ nbiRequest.setActDeActNssi(actDeActNssi)
+ execution.setVariable("nbiRequest", nbiRequest)
+ execution.setVariable("esrInfo", esrInfo)
+ execution.setVariable("serviceInfo", serviceInfo)
+
+ } catch (any) {
+ String exceptionMessage = "Bpmn error encountered in deallocate nssi. processDecomposition() - " + any.getMessage()
+ logger.debug(exceptionMessage)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
+ }
+ logger.debug("***** Exit processDecomposition *****")
+ }
+
+ /**
+ * send Create Request NSSMF
+ * @param execution
+ */
+ void sendCreateRequestNSSMF(DelegateExecution execution) {
+ NssmfAdapterNBIRequest nbiRequest = execution.getVariable("nbiRequest") as NssmfAdapterNBIRequest
+ String nssmfRequest = objectMapper.writeValueAsString(nbiRequest)
+ logger.debug("sendCreateRequestNSSMF: " + nssmfRequest)
+
+ String reqUrl = execution.getVariable("reqUrl")
+ String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, reqUrl, nssmfRequest)
+
+ if (response != null) {
+ NssiResponse nssiResponse = objectMapper.readValue(response, NssiResponse.class)
+ execution.setVariable("nssiAllocateResult", nssiResponse)
+ }
+ //todo: error
+ }
+
+ /**
+ * query nssi allocate status
+ * @param execution
+ */
+ void queryNSSIStatus(DelegateExecution execution) {
+ NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest()
+ EsrInfo esrInfo = execution.getVariable("esrInfo") as EsrInfo
+ ServiceInfo serviceInfo = execution.getVariable("serviceInfo") as ServiceInfo
+ nbiRequest.setEsrInfo(esrInfo)
+ nbiRequest.setServiceInfo(serviceInfo)
+
+ NssiResponse nssiAllocateResult = execution.getVariable("nssiAllocateResult") as NssiResponse
+ String jobId = nssiAllocateResult.getJobId()
+
+ String endpoint = String.format(NSSMF_QUERY_JOB_STATUS_URL, jobId)
+
+ String response =
+ nssmfAdapterUtils.sendPostRequestNSSMF(execution, endpoint, objectMapper.writeValueAsString(nbiRequest))
+
+ logger.debug("nssmf response nssiAllocateStatus:" + response)
+
+ if (response != null) {
+ JobStatusResponse jobStatusResponse = objectMapper.readValue(response, JobStatusResponse.class)
+
+ execution.setVariable("nssiAllocateStatus", jobStatusResponse)
+ if (jobStatusResponse.getResponseDescriptor().getProgress() == 100) {
+ execution.setVariable("jobFinished", true)
+ }
+ }
+ }
+
+ void timeDelay(DelegateExecution execution) {
+ logger.trace("Enter timeDelay in DoAllocateNSSI()")
+ try {
+ Thread.sleep(60000)
+
+ int currentCycle = execution.hasVariable("currentCycle") ?
+ execution.getVariable("currentCycle") as Integer : 1
+
+ currentCycle = currentCycle + 1
+ if(currentCycle > 60)
+ {
+ logger.trace("Completed all the retry times... but still nssmf havent completed the creation process...")
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, "NSSMF creation didnt complete by time...")
+ }
+ execution.setVariable("currentCycle", currentCycle)
+ } catch(InterruptedException e) {
+ logger.info("Time Delay exception" + e)
+ }
+ logger.trace("Exit timeDelay in DoAllocateNSSI()")
+ }
+
+ void sendSyncError (DelegateExecution execution) {
+ logger.trace("start sendSyncError")
+ try {
+ String errorMessage = ""
+ if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
+ WorkflowException wfe = execution.getVariable("WorkflowException")
+ errorMessage = wfe.getErrorMessage()
+ } else {
+ errorMessage = "Sending Sync Error."
+ }
+
+ String buildworkflowException =
+ """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
+ <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
+ <aetgt:ErrorCode>7000</aetgt:ErrorCode>
+ </aetgt:WorkflowException>"""
+
+ logger.debug(buildworkflowException)
+ sendWorkflowResponse(execution, 500, buildworkflowException)
+
+ } catch (Exception ex) {
+ logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
+ }
+ logger.trace("finished sendSyncError")
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoSendCommandToNSSMF.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoSendCommandToNSSMF.groovy
deleted file mode 100644
index a85f5d8ab3..0000000000
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoSendCommandToNSSMF.groovy
+++ /dev/null
@@ -1,423 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- # Copyright (c) 2019, CMCC Technologies Co., Ltd.
- #
- # Licensed under the Apache License, Version 2.0 (the "License")
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.bpmn.infrastructure.scripts
-
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.google.gson.Gson
-import com.google.gson.reflect.TypeToken
-import org.camunda.bpm.engine.delegate.BpmnError
-import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.so.beans.nsmf.*
-import org.onap.so.bpmn.common.scripts.*
-import org.onap.so.bpmn.core.UrnPropertiesReader
-import org.onap.so.bpmn.core.WorkflowException
-import org.onap.so.bpmn.core.domain.ServiceArtifact
-import org.onap.so.bpmn.core.domain.ServiceDecomposition
-import org.onap.so.bpmn.core.json.JsonUtils
-import org.onap.logging.filter.base.ErrorCode
-import org.onap.so.logger.LoggingAnchor
-import org.onap.so.logger.MessageEnum
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import org.springframework.web.util.UriUtils
-
-import java.lang.reflect.Type
-
-/**
- * This class supports the DoCreateVnf building block subflow
- * with the creation of a generic vnf for
- * infrastructure.
- *
- */
-class DoSendCommandToNSSMF extends AbstractServiceTaskProcessor {
-
- private static final Logger logger = LoggerFactory.getLogger( DoSendCommandToNSSMF.class);
- String Prefix="DoCNSSMF_"
- ExceptionUtil exceptionUtil = new ExceptionUtil()
- JsonUtils jsonUtil = new JsonUtils()
- VidUtils vidUtils = new VidUtils(this)
- SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
-
- private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil)
-
- /**
- * This method gets and validates the incoming
- * request.
- *
- * @param - execution
- *
- */
- public void preProcessRequest(DelegateExecution execution) {
-
- execution.setVariable("prefix",Prefix)
- logger.debug("STARTED Do sendcommandtoNssmf PreProcessRequest Process")
-
- /*******************/
- try{
- // Get Variables
- String e2eserviceInstanceId = execution.getVariable("e2eserviceInstanceId")
- String serviceInstanceId = execution.getVariable("e2eserviceInstanceId")
- execution.setVariable("e2eserviceInstanceId", e2eserviceInstanceId)
- execution.setVariable("serviceInstanceId", serviceInstanceId)
- logger.debug("Incoming e2eserviceInstanceId is: " + e2eserviceInstanceId)
-
- String NSIserviceid = execution.getVariable("NSIserviceid")
- execution.setVariable("NSIserviceid", NSIserviceid)
- logger.debug("Incoming NSI id is: " + NSIserviceid)
-
-
- String nssiMap = execution.getVariable("nssiMap")
- Type type = new TypeToken<HashMap<String, NSSI>>(){}.getType()
- Map<String, NSSI> DonssiMap = new Gson().fromJson(nssiMap,type)
- String strDonssiMap = mapToJsonStr(DonssiMap)
- execution.setVariable("DonssiMap",strDonssiMap)
- logger.debug("Incoming DonssiMap is: " + strDonssiMap)
-
- String requestId = execution.getVariable("msoRequestId")
- execution.setVariable("msoRequestId", requestId)
-
- String operationType = execution.getVariable("operationType")
- execution.setVariable("operationType", operationType.toLowerCase())
- logger.debug("Incoming operationType is: " + operationType)
-
- if (operationType == "activation") {
- execution.setVariable("activationSequence","an,tn,cn")
- }else {
- execution.setVariable("activationSequence","cn,tn,an")
- }
- execution.setVariable("activationIndex",0)
- execution.setVariable("miniute", "0")
- execution.setVariable("activateNumberSlice",0)
-
- logger.info("the end !!")
- }catch(BpmnError b){
- logger.debug("Rethrowing MSOWorkflowException")
- throw b
- }catch(Exception e){
- logger.info("the end of catch !!")
- logger.debug(" Error Occured in DoSendCommandToNSSMF PreProcessRequest method!" + e.getMessage())
- exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured in DoSendCommandToNSSMF PreProcessRequest")
-
- }
- logger.trace("COMPLETED DoSendCommandToNSSMF PreProcessRequest Process")
- }
-
- private String mapToJsonStr(Map<String, NSSI> stringNSSIHashMap) {
- HashMap<String, NSSI> map = new HashMap<String, NSSI>()
- for(Map.Entry<String, NSSI> child:stringNSSIHashMap.entrySet())
- {
- map.put(child.getKey(), child.getValue())
- }
- return new Gson().toJson(map)
- }
-
- public void getNSSIformlist(DelegateExecution execution) {
-
- String nssiMap = execution.getVariable("DonssiMap")
- Type type = new TypeToken<HashMap<String, NSSI>>(){}.getType()
- Map<String, NSSI> DonssiMap = new Gson().fromJson(nssiMap,type)
- String isNSSIActivate = execution.getVariable("isNSSIActivate")
-
- String activationSequence01 = execution.getVariable("activationSequence")
- String[] strlist = activationSequence01.split(",")
-
- int activationIndex = execution.getVariable("activationIndex")
- int indexcurrent = 0
- if (isNSSIActivate == "true")
- {
- execution.setVariable("isGetSuccessfull", "false")
- }else{for (int index = activationIndex; index < 3;index++) {
- String domaintype01 = strlist[index]
- if (DonssiMap.containsKey(domaintype01)) {
- NSSI nssiobject = DonssiMap.get(domaintype01)
- execution.setVariable("domainType", domaintype01)
- execution.setVariable("nssiId", nssiobject.getNssiId())
- execution.setVariable("modelInvariantUuid", nssiobject.getModelInvariantId())
- execution.setVariable("modelUuid", nssiobject.getModelVersionId())
- execution.setVariable("isGetSuccessfull", "true")
- String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
- String modelUuid = execution.getVariable("modelUuid")
- //here modelVersion is not set, we use modelUuid to decompose the service.
- String serviceModelInfo = """{
- "modelInvariantUuid":"${modelInvariantUuid}",
- "modelUuid":"${modelUuid}",
- "modelVersion":""
- }"""
- execution.setVariable("serviceModelInfo", serviceModelInfo)
- indexcurrent = index
- execution.setVariable("activationIndex", indexcurrent)
- break
- }else
- {
- indexcurrent = index + 1
-
- }
- }
- if ( activationIndex > 2) {
- execution.setVariable("isGetSuccessfull", "false")
- }
- execution.setVariable("activationIndex", indexcurrent)}
-
- }
-
- /**
- * get vendor Info
- * @param execution
- */
- private void processDecomposition(DelegateExecution execution) {
- logger.debug("***** processDecomposition *****")
-
- try {
- ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") as ServiceDecomposition
- ServiceArtifact serviceArtifact = serviceDecomposition.getServiceInfo().getServiceArtifact().get(0)
- String content = serviceArtifact.getContent()
- String vendor = jsonUtil.getJsonValue(content, "metadata.vendor")
- //String domainType = jsonUtil.getJsonValue(content, "metadata.domainType")
-
- execution.setVariable("vendor", vendor)
- // currentNSSI['domainType'] = domainType
- logger.info("processDecomposition, current vendor-domainType:" + vendor)
-
- } catch (any) {
- String exceptionMessage = "Bpmn error encountered in deallocate nssi. processDecomposition() - " + any.getMessage()
- logger.debug(exceptionMessage)
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
- }
- logger.debug("***** Exit processDecomposition *****")
- }
-
- public void UpdateIndex(DelegateExecution execution) {
- def activationIndex = execution.getVariable("activationIndex")
- int activateNumberSlice = execution.getVariable("activateNumberSlice") as Integer
- def activationCount= execution.getVariable("activationCount")
- //DecimalFormat df1 = new DecimalFormat("##%")
- int rate = (activateNumberSlice / activationCount) * 100
- if (rate == 100)
- {
- execution.setVariable("isNSSIActivate","true")
- }
- else{
- execution.setVariable("isNSSIActivate","false")
- }
- activationIndex = activationIndex + 1
- execution.setVariable("activationIndex",activationIndex)
- logger.trace("the Progress of activation is " + rate.toString() + "%" )
- try{
- String serviceId = execution.getVariable("serviceInstanceId")
- String operationId = UUID.randomUUID().toString()
- String operationType = execution.getVariable("operationType")
- String userId = ""
- String result = (operationType.equalsIgnoreCase("activation"))? "ACTIVATING": "DEACTIVATING"
- int progress = rate
- String reason = ""
- String operationContent = "Service activation in progress"
- logger.debug("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId)
- serviceId = UriUtils.encode(serviceId,"UTF-8")
- execution.setVariable("e2eserviceInstanceId", serviceId)
- execution.setVariable("operationId", operationId)
- execution.setVariable("operationType", operationType)
-
- def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint",execution)
- execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
- logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint)
-
- String payload =
- """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:ns="http://org.onap.so/requestsdb">
- <soapenv:Header/>
- <soapenv:Body>
- <ns:initServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
- <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
- <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
- <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
- <userId>${MsoUtils.xmlEscape(userId)}</userId>
- <result>${MsoUtils.xmlEscape(result)}</result>
- <operationContent>${MsoUtils.xmlEscape(operationContent)}</operationContent>
- <progress>${MsoUtils.xmlEscape(progress)}</progress>
- <reason>${MsoUtils.xmlEscape(reason)}</reason>
- </ns:initServiceOperationStatus>
- </soapenv:Body>
- </soapenv:Envelope>"""
-
- payload = utils.formatXml(payload)
- execution.setVariable("CVFMI_updateServiceOperStatusRequest", payload)
- logger.debug("Outgoing CVFMI_updateServiceOperStatusRequest: \n" + payload)
-
- }catch(Exception e){
- logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
- "Exception Occured Processing Activate Slice .", "BPMN",
- ErrorCode.UnknownError.getValue(), "Exception is:\n" + e)
- execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during Activate Slice Method:\n" + e.getMessage())
- }
- logger.trace("finished Activate Slice")
- }
-
- public void WaitForReturn(DelegateExecution execution) {
- //logger.debug("Query : "+ Jobid)
- String miniute = execution.getVariable("miniute")
- Thread.sleep(10000)
- int miniute01 = Integer.parseInt(miniute) + 1
- logger.debug("waiting for : "+ miniute + "miniutes")
- execution.setVariable("miniute", String.valueOf(miniute01))
- }
-
- public void GetTheStatusOfActivation(DelegateExecution execution) {
-
- String domaintype = execution.getVariable("domainType")
- String NSIserviceid=execution.getVariable("NSIserviceid")
- String nssiId = execution.getVariable("nssiId")
- String Jobid=execution.getVariable("JobId")
- String miniute=execution.getVariable("miniute")
- String vendor = execution.getVariable("vendor")
- String jobstatus
-
-
- logger.debug("Query the jobid activation of SNSSAI: "+ Jobid)
- logger.debug("the domain is : "+ domaintype)
- logger.debug("the NSSID is : "+nssiId)
- logger.debug("the NSIserviceid is : "+NSIserviceid)
-
- JobStatusRequest jobStatusRequest = new JobStatusRequest()
-
- EsrInfo info = new EsrInfo()
- info.setNetworkType(NetworkType.fromString(domaintype))
- info.setVendor(vendor)
-
- jobStatusRequest.setNsiId(NSIserviceid)
- jobStatusRequest.setNssiId(nssiId)
- jobStatusRequest.setEsrInfo(info)
-
-
- ObjectMapper mapper = new ObjectMapper()
- String nssmfRequest = mapper.writeValueAsString(jobStatusRequest)
- String isActivateSuccessfull
-
- String urlString = "/api/rest/provMns/v1/NSS/jobs/" +Jobid
-
- JobStatusResponse jobStatusResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest, JobStatusResponse.class)
-
- if (jobStatusResponse != null) {
- execution.setVariable("statusDescription", jobStatusResponse.getResponseDescriptor().getStatusDescription())
- jobstatus = jobStatusResponse.getResponseDescriptor().getStatus()
- switch(jobstatus) {
- case "started":
- case "processing":
- isActivateSuccessfull = "waitting"
- execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
- break
- case "finished":
- isActivateSuccessfull = "true"
- execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
- execution.setVariable("activateNumberSlice",execution.getVariable("activateNumberSlice")+ 1)
- break
- case "error":
- default:
- isActivateSuccessfull = "false"
- execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
-
- }
- if(Integer.parseInt(miniute) > 6 )
- {
- isActivateSuccessfull = "false"
- execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a timeout job status Response from NSSMF.")
- }
- } else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad job status Response from NSSMF.")
- isActivateSuccessfull = false
- execution.setVariable("isActivateSuccessfull", isActivateSuccessfull)
- }
- }
-
- public void SendCommandToNssmf(DelegateExecution execution) {
-
- String snssai= execution.getVariable("snssai")
- String domaintype = execution.getVariable("domainType")
- String NSIserviceid=execution.getVariable("NSIserviceid")
- String nssiId = execution.getVariable("nssiId")
- String vendor = execution.getVariable("vendor")
-
-
- logger.debug("the domain is : "+domaintype)
- logger.debug("SNSSAI: "+snssai +" will be activated")
- logger.debug("the NSSID is : "+nssiId)
- logger.debug("the NSIserviceid is : "+NSIserviceid)
-
- EsrInfo esr = new EsrInfo();
- esr.setNetworkType(NetworkType.fromString(domaintype))
- esr.setVendor(vendor)
-
- ActDeActNssi actNssi = new ActDeActNssi();
- actNssi.setNsiId(NSIserviceid);
- actNssi.setNssiId(nssiId);
- NssiActDeActRequest actRequest = new NssiActDeActRequest();
- actRequest.setActDeActNssi(actNssi);
- actRequest.setEsrInfo(esr)
-
- ObjectMapper mapper = new ObjectMapper()
- String nssmfRequest = mapper.writeValueAsString(actRequest)
-
- String operationType = execution.getVariable("operationType")
-
- String urlString = "/api/rest/provMns/v1/NSS/" + snssai + "/" + operationType.toLowerCase()
-
- NssiResponse nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlString, nssmfRequest, NssiResponse.class)
-
- if (nssmfResponse != null) {
- String isNSSIActivated = "true"
- execution.setVariable("isNSSIActivated", isNSSIActivated)
- String jobId = nssmfResponse.getJobId() ?: ""
- execution.setVariable("JobId", jobId)
- } else {
- exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.")
- String isNSSIActivated = "false"
- execution.setVariable("isNSSIActivated", isNSSIActivated)
- execution.setVariable("isNSSIActivate","false")
- }
-
- }
-
- void sendSyncError (DelegateExecution execution) {
- logger.trace("start sendSyncError")
- try {
- String errorMessage = ""
- if (execution.getVariable("WorkflowException") instanceof WorkflowException) {
- WorkflowException wfe = execution.getVariable("WorkflowException")
- errorMessage = wfe.getErrorMessage()
- } else {
- errorMessage = "Sending Sync Error."
- }
-
- String buildworkflowException =
- """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1">
- <aetgt:ErrorMessage>${MsoUtils.xmlEscape(errorMessage)}</aetgt:ErrorMessage>
- <aetgt:ErrorCode>7000</aetgt:ErrorCode>
- </aetgt:WorkflowException>"""
-
- logger.debug(buildworkflowException)
- sendWorkflowResponse(execution, 500, buildworkflowException)
-
- } catch (Exception ex) {
- logger.debug("Sending Sync Error Activity Failed. " + "\n" + ex.getMessage())
- }
- logger.trace("finished sendSyncError")
- }
-}