diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common')
21 files changed, 1609 insertions, 992 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/pom.xml b/bpmn/so-bpmn-infrastructure-common/pom.xml index 5dad9b8687..ebc0264c7e 100644 --- a/bpmn/so-bpmn-infrastructure-common/pom.xml +++ b/bpmn/so-bpmn-infrastructure-common/pom.xml @@ -143,17 +143,14 @@ <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxrs</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-service-description-swagger</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>com.h2database</groupId> 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/CreateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy index c5f77ff172..72fd052f31 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy @@ -20,6 +20,8 @@ package org.onap.so.bpmn.infrastructure.scripts +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder + import static org.apache.commons.lang3.StringUtils.* import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution @@ -52,11 +54,15 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { String Prefix = "CRESS_" ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + JsonSlurper jsonSlurper = new JsonSlurper() + ObjectMapper objectMapper = new ObjectMapper() + OofUtils oofUtils = new OofUtils() - NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + AAIResourcesClient client = getAAIClient() private static final Logger logger = LoggerFactory.getLogger(CreateSliceService.class) @@ -266,10 +272,8 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { execution.setVariable("sliceTaskParams", sliceTaskParams) - //todo:---------------------------------------- -// String paramJson = sliceTaskParams.convertToJson() -// execution.setVariable("CSSOT_paramJson", paramJson) - /*-------------------------------------------*/ + String paramJson = sliceTaskParams.convertToJson() + execution.setVariable("CSSOT_paramJson", paramJson) logger.debug("Finish createOrchestrationTask") } @@ -359,7 +363,8 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { logger.debug("Start prepareUpdateOrchestrationTask") String requestMethod = "PUT" String taskStatus = execution.getVariable("taskStatus") - SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") + SliceTaskParamsAdapter sliceTaskParams = + execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter String paramJson = sliceTaskParams.convertToJson() execution.setVariable("CSSOT_status", taskStatus) execution.setVariable("CSSOT_paramJson", paramJson) @@ -389,7 +394,7 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { OrchestrationTask orchestrationTask = objectMapper.readValue(response, OrchestrationTask.class) String paramJson = orchestrationTask.getParams() logger.debug("paramJson: " + paramJson) - SliceTaskParams sliceTaskParams = new SliceTaskParams() + SliceTaskParamsAdapter sliceTaskParams = new SliceTaskParamsAdapter() sliceTaskParams.convertFromJson(paramJson) execution.setVariable("sliceTaskParams", sliceTaskParams) logger.debug("Finish processUserOptions") @@ -403,7 +408,7 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { try { ServiceInstance si = new ServiceInstance() si.setOrchestrationStatus(orchStatus) - AAIResourcesClient client = new AAIResourcesClient() + AAIResourceUri uri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) client.update(uri, si) } catch (BpmnError e) { 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/DoActivateTnNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssi.groovy index 0900863a62..e5c9514fa5 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoActivateTnNssi.groovy @@ -158,7 +158,7 @@ public class DoActivateTnNssi extends AbstractServiceTaskProcessor { roStatus.setProgress(progress) roStatus.setStatus(status) roStatus.setStatusDescription(statusDescription) - requestDBUtil.prepareUpdateResourceOperationStatus(execution, status) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSI.groovy index 88014e7b54..3e834fa7bb 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSSI.groovy @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.apache.commons.lang3.StringUtils import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.beans.nsmf.EsrInfo +import org.onap.so.beans.nsmf.JobStatusResponse import org.onap.so.beans.nsmf.NssiResponse import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest import org.onap.so.beans.nsmf.ResponseDescriptor @@ -17,7 +18,6 @@ import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils import org.onap.so.bpmn.core.json.JsonUtils import org.slf4j.Logger import org.slf4j.LoggerFactory -import org.springframework.http.ResponseEntity class DoAllocateNSSI extends AbstractServiceTaskProcessor { @@ -34,7 +34,7 @@ class DoAllocateNSSI extends AbstractServiceTaskProcessor { private static final NSSMF_ALLOCATE_URL = "/api/rest/provMns/v1/NSS/SliceProfiles" - private static final NSSMF_QUERY_JOB_STATUS_URL = "/NSS/jobs/%s" + private static final NSSMF_QUERY_JOB_STATUS_URL = "/api/rest/provMns/v1/NSS/jobs/%s" @Override void preProcessRequest(DelegateExecution execution) { @@ -64,11 +64,12 @@ class DoAllocateNSSI extends AbstractServiceTaskProcessor { NssmfAdapterNBIRequest nbiRequest = execution.getVariable("nbiRequest") as NssmfAdapterNBIRequest String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, NSSMF_ALLOCATE_URL, objectMapper.writeValueAsString(nbiRequest)) - ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class) - String respBody = responseEntity.getBody() - NssiResponse result = objectMapper.readValue(respBody, NssiResponse.class) - //todo: if success - //todo: + + if (response != null) { + NssiResponse nssiResponse = objectMapper.readValue(response, NssiResponse.class) + execution.setVariable("nssiAllocateResult", nssiResponse) + } + execution.setVariable("serviceInfo", nbiRequest.getServiceInfo()) execution.setVariable("esrInfo", nbiRequest.getEsrInfo()) } @@ -96,13 +97,14 @@ class DoAllocateNSSI extends AbstractServiceTaskProcessor { String response = nssmfAdapterUtils.sendPostRequestNSSMF(execution, endpoint, objectMapper.writeValueAsString(nbiRequest)) - ResponseEntity responseEntity = objectMapper.readValue(response, ResponseEntity.class) - String result = responseEntity.getBody() - //todo;if success - ResponseDescriptor responseDescriptor = objectMapper.readValue(result, ResponseDescriptor.class) + if (response != null) { + JobStatusResponse jobStatusResponse = objectMapper.readValue(response, JobStatusResponse.class) + execution.setVariable("nssiAllocateStatus", jobStatusResponse) - //todo: handle status - execution.setVariable("nssiAllocateResult", responseDescriptor) + if (jobStatusResponse.getResponseDescriptor().getProgress() == 100) { + execution.setVariable("jobFinished", true) + } + } } void prepareUpdateOrchestrationTask(DelegateExecution execution) { @@ -111,10 +113,10 @@ class DoAllocateNSSI extends AbstractServiceTaskProcessor { SliceTaskParamsAdapter sliceParams = execution.getVariable("sliceTaskParams") as SliceTaskParamsAdapter - ResponseDescriptor response = execution.getVariable("nssiAllocateResult") as ResponseDescriptor + JobStatusResponse jobStatusResponse = execution.getVariable("nssiAllocateStatus") as JobStatusResponse + ResponseDescriptor response = jobStatusResponse.getResponseDescriptor() SubnetType subnetType = execution.getVariable("subnetType") as SubnetType - SliceTaskInfo sliceTaskInfo = execution.getVariable("sliceTaskInfo") as SliceTaskInfo sliceTaskInfo.progress = response.getProgress() sliceTaskInfo.status = response.getStatus() @@ -127,6 +129,7 @@ class DoAllocateNSSI extends AbstractServiceTaskProcessor { execution.setVariable("sliceTaskParams", sliceParams) execution.setVariable("sliceTaskInfo", sliceTaskInfo) + logger.debug("Finish prepareUpdateOrchestrationTask progress") } 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 e225c360ed..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 @@ -22,15 +22,9 @@ 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.CloudRegion -import org.onap.aai.domain.yang.GenericVnf -import org.onap.aai.domain.yang.ModelVer -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.ServiceSubscription -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.Tenant -import org.onap.aai.domain.yang.VfModule -import org.onap.aaiclient.client.aai.AAIObjectType +import org.json.JSONArray +import org.json.JSONObject +import org.onap.aai.domain.yang.v19.* import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.Relationships @@ -39,35 +33,20 @@ 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.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.RequestDBUtil +import org.onap.so.bpmn.common.scripts.* import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.client.HttpClient -import org.onap.so.db.request.beans.OperationStatus -import org.onap.so.requestsdb.RequestsDbConstant -import org.onap.so.serviceinstancebeans.CloudConfiguration -import org.onap.so.serviceinstancebeans.LineOfBusiness -import org.onap.so.serviceinstancebeans.ModelInfo -import org.onap.so.serviceinstancebeans.ModelType -import org.onap.so.serviceinstancebeans.OwningEntity -import org.onap.so.serviceinstancebeans.Project -import org.onap.so.serviceinstancebeans.RequestDetails -import org.onap.so.serviceinstancebeans.RequestInfo -import org.onap.so.serviceinstancebeans.RequestParameters -import org.onap.so.serviceinstancebeans.Resources -import org.onap.so.serviceinstancebeans.Service -import org.onap.so.serviceinstancebeans.SubscriberInfo -import org.onap.so.serviceinstancebeans.VfModules -import org.onap.so.serviceinstancebeans.Vnfs +import org.onap.so.db.request.beans.ResourceOperationStatus +import org.onap.so.serviceinstancebeans.* import org.slf4j.Logger import org.slf4j.LoggerFactory import javax.ws.rs.core.Response +import static org.apache.commons.lang3.StringUtils.isBlank - class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { +class DoCommonCoreNSSI extends AbstractServiceTaskProcessor { private final String PREFIX ="DoCommonCoreNSSI" @@ -83,10 +62,54 @@ import javax.ws.rs.core.Response def currentNSSI = execution.getVariable("currentNSSI") if (!currentNSSI) { - String msg = "currentNSSI is null" + currentNSSI = [:] + } + + // NSSI ID + String nssiId = execution.getVariable("serviceInstanceID") + if (isBlank(nssiId)) { + String msg = "NSSI service instance id is null" + LOGGER.error(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + else { + currentNSSI['nssiId'] = nssiId + } + + // NSI ID + String nsiId = execution.getVariable("nsiId") + if (isBlank(nsiId)) { + String msg = "nsiId is null" LOGGER.error(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) } + else { + currentNSSI['nsiId'] = nsiId + } + + + // Slice Profile + String sliceProfile = jsonUtil.getJsonValue(execution.getVariable("sliceParams"), "sliceProfile") + if (isBlank(sliceProfile)) { + String msg = "Slice Profile is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } else { + currentNSSI['sliceProfile'] = sliceProfile + } + + // S-NSSAI + def snssaiList = jsonUtil.StringArrayToList(jsonUtil.getJsonValue(sliceProfile, "snssaiList")) + + String sNssai = snssaiList.get(0) + currentNSSI['S-NSSAI'] = sNssai + + + // Slice Profile id + String sliceProfileId = jsonUtil.getJsonValue(sliceProfile, "sliceProfileId") + currentNSSI['sliceProfileId'] = sliceProfileId + + execution.setVariable("currentNSSI", currentNSSI) + LOGGER.trace("***** ${getPrefix()} Exit preProcessRequest") } @@ -223,11 +246,61 @@ import javax.ws.rs.core.Response 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()) @@ -257,7 +330,7 @@ import javax.ws.rs.core.Response List<String> snssais = new ArrayList<>() - String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" ) + String isCreateSliceProfileInstanceVar = execution.getVariable("isCreateSliceProfileInstance" ) // Not exist in case of Deallocate boolean isCreateSliceProfileInstance = Boolean.parseBoolean(isCreateSliceProfileInstanceVar) @@ -294,14 +367,14 @@ import javax.ws.rs.core.Response def currentNSSI = execution.getVariable("currentNSSI") try { - //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}/vnfs/{vnfId}" - def nsmfЕndpoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ??? + //url:/onap/so/infra/serviceInstantiation/v7/serviceInstances/{serviceInstanceId}" + def nsmfЕndPoint = UrnPropertiesReader.getVariable("mso.infra.endpoint.url", execution) // ??? ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] - GenericVnf constituteVnf = (GenericVnf)currentNSSI['constituteVnf'] + String url = String.format("${nsmfЕndPoint}/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId()) - String url = String.format("${nsmfЕndpoint}/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) + currentNSSI['putServiceInstanceURL'] = url String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) @@ -332,7 +405,7 @@ import javax.ws.rs.core.Response String putServiceInstanceResponse = "" if(errorCode == null || errorCode.isEmpty()) { // No error - putServiceInstanceResponse = callPUTServiceInstanceResponse // check the response ??? + putServiceInstanceResponse = callPUTServiceInstanceResponse } else { LOGGER.error(jsonUtil.getJsonValue(callPUTServiceInstanceResponse, "errorMessage")) @@ -430,9 +503,9 @@ import javax.ws.rs.core.Response SubscriberInfo prepareSubscriberInfo(DelegateExecution execution) { def currentNSSI = execution.getVariable("currentNSSI") - String globalSubscriberId = currentNSSI['globalSubscriberId'] + String globalSubscriberId = execution.getVariable("globalSubscriberId") - String subscriberName = currentNSSI['subscriberName'] + String subscriberName = execution.getVariable("subscriberName") SubscriberInfo subscriberInfo = new SubscriberInfo() subscriberInfo.setGlobalSubscriberId(globalSubscriberId) @@ -484,13 +557,13 @@ import javax.ws.rs.core.Response RequestInfo prepareRequestInfo(DelegateExecution execution, ServiceInstance networkServiceInstance) { def currentNSSI = execution.getVariable("currentNSSI") - String serviceId = currentNSSI['serviceId'] + String productFamilyId = execution.getVariable("productFamilyId") RequestInfo requestInfo = new RequestInfo() requestInfo.setInstanceName(networkServiceInstance.getServiceInstanceName()) requestInfo.setSource("VID") - requestInfo.setProductFamilyId(serviceId) + requestInfo.setProductFamilyId(productFamilyId) requestInfo.setRequestorId("NBI") return requestInfo @@ -564,13 +637,13 @@ import javax.ws.rs.core.Response * @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()) @@ -680,7 +753,7 @@ import javax.ws.rs.core.Response 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) @@ -716,8 +789,8 @@ import javax.ws.rs.core.Response * 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)) @@ -770,21 +843,21 @@ import javax.ws.rs.core.Response * @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()) @@ -802,12 +875,12 @@ import javax.ws.rs.core.Response * @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'] @@ -817,7 +890,7 @@ import javax.ws.rs.core.Response 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()) } @@ -927,22 +1000,48 @@ import javax.ws.rs.core.Response 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") } @@ -959,17 +1058,10 @@ import javax.ws.rs.core.Response def currentNSSI = execution.getVariable("currentNSSI") - SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI['sliceProfileS-NSSAI'] - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] - String nssiId = currentNSSI['nssiId'] - - // global-customer-id, service-type, service-instance-id, profile-id - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileContainsSNSSAI.getProfileId())) + AAIResourceUri sliceProfileInstanceURI = (AAIResourceUri)currentNSSI['sliceProfileInstanceUri'] try { - getAAIClient().delete(sliceProfileUri) + client.delete(sliceProfileInstanceURI) }catch(Exception e){ exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while Slice Profile Instance delete call: " + e.getMessage()) } @@ -979,27 +1071,180 @@ import javax.ws.rs.core.Response /** - * Updates operation status + * Prepares update resource operation status * @param execution */ - void updateServiceOperationStatus(DelegateExecution execution) { + void prepareUpdateResourceOperationStatus(DelegateExecution execution) { LOGGER.trace("${getPrefix()} Start updateServiceOperationStatus") def currentNSSI = execution.getVariable("currentNSSI") - OperationStatus operationStatus = new OperationStatus() - operationStatus.setServiceId(currentNSSI['e2eServiceInstanceId'] as String) - operationStatus.setOperationId(currentNSSI['operationId'] as String) - operationStatus.setOperation(currentNSSI['operationType'] as String) - operationStatus.setResult(RequestsDbConstant.Status.FINISHED) + //Prepare Update Status for PUT failure and success + String isTimeOutVar = execution.getVariable("isTimeOut") + if(!isBlank(isTimeOutVar) && isTimeOutVar.equals("YES")) { + LOGGER.error("TIMEOUT - SO PUT Failure") + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SO PUT Failure") + } else { + execution.setVariable("progress", "100") + execution.setVariable("status", "finished") + execution.setVariable("operationContent", "${getAction()} Core NSSI successful.") + } - requestDBUtil.prepareUpdateOperationStatus(execution, operationStatus) + setResourceOperationStatus(execution, "finished", "100", "Core NSSI ${getAction()} successful") LOGGER.trace("${getPrefix()} Exit updateServiceOperationStatus") } /** + * Prepares ResourceOperation status + * @param execution + * @param operationType + */ + void setResourceOperationStatus(DelegateExecution execution, String status, String progress, String statusDesc) { + LOGGER.trace("${getPrefix()} Start setResourceOperationStatus") + + def currentNSSI = execution.getVariable("currentNSSI") + + String serviceId = currentNSSI['nssiId'] + String jobId = execution.getVariable("jobId") + String nsiId = currentNSSI['nsiId'] + String operationType = execution.getVariable("operationType") + + ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus() + resourceOperationStatus.setServiceId(serviceId) + resourceOperationStatus.setOperationId(jobId) + resourceOperationStatus.setResourceTemplateUUID(nsiId) + resourceOperationStatus.setOperType(operationType) + resourceOperationStatus.setStatus(status) + resourceOperationStatus.setProgress(progress) + resourceOperationStatus.setStatusDescription(statusDesc) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, resourceOperationStatus) + + LOGGER.trace("${getPrefix()} Exit setResourceOperationStatus") + } + + + /** + * Prepares failed operation status update + * @param execution + */ + void prepareFailedOperationStatusUpdate(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start prepareFailedOperationStatusUpdate") + + setResourceOperationStatus(execution, "failed", "0", "Core NSSI ${getAction()} Failed") + + LOGGER.trace("${getPrefix()} Exit prepareFailedOperationStatusUpdate") + } + + + /** + * Gets progress status of ServiceInstance PUT operation + * @param execution + */ + public void getPUTServiceInstanceProgress(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start getPUTServiceInstanceProgress") + + def currentNSSI = execution.getVariable("currentNSSI") + + String url = currentNSSI['putServiceInstanceURL'] + + getProgress(execution, url, "putStatus") + + LOGGER.trace("${getPrefix()} Exit getPUTServiceInstanceProgress") + } + + + void getProgress(DelegateExecution execution, String url, String statusVariableName) { + String msg="" + try { + + ExternalAPIUtil externalAPIUtil = getExternalAPIUtilFactory().create() + Response response = externalAPIUtil.executeExternalAPIGetCall(execution, url) + int responseCode = response.getStatus() + execution.setVariable("GetServiceOrderResponseCode", responseCode) + LOGGER.debug("Get ServiceOrder response code is: " + responseCode) + + String extApiResponse = response.readEntity(String.class) + JSONObject responseObj = new JSONObject(extApiResponse) + execution.setVariable("GetServiceOrderResponse", extApiResponse) + LOGGER.debug("Create response body is: " + extApiResponse) + //Process Response //200 OK 201 CREATED 202 ACCEPTED + if(responseCode == 200 || responseCode == 201 || responseCode == 202 ) + { + LOGGER.debug("Get Create ServiceOrder Received a Good Response") + String orderState = responseObj.get("state") + if("REJECTED".equalsIgnoreCase(orderState)) { + prepareFailedOperationStatusUpdate(execution) + return + } + + JSONArray items = responseObj.getJSONArray("orderItem") + JSONObject item = items.get(0) + JSONObject service = item.get("service") + String networkServiceId = service.get("id") + if (networkServiceId == null || networkServiceId.equals("null")) { + prepareFailedOperationStatusUpdate(execution) + return + } + + execution.setVariable("networkServiceId", networkServiceId) + String serviceOrderState = item.get("state") + execution.setVariable("ServiceOrderState", serviceOrderState) + // Get serviceOrder State and process progress + if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) { + execution.setVariable(statusVariableName, "processing") + } + else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) { + execution.setVariable(statusVariableName, "processing") + } + else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) { + execution.setVariable(statusVariableName, "completed") + } + else if("FAILED".equalsIgnoreCase(serviceOrderState)) { + msg = "ServiceOrder failed" + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + else { + msg = "ServiceOrder failed" + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + } + else{ + msg = "Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode + prepareFailedOperationStatusUpdate(execution) + } + + }catch(Exception e){ + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage()) + } + + } + + + + /** + * Delays 5 sec + * @param execution + */ + void timeDelay(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start timeDelay") + + try { + LOGGER.debug("${getPrefix()} timeDelay going to sleep for 5 sec") + + Thread.sleep(5000) + + LOGGER.debug("${getPrefix()} ::: timeDelay wakeup after 5 sec") + } catch(InterruptedException e) { + LOGGER.error("${getPrefix()} ::: timeDelay exception" + e) + } + + LOGGER.trace("${getPrefix()} Exit timeDelay") + } + + + /** * Returns AAI client * @return AAI client */ @@ -1008,7 +1253,16 @@ import javax.ws.rs.core.Response } + ExternalAPIUtilFactory getExternalAPIUtilFactory() { + return new ExternalAPIUtilFactory() + } + + String getPrefix() { return PREFIX } + + String getAction() { + return "" + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy index 8993127dbc..1d5232f3c5 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy @@ -95,7 +95,7 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ List<TemplateInfo> nsstInfos = new ArrayList<>() ServiceDecomposition nstServiceDecomposition = execution.getVariable("nstServiceDecomposition") as ServiceDecomposition - //todo: + List<AllottedResource> allottedResources = nstServiceDecomposition.getAllottedResources() for (AllottedResource allottedResource : allottedResources) { TemplateInfo nsstInfo = new TemplateInfo() @@ -150,9 +150,6 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ execution.setVariable("nsstServiceDecompositions", nsstServiceDecompositions) - - - int num = execution.getVariable("maxNsstIndex") as Integer int index = execution.getVariable("currentNsstIndex") as Integer @@ -180,8 +177,6 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ List<SubnetCapability> subnetCapabilities = new ArrayList<>() - - for (ServiceDecomposition serviceDecomposition : nsstServiceDecompositions) { SubnetCapability subnetCapability = new SubnetCapability() handleByType(execution, serviceDecomposition, sliceParams, subnetCapability) @@ -206,7 +201,6 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ sliceParams.tnBHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid() sliceParams.tnBHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid() sliceParams.tnBHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName() - break case SubnetType.TN_MH: sliceParams.tnMHSliceTaskInfo.vendor = vendor @@ -215,7 +209,6 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ sliceParams.tnMHSliceTaskInfo.NSSTInfo.UUID = modelInfo.getModelUuid() sliceParams.tnMHSliceTaskInfo.NSSTInfo.invariantUUID = modelInfo.getModelInvariantUuid() sliceParams.tnMHSliceTaskInfo.NSSTInfo.name = modelInfo.getModelName() - break case SubnetType.AN_NF: sliceParams.anSliceTaskInfo.vendor = vendor @@ -236,9 +229,6 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ default: subnetType = null break - - //todo - } if (null == subnetType) { def msg = "Get subnetType failed, modelUUId=" + modelInfo.getModelUuid() @@ -297,17 +287,16 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ private static String buildQuerySubnetCapRequest(String vendor, SubnetType subnetType) { NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest() - List<String> subnetTypes = new ArrayList<>() - subnetTypes.add(subnetType.subnetType) +// List<String> subnetTypes = new ArrayList<>() +// subnetTypes.add(subnetType.subnetType) Map<String, Object> paramMap = new HashMap() - paramMap.put("subnetTypes", subnetTypes) + paramMap.put("subnetType", subnetType.subnetType) request.setSubnetCapabilityQuery(objectMapper.writeValueAsString(paramMap)) EsrInfo esrInfo = new EsrInfo() esrInfo.setVendor(vendor) esrInfo.setNetworkType(subnetType.networkType) - request.setEsrInfo(esrInfo) String strRequest = objectMapper.writeValueAsString(request) @@ -320,7 +309,8 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ * prepare select nsi request * @param execution */ - public void preNSIRequest(DelegateExecution execution, boolean preferReuse) { + public void preNSIRequest(DelegateExecution execution) { + boolean preferReuse = execution.getVariable("needQuerySliceProfile") ? false : true String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) logger.debug( "get NSI option OOF Url: " + urlString) @@ -378,8 +368,9 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ if (isSharable && solution.get("existingNSI")) { //sharedNSISolution processSharedNSI(solution, sliceTaskParams) + execution.setVariable("needQuerySliceProfile", true) } - else if(solution.containsKey("newNSISolution")) { + else { processNewNSI(solution, sliceTaskParams) } } @@ -395,6 +386,7 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ String nsiName = sharedNSISolution.get("NSIName") sliceParams.setSuggestNsiId(nsiId) sliceParams.setSuggestNsiName(nsiName) + } private void processNewNSI(Map<String, Object> solution, SliceTaskParamsAdapter sliceParams) { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy index 0f1bf0d8b4..7beafefc28 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateTnNssiInstance.groovy @@ -23,12 +23,10 @@ package org.onap.so.bpmn.infrastructure.scripts import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.SliceProfile -import org.onap.aaiclient.client.aai.AAIObjectType import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.core.json.JsonUtils @@ -38,6 +36,7 @@ import org.slf4j.LoggerFactory class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { private static final Logger logger = LoggerFactory.getLogger(DoCreateTnNssiInstance.class); + final String AAI_VERSION = "v21" JsonUtils jsonUtil = new JsonUtils() TnNssmfUtils tnNssmfUtils = new TnNssmfUtils() ExceptionUtil exceptionUtil = new ExceptionUtil() @@ -67,23 +66,26 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { void createSliceProfile(DelegateExecution execution) { - String sliceserviceInstanceId = execution.getVariable("sliceServiceInstanceId") + String ssInstanceId = execution.getVariable("sliceServiceInstanceId") String sliceProfileStr = execution.getVariable("sliceProfile") String sliceProfileId = UUID.randomUUID().toString() SliceProfile sliceProfile = new SliceProfile(); sliceProfile.setProfileId(sliceProfileId) sliceProfile.setLatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency"))) sliceProfile.setResourceSharingLevel(jsonUtil.getJsonValue(sliceProfileStr, "resourceSharingLevel")) - sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)) //TODO: should be list + //sliceProfile.setSNssai(tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr)) - sliceProfile.setE2ELatency(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "latency"))) sliceProfile.setMaxBandwidth(Integer.parseInt(jsonUtil.getJsonValue(sliceProfileStr, "maxBandwidth"))) - //TODO: new API - sliceProfile.setReliability(new Object()) + //sliceProfile.setReliability(new Object()) try { AAIResourcesClient client = getAAIClient() - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(sliceserviceInstanceId).sliceProfile(sliceProfileId)) + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(ssInstanceId) + .sliceProfile(sliceProfileId)) client.create(uri, sliceProfile) } catch (BpmnError e) { @@ -112,20 +114,25 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { ss.setOrchestrationStatus(serviceStatus) String modelInvariantUuid = execution.getVariable("modelInvariantUuid") String modelUuid = execution.getVariable("modelUuid") - ss.setModelInvariantId(modelInvariantUuid) - ss.setModelVersionId(modelUuid) + //TODO: need valid model ID from the caller, as AAI does not accept invalid IDs + //ss.setModelInvariantId(modelInvariantUuid) + //ss.setModelVersionId(modelUuid) String serviceInstanceLocationid = tnNssmfUtils.getFirstPlmnIdFromSliceProfile(sliceProfileStr) ss.setServiceInstanceLocationId(serviceInstanceLocationid) String snssai = tnNssmfUtils.getFirstSnssaiFromSliceProfile(sliceProfileStr) ss.setEnvironmentContext(snssai) ss.setServiceRole(serviceRole) AAIResourcesClient client = getAAIClient() - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(ssInstanceId)) + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(ssInstanceId)) client.create(uri, ss) } catch (BpmnError e) { throw e } catch (Exception ex) { - String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance. " + ex.getMessage() + String msg = "Exception in DoCreateTnNssiInstance.createServiceInstance: " + ex.getMessage() logger.info(msg) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } @@ -133,17 +140,19 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { void createAllottedResource(DelegateExecution execution) { - String serviceInstanceId = execution.getVariable('sliceServiceInstanceId') - - AAIResourcesClient resourceClient = getAAIClient() - AAIResourceUri ssServiceuri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) + String ssInstanceId = execution.getVariable('sliceServiceInstanceId') try { List<String> networkStrList = jsonUtil.StringArrayToList(execution.getVariable("transportSliceNetworks")) for (String networkStr : networkStrList) { String allottedResourceId = UUID.randomUUID().toString() - AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(execution.getVariable("globalSubscriberId")).serviceSubscription(execution.getVariable("subscriptionServiceType")).serviceInstance(execution.getVariable("sliceserviceInstanceId")).allottedResource(allottedResourceId)) + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(execution.getVariable("sliceServiceInstanceId")) + .allottedResource(allottedResourceId)) execution.setVariable("allottedResourceUri", allottedResourceUri) String modelInvariantId = execution.getVariable("modelInvariantUuid") String modelVersionId = execution.getVariable("modelUuid") @@ -152,27 +161,37 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { resource.setId(allottedResourceId) resource.setType("TsciNetwork") resource.setAllottedResourceName("network_" + execution.getVariable("sliceServiceInstanceName")) - resource.setModelInvariantId(modelInvariantId) - resource.setModelVersionId(modelVersionId) getAAIClient().create(allottedResourceUri, resource) - //AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceFromExistingURI(Types.SERVICE_INSTANCE, UriBuilder.fromPath(ssServiceuri).build()) - //getAAIClient().connect(allottedResourceUri,ssServiceuri) - //execution.setVariable("aaiARPath", allottedResourceUri.build().toString()); String linkArrayStr = jsonUtil.getJsonValue(networkStr, "connectionLinks") - createLogicalLinksForAllocatedResource(execution, linkArrayStr, serviceInstanceId, allottedResourceId) + createLogicalLinksForAllocatedResource(execution, linkArrayStr, ssInstanceId, allottedResourceId) } - + } catch (BpmnError e) { + throw e } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception in createAaiAR " + ex.getMessage()) + String msg = "Exception in DoCreateTnNssiInstance.createAllottedResource: " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } } void createLogicalLinksForAllocatedResource(DelegateExecution execution, - String linkArrayStr, String serviceInstanceId, + String linkArrayStr, String ssInstanceId, String allottedResourceId) { - try { + AAIResourceUri allottedResourceUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(execution.getVariable("globalSubscriberId")) + .serviceSubscription(execution.getVariable("subscriptionServiceType")) + .serviceInstance(ssInstanceId) + .allottedResource(allottedResourceId)) + + if (!getAAIClient().exists(allottedResourceUri)) { + logger.info("ERROR: createLogicalLinksForAllocatedResource: allottedResource not exist: uri={}", + allottedResourceUri) + return + } + List<String> linkStrList = jsonUtil.StringArrayToList(linkArrayStr) for (String linkStr : linkStrList) { @@ -186,15 +205,22 @@ class DoCreateTnNssiInstance extends AbstractServiceTaskProcessor { resource.setLinkId(logicalLinkId) resource.setLinkName(epA) resource.setLinkName2(epB) - resource.setModelInvariantId(modelInvariantId) - resource.setModelVersionId(modelVersionId) + resource.setLinkType("TsciConnectionLink") + resource.setInMaint(false) - AAIResourceUri logicalLinkUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(logicalLinkId)) + //epA is link-name + AAIResourceUri logicalLinkUri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLink(epA)) getAAIClient().create(logicalLinkUri, resource) + + tnNssmfUtils.attachLogicalLinkToAllottedResource(execution, AAI_VERSION, allottedResourceUri, epA); } + } catch (BpmnError e) { + throw e } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, - "Exception in createLogicalLinksForAllocatedResource" + ex.getMessage()) + String msg = "Exception in DoCreateTnNssiInstance.createLogicalLinksForAllocatedResource: " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } } 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 c94e2dd67d..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 @@ -20,19 +20,10 @@ 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.CloudRegion -import org.onap.aai.domain.yang.Customer -import org.onap.aai.domain.yang.ModelVer -import org.onap.aai.domain.yang.OwningEntities -import org.onap.aai.domain.yang.ServiceSubscription -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.GenericVnf -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.Tenant -import org.onap.aai.domain.yang.VfModule -import org.onap.aaiclient.client.aai.AAIClient +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 @@ -41,7 +32,6 @@ 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.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.RequestDBUtil @@ -49,22 +39,6 @@ import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.client.HttpClient import org.onap.so.client.HttpClientFactory -import org.onap.so.db.request.beans.OperationStatus -import org.onap.so.requestsdb.RequestsDbConstant -import org.onap.so.serviceinstancebeans.CloudConfiguration -import org.onap.so.serviceinstancebeans.LineOfBusiness -import org.onap.so.serviceinstancebeans.ModelInfo -import org.onap.so.serviceinstancebeans.ModelType -import org.onap.so.serviceinstancebeans.OwningEntity -import org.onap.so.serviceinstancebeans.Project -import org.onap.so.serviceinstancebeans.RequestDetails -import org.onap.so.serviceinstancebeans.RequestInfo -import org.onap.so.serviceinstancebeans.RequestParameters -import org.onap.so.serviceinstancebeans.Resources -import org.onap.so.serviceinstancebeans.Service -import org.onap.so.serviceinstancebeans.SubscriberInfo -import org.onap.so.serviceinstancebeans.VfModules -import org.onap.so.serviceinstancebeans.Vnfs import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -72,6 +46,7 @@ import javax.ws.rs.core.Response class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { private final String PREFIX ="DoDeallocateCoreNSSI" + private final String ACTION = "Deallocate" private ExceptionUtil exceptionUtil = new ExceptionUtil() private RequestDBUtil requestDBUtil = new RequestDBUtil() @@ -80,7 +55,7 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateCoreNSSI.class) -/** + /** * Queries OOF for NSSI termination * @param execution */ @@ -191,36 +166,6 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { } - String encryptBasicAuth(String basicAuth, String msoKey) { - return utils.encrypt(basicAuth, msoKey) - } - - - String getAuthHeader(DelegateExecution execution, String basicAuthValue, String msokey) { - String response = "" - String errorCode = "" - String errorMessage = "" - - LOGGER.debug("Obtained BasicAuth username and password for OOF: " + basicAuthValue) - try { - response = utils.getBasicAuth(basicAuthValue, msokey) - } catch (Exception ex) { - LOGGER.error("Unable to encode username and password string: ", ex) - - errorCode = "401" - errorMessage = "Internal Error - Unable to encode username and password string" - - response = "{\n" + - " \"errorCode\": \"${errorCode}\",\n" + - " \"errorMessage\": \"${errorMessage}\"\n" + - "}" - } - - return response - } - - - /** * Builds OOF request * @param execution @@ -263,7 +208,9 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { ServiceInstance networkServiceInstance = (ServiceInstance)currentNSSI['networkServiceInstance'] - String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId()) // Service Order ID = Network Service Instance ID + String url = String.format("${nbiEndpointUrl}/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId()) + + currentNSSI['deleteServiceOrderURL'] = url String msoKey = UrnPropertiesReader.getVariable("mso.msoKey", execution) String basicAuth = UrnPropertiesReader.getVariable("mso.infra.endpoint.auth", execution) @@ -356,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()) } @@ -387,17 +360,36 @@ class DoDeallocateCoreNSSI extends DoCommonCoreNSSI { try { getAAIClient().delete(nssiUri) }catch(Exception e){ - exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occured while NSSI Service Instance delete call: " + e.getMessage()) + exceptionUtil.buildAndThrowWorkflowException(execution, 25000, "Exception occurred while NSSI Service Instance delete call: " + e.getMessage()) } LOGGER.trace("${PREFIX} Exit deleteNSSIServiceInstance") } + /** + * Gets Delete Service Order progress + * @param execution + */ + void getDeleteServiceOrderProgress(DelegateExecution execution) { + LOGGER.trace("${getPrefix()} Start getDeleteServiceOrderProgress") + + def currentNSSI = execution.getVariable("currentNSSI") + + String url = currentNSSI['deleteServiceOrderURL'] + + getProgress(execution, url, "deleteStatus") + + } + @Override String getPrefix() { return PREFIX } + @Override + String getAction() { + return ACTION + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy index 9d6c4a1b2a..75ef7d347c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy @@ -19,8 +19,8 @@ */ package org.onap.so.bpmn.infrastructure.scripts +import com.fasterxml.jackson.databind.ObjectMapper import org.camunda.bpm.engine.delegate.DelegateExecution -import org.json.JSONObject 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 @@ -47,6 +47,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor private ExceptionUtil exceptionUtil = new ExceptionUtil() private JsonUtils jsonUtil = new JsonUtils() + ObjectMapper objectMapper = new ObjectMapper() private RequestDBUtil requestDBUtil = new RequestDBUtil() private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) @@ -133,10 +134,9 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor String nssiId = currentNSSI['nssiServiceInstanceId'] String nsiId = currentNSSI['nsiServiceInstanceId'] String scriptName = execution.getVariable("scriptName") - boolean modifyAction = execution.getVariable("terminateNSI") String serviceInvariantUuid = currentNSSI['modelInvariantId'] - String serviceUuid = currentNSSI['modelVersionId'] + String serviceUuid = currentNSSI['modelId'] String globalSubscriberId = currentNSSI['globalSubscriberId'] String subscriptionServiceType = execution.getVariable("serviceType") @@ -146,37 +146,37 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor deAllocateNssi.setTerminateNssiOption(0) deAllocateNssi.setSnssaiList(Arrays.asList(snssai)) deAllocateNssi.setScriptName(scriptName) - deAllocateNssi.setSliceProfileId(profileId) - deAllocateNssi.setModifyAction(modifyAction) ServiceInfo serviceInfo = new ServiceInfo() serviceInfo.setServiceInvariantUuid(serviceInvariantUuid) serviceInfo.setServiceUuid(serviceUuid) + serviceInfo.setNsiId(nsiId) serviceInfo.setGlobalSubscriberId(globalSubscriberId) serviceInfo.setSubscriptionServiceType(subscriptionServiceType) + String serviceInfoString = objectMapper.writeValueAsString(serviceInfo) EsrInfo esrInfo = getEsrInfo(currentNSSI) + String esrInfoString = objectMapper.writeValueAsString(esrInfo) execution.setVariable("deAllocateNssi",deAllocateNssi) - execution.setVariable("esrInfo",esrInfo) - execution.setVariable("serviceInfo",serviceInfo) + execution.setVariable("esrInfo", esrInfoString) + execution.setVariable("serviceInfo", serviceInfoString) String nssmfRequest = """ { - "deAllocateNssi": "${execution.getVariable("deAllocateNssi") as JSONObject}", - "esrInfo": ${execution.getVariable("esrInfo") as JSONObject}, - "serviceInfo": ${execution.getVariable("serviceInfo") as JSONObject} + "deAllocateNssi": ${objectMapper.writeValueAsString(deAllocateNssi)}, + "esrInfo": ${esrInfoString}, + "serviceInfo": ${serviceInfoString} } """ - String urlStr = String.format("/api/rest/provMns/v1/NSS/nssi/%s",nssiId) + String urlStr = String.format("/api/rest/provMns/v1/NSS/SliceProfiles/%s", profileId) NssiResponse nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlStr, nssmfRequest, NssiResponse.class) if (nssmfResponse != null) { currentNSSI['jobId']= nssmfResponse.getJobId() ?: "" currentNSSI['jobProgress'] = 0 execution.setVariable("currentNSSI", currentNSSI) - } - else { + } else { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.") } LOGGER.debug("*****${PREFIX} Exit sendRequestToNSSMF *****") @@ -190,32 +190,9 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor { def currentNSSI = execution.getVariable("currentNSSI") String jobId = currentNSSI['jobId'] - String nssiId = currentNSSI['nssiServiceInstanceId'] - String nsiId = currentNSSI['nsiServiceInstanceId'] - String serviceInvariantUuid = currentNSSI['modelInvariantId'] - String serviceUuid = currentNSSI['modelVersionId'] - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String subscriptionServiceType = execution.getVariable("serviceType") - String sST = currentNSSI['sST'] - String PLMNIdList = currentNSSI['PLMNIdList'] - String nssiName = currentNSSI['nssiName'] - + execution.setVariable("responseId", "3") - execution.setVariable("esrInfo", getEsrInfo(currentNSSI)) execution.setVariable("jobId", jobId) - - Map<String, ?> serviceInfoMap = new HashMap<>() - serviceInfoMap.put("nssiId", nssiId) - serviceInfoMap.put("nsiId", nsiId) - serviceInfoMap.put("nssiName", nssiName) - serviceInfoMap.put("sST", sST) - serviceInfoMap.put("PLMNIdList", PLMNIdList) - serviceInfoMap.put("globalSubscriberId", globalSubscriberId) - serviceInfoMap.put("subscriptionServiceType", subscriptionServiceType) - serviceInfoMap.put("serviceInvariantUuid", serviceInvariantUuid) - serviceInfoMap.put("serviceUuid", serviceUuid) - - execution.setVariable("serviceInfo", serviceInfoMap) } @@ -238,8 +215,9 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor LOGGER.error("job progress is null or empty!") exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Job progress from NSSMF.") } + def currentNSSI = execution.getVariable("currentNSSI") int oldProgress = currentNSSI['jobProgress'] - int currentProgress = progress + int currentProgress = Integer.parseInt(progress) execution.setVariable("isNSSIDeAllocated", (currentProgress == 100)) execution.setVariable("isNeedUpdateDB", (oldProgress != currentProgress)) @@ -247,6 +225,8 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor currentNSSI['status'] = status currentNSSI['statusDescription'] = statusDescription + String nssiId = currentNSSI['nssiServiceInstanceId'] + String nsiId = currentNSSI['nsiServiceInstanceId'] LOGGER.debug("job status result: nsiId = ${nsiId}, nssiId=${nssiId}, oldProgress=${oldProgress}, progress = ${currentProgress}" ) } else { @@ -256,7 +236,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor } catch (any) { - String msg = "Received a Bad Response from NSSMF." cause-"+any.getCause()" + String msg = "Received a Bad Response from NSSMF. cause-"+any.getCause() LOGGER.error(any.printStackTrace()) exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) } @@ -309,7 +289,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor String nssiServiceInstanceId = currentNSSI['nssiServiceInstanceId'] String profileId = currentNSSI['profileId'] String globalSubscriberId = currentNSSI["globalSubscriberId"] - String serviceType = currentNSSI["serviceType"] + String serviceType = execution.getVariable("serviceType") try { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy index a410b93d16..baf0333a19 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateTnNssi.groovy @@ -162,7 +162,7 @@ class DoDeallocateTnNssi extends AbstractServiceTaskProcessor { roStatus.setProgress(progress) roStatus.setStatus(status) roStatus.setStatusDescription(statusDescription) - requestDBUtil.prepareUpdateResourceOperationStatus(execution, status) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } } 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 ebeab3eb7d..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 @@ -21,57 +21,32 @@ package org.onap.so.bpmn.infrastructure.scripts import com.fasterxml.jackson.databind.ObjectMapper -import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.aai.domain.yang.CloudRegion -import org.onap.aai.domain.yang.Customer -import org.onap.aai.domain.yang.GenericVnf -import org.onap.aai.domain.yang.ModelVer -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.ServiceSubscription -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.Tenant -import org.onap.aai.domain.yang.VfModule -import org.onap.aaiclient.client.aai.AAIObjectType +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.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.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.RequestDBUtil -import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.HttpClient -import org.onap.so.db.request.beans.OperationStatus -import org.onap.so.requestsdb.RequestsDbConstant -import org.onap.so.serviceinstancebeans.CloudConfiguration -import org.onap.so.serviceinstancebeans.ModelInfo -import org.onap.so.serviceinstancebeans.ModelType -import org.onap.so.serviceinstancebeans.OwningEntity -import org.onap.so.serviceinstancebeans.Project -import org.onap.so.serviceinstancebeans.RequestDetails -import org.onap.so.serviceinstancebeans.RequestInfo -import org.onap.so.serviceinstancebeans.RequestParameters -import org.onap.so.serviceinstancebeans.Resources -import org.onap.so.serviceinstancebeans.Service -import org.onap.so.serviceinstancebeans.SubscriberInfo -import org.onap.so.serviceinstancebeans.VfModules -import org.onap.so.serviceinstancebeans.Vnfs import org.slf4j.Logger import org.slf4j.LoggerFactory -import javax.ws.rs.core.Response +import static org.apache.commons.lang3.StringUtils.isAllLowerCase +import static org.apache.commons.lang3.StringUtils.isBlank class DoModifyCoreNSSI extends DoCommonCoreNSSI { private final String PREFIX ="DoModifyCoreNSSI" + private final String ACTION = "Modify" private ExceptionUtil exceptionUtil = new ExceptionUtil() private RequestDBUtil requestDBUtil = new RequestDBUtil() @@ -80,22 +55,17 @@ 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 = execution.getVariable("sliceProfileID") - Map<String, Object> sliceProfileMap = execution.getVariable("sliceProfileCn") - Map<String, Object> serviceProfileMap = execution.getVariable("serviceProfile") - - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] - String nssiId = currentNSSI['nssiId'] + String sliceProfileID = currentNSSI['sliceProfileId'] + Map<String,Object> sliceProfileMap = new ObjectMapper().readValue(currentNSSI['sliceProfile'], Map.class) SliceProfile sliceProfile = new SliceProfile() sliceProfile.setServiceAreaDimension("") @@ -105,26 +75,117 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { sliceProfile.setExpDataRate(0) sliceProfile.setTrafficDensity(0) sliceProfile.setConnDensity(0) - sliceProfile.setSNssai(sliceProfileMap.get("sNSSAI").toString()) - sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString())) - sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString())) - sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString())) - sliceProfile.setResourceSharingLevel(sliceProfileMap.get("activityFactor").toString()) - sliceProfile.setUeMobilityLevel(serviceProfileMap.get("uEMobilityLevel").toString()) - sliceProfile.setCoverageAreaTAList(serviceProfileMap.get("coverageAreaTAList").toString()) - sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("activityFactor").toString())) - sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString())) + sliceProfile.setSNssai(currentNSSI['S-NSSAI']) + + if(!isBlank(sliceProfileMap.get("expDataRateUL"))) { + sliceProfile.setExpDataRateUL(Integer.parseInt(sliceProfileMap.get("expDataRateUL").toString())) + } + + if(!isBlank(sliceProfileMap.get("expDataRateDL"))) { + sliceProfile.setExpDataRateDL(Integer.parseInt(sliceProfileMap.get("expDataRateDL").toString())) + } + + if(!isBlank(sliceProfileMap.get("activityFactor"))) { + sliceProfile.setActivityFactor(Integer.parseInt(sliceProfileMap.get("activityFactor").toString())) + } + + if(!isBlank(sliceProfileMap.get("resourceSharingLevel"))) { + sliceProfile.setResourceSharingLevel(sliceProfileMap.get("resourceSharingLevel").toString()) + } + + if(!isBlank(sliceProfileMap.get("uEMobilityLevel"))) { + sliceProfile.setUeMobilityLevel(sliceProfileMap.get("uEMobilityLevel").toString()) + } + + if(!isBlank(sliceProfileMap.get("coverageAreaTAList"))) { + sliceProfile.setCoverageAreaTAList(sliceProfileMap.get("coverageAreaTAList").toString()) + } + + if(!isBlank(sliceProfileMap.get("maxNumberofUEs"))) { + sliceProfile.setMaxNumberOfUEs(Integer.parseInt(sliceProfileMap.get("maxNumberofUEs").toString())) + } + + if(!isBlank(sliceProfileMap.get("latency"))) { + sliceProfile.setLatency(Integer.parseInt(sliceProfileMap.get("latency").toString())) + } + 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(serviceType).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") @@ -132,34 +193,92 @@ 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 */ void associateSliceProfileInstanceWithNSSI(DelegateExecution execution) { LOGGER.trace("${PREFIX} Start associateSliceProfileInstanceWithNSSI") - String sliceProfileID = execution.getVariable("sliceProfileID") - def currentNSSI = execution.getVariable("currentNSSI") - String globalSubscriberId = currentNSSI['globalSubscriberId'] - String serviceType = currentNSSI['serviceType'] String nssiId = currentNSSI['nssiId'] - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).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() + } - getAAIClient().update(nssiUri, nssi) + allottedResources.getAllottedResource().add(allottedResource) + sliceProfileInstance.setAllottedResources(allottedResources) - 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()) + 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()) + } + + + // 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") @@ -171,4 +290,9 @@ class DoModifyCoreNSSI extends DoCommonCoreNSSI { return PREFIX } + + @Override + String getAction() { + return ACTION + } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy index 03a726c52c..4ff15a58c5 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyTnNssi.groovy @@ -387,7 +387,7 @@ public class DoModifyTnNssi extends AbstractServiceTaskProcessor { roStatus.setProgress(progress) roStatus.setStatus(status) roStatus.setStatusDescription(statusDescription) - requestDBUtil.prepareUpdateResourceOperationStatus(execution, status) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } } 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/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnAllocateNssi.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnAllocateNssi.groovy index 7d2e536af9..e856522fca 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnAllocateNssi.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnAllocateNssi.groovy @@ -27,11 +27,9 @@ import groovy.json.JsonSlurper import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aaiclient.client.aai.AAIObjectType import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil @@ -155,7 +153,7 @@ class TnAllocateNssi extends AbstractServiceTaskProcessor { "modelUuid":"${modelUuid}", "modelVersion":"" }""" - execution.setVariable("ssServiceModelInfo", serviceModelInfo) + execution.setVariable("serviceModelInfo", serviceModelInfo) logger.debug("Finish prepareDecomposeService") } @@ -186,13 +184,14 @@ class TnAllocateNssi extends AbstractServiceTaskProcessor { if (maxIndex < 1) { String msg = "Exception in TN NSST processDecomposition. There is no NSST associated with TN NSST " logger.info(msg) - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + //exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } else { + execution.setVariable("tnNsstInfoList", nsstInfoList) + execution.setVariable("tnModelVersion", tnModelVersion) + execution.setVariable("tnModelName", tnModelName) + execution.setVariable("currentIndex", currentIndex) + execution.setVariable("maxIndex", maxIndex) } - execution.setVariable("tnNsstInfoList", nsstInfoList) - execution.setVariable("tnModelVersion", tnModelVersion) - execution.setVariable("tnModelName", tnModelName) - execution.setVariable("currentIndex", currentIndex) - execution.setVariable("maxIndex", maxIndex) logger.debug("End processDecomposition") } @@ -334,7 +333,7 @@ class TnAllocateNssi extends AbstractServiceTaskProcessor { roStatus.setProgress(progress) roStatus.setStatus(status) roStatus.setStatusDescription(statusDescription) - requestDBUtil.prepareUpdateResourceOperationStatus(execution, status) + requestDBUtil.prepareUpdateResourceOperationStatus(execution, roStatus) } } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy index a1b883c34e..1bb0e8aca7 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/TnNssmfUtils.groovy @@ -20,8 +20,11 @@ package org.onap.so.bpmn.infrastructure.scripts - +import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.aai.domain.yang.Relationship +import org.onap.aaiclient.client.aai.AAIResourcesClient +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.scripts.MsoUtils import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils @@ -241,4 +244,40 @@ class TnNssmfUtils { return res } + + void createRelationShipInAAI(DelegateExecution execution, AAIResourceUri uri, Relationship relationship) { + logger.debug("createRelationShipInAAI Start") + String msg + AAIResourcesClient client = new AAIResourcesClient() + try { + if (!client.exists(uri)) { + logger.info("ERROR: createRelationShipInAAI: not exist: uri={}", uri) + return + } + AAIResourceUri from = ((AAIResourceUri) (uri.clone())).relationshipAPI() + client.create(from, relationship) + + } catch (BpmnError e) { + throw e + } catch (Exception ex) { + msg = "Exception in createRelationShipInAAI. " + ex.getMessage() + logger.info(msg) + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg) + } + logger.debug("createRelationShipInAAI Exit") + } + + void attachLogicalLinkToAllottedResource(DelegateExecution execution, String aaiVersion, AAIResourceUri arUri, + String logicalLinkId) { + + + String toLink = "aai/${aaiVersion}/network/logical-links/logical-link/${logicalLinkId}" + + Relationship relationship = new Relationship() + relationship.setRelatedLink(toLink) + relationship.setRelatedTo("logical-link") + relationship.setRelationshipLabel("org.onap.relationships.inventory.ComposedOf") + + createRelationShipInAAI(execution, arUri, relationship) + } } 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 2c943ffc7c..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 @@ -24,19 +24,24 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test import org.mockito.Mockito -import org.onap.aai.domain.yang.* -import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aai.domain.yang.v19.* import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.Relationships import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types -import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri +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 +import java.time.Instant + import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* @@ -50,13 +55,32 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { @Test void testPreProcessRequest() { - def currentNSSI = [:] - currentNSSI.put("nssiId","5G-999") - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String nssiId = "5G-999" + when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId) + + String nsiId = "5G-777" + when(mockExecution.getVariable("nsiId")).thenReturn(nsiId) + + String snssai = "S-NSSAI" + String snssaiList = "[ \"${snssai}\" ]" + String sliceProfileId = "slice-profile-id" + String sliceParams = "{\n" + + "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" + + "}" + when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams) DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI() dcnssi.preProcessRequest(mockExecution) - Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI") + + def currentNSSI = [:] + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}") + currentNSSI.put("S-NSSAI", snssai) + currentNSSI.put("sliceProfileId", sliceProfileId) + Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI) + } @@ -90,13 +114,13 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { Relationships rsMock = mock(Relationships.class) Optional<Relationships> orsMock = Optional.of(rsMock) List<AAIResourceUri> arus = new ArrayList<>() - AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri) + AAIResourceUri aru = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId())) arus.add(aru) when(client.get(nssiUri)).thenReturn(wrapperMock) when(wrapperMock.getRelationships()).thenReturn(orsMock) - when(rsMockgetRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus) when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt) spy.getNetworkServiceInstance(mockExecution) @@ -145,7 +169,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock) when(wrapperMock.getRelationships()).thenReturn(orsMock) - when(rsMockgetRelatedUris(Types.GENERIC_VNF)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.GENERIC_VNF)).thenReturn(arus) when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt) spy.getConstituteVNFFromNetworkServiceInst(mockExecution) @@ -162,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() @@ -171,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)) } @@ -190,13 +252,9 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { networkServiceInstance.setServiceInstanceId("NS-777") networkServiceInstance.setServiceRole("Network Service") - GenericVnf constituteVnf = new GenericVnf() - constituteVnf.setVnfId("VNF-1") - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) currentNSSI.put("networkServiceInstance", networkServiceInstance) - currentNSSI.put("constituteVnf", constituteVnf) when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088") when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey") @@ -211,7 +269,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse) - String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) + String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId()) String callPUTServiceInstanceResponse = "put" @@ -243,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) @@ -265,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)) } @@ -281,29 +359,16 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - String globalSubscriberId = "global-id" - String serviceType = "service" - String nssiId = "5G-999" + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type"). + serviceInstance("slice-profile-instance-id")) - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) - 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) @@ -311,26 +376,6 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { @Test - void testUpdateServiceOperationStatus() { - def currentNSSI = [:] - - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - String nssiId = "5G-999" - - currentNSSI.put("nssiId", nssiId) - currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") - currentNSSI.put("operationId", "operationId") - currentNSSI.put("operationType", "operationType") - - DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) - - spy.updateServiceOperationStatus(mockExecution) - - } - - - @Test void testPrepareRequestDetails() { def currentNSSI = [:] @@ -426,7 +471,130 @@ 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()) + } + + + @Test + void testPrepareFailedOperationStatusUpdate() { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + when(mockExecution.getVariable("jobId")).thenReturn("job-id") + when(mockExecution.getVariable("operationType")).thenReturn("operation-type") + + String nssiId = "5G-999" + String nsiId = "5G-777" + + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") + currentNSSI.put("operationId", "operationId") + currentNSSI.put("operationType", "operationType") + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + spy.prepareFailedOperationStatusUpdate(mockExecution) + } + + + @Test + void testPrepareUpdateResourceOperationStatus() { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + when(mockExecution.getVariable("jobId")).thenReturn("job-id") + when(mockExecution.getVariable("operationType")).thenReturn("operation-type") + + String nssiId = "5G-999" + String nsiId = "5G-777" + + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") + currentNSSI.put("operationId", "operationId") + currentNSSI.put("operationType", "operationType") + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + spy.prepareUpdateResourceOperationStatus(mockExecution) + + } + + + @Test + void testGetPUTServiceInstanceProgressAcknowledged() { + + executePUTServiceInstanceProgress("ACKNOWLEDGED") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing") + } + + + @Test + void testGetPUTServiceInstanceProgressInProgress() { + + executePUTServiceInstanceProgress("INPROGRESS") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing") + } + + + @Test + void testGetPUTServiceInstanceProgressCompleted() { + + executePUTServiceInstanceProgress("COMPLETED") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed") + } + + + @Test + void testTimeDelay() { + DoCommonCoreNSSI obj = spy(DoCommonCoreNSSI.class) + + long before = Instant.now().toEpochMilli() + obj.timeDelay(mockExecution) + + long after = Instant.now().toEpochMilli() + + long delay = 5L + + assertTrue(String.format("Didn't wait %d sec", delay), ((after - before) >= delay)) + } + + + void executePUTServiceInstanceProgress(String state) { + + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777" + + currentNSSI.put("putServiceInstanceURL", url) + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class) + when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock) + + ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class) + + when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) + + Response responseMock = mock(Response.class) + when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock) + + when(responseMock.getStatus()).thenReturn(200) + + String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}" + when(responseMock.readEntity(String.class)).thenReturn(entity) + + spy.getPUTServiceInstanceProgress(mockExecution) } @@ -446,7 +614,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.PROJECT)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.PROJECT)).thenReturn(arus) Optional<Project> projectOpt = Optional.of(project) @@ -472,7 +640,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus) Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity) @@ -494,7 +662,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.CLOUD_REGION)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.CLOUD_REGION)).thenReturn(arus) CloudRegion cloudRegion = new CloudRegion() cloudRegion.setCloudRegionId("cloud-region-id") @@ -527,7 +695,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { arus.add(serviceSubscriptionUri) - when(rsMockgetRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus) ServiceSubscription serviceSubscription = new ServiceSubscription() serviceSubscription.setServiceType("service-type") @@ -537,7 +705,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock) - when(rsMockgetRelatedUris(Types.CUSTOMER)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.CUSTOMER)).thenReturn(arus) Customer customer = new Customer() customer.setSubscriberName("subscriber-name") 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 eae788666d..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 @@ -20,19 +20,20 @@ package org.onap.so.bpmn.infrastructure.scripts - import org.junit.Before import org.junit.Test -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.SliceProfiles -import org.onap.aaiclient.client.aai.AAIObjectType +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 import org.onap.so.bpmn.common.scripts.MsoGroovyTest +import javax.ws.rs.core.Response + import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* @@ -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) @@ -263,4 +260,56 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { } + @Test + void testDeleteServiceOrderProgressAcknowledged() { + + executeDeleteServiceOrderProgress("ACKNOWLEDGED") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing") + } + + @Test + void testDeleteServiceOrderProgressInProgress() { + + executeDeleteServiceOrderProgress("INPROGRESS") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing") + } + + + @Test + void testDeleteServiceOrderProgressCompleted() { + + executeDeleteServiceOrderProgress("COMPLETED") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed") + } + + + void executeDeleteServiceOrderProgress(String state) { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777" + + currentNSSI.put("deleteServiceOrderURL", url) + + DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class) + + ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class) + when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock) + + ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class) + + when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) + + Response responseMock = mock(Response.class) + when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock) + + when(responseMock.getStatus()).thenReturn(200) + + String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}" + when(responseMock.readEntity(String.class)).thenReturn(entity) + + spy.getDeleteServiceOrderProgress(mockExecution) + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy index bbc237f1f9..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 @@ -20,13 +20,14 @@ package org.onap.so.bpmn.infrastructure.scripts - +import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.SliceProfiles -import org.onap.aaiclient.client.aai.AAIObjectType +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 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory @@ -47,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) @@ -155,44 +131,42 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String sliceProfileId = "sliceProfileId" - when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId) - - Map<String, Object> sliceProfileMap = new HashMap<>() - sliceProfileMap.put("expDataRateUL", "12") - sliceProfileMap.put("expDataRateDL", 5) - sliceProfileMap.put("activityFactor", 2) - sliceProfileMap.put("latency", 10) - - when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap) - - - Map<String, Object> serviceProfileMap = new HashMap<>() - when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap) + 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) String globalSubscriberId = "globalSubscriberId" - String serviceType = "serviceType" + String subscriptionServiceType = "subscription-service-type" String nssiId = "nssiId" - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) + currentNSSI.put("nssiId", nssiId) - currentNSSI.put("sliceProfileId", sliceProfileId) - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).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) + } @@ -213,32 +187,50 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nssiId", nssiId) String globalSubscriberId = "globalSubscriberId" - String serviceType = "serviceType" + String subscriptionServiceType = "subscriptionServiceType" - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).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) - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) currentNSSI.put("sliceProfileId", sliceProfileId) 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)) } - } |