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
33 import static org.apache.commons.lang3.StringUtils.isBlank
35 class DeleteServiceIntentInstance extends AbstractServiceTaskProcessor {
36 String Prefix = "DCLL_"
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
38 JsonUtils jsonUtil = new JsonUtils()
39 RequestDBUtil requestDBUtil = new RequestDBUtil()
40 ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
42 private static final Logger logger = LoggerFactory.getLogger(DeleteServiceIntentInstance.class)
45 void preProcessRequest(DelegateExecution execution) {
46 logger.debug(Prefix + "preProcessRequest Start")
47 execution.setVariable("prefix", Prefix)
48 execution.setVariable("startTime", System.currentTimeMillis())
52 String subnetInstanceReq = execution.getVariable("bpmnRequest")
53 logger.debug(subnetInstanceReq)
55 serviceIntentUtils.setCommonExecutionVars(execution)
57 String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
58 if (isBlank(serviceInstanceID)) {
59 msg = "Input serviceInstanceID is null"
61 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
63 execution.setVariable("serviceInstanceID", serviceInstanceID)
66 String jobId = UUID.randomUUID().toString()
67 execution.setVariable("jobId", jobId)
69 } catch (BpmnError e) {
71 } catch (Exception ex) {
72 msg = "Exception in DeAllocateSliceSubnet.preProcessRequest " + ex.getMessage()
74 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
76 logger.debug(Prefix + "preProcessRequest Exit")
81 * create operation status in request db
83 * Init the Operation Status
85 def prepareInitOperationStatus = { DelegateExecution execution ->
86 logger.debug(Prefix + "prepareInitOperationStatus Start")
88 String siId = execution.getVariable("serviceInstanceID")
89 String jobId = execution.getVariable("jobId")
91 String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId)
92 logger.debug("Generated new job for Service Instance serviceId:" + nsiId + " jobId:" + jobId)
94 ResourceOperationStatus initStatus = new ResourceOperationStatus()
95 initStatus.setServiceId(nsiId)
96 initStatus.setOperationId(jobId)
97 initStatus.setResourceTemplateUUID(modelUuid)
98 initStatus.setOperType("Delete")
99 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
101 logger.debug(Prefix + "prepareInitOperationStatus Exit")
106 * return sync response
108 def sendSyncResponse = { DelegateExecution execution ->
109 logger.debug(Prefix + "sendSyncResponse Start")
111 String jobId = execution.getVariable("jobId")
112 String deAllocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""".trim().replaceAll(" ", "")
114 logger.debug("sendSyncResponse to APIH:" + "\n" + deAllocateSyncResponse)
115 sendWorkflowResponse(execution, 202, deAllocateSyncResponse)
117 execution.setVariable("sentSyncResponse", true)
118 } catch (Exception ex) {
119 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
121 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
123 logger.debug(Prefix + "sendSyncResponse Exit")