diff options
Diffstat (limited to 'bpmn')
11 files changed, 938 insertions, 654 deletions
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 index c7fe7e36a6..eabe58488e 100644 --- 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 @@ -32,150 +32,148 @@ 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") - } - + String Prefix="ActivateSliceSubnet_" + 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 index 5a7722d679..9100f2773b 100644 --- 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 @@ -33,158 +33,158 @@ 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") - } - + String Prefix="AllocateSliceSubnet_" + 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 index 964baa7a9d..65885f3516 100644 --- 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 @@ -32,14 +32,13 @@ 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 + String Prefix="DeAllocateSliceSubnet_" + 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) @@ -62,8 +61,8 @@ class DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { } else { execution.setVariable("globalSubscriberId", globalSubscriberId) } - - //NSSI ID + + //NSSI ID String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID") if (isBlank(serviceInstanceID)) { msg = "Input serviceInstanceID is null" @@ -73,27 +72,27 @@ class DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { { 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()) - } - + + 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)) { @@ -106,9 +105,9 @@ class DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { String jobId = UUID.randomUUID().toString() execution.setVariable("jobId", jobId) - - String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties") - execution.setVariable("sliceParams", sliceParams) + + String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties") + execution.setVariable("sliceParams", sliceParams) } catch(BpmnError e) { throw e @@ -131,13 +130,13 @@ class DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { String serviceId = execution.getVariable("serviceInstanceID") String jobId = execution.getVariable("jobId") - String nsiId = execution.getVariable("nsiId") + 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.setResourceTemplateUUID(nsiId) initStatus.setOperType("Deallocate") requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus) @@ -145,26 +144,26 @@ class DeAllocateSliceSubnet extends AbstractServiceTaskProcessor { } - - /** - * 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") - } + + /** + * 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/DoCommonCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy index 567725246e..646861a6a0 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSI.groovy @@ -246,11 +246,61 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { void getNSSIAssociatedProfiles(DelegateExecution execution) { LOGGER.trace("${getPrefix()} Start getNSSIAssociatedProfiles") + List<SliceProfile> associatedProfiles = new ArrayList<>() + + AAIResourcesClient client = getAAIClient() + def currentNSSI = execution.getVariable("currentNSSI") ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() + String nssiId = currentNSSI['nssiId'] + + // NSSI + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + AAIResultWrapper nssiWrapper = client.get(nssiUri) + Optional<Relationships> nssiRelationships = nssiWrapper.getRelationships() + + if (nssiRelationships.isPresent()) { + // Allotted Resource + for (AAIResourceUri allottedResourceUri : nssiRelationships.get().getRelatedUris(Types.ALLOTTED_RESOURCE)) { + AAIResultWrapper arWrapper = client.get(allottedResourceUri) + Optional<Relationships> arRelationships = arWrapper.getRelationships() + + boolean isFound = false + if(arRelationships.isPresent()) { + // Slice Profile Instance + for (AAIResourceUri sliceProfileInstanceUri : arRelationships.get().getRelatedUris(Types.SERVICE_INSTANCE)) { + Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri) + + if (sliceProfileInstanceOpt.isPresent()) { + ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get() + if(sliceProfileInstance.getServiceRole().equals("slice-profile-instance")) { // Service instance as a Slice Profile Instance + associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile() + + currentNSSI['sliceProfileInstanceUri'] = sliceProfileInstanceUri + + isFound = true + break // Should be only one + } + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No Slice Profile Instance found") + } + } + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for Allotted Resource") + } + + if(isFound) { + break + } + } + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No relationships found for nssi id = " + nssiId) + } if(associatedProfiles.isEmpty()) { String msg = String.format("No associated profiles found for NSSI %s in AAI", nssi.getServiceInstanceId()) @@ -587,13 +637,13 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { * @param constituteVnf * @return List<VfModules> */ - List<VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) { + List<org.onap.so.serviceinstancebeans.VfModules> prepareVfModules(DelegateExecution execution, GenericVnf constituteVnf) { AAIResourcesClient client = getAAIClient() - List<VfModules> vfModuless = new ArrayList<>() + List<org.onap.so.serviceinstancebeans.VfModules> vfModuless = new ArrayList<>() for (VfModule vfModule : constituteVnf.getVfModules().getVfModule()) { - VfModules vfmodules = new VfModules() + org.onap.so.serviceinstancebeans.VfModules vfmodules = new org.onap.so.serviceinstancebeans.VfModules() ModelInfo vfModuleModelInfo = new ModelInfo() vfModuleModelInfo.setModelInvariantUuid(vfModule.getModelInvariantId()) @@ -703,7 +753,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { Vnfs vnf = new Vnfs() // Line of Business - LineOfBusiness lob = new LineOfBusiness() + org.onap.so.serviceinstancebeans.LineOfBusiness lob = new org.onap.so.serviceinstancebeans.LineOfBusiness() lob.setLineOfBusinessName("VNF") vnf.setLineOfBusiness(lob) @@ -739,8 +789,8 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { * Prepare Service * @return Service */ - Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { - Service service = new Service() + org.onap.so.serviceinstancebeans.Service prepareService(DelegateExecution execution, ServiceInstance networkServiceInstance, ModelInfo modelInfo) { + org.onap.so.serviceinstancebeans.Service service = new org.onap.so.serviceinstancebeans.Service() // Model Info service.setModelInfo(prepareServiceModelInfo(networkServiceInstance, modelInfo)) @@ -793,21 +843,21 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { * @param execution * @return OwningEntity */ - OwningEntity prepareOwningEntity(DelegateExecution execution) { + org.onap.so.serviceinstancebeans.OwningEntity prepareOwningEntity(DelegateExecution execution) { def currentNSSI = execution.getVariable("currentNSSI") AAIResourcesClient client = getAAIClient() AAIResourceUri networkServiceInstanceUri = (AAIResourceUri)currentNSSI['networkServiceInstanceUri'] - OwningEntity owningEntity = new OwningEntity() + org.onap.so.serviceinstancebeans.OwningEntity owningEntity = new org.onap.so.serviceinstancebeans.OwningEntity() AAIResultWrapper wrapper = client.get(networkServiceInstanceUri) Optional<Relationships> owningEntityRelationshipsOps = wrapper.getRelationships() if (owningEntityRelationshipsOps.isPresent()) { List<AAIResourceUri> owningEntityRelatedAAIUris = owningEntityRelationshipsOps.get().getRelatedUris(Types.OWNING_ENTITY) if (!(owningEntityRelatedAAIUris == null || owningEntityRelatedAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation + Optional<org.onap.aai.domain.yang.OwningEntity> owningEntityOpt = client.get(org.onap.aai.domain.yang.v19.OwningEntity.class, owningEntityRelatedAAIUris.get(0)) // Many-To-One relation if (owningEntityOpt.isPresent()) { owningEntity.setOwningEntityId(owningEntityOpt.get().getOwningEntityId()) owningEntity.setOwningEntityName(owningEntityOpt.get().getOwningEntityName()) @@ -825,12 +875,12 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { * @param execution * @return Project */ - Project prepareProject(DelegateExecution execution) { + org.onap.so.serviceinstancebeans.Project prepareProject(DelegateExecution execution) { def currentNSSI = execution.getVariable("currentNSSI") AAIResourcesClient client = getAAIClient() - Project project = new Project() + org.onap.so.serviceinstancebeans.Project project = new org.onap.so.serviceinstancebeans.Project() AAIResourceUri cloudRegionRelatedAAIUri = (AAIResourceUri)currentNSSI['cloudRegionRelatedAAIUri'] @@ -840,7 +890,7 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { if (cloudRegionOps.isPresent()) { List<AAIResourceUri> projectAAIUris = cloudRegionOps.get().getRelatedUris(Types.PROJECT) if (!(projectAAIUris == null || projectAAIUris.isEmpty())) { - Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.Project.class, projectAAIUris.get(0)) + Optional<org.onap.aai.domain.yang.Project> projectOpt = client.get(org.onap.aai.domain.yang.v19.Project.class, projectAAIUris.get(0)) if (projectOpt.isPresent()) { project.setProjectName(projectOpt.get().getProjectName()) } @@ -950,23 +1000,49 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { def currentNSSI = execution.getVariable("currentNSSI") - ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] - String nssiId = currentNSSI['nssiId'] AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() + AAIResourceUri sliceProfileInstanceUri = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri'] - String currentSNSSAI = currentNSSI['S-NSSAI'] + Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri) + if (sliceProfileInstanceOpt.isPresent()) { + ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get() + + List<SliceProfile> associatedProfiles = sliceProfileInstance.getSliceProfiles()?.getSliceProfile() + + String currentSNSSAI = currentNSSI['S-NSSAI'] + + if(!(associatedProfiles == null || associatedProfiles.isEmpty())) { + // Removes slice profile which contains given S-NSSAI and updates Slice Profile Instance + associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) }) + + try { + client.update(sliceProfileInstanceUri, sliceProfileInstance) + + currentNSSI['sliceProfileInstance'] = sliceProfileInstance + } catch (Exception e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage()) + } + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profiles found") + } - associatedProfiles.removeIf({ associatedProfile -> (associatedProfile.getSNssai().equals(currentSNSSAI)) }) + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found") + } + // Removes SLice Profile Instance association with NSSI try { - getAAIClient().update(nssiUri, nssi) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI update call: " + e.getMessage()) + client.disconnect(nssiUri, sliceProfileInstanceUri) + } + catch (Exception e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance association with NSSI dosconnect call: " + e.getMessage()) } + LOGGER.trace("${getPrefix()} Exit removeSPAssociationWithNSSI") } @@ -982,17 +1058,10 @@ class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { def currentNSSI = execution.getVariable("currentNSSI") - SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI'] - - String globalSubscriberId = execution.getVariable("globalSubscriberId") - String subscriptionServiceType = execution.getVariable("subscriptionServiceType") - String nssiId = currentNSSI['nssiId'] - - // global-customer-id, service-type, service-instance-id, profile-id - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileContainsSNSSAI.getProfileId())) + AAIResourceUri sliceProfileInstanceURI = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri'] try { - client.delete(sliceProfileUri) + client.delete(sliceProfileInstanceURI) }catch(Exception e){ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage()) } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy index 055cbfc9cc..fe881eb888 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSI.groovy @@ -22,10 +22,14 @@ package org.onap.so.bpmn.infrastructure.scripts import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.v19.AllottedResource import org.onap.aai.domain.yang.v19.ServiceInstance import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper +import org.onap.aaiclient.client.aai.entities.Relationships import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types import org.onap.logging.filter.base.ONAPComponents import org.onap.so.bpmn.common.scripts.ExceptionUtil @@ -299,12 +303,38 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { String nssiId = currentNSSI['nssiId'] String nsiId = currentNSSI['nsiId'] + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + // NSSI AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + ServiceInstance nssi = currentNSSI['nssi'] + + String allottedResourceId = null + + // Removes Allotted resource + List<AllottedResource> allottedResources = nssi.getAllottedResources()?.getAllottedResource() + if(allottedResources != null && allottedResources.size() == 1) { // Shouldn contain one allotted resource + allottedResourceId = allottedResources.get(0).getId() + allottedResources.remove(0) + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No allotted resource found for NSSI id = " + nssiId) + } + + try { + client.update(nssiUri, nssi) + }catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage()) + } + + + // Remove association between NSI and Allotted Resource AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId)) + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResourceId)) try { - client.disconnect(nssiUri, nsiUri) + client.disconnect(nsiUri, allottedResourceUri) }catch(Exception e){ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI association with NSI disconnect call: " + e.getMessage()) } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy index 4ccea61ed4..ff16184f02 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSI.groovy @@ -22,8 +22,11 @@ package org.onap.so.bpmn.infrastructure.scripts import com.fasterxml.jackson.databind.ObjectMapper import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.v19.AllottedResource +import org.onap.aai.domain.yang.v19.AllottedResources import org.onap.aai.domain.yang.v19.ServiceInstance import org.onap.aai.domain.yang.v19.SliceProfile +import org.onap.aai.domain.yang.v19.SliceProfiles import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri @@ -37,6 +40,7 @@ import org.onap.so.bpmn.core.json.JsonUtils import org.slf4j.Logger import org.slf4j.LoggerFactory +import static org.apache.commons.lang3.StringUtils.isAllLowerCase import static org.apache.commons.lang3.StringUtils.isBlank class DoModifyCoreNSSI extends DoCommonCoreNSSI { @@ -51,22 +55,18 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { private static final Logger LOGGER = LoggerFactory.getLogger( DoModifyCoreNSSI.class) + /** - * Creates Slice Profile Instance + * Prepares Slice Profile * @param execution + * @return SLice Profile */ - void createSliceProfileInstance(DelegateExecution execution) { - LOGGER.trace("${PREFIX} Start createSliceProfileInstance") - + SliceProfile prepareSliceProfile(DelegateExecution execution) { def currentNSSI = execution.getVariable("currentNSSI") String sliceProfileID = currentNSSI['sliceProfileId'] Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class) - String globalSubscriberId = execution.getVariable("globalSubscriberId") - String subscriptionServiceType = execution.getVariable("subscriptionServiceType") - String nssiId = currentNSSI['nssiId'] - SliceProfile sliceProfile = new SliceProfile() sliceProfile.setServiceAreaDimension("") sliceProfile.setPayloadSize(0) @@ -112,14 +112,80 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { sliceProfile.setProfileId(sliceProfileID) sliceProfile.setE2ELatency(0) + return sliceProfile + } + + + /** + * Prepares Slice Profile Instance + * @param execution + * @return Slice Profile Instance + */ + ServiceInstance prepareSliceProfileInstance(DelegateExecution execution) { + + def currentNSSI = execution.getVariable("currentNSSI") + + ServiceInstance sliceProfileInstance = new ServiceInstance() + String sliceProfileInstanceId = UUID.randomUUID().toString() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + + + String sliceInstanceName = "sliceprofile_" + sliceProfileInstanceId + sliceProfileInstance.setServiceInstanceName(sliceInstanceName) + + String serviceType = jsonUtil.getJsonValue(currentNSSI['sliceProfile'], "sST") + sliceProfileInstance.setServiceType(serviceType) + + String serviceStatus = "deactivated" + sliceProfileInstance.setOrchestrationStatus(serviceStatus) + + String serviceInstanceLocationid = jsonUtil.getJsonValue(currentNSSI['sliceProfile'], "plmnIdList") + sliceProfileInstance.setServiceInstanceLocationId(serviceInstanceLocationid) + + String serviceRole = "slice-profile-instance" + sliceProfileInstance.setServiceRole(serviceRole) + List<String> snssaiList = (List<String>)currentNSSI['S-NSSAIs'] + String snssai = snssaiList.get(0) + + sliceProfileInstance.setEnvironmentContext(snssai) + sliceProfileInstance.setWorkloadContext("CN-NF") + + // TO DO: Model info + + return sliceProfileInstance + } + + + + /** + * Creates Slice Profile Instance + * @param execution + */ + void createSliceProfileInstance(DelegateExecution execution) { + LOGGER.trace("${PREFIX} Start createSliceProfileInstance") + + def currentNSSI = execution.getVariable("currentNSSI") + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + + SliceProfile sliceProfile = prepareSliceProfile(execution) + + ServiceInstance sliceProfileInstance = prepareSliceProfileInstance(execution) + + SliceProfiles sliceProfiles = new SliceProfiles() + sliceProfiles.getSliceProfile().add(sliceProfile) + sliceProfileInstance.setSliceProfiles(sliceProfiles) + try { AAIResourcesClient client = getAAIClient() - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileID)) - client.create(uri, sliceProfile) + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType). + serviceInstance(sliceProfileInstance.getServiceInstanceId())) + client.create(uri, sliceProfileInstance) - currentNSSI['createdSliceProfile'] = sliceProfile + currentNSSI['createdSliceProfileInstanceId'] = sliceProfileInstance.getServiceInstanceId() } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile create call:" + ex.getMessage()) + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Slice Profile create call:" + ex.getMessage()) } LOGGER.trace("${PREFIX} Exit createSliceProfileInstance") @@ -127,6 +193,42 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { /** + * Creates Allotted Resource + * @param execution + * @return AllottedResource + */ + AllottedResource createAllottedResource(DelegateExecution execution) { + def currentNSSI = execution.getVariable("currentNSSI") + + String globalSubscriberId = execution.getVariable("globalSubscriberId") + String subscriptionServiceType = execution.getVariable("subscriptionServiceType") + String sliceProfileInstanceId = currentNSSI['createdSliceProfileInstanceId'] + + AllottedResource allottedResource = new AllottedResource() + + String allottedResourceId = UUID.randomUUID().toString() + + allottedResource.setId(allottedResourceId) + + // TO DO: No other info + + try { + AAIResourcesClient client = getAAIClient() + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstanceId).allottedResource(allottedResourceId)) + + client.create(allottedResourceUri, allottedResource) + + currentNSSI['allottedResourceUri'] = allottedResourceUri + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while Allotted Resource create call:" + ex.getMessage()) + } + + return allottedResource + } + + + + /** * Creates Slice Profile association with NSSI * @param execution */ @@ -135,26 +237,48 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { def currentNSSI = execution.getVariable("currentNSSI") - String sliceProfileID = currentNSSI['sliceProfileId'] - - String globalSubscriberId = execution.getVariable("globalSubscriberId") - String subscriptionServiceType = execution.getVariable("subscriptionServiceType") String nssiId = currentNSSI['nssiId'] - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileID)) + String sliceProfileInstanceId = currentNSSI['createdSliceProfileInstanceId'] + AAIResourcesClient client = getAAIClient() + + // Creates Allotted Resource + AllottedResource allottedResource = createAllottedResource(execution) + AAIResourceUri allottedResourceUri = (AAIResourceUri)currentNSSI['allottedResourceUri'] + + // Updates Slice Profile Instance with Allotted Resource try { - SliceProfile createdSliceProfile = (SliceProfile)currentNSSI['createdSliceProfile'] - ServiceInstance nssi = (ServiceInstance)currentNSSI['nssi'] - List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile() - associatedProfiles.add(createdSliceProfile) + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId)) + Optional<ServiceInstance> sliceProfileInstanceOpt = client.get(ServiceInstance.class, sliceProfileInstanceUri) + if (sliceProfileInstanceOpt.isPresent()) { + ServiceInstance sliceProfileInstance = sliceProfileInstanceOpt.get() + + AllottedResources allottedResources = sliceProfileInstance.getAllottedResources() + if(allottedResources == null) { + allottedResources = new AllottedResources() + } + + allottedResources.getAllottedResource().add(allottedResource) + sliceProfileInstance.setAllottedResources(allottedResources) + + client.update(sliceProfileInstanceUri, sliceProfileInstance) + } + else { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, "No slice profile instance found with id = " + sliceProfileInstanceId) + } + + } catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance update call: " + e.getMessage()) + } - getAAIClient().update(nssiUri, nssi) - getAAIClient().connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO) - }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile association with NSSI disconnect call: " + e.getMessage()) + // Associates NSSI with Allotted Resource + try { + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + client.connect(nssiUri, allottedResourceUri, AAIEdgeLabel.USES) + } catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI with Allotted Resource connect call: " + e.getMessage()) } LOGGER.trace("${PREFIX} Exit associateSliceProfileInstanceWithNSSI") 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 index 47489b7b84..0465a433eb 100644 --- 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 @@ -32,142 +32,142 @@ 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") - } + String Prefix="ModifySliceSubnet_" + 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/DoCommonCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy index 6ca3937d68..9707dd2242 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy @@ -36,6 +36,7 @@ import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.T import org.onap.so.bpmn.common.scripts.ExternalAPIUtil import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory import org.onap.so.bpmn.common.scripts.MsoGroovyTest +import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.serviceinstancebeans.RequestDetails import javax.ws.rs.core.Response @@ -185,8 +186,10 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + String nssiId = "5G-999" ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") + nssi.setServiceInstanceId(nssiId) + currentNSSI.put("nssiId", nssiId) SliceProfiles sliceProfiles = new SliceProfiles() @@ -194,13 +197,49 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { slProfiles.add(new SliceProfile()) slProfiles.add(new SliceProfile()) - nssi.setSliceProfiles(sliceProfiles) + //nssi.setSliceProfiles(sliceProfiles) currentNSSI.put("nssi", nssi) - DoCommonCoreNSSI obj = new DoCommonCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + when(spy.getAAIClient()).thenReturn(client) + + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json) + Relationships rsMock = mock(Relationships.class) + Optional<Relationships> orsMock = Optional.of(rsMock) + List<AAIResourceUri> allottedUris = new ArrayList<>() + AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id")) + allottedUris.add(allottedUri) + + when(client.get(nssiUri)).thenReturn(wrapperMock) + when(wrapperMock.getRelationships()).thenReturn(orsMock) + when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris) + + String sliceProfileInstanceId = "slice-profile-instance-id" + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + sliceProfileInstance.setServiceRole("slice-profile-instance") + + List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>() + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId())) + sliceProfileInstanceUris.add(sliceProfileInstanceUri) + + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(allottedUri)).thenReturn(wrapperMock) + when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris) + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + + + SliceProfiles sps = new SliceProfiles() + sps.getSliceProfile().addAll(slProfiles) + sliceProfileInstance.setSliceProfiles(sps) + + spy.getNSSIAssociatedProfiles(mockExecution) List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") + assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null) assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) } @@ -262,6 +301,20 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type"). + serviceInstance("slice-profile-instance-id")) + + String sliceProfileInstanceId = "slice-profile-instance-id" + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + sliceProfileInstance.setServiceRole("slice-profile-instance") + + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + + currentNSSI.put("sliceProfileInstanceUri", sliceProfileInstanceUri) + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) @@ -284,13 +337,19 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { associatedProfiles.add(sliceProfile2) associatedProfiles.add(sliceProfile3) + SliceProfiles sps = new SliceProfiles() + sps.getSliceProfile().addAll(associatedProfiles) + sliceProfileInstance.setSliceProfiles(sps) + int sizeBefore = associatedProfiles.size() - doNothing().when(client).update(nssiUri, nssi) + doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance) + + doNothing().when(client). disconnect(nssiUri, sliceProfileInstanceUri) spy.removeSPAssociationWithNSSI(mockExecution) - assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1)) + assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1)) } @@ -300,30 +359,16 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - String globalSubscriberId = "global-id" - String subscriptionServiceType = "subscription-service-type" - String nssiId = "5G-999" + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type"). + serviceInstance("slice-profile-instance-id")) - when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) - when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) - - currentNSSI.put("nssiId", nssiId) - - String theSNSSAI = "theS-NSSAI" - - SliceProfile sliceProfile = new SliceProfile() - sliceProfile.setSNssai(theSNSSAI) - sliceProfile.setProfileId("prof-id") - - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - - currentNSSI.put("sliceProfileS-NSSAI", sliceProfile) + currentNSSI.put("sliceProfileInstanceUri", uri) DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) - doNothing().when(client).delete(nssiUri) + doNothing().when(client).delete(uri) spy.deleteSliceProfileInstance(mockExecution) @@ -426,8 +471,13 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { prepareProject(cloudRegionAAIUri) - String requestDetails = spy.prepareRequestDetails(mockExecution) + String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution) + + JsonUtils jsonUtil = new JsonUtils() + String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode") + String errMsg = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage") + assertTrue(errMsg, errorCode == null || errorCode.isEmpty()) } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy index c6e874591f..26b96a0a4a 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy @@ -26,6 +26,7 @@ import org.mockito.Mockito import org.onap.aai.domain.yang.v19.* 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.ExternalAPIUtil import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory @@ -153,31 +154,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { @Test - void testGetNSSIAssociatedProfiles() { - def currentNSSI = [:] - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") - - SliceProfiles sliceProfiles = new SliceProfiles() - - List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile() - slProfiles.add(new SliceProfile()) - slProfiles.add(new SliceProfile()) - - nssi.setSliceProfiles(sliceProfiles) - currentNSSI.put("nssi", nssi) - - DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") - assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) - } - - - @Test void testCalculateSNSSAI() { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) @@ -232,9 +208,30 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nsiId", nsiId) AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + ServiceInstance nssi = new ServiceInstance() + nssi.setServiceInstanceId(nssiId) + + AllottedResources allottedResources = new AllottedResources() + AllottedResource allottedResource = new AllottedResource() + allottedResource.setId(UUID.randomUUID().toString()) + allottedResources.getAllottedResource().add(allottedResource) + nssi.setAllottedResources(allottedResources) + + currentNSSI.put("nssi", nssi) + AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId)) - doNothing().when(client).disconnect(nssiUri, nsiUri) + doNothing().when(client).update(nssiUri, nssi) + + String globalSubscriberId = "globalSubscriberId" + String subscriptionServiceType = "subscription-service-type" + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResource.getId())) + + doNothing().when(client).disconnect(nsiUri, allottedResourceUri) spy.removeNSSIAssociationWithNSI(mockExecution) diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy index 32c4c1aa57..ac6f897dfa 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy @@ -23,6 +23,8 @@ package org.onap.so.bpmn.infrastructure.scripts import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test +import org.mockito.Mockito +import org.onap.aai.domain.yang.v19.AllottedResource import org.onap.aai.domain.yang.v19.ServiceInstance import org.onap.aai.domain.yang.v19.SliceProfile import org.onap.aai.domain.yang.v19.SliceProfiles @@ -46,31 +48,6 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { @Test - void testGetNSSIAssociatedProfiles() { - def currentNSSI = [:] - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") - - SliceProfiles sliceProfiles = new SliceProfiles() - - List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile() - slProfiles.add(new SliceProfile()) - slProfiles.add(new SliceProfile()) - - nssi.setSliceProfiles(sliceProfiles) - currentNSSI.put("nssi", nssi) - - DoModifyCoreNSSI obj = new DoModifyCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") - assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) - } - - - @Test void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) @@ -154,9 +131,15 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String sliceProfileId = "sliceProfileId" - currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\"}") + currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\",\"expDataRateDL\":\"5\"," + + "\"activityFactor\":\"2\",\"resourceSharingLevel\":\"resource-sharing-level\",\"uEMobilityLevel\":\"ue-mobility-level\",\"coverageAreaTAList\":\"coverage-area-ta-list\"," + + "\"maxNumberofUEs\":\"10000\",\"latency\":\"7\"}") currentNSSI.put("sliceProfileId", sliceProfileId) + List<String> snssais = new ArrayList<>() + snssais.add("s-nssai") + currentNSSI.put("S-NSSAIs", snssais) + DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) @@ -169,17 +152,21 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nssiId", nssiId) - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(UUID.randomUUID().toString()) + + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType). + serviceInstance(sliceProfileInstance.getServiceInstanceId())) SliceProfile sliceProfile = new SliceProfile() sliceProfile.setProfileId(sliceProfileId) - doNothing().when(client).create(uri, sliceProfile) + doNothing().when(client).create(uri, sliceProfileInstance) spy.createSliceProfileInstance(mockExecution) - assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile")) - assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId())) + assertTrue("Slice Profile Instance Id doesn't exist", (currentNSSI.get("createdSliceProfileInstanceId")) != null) + } @@ -202,8 +189,19 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String globalSubscriberId = "globalSubscriberId" String subscriptionServiceType = "subscriptionServiceType" - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + String sliceProfileInstanceId = "slice-rpofile-instance-id" + currentNSSI.put("createdSliceProfileInstanceId", sliceProfileInstanceId) + + AllottedResource allottedResource = new AllottedResource() + + String allottedResourceId = UUID.randomUUID().toString() + + allottedResource.setId(allottedResourceId) + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstanceId).allottedResource(allottedResourceId)) + doNothing().when(client).create(allottedResourceUri, allottedResource) + + currentNSSI.put("allottedResourceUri", allottedResourceUri) when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) @@ -213,19 +211,26 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { SliceProfile sliceProfile = new SliceProfile() currentNSSI.put("createdSliceProfile", sliceProfile) + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId)) + + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance) + ServiceInstance nssi = new ServiceInstance() nssi.setServiceInstanceId(nssiId) nssi.setSliceProfiles(new SliceProfiles()) currentNSSI.put("nssi", nssi) - int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size() - - doNothing().when(client).update(nssiUri, nssi) - doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO) + doNothing().when(client).connect(nssiUri, sliceProfileInstanceUri, AAIEdgeLabel.USES) spy.associateSliceProfileInstanceWithNSSI(mockExecution) - assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1)) } } 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 index 450faaebca..29f024991d 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/AllocateSliceSubnet.bpmn @@ -91,13 +91,6 @@ nss.prepareInitOperationStatus(execution)</bpmn:script> </bpmn:scriptTask> <bpmn:sequenceFlow id="Flow_0ou7wr9" sourceRef="Activity_1hyt0pb" targetRef="Activity_1ydx2rx" /> <bpmn:sequenceFlow id="Flow_18cgkru" sourceRef="Activity_1ydx2rx" targetRef="Activity_0qlstj2" /> - <bpmn:callActivity id="CallDoAllocateTransportNSSI" name="Call TNAllocateNSSI" calledElement="DoAllocateTransportNSSI"> - <bpmn:extensionElements> - <camunda:in source="servicename" target="servicename" /> - </bpmn:extensionElements> - <bpmn:incoming>Flow_0g7721r</bpmn:incoming> - <bpmn:outgoing>Flow_189zwjw</bpmn:outgoing> - </bpmn:callActivity> <bpmn:sequenceFlow id="Flow_189zwjw" sourceRef="CallDoAllocateTransportNSSI" targetRef="Event_18u424w" /> <bpmn:callActivity id="CallDoAllocateCoreNSSI" name="Call CNAllocateNSSI" calledElement="DoAllocateCoreNSSI"> <bpmn:extensionElements> @@ -118,6 +111,24 @@ nss.prepareInitOperationStatus(execution)</bpmn:script> <bpmn:outgoing>Flow_1coedjo</bpmn:outgoing> </bpmn:callActivity> <bpmn:sequenceFlow id="Flow_1coedjo" sourceRef="CallDoAllocateCoreNSSI" targetRef="Event_18u424w" /> + <bpmn:callActivity id="CallDoAllocateTransportNSSI" name="Call TNAllocateNSSI" calledElement="DoAllocateTransportNSSI"> + <bpmn:extensionElements> + <camunda:in source="msoRequestId" target="msoRequestId" /> + <camunda:in source="modelInvariantUuid" target="modelInvariantUuid" /> + <camunda:in source="modelUuid" target="modelUuid" /> + <camunda:in source="globalSubscriberId" target="globalSubscriberId" /> + <camunda:in source="dummyServiceId" target="dummyServiceId" /> + <camunda:in source="nsiId" target="nsiId" /> + <camunda:in source="networkType" target="networkType" /> + <camunda:in source="subscriptionServiceType" target="subscriptionServiceType" /> + <camunda:in source="jobId" target="jobId" /> + <camunda:in source="sliceParams" target="sliceParams" /> + <camunda:out source="WorkflowException" target="WorkflowException" /> + <camunda:in source="servicename" target="servicename" /> + </bpmn:extensionElements> + <bpmn:incoming>Flow_0g7721r</bpmn:incoming> + <bpmn:outgoing>Flow_189zwjw</bpmn:outgoing> + </bpmn:callActivity> </bpmn:process> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="AllocateSliceSubnet"> @@ -126,8 +137,8 @@ nss.prepareInitOperationStatus(execution)</bpmn:script> <di:waypoint x="1152" y="190" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_189zwjw_di" bpmnElement="Flow_189zwjw"> - <di:waypoint x="1080" y="300" /> - <di:waypoint x="1170" y="300" /> + <di:waypoint x="1080" y="290" /> + <di:waypoint x="1170" y="290" /> <di:waypoint x="1170" y="208" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_18cgkru_di" bpmnElement="Flow_18cgkru"> @@ -153,10 +164,10 @@ nss.prepareInitOperationStatus(execution)</bpmn:script> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_0g7721r_di" bpmnElement="Flow_0g7721r"> <di:waypoint x="890" y="215" /> - <di:waypoint x="890" y="300" /> - <di:waypoint x="980" y="300" /> + <di:waypoint x="890" y="290" /> + <di:waypoint x="980" y="290" /> <bpmndi:BPMNLabel> - <dc:Bounds x="912" y="273" width="36" height="14" /> + <dc:Bounds x="912" y="263" width="36" height="14" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge id="Flow_1fij4ds_di" bpmnElement="Flow_1fij4ds"> @@ -208,12 +219,13 @@ nss.prepareInitOperationStatus(execution)</bpmn:script> <bpmndi:BPMNShape id="Activity_1ydx2rx_di" bpmnElement="Activity_1ydx2rx"> <dc:Bounds x="380" y="150" width="100" height="80" /> </bpmndi:BPMNShape> - <bpmndi:BPMNShape id="Activity_008nbm9_di" bpmnElement="CallDoAllocateTransportNSSI"> - <dc:Bounds x="980" y="260" width="100" height="80" /> - </bpmndi:BPMNShape> <bpmndi:BPMNShape id="Activity_01669p4_di" bpmnElement="CallDoAllocateCoreNSSI"> <dc:Bounds x="980" y="150" width="100" height="80" /> </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_00awuik_di" bpmnElement="CallDoAllocateTransportNSSI"> + <dc:Bounds x="980" y="250" width="100" height="80" /> + </bpmndi:BPMNShape> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn:definitions> + |