aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2021-08-13 15:15:51 +0000
committerGerrit Code Review <gerrit@onap.org>2021-08-13 15:15:51 +0000
commiteb802bafa4a955dcd6ddba194808dcb7e3cac291 (patch)
tree53712f2ef138325806b52ceb5b528c3df578ee38 /bpmn/so-bpmn-infrastructure-common/src
parentd30a899340e9b43d7e0fc4ff430cf91a0aaafce8 (diff)
parent06fb1d8bc8727d476c0998ff19f90a07f14edade (diff)
Merge "SO changes for Service Intent"
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy153
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy127
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy391
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy174
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy502
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy128
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy669
7 files changed, 2144 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy
new file mode 100644
index 0000000000..303b685a38
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateServiceIntentInstance.groovy
@@ -0,0 +1,153 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, Wipro Limited.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+
+class CreateServiceIntentInstance extends AbstractServiceTaskProcessor {
+
+ String Prefix = "CreateSiInstance_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+ private static final Logger logger = LoggerFactory.getLogger(CreateServiceIntentInstance.class)
+
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug(Prefix + "preProcessRequest Start")
+ execution.setVariable("prefix", Prefix)
+ execution.setVariable("startTime", System.currentTimeMillis())
+ def msg
+ try {
+ // get request input
+ String subnetInstanceReq = execution.getVariable("bpmnRequest")
+ logger.debug(subnetInstanceReq)
+
+ serviceIntentUtils.setCommonExecutionVars(execution)
+
+ //modelInfo
+ String modelInvariantUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelInvariantUuid")
+ if (isBlank(modelInvariantUuid)) {
+ msg = "Input modelInvariantUuid is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("modelInvariantUuid", modelInvariantUuid)
+ }
+
+ logger.debug("modelInvariantUuid: " + modelInvariantUuid)
+
+ String modelUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelUuid")
+ if (isBlank(modelUuid)) {
+ msg = "Input modelUuid is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("modelUuid", modelUuid)
+ }
+
+ logger.debug("modelUuid: " + modelUuid)
+
+ String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
+ String siId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug
+ if (isBlank(siId)) {
+ siId = UUID.randomUUID().toString()
+ }
+
+ logger.debug("serviceInstanceID: " + modelUuid)
+ execution.setVariable("serviceInstanceID", siId)
+
+ String sST = jsonUtil.getJsonValue(subnetInstanceReq, "sst")
+ execution.setVariable("sst", sST)
+
+ String jobId = UUID.randomUUID().toString()
+ execution.setVariable("jobId", jobId)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in CreateServiceIntentInstance.preProcessRequest " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "preProcessRequest Exit")
+ }
+
+
+ /**
+ * create operation status in request db
+ *
+ * Init the Operation Status
+ */
+ def prepareInitOperationStatus = { DelegateExecution execution ->
+ logger.debug(Prefix + "prepareInitOperationStatus Start")
+
+ String modelUuid = execution.getVariable("modelUuid")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = execution.getVariable("serviceInstanceID")
+ logger.debug("Generated new job for Service Instance serviceId:" + modelUuid + " jobId:" + jobId)
+
+ ResourceOperationStatus initStatus = new ResourceOperationStatus()
+ initStatus.setServiceId(nsiId) // set nsiId to this field
+ initStatus.setOperationId(jobId) // set jobId to this field
+ initStatus.setResourceTemplateUUID(modelUuid) // set modelUuid to this field
+ initStatus.setOperType("Create")
+ //initStatus.setResourceInstanceID() // set nssiId to this field
+ requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
+
+ logger.debug(Prefix + "prepareInitOperationStatus Exit")
+ }
+
+
+ /**
+ * return sync response
+ */
+ def sendSyncResponse = { DelegateExecution execution ->
+ logger.debug(Prefix + "sendSyncResponse Start")
+ try {
+ String jobId = execution.getVariable("jobId")
+ String allocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
+ .trim().replaceAll(" ", "").trim().replaceAll(" ", "")
+
+ logger.debug("sendSyncResponse to APIH:" + "\n" + allocateSyncResponse)
+ sendWorkflowResponse(execution, 202, allocateSyncResponse)
+
+ execution.setVariable("sentSyncResponse", true)
+ } catch (Exception ex) {
+ String msg = "Exception in sendSyncResponse:" + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "sendSyncResponse Exit")
+ }
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy
new file mode 100644
index 0000000000..59cf5ee7fe
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteServiceIntentInstance.groovy
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, Wipro Limited.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+
+class DeleteServiceIntentInstance extends AbstractServiceTaskProcessor {
+ String Prefix = "DCLL_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+
+ private static final Logger logger = LoggerFactory.getLogger(DeleteServiceIntentInstance.class)
+
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug(Prefix + "preProcessRequest Start")
+ execution.setVariable("prefix", Prefix)
+ execution.setVariable("startTime", System.currentTimeMillis())
+ def msg
+ try {
+ // get request input
+ String subnetInstanceReq = execution.getVariable("bpmnRequest")
+ logger.debug(subnetInstanceReq)
+
+ serviceIntentUtils.setCommonExecutionVars(execution)
+
+ String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
+ if (isBlank(serviceInstanceID)) {
+ msg = "Input serviceInstanceID is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("serviceInstanceID", serviceInstanceID)
+ }
+
+ String jobId = UUID.randomUUID().toString()
+ execution.setVariable("jobId", jobId)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in DeAllocateSliceSubnet.preProcessRequest " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "preProcessRequest Exit")
+ }
+
+
+ /**
+ * create operation status in request db
+ *
+ * Init the Operation Status
+ */
+ def prepareInitOperationStatus = { DelegateExecution execution ->
+ logger.debug(Prefix + "prepareInitOperationStatus Start")
+
+ String siId = execution.getVariable("serviceInstanceID")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = siId
+ String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId)
+ logger.debug("Generated new job for Service Instance serviceId:" + nsiId + " jobId:" + jobId)
+
+ ResourceOperationStatus initStatus = new ResourceOperationStatus()
+ initStatus.setServiceId(nsiId)
+ initStatus.setOperationId(jobId)
+ initStatus.setResourceTemplateUUID(modelUuid)
+ initStatus.setOperType("Delete")
+ requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
+
+ logger.debug(Prefix + "prepareInitOperationStatus Exit")
+ }
+
+
+ /**
+ * return sync response
+ */
+ def sendSyncResponse = { DelegateExecution execution ->
+ logger.debug(Prefix + "sendSyncResponse Start")
+ try {
+ String jobId = execution.getVariable("jobId")
+ String deAllocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""".trim().replaceAll(" ", "")
+
+ logger.debug("sendSyncResponse to APIH:" + "\n" + deAllocateSyncResponse)
+ sendWorkflowResponse(execution, 202, deAllocateSyncResponse)
+
+ execution.setVariable("sentSyncResponse", true)
+ } catch (Exception ex) {
+ String msg = "Exception in sendSyncResponse:" + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "sendSyncResponse Exit")
+ }
+
+}
+
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy
new file mode 100644
index 0000000000..2e0f3cfd66
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineCreate.groovy
@@ -0,0 +1,391 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.NetworkPolicy
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aaiclient.client.aai.AAIResourcesClient
+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.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.web.util.UriUtils
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+
+class DoCloudLeasedLineCreate extends AbstractServiceTaskProcessor {
+
+ private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineCreate.class);
+ JsonUtils jsonUtil = new JsonUtils()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ String Prefix = "CLLC_"
+
+
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug("Start preProcessRequest")
+ execution.setVariable("prefix", Prefix)
+ String msg = ""
+
+ try {
+ execution.setVariable("startTime", System.currentTimeMillis())
+
+ msg = serviceIntentUtils.getExecutionInputParams(execution)
+ logger.debug("Create CLL input parameters: " + msg)
+
+ serviceIntentUtils.setSdncCallbackUrl(execution, true)
+ logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
+
+ String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
+
+ String cllId = jsonUtil.getJsonValue(additionalPropJsonStr, "serviceInstanceID") //for debug
+ if (isBlank(cllId)) {
+ cllId = UUID.randomUUID().toString()
+ }
+
+ String operationId = UUID.randomUUID().toString()
+ execution.setVariable("operationId", operationId)
+
+ logger.debug("Generate new CLL ID:" + cllId)
+ cllId = UriUtils.encode(cllId, "UTF-8")
+ execution.setVariable("cllId", cllId)
+
+ String cllName = execution.getVariable("servicename")
+ execution.setVariable("cllName", cllName)
+
+ String sst = execution.getVariable("sst")
+ execution.setVariable("sst", sst)
+
+ String transportNetworks = jsonUtil.getJsonValue(additionalPropJsonStr, "transportNetworks")
+ if (isBlank(transportNetworks)) {
+ msg = "ERROR: preProcessRequest: Input transportNetworks is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("transportNetworks", transportNetworks)
+ }
+ logger.debug("transportNetworks: " + transportNetworks)
+
+ if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr,
+ "enableSdnc", "enableSdnc"))) {
+ serviceIntentUtils.setEnableSdncConfig(execution)
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in preProcessRequest " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug("Finish preProcessRequest")
+ }
+
+ void updateAAIOrchStatus(DelegateExecution execution) {
+ logger.debug("Start updateAAIOrchStatus")
+ String cllId = execution.getVariable("cllId")
+ String orchStatus = execution.getVariable("orchestrationStatus")
+
+ try {
+ ServiceInstance si = new ServiceInstance()
+ si.setOrchestrationStatus(orchStatus)
+ AAIResourcesClient client = new AAIResourcesClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE.getFragment(cllId))
+ client.update(uri, si)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ logger.debug("Finish updateAAIOrchStatus")
+ }
+
+ void prepareUpdateJobStatus(DelegateExecution execution,
+ String status,
+ String progress,
+ String statusDescription) {
+ String cllId = execution.getVariable("cllId")
+ String modelUuid = execution.getVariable("modelUuid")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = cllId
+ String operType = "CREATE"
+
+ ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
+ jobId, nsiId, operType, status, progress, statusDescription)
+
+ logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
+ requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
+ }
+
+
+ void createServiceInstance(DelegateExecution execution) {
+
+ String serviceRole = "cll"
+ String serviceType = execution.getVariable("serviceType")
+ String cllId = execution.getVariable("cllId")
+ try {
+ org.onap.aai.domain.yang.ServiceInstance ss = new org.onap.aai.domain.yang.ServiceInstance()
+ ss.setServiceInstanceId(cllId)
+ String cllName = execution.getVariable("cllName")
+ if (isBlank(cllName)) {
+ logger.error("ERROR: createServiceInstance: cllName is null")
+ cllName = cllId
+ }
+ ss.setServiceInstanceName(cllName)
+ ss.setServiceType(serviceType)
+ String serviceStatus = "created"
+ ss.setOrchestrationStatus(serviceStatus)
+ String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
+ String modelUuid = execution.getVariable("modelUuid")
+ ss.setModelInvariantId(modelInvariantUuid)
+ ss.setModelVersionId(modelUuid)
+ ss.setEnvironmentContext("cll")
+ ss.setServiceRole(serviceRole)
+
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(cllId))
+ client.create(uri, ss)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoCloudLeasedLineCreate.createServiceInstance: " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+
+ void createAllottedResource(DelegateExecution execution) {
+ String cllId = execution.getVariable('cllId')
+
+ try {
+ List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks"))
+
+ for (String networkStr : networkStrList) {
+ String networkId = jsonUtil.getJsonValue(networkStr, "id")
+ String allottedResourceId = isBlank(networkId) ? UUID.randomUUID().toString() : networkId
+
+ AAIResourceUri allottedResourceUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(execution.getVariable("cllId"))
+ .allottedResource(allottedResourceId))
+ execution.setVariable("allottedResourceUri", allottedResourceUri)
+ String modelInvariantId = execution.getVariable("modelInvariantUuid")
+ String modelVersionId = execution.getVariable("modelUuid")
+
+ String slaStr = jsonUtil.getJsonValue(networkStr, "sla")
+ if (slaStr == null || slaStr.isEmpty()) {
+ String msg = "ERROR: createNetworkPolicy: SLA is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ org.onap.aai.domain.yang.AllottedResource resource = new org.onap.aai.domain.yang.AllottedResource()
+ resource.setId(allottedResourceId)
+ resource.setType("TsciNetwork")
+ resource.setAllottedResourceName("network_" + allottedResourceId)
+ getAAIClient().create(allottedResourceUri, resource)
+
+ createNetworkPolicyForAllocatedResource(execution, cllId, allottedResourceId, slaStr)
+
+ String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks")
+ createLogicalLinksForAllocatedResource(execution, linkArrayStr, cllId, allottedResourceId)
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoCloudLeasedLineCreate.createAllottedResource: " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void createNetworkPolicy(DelegateExecution execution, String cllId, String networkPolicyId, String slaStr) {
+ try {
+
+
+ NetworkPolicy networkPolicy = new NetworkPolicy();
+ networkPolicy.setNetworkPolicyId(networkPolicyId)
+ networkPolicy.setName("TSCi policy")
+ networkPolicy.setType("SLA")
+ networkPolicy.setNetworkPolicyFqdn(cllId)
+
+ String latencyStr = jsonUtil.getJsonValue(slaStr, "latency")
+ if (latencyStr != null && !latencyStr.isEmpty()) {
+ networkPolicy.setLatency(Integer.parseInt(latencyStr))
+ }
+
+ String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth")
+ if (bwStr != null && !bwStr.isEmpty()) {
+ networkPolicy.setMaxBandwidth(Integer.parseInt(bwStr))
+ } else {
+ logger.debug("ERROR: createNetworkPolicy: maxBandwidth is null")
+ }
+
+ //networkPolicy.setReliability(new Object())
+
+ AAIResourceUri networkPolicyUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
+ getAAIClient().create(networkPolicyUri, networkPolicy)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void createNetworkPolicyForAllocatedResource(DelegateExecution execution,
+ String cllId,
+ String allottedResourceId, String slaStr) {
+ try {
+ AAIResourceUri allottedResourceUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(cllId)
+ .allottedResource(allottedResourceId))
+
+ if (!getAAIClient().exists(allottedResourceUri)) {
+ logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
+ allottedResourceUri)
+ return
+ }
+
+ String networkPolicyId = UUID.randomUUID().toString()
+ createNetworkPolicy(execution, cllId, networkPolicyId, slaStr)
+
+ serviceIntentUtils.attachNetworkPolicyToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
+ allottedResourceUri,
+ networkPolicyId);
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoCreateSliceServiceInstance.instantiateSliceService. " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void createLogicalLinksForAllocatedResource(DelegateExecution execution,
+ String linkArrayStr, String cllId,
+ String allottedResourceId) {
+ try {
+ AAIResourceUri allottedResourceUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(cllId)
+ .allottedResource(allottedResourceId))
+
+ if (!getAAIClient().exists(allottedResourceUri)) {
+ logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
+ allottedResourceUri)
+ return
+ }
+
+ List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr)
+
+ for (String linkStr : linkStrList) {
+ String linkId = jsonUtil.getJsonValue(linkStr, "name")
+ if (isBlank(linkId)) {
+ linkId = "cll-" + UUID.randomUUID().toString()
+ }
+ logger.debug("createLogicalLinksForAllocatedResource: linkId=" + linkId)
+
+ String epA = jsonUtil.getJsonValue(linkStr, "transportEndpointA")
+ String epB = jsonUtil.getJsonValue(linkStr, "transportEndpointB")
+ String modelInvariantId = execution.getVariable("modelInvariantUuid")
+ String modelVersionId = execution.getVariable("modelUuid")
+
+ org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
+ resource.setLinkId(linkId)
+ resource.setLinkName(epA)
+ resource.setLinkName2(epB)
+ resource.setLinkType("TsciConnectionLink")
+ resource.setInMaint(false)
+
+ //epA is link-name
+ AAIResourceUri logicalLinkUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
+ getAAIClient().create(logicalLinkUri, resource)
+
+ serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
+ allottedResourceUri, epA);
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoCloudLeasedLineCreate.createLogicalLinksForAllocatedResource: " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void preprocessSdncCreateCllRequest(DelegateExecution execution) {
+ def method = getClass().getSimpleName() + '.preProcessSDNCActivateRequest(' +
+ 'execution=' + execution.getId() +
+ ')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logger.trace('Entered ' + method)
+
+ logger.trace("STARTED preProcessSDNCActivateRequest Process")
+ try {
+ String serviceInstanceId = execution.getVariable("cllId")
+
+ String createSDNCRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "create")
+
+ execution.setVariable("CLL_SDNCRequest", createSDNCRequest)
+ logger.debug("Outgoing SDNCRequest is: \n" + createSDNCRequest)
+
+ } catch (Exception e) {
+ logger.debug("Exception Occured Processing preProcessSDNCActivateRequest. Exception is:\n" + e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002,
+ "Error Occured during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
+ }
+ logger.trace("COMPLETED preProcessSDNCActivateRequest Process")
+ }
+
+
+ void validateSDNCResponse(DelegateExecution execution, String response, String method) {
+ serviceIntentUtils.validateSDNCResponse(execution, response, method)
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy
new file mode 100644
index 0000000000..b7f206cedc
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineDelete.groovy
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aaiclient.client.aai.AAIResourcesClient
+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.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.apache.commons.lang3.StringUtils.isEmpty
+
+class DoCloudLeasedLineDelete extends AbstractServiceTaskProcessor {
+ String Prefix = "DCLL_"
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+ private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineDelete.class)
+
+
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug("Start preProcessRequest")
+
+ execution.setVariable("startTime", System.currentTimeMillis())
+ String msg = serviceIntentUtils.getExecutionInputParams(execution)
+ logger.debug("Deallocate CLL input parameters: " + msg)
+
+ execution.setVariable("prefix", Prefix)
+
+ serviceIntentUtils.setSdncCallbackUrl(execution, true)
+ logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
+
+ String cllId = execution.getVariable("serviceInstanceID")
+ execution.setVariable("cllId", cllId)
+
+ String cllName = execution.getVariable("servicename")
+ execution.setVariable("cllName", cllName)
+
+ String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
+ String modelUuid = execution.getVariable("modelUuid")
+ if (isEmpty(modelUuid)) {
+ modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID"))
+ }
+ def isDebugLogEnabled = true
+ execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
+ String serviceModelInfo = """{
+ "modelInvariantUuid":"${modelInvariantUuid}",
+ "modelUuid":"${modelUuid}",
+ "modelVersion":""
+ }"""
+ execution.setVariable("serviceModelInfo", serviceModelInfo)
+
+ String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
+ if (isBlank(additionalPropJsonStr) ||
+ isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution,
+ additionalPropJsonStr,
+ "enableSdnc", "enableSdnc"))) {
+ serviceIntentUtils.setEnableSdncConfig(execution)
+ }
+
+ logger.debug("Finish preProcessRequest")
+ }
+
+ void preprocessSdncDeleteCllRequest(DelegateExecution execution) {
+ def method = getClass().getSimpleName() + '.preprocessSdncDeallocateCllRequest(' +
+ 'execution=' + execution.getId() + ')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logger.trace('Entered ' + method)
+
+ try {
+ String serviceInstanceId = execution.getVariable("serviceInstanceID")
+
+ String sdncRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "delete")
+
+ execution.setVariable("CLL_SDNCRequest", sdncRequest)
+ logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
+
+ } catch (Exception e) {
+ logger.debug("Exception Occurred Processing preprocessSdncDeallocateCllRequest. Exception is:\n" + e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
+ }
+ logger.trace("COMPLETED preprocessSdncDeallocateCllRequest Process")
+ }
+
+
+ void validateSDNCResponse(DelegateExecution execution, String response, String method) {
+ serviceIntentUtils.validateSDNCResponse(execution, response, method)
+ }
+
+ void deleteServiceInstance(DelegateExecution execution) {
+ try {
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID")))
+ client.delete(uri)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoDeallocateCll.deleteServiceInstance. " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ public void updateAAIOrchStatus(DelegateExecution execution) {
+ logger.debug("Start updateAAIOrchStatus")
+ String cllId = execution.getVariable("cllId")
+ String orchStatus = execution.getVariable("orchestrationStatus")
+
+ try {
+ ServiceInstance si = new ServiceInstance()
+ si.setOrchestrationStatus(orchStatus)
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(cllId))
+ client.update(uri, si)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ logger.debug("Finish updateAAIOrchStatus")
+ }
+
+ void prepareUpdateJobStatus(DelegateExecution execution,
+ String status,
+ String progress,
+ String statusDescription) {
+ String cllId = execution.getVariable("cllId")
+ String modelUuid = execution.getVariable("modelUuid")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = execution.getVariable("nsiId")
+
+ ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
+ jobId, nsiId, "DELETE", status, progress, statusDescription)
+
+ logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
+ requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
+ }
+}
+
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy
new file mode 100644
index 0000000000..5c9877840d
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCloudLeasedLineModify.groovy
@@ -0,0 +1,502 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.AllottedResource
+import org.onap.aai.domain.yang.AllottedResources
+import org.onap.aai.domain.yang.NetworkPolicy
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aaiclient.client.aai.AAIResourcesClient
+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.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.apache.commons.lang3.StringUtils.isEmpty
+import static org.apache.commons.lang3.StringUtils.isNotBlank
+
+public class DoCloudLeasedLineModify extends AbstractServiceTaskProcessor {
+ String Prefix = "MCLL_"
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+ private static final Logger logger = LoggerFactory.getLogger(DoCloudLeasedLineModify.class)
+
+
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug("Start preProcessRequest")
+ execution.setVariable("prefix", Prefix)
+ String msg = ""
+
+ try {
+ execution.setVariable("startTime", System.currentTimeMillis())
+ msg = serviceIntentUtils.getExecutionInputParams(execution)
+ logger.debug("Modify CLL input parameters: " + msg)
+
+ execution.setVariable("prefix", Prefix)
+
+ serviceIntentUtils.setSdncCallbackUrl(execution, true)
+ logger.debug("SDNC Callback URL: " + execution.getVariable("sdncCallbackUrl"))
+
+ String additionalPropJsonStr = execution.getVariable("serviceIntentParams")
+ if (isBlank(additionalPropJsonStr)) {
+ msg = "ERROR: preProcessRequest: additionalPropJsonStr is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+
+ String cllId = execution.getVariable("serviceInstanceID")
+ if (isBlank(cllId)) {
+ msg = "ERROR: cllId is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ execution.setVariable("cllId", cllId)
+
+ String cllName = execution.getVariable("servicename")
+ execution.setVariable("cllName", cllName)
+
+ String operationId = UUID.randomUUID().toString()
+ execution.setVariable("operationId", operationId)
+
+ String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
+ String modelUuid = execution.getVariable("modelUuid")
+ if (isEmpty(modelUuid)) {
+ modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(execution.getVariable("serviceInstanceID"))
+ }
+
+ def isDebugLogEnabled = true
+ execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)
+ String serviceModelInfo = """{
+ "modelInvariantUuid":"${modelInvariantUuid}",
+ "modelUuid":"${modelUuid}",
+ "modelVersion":""
+ }"""
+ execution.setVariable("serviceModelInfo", serviceModelInfo)
+
+
+ serviceIntentUtils.setExecVarFromJsonStr(execution, additionalPropJsonStr,
+ "transportNetworks", "transportNetworks", true)
+ logger.debug("transportNetworks: " + execution.getVariable("transportNetworks"))
+
+ if (isBlank(serviceIntentUtils.setExecVarFromJsonIfExists(execution, additionalPropJsonStr,
+ "enableSdnc", "enableSdnc"))) {
+ serviceIntentUtils.setEnableSdncConfig(execution)
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in preProcessRequest " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug("Finish preProcessRequest")
+ }
+
+
+ void deleteServiceInstance(DelegateExecution execution) {
+ try {
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("serviceInstanceID")))
+ client.delete(uri)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoDeallocateTnNssi.deleteServiceInstance. " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+
+ void getExistingServiceInstance(DelegateExecution execution) {
+ String serviceInstanceId = execution.getVariable("cllId")
+
+ AAIResourcesClient resourceClient = getAAIClient()
+ AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))
+
+ try {
+ Optional<ServiceInstance> ssOpt = resourceClient.get(ServiceInstance.class, ssServiceuri)
+ if (ssOpt.isPresent()) {
+ ServiceInstance ss = ssOpt.get()
+ AllottedResources ars = serviceIntentUtils.getAllottedResourcesFromAai(execution, serviceInstanceId, true)
+ if (ars != null) {
+ List<AllottedResource> arList = ars.getAllottedResource()
+ List<String> arIdList = new ArrayList<>()
+ Map<String, String> policyMap = new HashMap<>()
+ Map<String, List<String>> logicalLinksMap = new HashMap<>()
+ for (AllottedResource ar : arList) {
+ String arId = ar.getId()
+ arIdList.add(arId)
+ String policyId = serviceIntentUtils.getPolicyIdFromAr(execution, serviceInstanceId, arId, true)
+ policyMap.put(arId, policyId)
+ List<String> logicalLinkList = serviceIntentUtils.getLogicalLinkNamesFromAr(execution,
+ serviceInstanceId, arId, true)
+ logicalLinksMap.put(arId, logicalLinkList)
+ }
+ execution.setVariable("arIdList", arIdList)
+ execution.setVariable("arPolicyMap", policyMap)
+ execution.setVariable("arLogicalLinkMap", logicalLinksMap)
+ } else {
+ logger.error("ERROR: getExistingServiceInstance: getAllottedResources() returned null. ss=" + ss
+ .toString())
+ }
+ } else {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Service instance was not found in aai to " +
+ "associate allotted resource for service :" + serviceInstanceId)
+ }
+ } catch (BpmnError e) {
+ throw e;
+ } catch (Exception ex) {
+ String msg = "Exception in getExistingServiceInstance. " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void updateServiceInstanceInAAI(DelegateExecution execution) {
+ getExistingServiceInstance(execution)
+ updateTsciNetworks(execution)
+ }
+
+ void updateServiceInstance(DelegateExecution execution) {
+ String cllId = execution.getVariable("cllId")
+ try {
+ ServiceInstance ss = new ServiceInstance()
+ //ss.setServiceInstanceId(cllId)
+ String serviceStatus = "modified"
+ ss.setOrchestrationStatus(serviceStatus)
+ ss.setEnvironmentContext("tn")
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(
+ AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(cllId))
+ client.update(uri, ss)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoModifyCllInstance.updateServiceInstance. " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+
+ String getValidArId(DelegateExecution execution, String arIdStr) {
+ List<String> arIdList = execution.getVariable("arIdList")
+ /*
+ * If arId is not specified by the caller, then we assume the caller
+ * wants to modify the first network (i.e., allotted resource) in the TSCi tree.
+ */
+ String arId = isBlank(arIdStr) ? arIdList.get(0) : arIdStr
+
+ return arId
+ }
+
+ void updateLogicalLinksInAr(DelegateExecution execution, String arId, String linkArrayJsonStr) {
+ try {
+ String serviceInstanceId = execution.getVariable('cllId')
+
+ /*
+ * Each TSCi connection-link in linkArrayJsonStr is considered as an "ADD" new
+ * link to allotted-resource. So, if the link already exists under AR, then do
+ * nothing. Otherwise, create logical-link.
+ */
+ List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayJsonStr)
+ for (String linkStr : linkStrList) {
+ if (logicalLinkExists(execution, arId, linkStr)) {
+ continue
+ }
+
+ createLogicalLinkForAllocatedResource(execution, linkStr, serviceInstanceId, arId)
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
+ "Exception in updateLogicalLinksInAr" + ex.getMessage())
+ }
+ }
+
+ void updateLogicalLinksInNetwork(DelegateExecution execution, String networkJsonStr) {
+ try {
+ String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id"))
+ String linkArrayStr = jsonUtil.getJsonValue(networkJsonStr, "connectionLinks")
+ updateLogicalLinksInAr(execution, arId, linkArrayStr)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = String.format("ERROR: updateLogicalLinksInNetwork: exception: %s", ex.getMessage())
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+ }
+
+ void updateTsciNetworks(DelegateExecution execution) {
+ try {
+ List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportNetworks"))
+ for (String networkStr : networkStrList) {
+ updateLogicalLinksInNetwork(execution, networkStr)
+ updateNetworkPolicy(execution, networkStr)
+ }
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
+ "Exception in updateTsciNetworks" + ex.getMessage())
+ }
+ }
+
+ int getMaxBwFromNetworkJsonStr(DelegateExecution execution, String networkJsonStr) {
+ int maxBw = 0
+ try {
+ if (isBlank(networkJsonStr)) {
+ String msg = "ERROR: getMaxBw: networkJsonStr is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ String slaStr = jsonUtil.getJsonValue(networkJsonStr, "sla")
+ if (isBlank(slaStr)) {
+ String msg = "ERROR: getMaxBw: slaStr is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ String bwStr = jsonUtil.getJsonValue(slaStr, "maxBandwidth")
+ if (isNotBlank(bwStr)) {
+ maxBw = Integer.parseInt(bwStr)
+ } else {
+ logger.error("ERROR: getMaxBw: maxBandwidth is null")
+ }
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000,
+ "Exception in getMaxBw" + ex.getMessage())
+ }
+
+ return maxBw
+ }
+
+ void updatePolicyMaxBandwidthInAAI(DelegateExecution execution, String policyId, int maxBw) {
+ try {
+ NetworkPolicy networkPolicy = new NetworkPolicy()
+ networkPolicy.setMaxBandwidth(maxBw)
+ AAIResourceUri networkPolicyUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(policyId))
+ getAAIClient().update(networkPolicyUri, networkPolicy)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoModifyCllInstance.updatePolicyMaxBandwidthInAAI. " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+ void updateNetworkPolicy(DelegateExecution execution, String networkJsonStr) {
+ try {
+ int maxBw = getMaxBwFromNetworkJsonStr(execution, networkJsonStr)
+
+ String arId = getValidArId(execution, jsonUtil.getJsonValue(networkJsonStr, "id"))
+ Map<String, String> policyMap = execution.getVariable("arPolicyMap")
+ String policyId = policyMap.get(arId)
+ if (isBlank(policyId)) {
+ String msg = String.format("ERROR: updateNetworkPolicy: policyId not found. arId=%s", arId)
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ updatePolicyMaxBandwidthInAAI(execution, policyId, maxBw)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = String.format("ERROR: updateNetworkPolicy: exception: %s", ex.getMessage())
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
+ }
+ }
+
+
+ void createLogicalLinkForAllocatedResource(DelegateExecution execution,
+ String linkJsonStr, String cllId,
+ String allottedResourceId) {
+ try {
+ AAIResourceUri allottedResourceUri = serviceIntentUtils.buildAllottedResourceUri(execution,
+ cllId, allottedResourceId)
+
+ if (!getAAIClient().exists(allottedResourceUri)) {
+ logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}",
+ allottedResourceUri)
+ return
+ }
+
+ String linkId = jsonUtil.getJsonValue(linkJsonStr, "id")
+ if (isBlank(linkId)) {
+ linkId = "cll-" + UUID.randomUUID().toString()
+ }
+ logger.debug("createLogicalLinkForAllocatedResource: linkId=" + linkId)
+
+ String epA = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointA")
+ String epB = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointB")
+ String modelInvariantId = execution.getVariable("modelInvariantUuid")
+ String modelVersionId = execution.getVariable("modelUuid")
+
+ org.onap.aai.domain.yang.LogicalLink resource = new org.onap.aai.domain.yang.LogicalLink()
+ resource.setLinkId(linkId)
+ resource.setLinkName(epA)
+ resource.setLinkName2(epB)
+ resource.setLinkType("TsciConnectionLink")
+ resource.setInMaint(false)
+
+ //epA is link-name
+ AAIResourceUri logicalLinkUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA))
+ getAAIClient().create(logicalLinkUri, resource)
+
+ serviceIntentUtils.attachLogicalLinkToAllottedResource(execution, serviceIntentUtils.AAI_VERSION,
+ allottedResourceUri, epA);
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in DoModifyCllInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage()
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+
+
+ void preprocessSdncModifyCllRequest(DelegateExecution execution) {
+ def method = getClass().getSimpleName() + '.preprocessSdncModifyCllRequest(' +
+ 'execution=' + execution.getId() + ')'
+ def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
+ logger.trace('Entered ' + method)
+
+ try {
+ String serviceInstanceId = execution.getVariable("cllId")
+
+ String sdncRequest = serviceIntentUtils.buildSDNCRequest(execution, serviceInstanceId, "update")
+
+ execution.setVariable("CLL_SDNCRequest", sdncRequest)
+ logger.debug("Outgoing SDNCRequest is: \n" + sdncRequest)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception e) {
+ logger.debug("Exception Occurred Processing preprocessSdncModifyCllRequest. Exception is:\n" + e)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1002, "Error Occurred during preProcessSDNCActivateRequest Method:\n" + e.getMessage())
+ }
+ logger.trace("COMPLETED preprocessSdncModifyCllRequest Process")
+ }
+
+
+ void validateSDNCResponse(DelegateExecution execution, String response, String method) {
+ serviceIntentUtils.validateSDNCResponse(execution, response, method)
+ }
+
+
+ void updateAAIOrchStatus(DelegateExecution execution) {
+ logger.debug("Start updateAAIOrchStatus")
+ String cllId = execution.getVariable("cllId")
+ String orchStatus = execution.getVariable("orchestrationStatus")
+
+ try {
+ ServiceInstance si = new ServiceInstance()
+ si.setOrchestrationStatus(orchStatus)
+ AAIResourcesClient client = getAAIClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(cllId))
+ client.update(uri, si)
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ String msg = "Exception in CreateSliceService.updateAAIOrchStatus " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+
+ logger.debug("Finish updateAAIOrchStatus")
+ }
+
+ void prepareUpdateJobStatus(DelegateExecution execution,
+ String status,
+ String progress,
+ String statusDescription) {
+ String cllId = execution.getVariable("cllId")
+ String modelUuid = execution.getVariable("modelUuid")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = cllId
+ String operType = "MODIFY"
+
+ ResourceOperationStatus roStatus = serviceIntentUtils.buildRoStatus(modelUuid, cllId,
+ jobId, nsiId, operType, status, progress, statusDescription)
+
+ logger.debug("prepareUpdateJobStatus: roStatus={}", roStatus)
+ requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus)
+ }
+
+ boolean logicalLinkExists(DelegateExecution execution, String arIdStr, String linkJsonStr) {
+ if (isBlank(arIdStr)) {
+ logger.error("ERROR: logicalLinkExists: arIdStr is empty")
+ return false
+ }
+ if (isBlank(linkJsonStr)) {
+ logger.error("ERROR: logicalLinkExists: linkJsonStr is empty")
+ return false
+ }
+
+ Map<String, List<String>> logicalLinksMap = execution.getVariable("arLogicalLinkMap")
+ if (logicalLinksMap == null) {
+ logger.error("ERROR: logicalLinkExists: logicalLinksMap is null")
+ return false
+ }
+
+ List<String> logicalLinkNameList = logicalLinksMap.get(arIdStr)
+ if (logicalLinksMap == null) {
+ logger.error("ERROR: logicalLinkExists: logicalLinkNameList is null. arIdStr=" + arIdStr)
+ return false
+ }
+
+ String linkName = jsonUtil.getJsonValue(linkJsonStr, "transportEndpointA")
+ if (isBlank(linkName)) {
+ logger.error("ERROR: logicalLinkExists: epA is empty")
+ return false
+ }
+
+ return logicalLinkNameList.contains(linkName)
+ }
+}
+
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy
new file mode 100644
index 0000000000..df817ed90b
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifyServiceIntentInstance.groovy
@@ -0,0 +1,128 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, Wipro Limited.
+ #
+ # Licensed under the Apache License, Version 2.0 (the "License")
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
+ #
+ # http://www.apache.org/licenses/LICENSE-2.0
+ #
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
+import org.onap.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.RequestDBUtil
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+
+class ModifyServiceIntentInstance extends AbstractServiceTaskProcessor {
+ String Prefix="MCLL_"
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ RequestDBUtil requestDBUtil = new RequestDBUtil()
+ ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
+
+ private static final Logger logger = LoggerFactory.getLogger(ModifyServiceIntentInstance.class)
+
+ @Override
+ void preProcessRequest(DelegateExecution execution) {
+ logger.debug(Prefix + "preProcessRequest Start")
+ execution.setVariable("prefix", Prefix)
+ execution.setVariable("startTime", System.currentTimeMillis())
+ def msg
+ try {
+ // get request input
+ String subnetInstanceReq = execution.getVariable("bpmnRequest")
+ logger.debug(subnetInstanceReq)
+
+ serviceIntentUtils.setCommonExecutionVars(execution)
+
+ String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
+ if (isBlank(serviceInstanceID)) {
+ msg = "Input serviceInstanceID is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else
+ {
+ execution.setVariable("serviceInstanceID", serviceInstanceID)
+ }
+
+ String jobId = UUID.randomUUID().toString()
+ execution.setVariable("jobId", jobId)
+
+ } catch(BpmnError e) {
+ throw e
+ } catch(Exception ex) {
+ msg = "Exception in ModifyServiceIntentInstance.preProcessRequest " + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "preProcessRequest Exit")
+ }
+
+
+ /**
+ * create operation status in request db
+ *
+ * Init the Operation Status
+ */
+ def prepareInitOperationStatus = { DelegateExecution execution ->
+ logger.debug(Prefix + "prepareInitOperationStatus Start")
+
+ String siId = execution.getVariable("serviceInstanceID")
+ String jobId = execution.getVariable("jobId")
+ String nsiId = siId
+ String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId)
+ logger.debug("Generated new job for Service Instance serviceId:" + nsiId + "jobId:" + jobId)
+
+ ResourceOperationStatus initStatus = new ResourceOperationStatus()
+ initStatus.setServiceId(nsiId)
+ initStatus.setOperationId(jobId)
+ initStatus.setResourceTemplateUUID(modelUuid)
+ initStatus.setOperType("Modify")
+ requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
+
+ logger.debug(Prefix + "prepareInitOperationStatus Exit")
+ }
+
+
+
+ /**
+ * return sync response
+ */
+ def sendSyncResponse = { DelegateExecution execution ->
+ logger.debug(Prefix + "sendSyncResponse Start")
+ try {
+ String jobId = execution.getVariable("jobId")
+ String modifySyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
+ .trim().replaceAll(" ", "")
+ logger.debug("sendSyncResponse to APIH:" + "\n" + modifySyncResponse)
+ sendWorkflowResponse(execution, 202, modifySyncResponse)
+
+ execution.setVariable("sentSyncResponse", true)
+ } catch (Exception ex) {
+ String msg = "Exception in sendSyncResponse:" + ex.getMessage()
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug(Prefix + "sendSyncResponse Exit")
+ }
+
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy
new file mode 100644
index 0000000000..f60bfa1c47
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ServiceIntentUtils.groovy
@@ -0,0 +1,669 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.scripts
+
+import org.camunda.bpm.engine.delegate.BpmnError
+import org.camunda.bpm.engine.delegate.DelegateExecution
+import org.onap.aai.domain.yang.AllottedResources
+import org.onap.aai.domain.yang.LogicalLink
+import org.onap.aai.domain.yang.NetworkPolicy
+import org.onap.aai.domain.yang.Relationship
+import org.onap.aai.domain.yang.ServiceInstance
+import org.onap.aaiclient.client.aai.AAIResourcesClient
+import org.onap.aaiclient.client.aai.AAIVersion
+import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
+import org.onap.aaiclient.client.aai.entities.Relationships
+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.so.bpmn.common.scripts.ExceptionUtil
+import org.onap.so.bpmn.common.scripts.MsoUtils
+import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
+import org.onap.so.bpmn.core.RollbackData
+import org.onap.so.bpmn.core.UrnPropertiesReader
+import org.onap.so.bpmn.core.WorkflowException
+import org.onap.so.bpmn.core.json.JsonUtils
+import org.onap.so.db.request.beans.ResourceOperationStatus
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static org.apache.commons.lang3.StringUtils.isBlank
+import static org.apache.commons.lang3.StringUtils.isNotBlank
+
+class ServiceIntentUtils {
+ static final String AAI_VERSION = AAIVersion.LATEST
+ private static final Logger logger = LoggerFactory.getLogger(ServiceIntentUtils.class);
+
+
+ ExceptionUtil exceptionUtil = new ExceptionUtil()
+ JsonUtils jsonUtil = new JsonUtils()
+ MsoUtils msoUtils = new MsoUtils()
+ SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
+
+ ServiceIntentUtils() {
+ }
+
+
+ void setCommonExecutionVars(DelegateExecution execution) {
+ setCommonExecutionVars(execution, true)
+ }
+
+ void setCommonExecutionVars(DelegateExecution execution, boolean exceptionOnErr) {
+ def msg
+ try {
+ // get request input
+ String bpmnRequestStr = execution.getVariable("bpmnRequest")
+ logger.debug("Input Request: " + bpmnRequestStr)
+
+ String requestId = execution.getVariable("mso-request-id")
+ execution.setVariable("msoRequestId", requestId)
+ logger.debug("requestId: " + requestId)
+
+ //subscriberInfo
+ String globalSubscriberId = jsonUtil.getJsonValue(bpmnRequestStr, "globalSubscriberId")
+ if (isBlank(globalSubscriberId) && exceptionOnErr) {
+ msg = "Input globalSubscriberId' is null"
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("globalSubscriberId", globalSubscriberId)
+ }
+
+ String serviceType = jsonUtil.getJsonValue(bpmnRequestStr, "serviceType")
+ if (isBlank(serviceType) && exceptionOnErr) {
+ msg = "Input serviceType is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("serviceType", serviceType)
+ }
+
+ String servicename = jsonUtil.getJsonValue(bpmnRequestStr, "name")
+ if (isNotBlank(servicename)) {
+ execution.setVariable("servicename", servicename)
+ } else {
+ logger.debug("erviceIntentUtils.setCommonExecutionVars: servicename is NOT set")
+ }
+
+ //requestParameters, subscriptionServiceType is 5G
+ String subscriptionServiceType = jsonUtil.getJsonValue(bpmnRequestStr, "subscriptionServiceType")
+ if (isBlank(subscriptionServiceType)) {
+ msg = "Input subscriptionServiceType is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable("subscriptionServiceType", subscriptionServiceType)
+ }
+
+ String jobId = UUID.randomUUID().toString()
+ execution.setVariable("jobId", jobId)
+
+ String sliceParams = jsonUtil.getJsonValue(bpmnRequestStr, "additionalProperties")
+ execution.setVariable("serviceIntentParams", sliceParams)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in ServiceIntentUtils.setCommonExecutionVars: " + ex.getMessage()
+ logger.debug(msg)
+ if (exceptionOnErr) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ }
+ }
+
+ void setSdncCallbackUrl(DelegateExecution execution, boolean exceptionOnErr) {
+ setSdncCallbackUrl(execution, "sdncCallbackUrl", exceptionOnErr)
+ }
+
+ void setSdncCallbackUrl(DelegateExecution execution, String variableName, boolean exceptionOnErr) {
+ String sdncCallbackUrl = UrnPropertiesReader.getVariable('mso.workflow.sdncadapter.callback', execution)
+
+ if (isBlank(sdncCallbackUrl) && exceptionOnErr) {
+ String msg = "mso.workflow.sdncadapter.callback is null"
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ } else {
+ execution.setVariable(variableName, sdncCallbackUrl)
+ }
+ }
+
+ String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction) {
+ String reqAction
+ switch (svcAction) {
+ case "create":
+ reqAction = "CreateCloudLeasedLineInstance"
+ break
+ case "delete":
+ reqAction = "DeleteCloudLeasedLineInstance"
+ break
+ case "activate":
+ reqAction = "ActivateCloudLeasedLineInstance"
+ break
+ case "deactivate":
+ reqAction = "DeactivateCloudLeasedLineInstance"
+ break
+ case "update":
+ reqAction = "ModifyCloudLeasedLineInstance"
+ break
+ default:
+ reqAction = svcAction
+ }
+
+ buildSDNCRequest(execution, svcInstId, svcAction, reqAction)
+ }
+
+ String buildSDNCRequest(DelegateExecution execution, String svcInstId, String svcAction, String reqAction) {
+
+ String uuid = execution.getVariable('testReqId') // for junits
+ if (uuid == null) {
+ uuid = execution.getVariable("msoRequestId") + "-" + System.currentTimeMillis()
+ }
+
+ def callbackURL = execution.getVariable("sdncCallbackUrl")
+ def requestId = execution.getVariable("msoRequestId")
+ def serviceId = execution.getVariable("sliceServiceInstanceId")
+ def subServiceType = execution.getVariable("subscriptionServiceType")
+ def vnfType = execution.getVariable("serviceType")
+ def vnfName = execution.getVariable("sliceServiceInstanceName")
+ def tenantId = execution.getVariable("sliceServiceInstanceId")
+ def source = execution.getVariable("sliceServiceInstanceId")
+ def vnfId = execution.getVariable("sliceServiceInstanceId")
+ def cloudSiteId = execution.getVariable("sliceServiceInstanceId")
+ def serviceModelInfo = execution.getVariable("serviceModelInfo")
+ def vnfModelInfo = execution.getVariable("serviceModelInfo")
+ def globalSubscriberId = execution.getVariable("globalSubscriberId")
+
+ String vnfNameString = """<vnf-name>${MsoUtils.xmlEscape(vnfName)}</vnf-name>"""
+ String serviceEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(serviceModelInfo)
+ String vnfEcompModelInformation = sdncAdapterUtils.modelInfoToEcompModelInformation(vnfModelInfo)
+
+ String sdncVNFParamsXml = ""
+
+ if (execution.getVariable("vnfParamsExistFlag") == true) {
+ sdncVNFParamsXml = buildSDNCParamsXml(execution)
+ } else {
+ sdncVNFParamsXml = buildDefaultVnfInputParams(vnfId)
+ }
+
+ String sdncRequest =
+ """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.onap/so/request/types/v1"
+ xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
+ xmlns:sdncadapter="http://org.onap/workflow/sdnc/adapter/schema/v1">
+ <sdncadapter:RequestHeader>
+ <sdncadapter:RequestId>${MsoUtils.xmlEscape(uuid)}</sdncadapter:RequestId>
+ <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(svcInstId)}</sdncadapter:SvcInstanceId>
+ <sdncadapter:SvcAction>${MsoUtils.xmlEscape(svcAction)}</sdncadapter:SvcAction>
+ <sdncadapter:SvcOperation>vnf-topology-operation</sdncadapter:SvcOperation>
+ <sdncadapter:CallbackUrl>${MsoUtils.xmlEscape(callbackURL)}</sdncadapter:CallbackUrl>
+ <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
+ </sdncadapter:RequestHeader>
+ <sdncadapterworkflow:SDNCRequestData>
+ <request-information>
+ <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
+ <request-action>${MsoUtils.xmlEscape(reqAction)}</request-action>
+ <source>${MsoUtils.xmlEscape(source)}</source>
+ <notification-url/>
+ <order-number/>
+ <order-version/>
+ </request-information>
+ <service-information>
+ <service-id>${MsoUtils.xmlEscape(serviceId)}</service-id>
+ <subscription-service-type>${MsoUtils.xmlEscape(subServiceType)}</subscription-service-type>
+ ${serviceEcompModelInformation}
+ <service-instance-id>${MsoUtils.xmlEscape(svcInstId)}</service-instance-id>
+ <global-customer-id>${MsoUtils.xmlEscape(globalSubscriberId)}</global-customer-id>
+ </service-information>
+ <vnf-information>
+ <vnf-id>${MsoUtils.xmlEscape(vnfId)}</vnf-id>
+ <vnf-type>${MsoUtils.xmlEscape(vnfType)}</vnf-type>
+ ${vnfEcompModelInformation}
+ </vnf-information>
+ <vnf-request-input>
+ ${vnfNameString}
+ <tenant>${MsoUtils.xmlEscape(tenantId)}</tenant>
+ <aic-cloud-region>${MsoUtils.xmlEscape(cloudSiteId)}</aic-cloud-region>
+ ${sdncVNFParamsXml}
+ </vnf-request-input>
+ </sdncadapterworkflow:SDNCRequestData>
+ </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
+
+ logger.debug("sdncRequest: " + sdncRequest)
+ return sdncRequest
+ }
+
+
+ String buildDefaultVnfInputParams(String vnfName) {
+ String res =
+ """<vnf-input-parameters>
+ <param>
+ <name>${MsoUtils.xmlEscape(vnfName)}</name>
+ </param>
+ </vnf-input-parameters>"""
+
+ return res
+ }
+
+ String buildSDNCParamsXml(DelegateExecution execution) {
+ String params = ""
+ StringBuilder sb = new StringBuilder()
+ Map<String, String> paramsMap = execution.getVariable("TNNSSMF_vnfParamsMap")
+
+ for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
+ String paramsXml
+ String key = entry.getKey();
+ String value = entry.getValue()
+ paramsXml = """<${key}>$value</$key>"""
+ params = sb.append(paramsXml)
+ }
+ return params
+ }
+
+ void validateSDNCResponse(DelegateExecution execution, String response, String method) {
+ validateSDNCResponse(execution, response, method, true)
+ }
+
+ void validateSDNCResponse(DelegateExecution execution, String response, String method, boolean exceptionOnErr) {
+ logger.debug("STARTED ValidateSDNCResponse Process")
+
+ String msg
+
+ String prefix = execution.getVariable("prefix")
+ if (isBlank(prefix)) {
+ if (exceptionOnErr) {
+ msg = "validateSDNCResponse: prefix is null"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ return
+ }
+
+ WorkflowException workflowException = execution.getVariable("WorkflowException")
+ boolean successIndicator = execution.getVariable("SDNCA_SuccessIndicator")
+
+ logger.debug("ServiceIntentUtils.validateSDNCResponse: SDNCResponse: " + response)
+ logger.debug("ServiceIntentUtils.validateSDNCResponse: workflowException: " + workflowException)
+
+ sdncAdapterUtils.validateSDNCResponse(execution, response, workflowException, successIndicator)
+
+ String sdncResponse = response
+ if (execution.getVariable(prefix + 'sdncResponseSuccess') == true) {
+ logger.debug("Received a Good Response from SDNC Adapter for " + method + " SDNC Call. Response is: \n" + sdncResponse)
+ RollbackData rollbackData = execution.getVariable("rollbackData")
+ if (rollbackData == null) {
+ rollbackData = new RollbackData()
+ }
+
+ if (method.equals("allocate")) {
+ rollbackData.put("VNFMODULE", "rollbackSDNCRequestAllocate", "true")
+ } else if (method.equals("deallocate")) {
+ rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeallocate", "true")
+ } else if (method.equals("activate")) {
+ rollbackData.put("VNFMODULE", "rollbackSDNCRequestActivate", "true")
+ } else if (method.equals("deactivate")) {
+ rollbackData.put("VNFMODULE", "rollbackSDNCRequestDeactivate", "true")
+ } else if (method.equals("modify")) {
+ rollbackData.put("VNFMODULE", "rollbackSDNCRequestModify", "true")
+ }
+ execution.setVariable("rollbackData", rollbackData)
+ } else {
+ if (exceptionOnErr) {
+ msg = "ServiceIntentUtils.validateSDNCResponse: bad Response from SDNC Adapter for " + method + " SDNC Call."
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ }
+
+ logger.debug("COMPLETED ValidateSDNCResponse Process")
+ }
+
+ String getExecutionInputParams(DelegateExecution execution) {
+ String res = "\n msoRequestId=" + execution.getVariable("msoRequestId") +
+ "\n modelInvariantUuid=" + execution.getVariable("modelInvariantUuid") +
+ "\n modelUuid=" + execution.getVariable("modelUuid") +
+ "\n serviceInstanceID=" + execution.getVariable("serviceInstanceID") +
+ "\n operationType=" + execution.getVariable("operationType") +
+ "\n globalSubscriberId=" + execution.getVariable("globalSubscriberId") +
+ "\n dummyServiceId=" + execution.getVariable("dummyServiceId") +
+ "\n nsiId=" + execution.getVariable("nsiId") +
+ "\n serviceType=" + execution.getVariable("serviceType") +
+ "\n subscriptionServiceType=" + execution.getVariable("subscriptionServiceType") +
+ "\n jobId=" + execution.getVariable("jobId") +
+ "\n serviceIntentParams=" + execution.getVariable("serviceIntentParams") +
+ "\n servicename=" + execution.getVariable("servicename")
+
+ return res
+ }
+
+ String getFirstSnssaiFromSliceProfile(String sliceProfileStr) {
+ String snssaiListStr = jsonUtil.getJsonValue(sliceProfileStr, "snssaiList")
+ String snssai = jsonUtil.StringArrayToList(snssaiListStr).get(0)
+
+ return snssai
+ }
+
+ String getFirstPlmnIdFromSliceProfile(String sliceProfileStr) {
+ String plmnListStr = jsonUtil.getJsonValue(sliceProfileStr, "plmnIdList")
+ String res = jsonUtil.StringArrayToList(plmnListStr).get(0)
+
+ return res
+ }
+
+ void createRelationShipInAAI(DelegateExecution execution, AAIResourceUri uri, Relationship relationship) {
+ logger.debug("createRelationShipInAAI Start")
+ String msg
+ AAIResourcesClient client = new AAIResourcesClient()
+ try {
+ if (!client.exists(uri)) {
+ logger.info("ERROR: createRelationShipInAAI: not exist: uri={}", uri)
+ return
+ }
+ AAIResourceUri from = ((AAIResourceUri) (uri.clone())).relationshipAPI()
+ client.create(from, relationship)
+
+ } catch (BpmnError e) {
+ throw e
+ } catch (Exception ex) {
+ msg = "Exception in createRelationShipInAAI. " + ex.getMessage()
+ logger.info(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
+ }
+ logger.debug("createRelationShipInAAI Exit")
+ }
+
+ void attachLogicalLinkToAllottedResource(DelegateExecution execution, String aaiVersion, AAIResourceUri arUri,
+ String logicalLinkId) {
+
+ String toLink = "aai/${aaiVersion}/network/logical-links/logical-link/${logicalLinkId}"
+
+ Relationship relationship = new Relationship()
+ relationship.setRelatedLink(toLink)
+ relationship.setRelatedTo("logical-link")
+ relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf")
+
+ createRelationShipInAAI(execution, arUri, relationship)
+ }
+
+ void attachNetworkPolicyToAllottedResource(DelegateExecution execution, String aaiVersion,
+ AAIResourceUri aaiResourceUri, String networkPolicyId) {
+
+ String toLink = "aai/${aaiVersion}/network/network-policies/network-policy/${networkPolicyId}"
+
+ Relationship relationship = new Relationship()
+ relationship.setRelatedLink(toLink)
+ relationship.setRelatedTo("network-policy")
+ relationship.setRelationshipLabel("org.onap.relationships.inventory.Uses")
+
+ createRelationShipInAAI(execution, aaiResourceUri, relationship)
+
+ }
+
+ ResourceOperationStatus buildRoStatus(String nsstId,
+ String nssiId,
+ String jobId,
+ String nsiId,
+ String action,
+ String status,
+ String progress,
+ String statusDescription) {
+ ResourceOperationStatus roStatus = new ResourceOperationStatus()
+ roStatus.setResourceTemplateUUID(nsstId)
+ roStatus.setResourceInstanceID(nssiId)
+ roStatus.setServiceId(nsiId)
+ roStatus.setOperationId(jobId)
+ roStatus.setOperType(action)
+ roStatus.setProgress(progress)
+ roStatus.setStatus(status)
+ roStatus.setStatusDescription(statusDescription)
+
+ return roStatus
+ }
+
+
+ void setEnableSdncConfig(DelegateExecution execution) {
+ String enableSdnc = UrnPropertiesReader.getVariable(
+ "mso.workflow.TnNssmf.enableSDNCNetworkConfig")
+ if (isBlank(enableSdnc)) {
+ logger.debug("mso.workflow.TnNssmf.enableSDNCNetworkConfig is undefined, so use default value (true)")
+ enableSdnc = "true"
+ }
+
+ logger.debug("setEnableSdncConfig: enableSdnc=" + enableSdnc)
+
+ execution.setVariable("enableSdnc", enableSdnc)
+ }
+
+ String setExecVarFromJsonIfExists(DelegateExecution execution,
+ String jsonStr, String jsonKey, String varName) {
+ return setExecVarFromJsonStr(execution, jsonStr, jsonKey, varName, false)
+ }
+
+ String setExecVarFromJsonStr(DelegateExecution execution,
+ String jsonStr, String jsonKey, String varName,
+ boolean exceptionOnErr) {
+ String msg = ""
+ String valueStr = jsonUtil.getJsonValue(jsonStr, jsonKey)
+ if (isBlank(valueStr)) {
+ if (exceptionOnErr) {
+ msg = "cannot find " + jsonKey + " in " + jsonStr
+ logger.debug(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
+ }
+ } else {
+ execution.setVariable(varName, valueStr)
+ }
+
+ return valueStr
+ }
+
+ ServiceInstance getServiceInstanceFromAai(String serviceInstanceId) {
+ if (isBlank(serviceInstanceId)) {
+ logger.error("ERROR: getServiceInstanceFromAai: serviceInstanceId is blank")
+ return null
+ }
+
+ ServiceInstance nssi = null
+ AAIResourcesClient client = new AAIResourcesClient()
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.Types.SERVICE_INSTANCE
+ .getFragment(serviceInstanceId))
+ Optional<ServiceInstance> nssiOpt = client.get(ServiceInstance.class, uri)
+
+ if (nssiOpt.isPresent()) {
+ nssi = nssiOpt.get()
+ return nssi
+ } else {
+ String msg = String.format("ERROR: getServiceInstanceFromAai: NSSI %s not found in AAI", serviceInstanceId)
+ logger.error(msg)
+ }
+
+ return nssi;
+ }
+
+ String getModelUuidFromServiceInstance(String serviceInstanceId) {
+ ServiceInstance si = getServiceInstanceFromAai(serviceInstanceId)
+ if (si == null) {
+ String msg = String.format("ERROR: getModelUuidFromServiceInstance: getServiceInstanceFromAai() failed. " +
+ "serviceInstanceId=%s", serviceInstanceId)
+ logger.error(msg)
+ return null
+ }
+
+ return si.getModelVersionId()
+ }
+
+ AAIResourceUri buildNetworkPolicyUri(String networkPolicyId) {
+ AAIResourceUri networkPolicyUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicy(networkPolicyId))
+
+ return networkPolicyUri
+ }
+
+ AAIResourceUri buildAllottedResourceUri(DelegateExecution execution, String serviceInstanceId,
+ String allottedResourceId) {
+
+ AAIResourceUri allottedResourceUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(serviceInstanceId)
+ .allottedResource(allottedResourceId))
+
+ return allottedResourceUri
+ }
+
+ AAIPluralResourceUri buildAllottedResourcesUri(DelegateExecution execution, String serviceInstanceId) {
+
+ AAIPluralResourceUri arsUri =
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business()
+ .customer(execution.getVariable("globalSubscriberId"))
+ .serviceSubscription(execution.getVariable("subscriptionServiceType"))
+ .serviceInstance(serviceInstanceId)
+ .allottedResources())
+
+ return arsUri
+ }
+
+ AllottedResources getAllottedResourcesFromAai(DelegateExecution execution, String serviceInstanceId, boolean exceptionOnErr) {
+ AllottedResources res
+ try {
+ AAIResourcesClient client = new AAIResourcesClient()
+
+ AAIPluralResourceUri arsUri = buildAllottedResourcesUri(execution, serviceInstanceId)
+
+ //AAIResultWrapper wrapperAllotted = client.get(arsUri, NotFoundException.class)
+ //Optional<AllottedResources> allAllotted = wrapperAllotted.asBean(AllottedResources.class)
+ //AllottedResources allottedResources = allAllotted.get()
+
+ Optional<AllottedResources> arsOpt = client.get(AllottedResources.class, arsUri)
+ if (arsOpt.isPresent()) {
+ res = arsOpt.get()
+ return res
+ } else {
+ String msg = String.format("ERROR: getAllottedResourcesFromAai: ars not found. nssiId=%s", serviceInstanceId)
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ } catch (BpmnError e) {
+ if (exceptionOnErr) {
+ throw e;
+ }
+ } catch (Exception ex) {
+ if (exceptionOnErr) {
+ String msg = String.format("ERROR: getAllottedResourcesFromAai: %s", ex.getMessage())
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+
+ return res
+ }
+
+ String getPolicyIdFromAr(DelegateExecution execution, String serviceInstanceId,
+ String arId, boolean exceptionOnErr) {
+ String res
+ try {
+ AAIResourcesClient client = new AAIResourcesClient()
+
+ AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
+ List<AAIResourceUri> policyUriList = getRelationshipUriListInAai(execution, arUri,
+ AAIFluentTypeBuilder.Types.NETWORK_POLICY, exceptionOnErr)
+ for (AAIResourceUri policyUri : policyUriList) {
+ Optional<NetworkPolicy> policyOpt = client.get(NetworkPolicy.class, policyUri)
+ if (policyOpt.isPresent()) {
+ NetworkPolicy policy = policyOpt.get()
+ return policy.getNetworkPolicyId()
+ } else {
+ String msg = String.format("ERROR: getPolicyIdFromAr: arUri=%s", policyUri)
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+ } catch (BpmnError e) {
+ if (exceptionOnErr) {
+ throw e;
+ }
+ } catch (Exception ex) {
+ if (exceptionOnErr) {
+ String msg = String.format("ERROR: getPolicyIdFromAr: %s", ex.getMessage())
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+
+ return res
+ }
+
+
+ List<AAIResourceUri> getRelationshipUriListInAai(DelegateExecution execution,
+ AAIResourceUri uri,
+ Object info,
+ boolean exceptionOnErr) {
+ AAIResourcesClient client = new AAIResourcesClient()
+ AAIResultWrapper wrapper = client.get(uri);
+ Optional<Relationships> relationships = wrapper.getRelationships()
+ if (relationships.isPresent()) {
+ return relationships.get().getRelatedUris(info)
+ } else {
+ if (exceptionOnErr) {
+ String msg = "ERROR: getRelationshipUriListInAai: No relationship found"
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+
+ return null
+ }
+
+ List<String> getLogicalLinkNamesFromAr(DelegateExecution execution, String serviceInstanceId,
+ String arId, boolean exceptionOnErr) {
+ List<String> res = new ArrayList<>()
+ try {
+ AAIResourcesClient client = new AAIResourcesClient()
+
+ AAIResourceUri arUri = buildAllottedResourceUri(execution, serviceInstanceId, arId)
+ List<AAIResourceUri> logicalLinkUriList = getRelationshipUriListInAai(execution, arUri,
+ AAIFluentTypeBuilder.Types.LOGICAL_LINK, exceptionOnErr)
+ for (AAIResourceUri logicalLinkUri : logicalLinkUriList) {
+ Optional<LogicalLink> logicalLinkOpt = client.get(LogicalLink.class, logicalLinkUri)
+ if (logicalLinkOpt.isPresent()) {
+ LogicalLink logicalLink = logicalLinkOpt.get()
+ res.add(logicalLink.getLinkName())
+ } else {
+ String msg = String.format("ERROR: getLogicalLinkNamesFromAr: logicalLinkUri=%s", logicalLinkUri)
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+ } catch (BpmnError e) {
+ if (exceptionOnErr) {
+ throw e;
+ }
+ } catch (Exception ex) {
+ if (exceptionOnErr) {
+ String msg = String.format("ERROR: getLogicalLinkNamesFromAr: %s", ex.getMessage())
+ logger.error(msg)
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
+ }
+ }
+
+ return res
+ }
+} \ No newline at end of file