From 48c44edbec6adf3a9b5b49f147cb026b8251ce7b Mon Sep 17 00:00:00 2001 From: Priyadharshini Date: Thu, 20 Aug 2020 06:06:49 -0700 Subject: Implement Workflows to handle NSSMF Common functionalities Issue-ID: SO-3190 Signed-off-by: Priyadharshini Change-Id: I38ce91415fc5ced083e017ed4306873d17d5fa24 --- .../so/bpmn/common/scripts/RequestDBUtil.groovy | 97 +++++++++ .../scripts/ActivateSliceSubnet.groovy | 181 +++++++++++++++++ .../scripts/AllocateSliceSubnet.groovy | 190 +++++++++++++++++ .../scripts/DeAllocateSliceSubnet.groovy | 170 ++++++++++++++++ .../scripts/ModifySliceSubnet.groovy | 173 ++++++++++++++++ .../scripts/ActivateSliceSubnetTest.groovy | 68 +++++++ .../scripts/AllocateSliceSubnetTest.groovy | 135 +++++++++++++ .../scripts/DeAllocateSliceSubnetTest.groovy | 72 +++++++ .../scripts/ModifySliceSubnetTest.groovy | 72 +++++++ .../resources/process/ActivateSliceSubnet.bpmn | 224 +++++++++++++++++++++ .../resources/process/AllocateSliceSubnet.bpmn | 219 ++++++++++++++++++++ .../resources/process/DeAllocateSliceSubnet.bpmn | 224 +++++++++++++++++++++ .../main/resources/process/ModifySliceSubnet.bpmn | 224 +++++++++++++++++++++ 13 files changed, 2049 insertions(+) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnet.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnet.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnet.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnet.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnetTest.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnetTest.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnetTest.groovy create mode 100644 bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnetTest.groovy create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSliceSubnet.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeAllocateSliceSubnet.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifySliceSubnet.bpmn (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy index b35042e3c0..23dfdce753 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/RequestDBUtil.groovy @@ -22,6 +22,7 @@ package org.onap.so.bpmn.common.scripts import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.db.request.beans.OperationStatus +import org.onap.so.db.request.beans.ResourceOperationStatus import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.web.util.UriUtils @@ -116,4 +117,100 @@ class RequestDBUtil { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) } } + + /** + * init resource operation status in requestDB + * @param execution + * @param resourceoperationStatus + */ + void prepareInitResourceOperationStatus(DelegateExecution execution, final ResourceOperationStatus resourceoperationStatus){ + logger.debug("start prepareinitResourceOperationStatus") + try{ + def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution) + execution.setVariable("dbAdapterEndpoint", dbAdapterEndpoint) + logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint) + + String serviceId = resourceoperationStatus.getServiceId() + serviceId = UriUtils.encode(serviceId,"UTF-8") + String operationId = resourceoperationStatus.getOperationId() + String resourceTemplateUUID = resourceoperationStatus.getResourceTemplateUUID() + String operType = resourceoperationStatus.getOperType() + + String payload = + """ + + + + ${MsoUtils.xmlEscape(serviceId)} + ${MsoUtils.xmlEscape(operationId)} + ${MsoUtils.xmlEscape(operType)} + ${MsoUtils.xmlEscape(resourceTemplateUUID)} + + + + """ + execution.setVariable("initResourceOperationStatus", payload) + + }catch(any){ + String exceptionMessage = "Prepare init ResourceOperationStatus failed. cause - " + any.getMessage() + logger.debug(exceptionMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + logger.trace("finished init ResourceOperationStatus") + } + + /** + * update resource operation status in requestDB + * @param execution + * @param resourceoperationStatus + */ + void prepareUpdateResourceOperationStatus(DelegateExecution execution, final ResourceOperationStatus resourceoperationStatus){ + logger.debug("start prepareUpdateResourceOperationStatus") + try{ + def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution) + execution.setVariable("dbAdapterEndpoint", dbAdapterEndpoint) + logger.debug("DB Adapter Endpoint is: " + dbAdapterEndpoint) + + String serviceId = resourceoperationStatus.getServiceId() + serviceId = UriUtils.encode(serviceId,"UTF-8") + String operationId = resourceoperationStatus.getOperationId() + String resourceTemplateUUID = resourceoperationStatus.getResourceTemplateUUID() + String operType = resourceoperationStatus.getOperType() + String resourceInstanceID = resourceoperationStatus.getResourceInstanceID() + String jobId = resourceoperationStatus.getJobId() + String status = resourceoperationStatus.getStatus() + String progress = resourceoperationStatus.getProgress() + String errorCode = resourceoperationStatus.getErrorCode()?: "" + String statusDescription = resourceoperationStatus.getStatusDescription()?: "" + + String payload = + """ + + + + ${MsoUtils.xmlEscape(serviceId)} + ${MsoUtils.xmlEscape(operationId)} + ${MsoUtils.xmlEscape(resourceTemplateUUID)} + ${MsoUtils.xmlEscape(operType)} + ${MsoUtils.xmlEscape(jobId)} + ${MsoUtils.xmlEscape(status)} + ${MsoUtils.xmlEscape(progress)} + ${MsoUtils.xmlEscape(errorCode)} + ${MsoUtils.xmlEscape(statusDescription)} + + + + """ + execution.setVariable("updateResourceOperationStatus", payload) + + }catch(any){ + String exceptionMessage = "Prepare update ResourceOperationStatus failed. cause - " + any.getMessage() + logger.debug(exceptionMessage) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage) + } + logger.trace("finished update ResourceOperationStatus") + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnet.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnet.groovy new file mode 100644 index 0000000000..c7fe7e36a6 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnet.groovy @@ -0,0 +1,181 @@ +/* + * ============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 ActivateSliceSubnet extends AbstractServiceTaskProcessor { + String Prefix="ActSS" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + + private static final Logger logger = LoggerFactory.getLogger(ActivateSliceSubnet.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) + + String requestId = execution.getVariable("mso-request-id") + execution.setVariable("msoRequestId", requestId) + logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId) + + //subscriberInfo + String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId") + if (isBlank(globalSubscriberId)) { + msg = "Input globalSubscriberId' is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("globalSubscriberId", globalSubscriberId) + } + + //NSSI ID + 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 nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiId") + if (isBlank(nsiId)) { + msg = "Input nsiId is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("nsiId", nsiId) + } + String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType") + if (isBlank(networkType)) { + msg = "Input networkType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("networkType", networkType.toUpperCase()) + } + + //requestParameters, subscriptionServiceType is 5G + String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType") + if (isBlank(subscriptionServiceType)) { + msg = "Input subscriptionServiceType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("subscriptionServiceType", subscriptionServiceType) + } + + //operationType = deactivateInstance/activateInstance + String operationType = execution.getVariable("requestAction") + if (isBlank(operationType)) { + msg = "Input operationType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("operationType", operationType) + } + + String jobId = UUID.randomUUID().toString() + execution.setVariable("jobId", jobId) + + String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties") + execution.setVariable("sliceParams", sliceParams) + + } catch(BpmnError e) { + throw e + } catch(Exception ex) { + msg = "Exception in ActivateSliceSubnet.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 serviceId = execution.getVariable("serviceInstanceID") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + String operationType = execution.getVariable("operationType") + logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(serviceId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(nsiId) + initStatus.setOperType(operationType) + 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 activateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""" + .trim().replaceAll(" ", "") + + logger.debug("sendSyncResponse to APIH:" + "\n" + activateSyncResponse) + sendWorkflowResponse(execution, 202, activateSyncResponse) + + 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/AllocateSliceSubnet.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnet.groovy new file mode 100644 index 0000000000..5a7722d679 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnet.groovy @@ -0,0 +1,190 @@ +/* + * ============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 AllocateSliceSubnet extends AbstractServiceTaskProcessor { + + String Prefix="ASS_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + RequestDBUtil requestDBUtil = new RequestDBUtil() + JsonUtils jsonUtil = new JsonUtils() + private static final Logger logger = LoggerFactory.getLogger(AllocateSliceSubnet.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) + + String requestId = execution.getVariable("mso-request-id") + execution.setVariable("msoRequestId", requestId) + logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId) + + //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) + + + //subscriberInfo + String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId") + if (isBlank(globalSubscriberId)) { + msg = "Input globalSubscriberId' is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("globalSubscriberId", globalSubscriberId) + } + String dummyServiceId = new UUID(0,0).toString(); + execution.setVariable("dummyServiceId", dummyServiceId) + logger.debug("dummyServiceId: " + dummyServiceId) + String servicename = jsonUtil.getJsonValue(subnetInstanceReq, "name") + execution.setVariable("servicename", servicename) + + String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiInfo.nsiId") + if (isBlank(nsiId)) { + msg = "Input nsiId is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("nsiId", nsiId) + } + + String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType") + if (isBlank(networkType)) { + msg = "Input networkType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("networkType", networkType.toUpperCase()) + } + + //requestParameters, subscriptionServiceType is 5G + String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "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(subnetInstanceReq, "additionalProperties") + execution.setVariable("sliceParams", sliceParams) + + } catch(BpmnError e) { + throw e + } catch(Exception ex) { + msg = "Exception in AllocateSliceSubnet.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 serviceId = execution.getVariable("dummyServiceId") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(serviceId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(nsiId) + initStatus.setOperType("Allocate") + 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/DeAllocateSliceSubnet.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnet.groovy new file mode 100644 index 0000000000..964baa7a9d --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnet.groovy @@ -0,0 +1,170 @@ +/*- + * ============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 DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { + String Prefix="DeASS_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + + private static final Logger logger = LoggerFactory.getLogger(DeAllocateSliceSubnet.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) + + String requestId = execution.getVariable("mso-request-id") + execution.setVariable("msoRequestId", requestId) + logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId) + + //subscriberInfo + String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId") + if (isBlank(globalSubscriberId)) { + msg = "Input globalSubscriberId' is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("globalSubscriberId", globalSubscriberId) + } + + //NSSI ID + 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 nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiId") + if (isBlank(nsiId)) { + msg = "Input nsiId is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("nsiId", nsiId) + } + + String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType") + if (isBlank(networkType)) { + msg = "Input networkType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("networkType", networkType.toUpperCase()) + } + + //requestParameters, subscriptionServiceType is 5G + String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "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(subnetInstanceReq, "additionalProperties") + execution.setVariable("sliceParams", sliceParams) + + } 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 serviceId = execution.getVariable("serviceInstanceID") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(serviceId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(nsiId) + initStatus.setOperType("Deallocate") + 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/ModifySliceSubnet.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnet.groovy new file mode 100644 index 0000000000..47489b7b84 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnet.groovy @@ -0,0 +1,173 @@ +/* + * ============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 ModifySliceSubnet extends AbstractServiceTaskProcessor { + String Prefix="MSS_" + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + RequestDBUtil requestDBUtil = new RequestDBUtil() + + private static final Logger logger = LoggerFactory.getLogger(ModifySliceSubnet.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) + + String requestId = execution.getVariable("mso-request-id") + execution.setVariable("msoRequestId", requestId) + logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId) + + //subscriberInfo + String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId") + if (isBlank(globalSubscriberId)) { + msg = "Input globalSubscriberId' is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + execution.setVariable("globalSubscriberId", globalSubscriberId) + } + + //NSSI Info + 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 servicename = jsonUtil.getJsonValue(subnetInstanceReq, "name") + execution.setVariable("servicename", servicename) + + String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiInfo.nsiId") + if (isBlank(nsiId)) { + msg = "Input nsiId is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("nsiId", nsiId) + } + + String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType") + if (isBlank(networkType)) { + msg = "Input networkType is null" + logger.debug(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else + { + execution.setVariable("networkType", networkType.toUpperCase()) + } + + //requestParameters, subscriptionServiceType is 5G + String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "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(subnetInstanceReq, "additionalProperties") + execution.setVariable("sliceParams", sliceParams) + + } catch(BpmnError e) { + throw e + } catch(Exception ex) { + msg = "Exception in ModifySliceSubnet.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 serviceId = execution.getVariable("serviceInstanceID") + String jobId = execution.getVariable("jobId") + String nsiId = execution.getVariable("nsiId") + logger.debug("Generated new job for Service Instance serviceId:" + serviceId + "jobId:" + jobId) + + ResourceOperationStatus initStatus = new ResourceOperationStatus() + initStatus.setServiceId(serviceId) + initStatus.setOperationId(jobId) + initStatus.setResourceTemplateUUID(nsiId) + 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/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnetTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnetTest.groovy new file mode 100644 index 0000000000..adb83e7714 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ActivateSliceSubnetTest.groovy @@ -0,0 +1,68 @@ +package org.onap.so.bpmn.infrastructure.scripts + +import static org.junit.Assert.* + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor + +class ActivateSliceSubnetTest { + @Before + void init() throws IOException { + super.init("ActivateSliceSubnet") + } + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testPreProcessRequest() { + when(mockExecution.getVariable("bpmnRequest")).thenReturn(""" + { + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX ", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + } +} +""".replaceAll("\\s+", "")) + when(mockExecution.getVariable("mso-request-id")).thenReturn("edb08d97-e0f9-4c71-840a-72080d7be42e") + when(mockExecution.getVariable("requestAction")).thenReturn("activateInstance") + ActivateSliceSubnet sliceSubnet = new ActivateSliceSubnet() + sliceSubnet.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture() as String, captor.capture()) + List values = captor.getAllValues() + assertNotNull(values) + } + + @Test + void testPrepareInitOperationStatus() { + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("54321") + when(mockExecution.getVariable("jobId")).thenReturn("54321") + when(mockExecution.getVariable("nsiId")).thenReturn("11111") + ActivateSliceSubnet sliceSubnet = new ActivateSliceSubnet() + sliceSubnet.prepareInitOperationStatus(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("initResourceOperationStatus"), captor.capture()) + String res = captor.getValue() + assertNotNull(res) + } + + + @Test + void testSendSyncResponse() { + when(mockExecution.getVariable("jobId")).thenReturn("123456") + ActivateSliceSubnet sliceSubnet = new ActivateSliceSubnet() + sliceSubnet.sendSyncResponse(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture()) + def updateVolumeGroupRequest = captor.getValue() + assertEquals(updateVolumeGroupRequest, true) + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnetTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnetTest.groovy new file mode 100644 index 0000000000..a9b4e095e7 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/AllocateSliceSubnetTest.groovy @@ -0,0 +1,135 @@ +/* + * ============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 static org.junit.Assert.* +import static org.mockito.Mockito.times +import static org.mockito.Mockito.when + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor +import org.mockito.Mockito +import org.onap.so.bpmn.common.scripts.MsoGroovyTest + + +class AllocateSliceSubnetTest extends MsoGroovyTest { + + @Before + void init() throws IOException { + super.init("AllocateSliceSubnet") + } + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testPreProcessRequest() { + when(mockExecution.getVariable("serviceInstanceID")).thenReturn("12345") + when(mockExecution.getVariable("bpmnRequest")).thenReturn(""" + { + "name": "eMBB-001", + "modelInvariantUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX", + "modelUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX-UUID", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "networkType": "an/cn/tn", + "additionalProperties": { + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + "perfReqEmbbList ": [ + { + "activityFactor": 50 + } + ] + }, + "maxNumberofUEs": 200, + "coverageAreaTAList": [ + "1", + "2", + "3", + "4" + ], + "latency": 2, + "resourceSharingLevel": "non-shared" + }, + "endPoints": [ + { + "nodeId": "", + "additionalInfo": { + "xxx": "xxx" + } + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + } +} +""".replaceAll("\\s+", "")) + when(mockExecution.getVariable("mso-request-id")).thenReturn("edb08d97-e0f9-4c71-840a-72080d7be42e") + AllocateSliceSubnet sliceSubnet = new AllocateSliceSubnet() + sliceSubnet.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture() as String, captor.capture()) + List values = captor.getAllValues() + assertNotNull(values) + } + + @Test + void testPrepareInitOperationStatus() { + + when(mockExecution.getVariable("dummyServiceId")).thenReturn("12345") + when(mockExecution.getVariable("jobId")).thenReturn("54321") + + when(mockExecution.getVariable("nsiId")).thenReturn("11111") + + AllocateSliceSubnet sliceSubnet = new AllocateSliceSubnet() + + sliceSubnet.prepareInitOperationStatus(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("initResourceOperationStatus"), captor.capture()) + String res = captor.getValue() + assertNotNull(res) + } + + + @Test + void testSendSyncResponse() { + when(mockExecution.getVariable("jobId")).thenReturn("123456") + AllocateSliceSubnet sliceSubnet = new AllocateSliceSubnet() + sliceSubnet.sendSyncResponse(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture()) + def updateVolumeGroupRequest = captor.getValue() + assertEquals(updateVolumeGroupRequest, true) + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnetTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnetTest.groovy new file mode 100644 index 0000000000..a254a90576 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DeAllocateSliceSubnetTest.groovy @@ -0,0 +1,72 @@ +package org.onap.so.bpmn.infrastructure.scripts + +import static org.junit.Assert.* + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor + +class DeAllocateSliceSubnetTest { + + @Before + void init() throws IOException { + super.init("DeAllocateSliceSubnet") + } + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testPreProcessRequest() { + when(mockExecution.getVariable("bpmnRequest")).thenReturn(""" + { + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX ", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "snssaiList": [ + "001-100001" + ], + "scriptName": "AN1", + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + } +} +""".replaceAll("\\s+", "")) + when(mockExecution.getVariable("mso-request-id")).thenReturn("edb08d97-e0f9-4c71-840a-72080d7be42e") + DeAllocateSliceSubnet sliceSubnet = new DeAllocateSliceSubnet() + sliceSubnet.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture() as String, captor.capture()) + List values = captor.getAllValues() + assertNotNull(values) + } + + @Test + void testPrepareInitOperationStatus() { + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("54321") + when(mockExecution.getVariable("jobId")).thenReturn("54321") + when(mockExecution.getVariable("nsiId")).thenReturn("11111") + DeAllocateSliceSubnet sliceSubnet = new DeAllocateSliceSubnet() + sliceSubnet.prepareInitOperationStatus(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("initResourceOperationStatus"), captor.capture()) + String res = captor.getValue() + assertNotNull(res) + } + + + @Test + void testSendSyncResponse() { + when(mockExecution.getVariable("jobId")).thenReturn("123456") + DeAllocateSliceSubnet sliceSubnet = new DeAllocateSliceSubnet() + sliceSubnet.sendSyncResponse(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture()) + def updateVolumeGroupRequest = captor.getValue() + assertEquals(updateVolumeGroupRequest, true) + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnetTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnetTest.groovy new file mode 100644 index 0000000000..b7515a487c --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/ModifySliceSubnetTest.groovy @@ -0,0 +1,72 @@ +package org.onap.so.bpmn.infrastructure.scripts + +import static org.junit.Assert.* + +import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity +import org.junit.Before +import org.junit.Test +import org.mockito.ArgumentCaptor +import org.mockito.Captor + +class ModifySliceSubnetTest { + @Before + void init() throws IOException { + super.init("ModifySliceSubnet") + } + + @Captor + static ArgumentCaptor captor = ArgumentCaptor.forClass(ExecutionEntity.class) + + @Test + public void testPreProcessRequest() { + when(mockExecution.getVariable("bpmnRequest")).thenReturn(""" + { + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX ", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + } +} +""".replaceAll("\\s+", "")) + when(mockExecution.getVariable("mso-request-id")).thenReturn("edb08d97-e0f9-4c71-840a-72080d7be42e") + ModifySliceSubnet sliceSubnet = new ModifySliceSubnet() + sliceSubnet.preProcessRequest(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(captor.capture() as String, captor.capture()) + List values = captor.getAllValues() + assertNotNull(values) + } + + @Test + void testPrepareInitOperationStatus() { + when(mockExecution.getVariable("serviceInstanceId")).thenReturn("54321") + when(mockExecution.getVariable("jobId")).thenReturn("54321") + when(mockExecution.getVariable("nsiId")).thenReturn("11111") + ModifySliceSubnet sliceSubnet = new ModifySliceSubnet() + sliceSubnet.prepareInitOperationStatus(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("initResourceOperationStatus"), captor.capture()) + String res = captor.getValue() + assertNotNull(res) + } + + + @Test + void testSendSyncResponse() { + when(mockExecution.getVariable("jobId")).thenReturn("123456") + ModifySliceSubnet sliceSubnet = new ModifySliceSubnet() + sliceSubnet.sendSyncResponse(mockExecution) + Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture()) + def updateVolumeGroupRequest = captor.getValue() + assertEquals(updateVolumeGroupRequest, true) + } + + @Test + public void test() { + fail("Not yet implemented") + } + +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSliceSubnet.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSliceSubnet.bpmn new file mode 100644 index 0000000000..a2b7f4f67a --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ActivateSliceSubnet.bpmn @@ -0,0 +1,224 @@ + + + + + Flow_1rnck9o + + + Flow_1rnck9o + Flow_1ruhu5s + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ActivateSliceSubnet() +nss.preProcessRequest(execution) + + + Flow_1da78f4 + Flow_17ebcpc + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ActivateSliceSubnet() +nss.sendSyncResponse(execution) + + + Flow_17ebcpc + Flow_1t9x0sg + Flow_1q1kc3c + Flow_0ptiwv3 + + + Flow_0krl0oq + Flow_0wwue07 + Flow_115ylm7 + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_0wjhvtf + Flow_1da78f4 + + + + + + #{execution.getVariable("networkType") == "CN"} + + + #{execution.getVariable("networkType") == "TN"} + + + + + + + + + + + + + + + Flow_0ptiwv3 + Flow_0krl0oq + + + #{execution.getVariable("networkType") == "AN"} + + + + + + + + + + + + + + + + Flow_1t9x0sg + Flow_0wwue07 + + + + + + + + + + + + + + + + Flow_1q1kc3c + Flow_115ylm7 + + + + Flow_1ruhu5s + Flow_0wjhvtf + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ActivateSliceSubnet() +nss.prepareInitOperationStatus(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn new file mode 100644 index 0000000000..450faaebca --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn @@ -0,0 +1,219 @@ + + + + + Flow_0cmaj9d + + + Flow_0cmaj9d + Flow_0ou7wr9 + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new AllocateSliceSubnet() +nss.preProcessRequest(execution) + + + Flow_0ayd6dj + Flow_0m5n6md + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new AllocateSliceSubnet() +nss.sendSyncResponse(execution) + + + Flow_0m5n6md + Flow_1fij4ds + Flow_0g7721r + Flow_1kk0exp + + + Flow_09b50tn + Flow_189zwjw + Flow_1coedjo + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_18cgkru + Flow_0ayd6dj + + + + + + #{execution.getVariable("networkType") == "CN"} + + + #{execution.getVariable("networkType") == "TN"} + + + #{execution.getVariable("networkType") == "AN"} + + + + + + + + + + + + + + + + + + Flow_1kk0exp + Flow_09b50tn + + + Flow_0ou7wr9 + Flow_18cgkru + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new AllocateSliceSubnet() +nss.prepareInitOperationStatus(execution) + + + + + + + + Flow_0g7721r + Flow_189zwjw + + + + + + + + + + + + + + + + + + Flow_1fij4ds + Flow_1coedjo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeAllocateSliceSubnet.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeAllocateSliceSubnet.bpmn new file mode 100644 index 0000000000..bf08c6e630 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/DeAllocateSliceSubnet.bpmn @@ -0,0 +1,224 @@ + + + + + Flow_143ck2k + + + + Flow_143ck2k + Flow_0pttfuf + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeAllocateSliceSubnet() +nss.preProcessRequest(execution) + + + Flow_1c1j5i1 + Flow_1kljyhj + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeAllocateSliceSubnet() +nss.sendSyncResponse(execution) + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_04jsg9s + Flow_1c1j5i1 + + + + + Flow_0pttfuf + Flow_04jsg9s + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new DeAllocateSliceSubnet() +nss.prepareInitOperationStatus(execution) + + + + Flow_1kljyhj + Flow_0fp8gep + Flow_0zwyxxc + Flow_0roz1jy + + + + + + + + + + + + + + + Flow_0fp8gep + Flow_1hij53h + + + + + + + + + + + + + + + Flow_0roz1jy + Flow_1fth8go + + + + + + + + + + + + + + + Flow_0zwyxxc + Flow_1l74oic + + + Flow_1hij53h + Flow_1fth8go + Flow_1l74oic + + + #{execution.getVariable("networkType") == "TN"} + + + #{execution.getVariable("networkType") == "AN"} + + + #{execution.getVariable("networkType") == "CN"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifySliceSubnet.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifySliceSubnet.bpmn new file mode 100644 index 0000000000..38ddf2edcd --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ModifySliceSubnet.bpmn @@ -0,0 +1,224 @@ + + + + + Flow_1t0w8dn + + + Flow_1t0w8dn + Flow_0fzchbl + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifySliceSubnet() +nss.preProcessRequest(execution) + + + Flow_1q030ul + Flow_0ps6iyc + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifySliceSubnet() +nss.sendSyncResponse(execution) + + + Flow_0ps6iyc + Flow_15luvlg + Flow_0usuozn + Flow_1dfyoe6 + + + Flow_1b2k523 + Flow_0pklfqu + Flow_1bbqkjv + + + + + + ${dbAdapterEndpoint} + + + application/soap+xml + Basic YnBlbDpwYXNzd29yZDEk + + + ${initResourceOperationStatus} + POST + ${statusCode} + ${response} + + http-connector + + + Flow_1grhlet + Flow_1q030ul + + + + + + + #{execution.getVariable("networkType") == "TN"} + + + #{execution.getVariable("networkType") == "AN"} + + + Flow_0fzchbl + Flow_1grhlet + import org.onap.so.bpmn.infrastructure.scripts.* +def nss = new ModifySliceSubnet() +nss.prepareInitOperationStatus(execution) + + + + + + + + + + + + + + + + Flow_0usuozn + Flow_1b2k523 + + + + + + + + + + + + + + + + Flow_1dfyoe6 + Flow_0pklfqu + + + + + + + + + + + + + + + Flow_15luvlg + Flow_1bbqkjv + + + + #{execution.getVariable("networkType") == "CN"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg