2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  # Copyright (c) 2020, Wipro Limited.
 
   7  # Licensed under the Apache License, Version 2.0 (the "License")
 
   8  # you may not use this file except in compliance with the License.
 
   9  # You may obtain a copy of the License at
 
  11  #       http://www.apache.org/licenses/LICENSE-2.0
 
  13  # Unless required by applicable law or agreed to in writing, software
 
  14  # distributed under the License is distributed on an "AS IS" BASIS,
 
  15  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  # See the License for the specific language governing permissions and
 
  17  # limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.scripts
 
  23 import org.camunda.bpm.engine.delegate.BpmnError
 
  24 import org.camunda.bpm.engine.delegate.DelegateExecution
 
  25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
 
  26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
 
  27 import org.onap.so.bpmn.common.scripts.RequestDBUtil
 
  28 import org.onap.so.bpmn.core.json.JsonUtils
 
  29 import org.onap.so.db.request.beans.ResourceOperationStatus
 
  30 import org.slf4j.Logger
 
  31 import org.slf4j.LoggerFactory
 
  32 import static org.apache.commons.lang3.StringUtils.isBlank
 
  34 class AllocateSliceSubnet extends AbstractServiceTaskProcessor {
 
  37         ExceptionUtil exceptionUtil = new ExceptionUtil()
 
  38         RequestDBUtil requestDBUtil = new RequestDBUtil()
 
  39         JsonUtils jsonUtil = new JsonUtils()
 
  40         private static final Logger logger = LoggerFactory.getLogger(AllocateSliceSubnet.class)
 
  43         void preProcessRequest(DelegateExecution execution) {
 
  44                 logger.debug(Prefix + "preProcessRequest Start")
 
  45                 execution.setVariable("prefix", Prefix)
 
  46                 execution.setVariable("startTime", System.currentTimeMillis())
 
  50                         String subnetInstanceReq = execution.getVariable("bpmnRequest")
 
  51                         logger.debug(subnetInstanceReq)
 
  53                         String requestId = execution.getVariable("mso-request-id")
 
  54                         execution.setVariable("msoRequestId", requestId)
 
  55                         logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId)
 
  58                         String modelInvariantUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelInvariantUuid")
 
  59                         if (isBlank(modelInvariantUuid)) {
 
  60                                 msg = "Input modelInvariantUuid is null"
 
  62                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  65                                 execution.setVariable("modelInvariantUuid", modelInvariantUuid)
 
  68                         logger.debug("modelInvariantUuid: " + modelInvariantUuid)
 
  70                         String modelUuid = jsonUtil.getJsonValue(subnetInstanceReq, "modelUuid")
 
  71                         if (isBlank(modelUuid)) {
 
  72                                 msg = "Input modelUuid is null"
 
  74                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  77                                 execution.setVariable("modelUuid", modelUuid)
 
  80                         logger.debug("modelUuid: " + modelUuid)
 
  84                         String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId")
 
  85                         if (isBlank(globalSubscriberId)) {
 
  86                                 msg = "Input globalSubscriberId' is null"
 
  87                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
  89                                 execution.setVariable("globalSubscriberId", globalSubscriberId)
 
  91                         String dummyServiceId = new UUID(0,0).toString();
 
  92                         execution.setVariable("dummyServiceId", dummyServiceId)
 
  93                         logger.debug("dummyServiceId: " + dummyServiceId)
 
  94                         String servicename = jsonUtil.getJsonValue(subnetInstanceReq, "name")
 
  95                         execution.setVariable("servicename", servicename)
 
  97                         String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiInfo.nsiId")
 
  99                                 msg = "Input nsiId is null"
 
 101                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 104                                 execution.setVariable("nsiId", nsiId)
 
 107                         String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
 
 108                         if (isBlank(networkType)) {
 
 109                                 msg = "Input networkType is null"
 
 111                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 114                                 execution.setVariable("networkType", networkType.toUpperCase())
 
 117                         //requestParameters, subscriptionServiceType is 5G
 
 118                         String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
 
 119                         if (isBlank(subscriptionServiceType)) {
 
 120                                 msg = "Input subscriptionServiceType is null"
 
 122                                 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
 
 124                                 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
 
 127                         String jobId = UUID.randomUUID().toString()
 
 128                         execution.setVariable("jobId", jobId)
 
 130                         String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
 
 131                         execution.setVariable("sliceParams", sliceParams)
 
 133                 } catch(BpmnError e) {
 
 135                 } catch(Exception ex) {
 
 136                         msg = "Exception in AllocateSliceSubnet.preProcessRequest " + ex.getMessage()
 
 138                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 140                 logger.debug(Prefix + "preProcessRequest Exit")
 
 145          * create operation status in request db
 
 147          * Init the Operation Status
 
 149         def prepareInitOperationStatus = { DelegateExecution execution ->
 
 150                 logger.debug(Prefix + "prepareInitOperationStatus Start")
 
 152                 String serviceId = execution.getVariable("dummyServiceId")
 
 153                 String jobId = execution.getVariable("jobId")
 
 154                 String nsiId = execution.getVariable("nsiId")
 
 155                 logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " jobId:" + jobId)
 
 157                 ResourceOperationStatus initStatus = new ResourceOperationStatus()
 
 158                 initStatus.setServiceId(serviceId)
 
 159                 initStatus.setOperationId(jobId)
 
 160                 initStatus.setResourceTemplateUUID(nsiId)
 
 161                 initStatus.setOperType("Allocate")
 
 162                 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
 
 164                 logger.debug(Prefix + "prepareInitOperationStatus Exit")
 
 169          * return sync response
 
 171         def sendSyncResponse = { DelegateExecution execution ->
 
 172                 logger.debug(Prefix + "sendSyncResponse Start")
 
 174                         String jobId = execution.getVariable("jobId")
 
 175                         String allocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
 
 176                                                                                                 .trim().replaceAll(" ", "").trim().replaceAll(" ", "")
 
 178                         logger.debug("sendSyncResponse to APIH:" + "\n" + allocateSyncResponse)
 
 179                         sendWorkflowResponse(execution, 202, allocateSyncResponse)
 
 181                         execution.setVariable("sentSyncResponse", true)
 
 182                 } catch (Exception ex) {
 
 183                         String msg = "Exception in sendSyncResponse:" + ex.getMessage()
 
 185                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
 
 187                 logger.debug(Prefix + "sendSyncResponse Exit")