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 DeAllocateSliceSubnet extends AbstractServiceTaskProcessor {
35 String Prefix="DeASS_"
36 ExceptionUtil exceptionUtil = new ExceptionUtil()
37 JsonUtils jsonUtil = new JsonUtils()
38 RequestDBUtil requestDBUtil = new RequestDBUtil()
40 private static final Logger logger = LoggerFactory.getLogger(DeAllocateSliceSubnet.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 globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId")
59 if (isBlank(globalSubscriberId)) {
60 msg = "Input globalSubscriberId' is null"
61 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
63 execution.setVariable("globalSubscriberId", globalSubscriberId)
67 String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
68 if (isBlank(serviceInstanceID)) {
69 msg = "Input serviceInstanceID is null"
71 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
74 execution.setVariable("serviceInstanceID", serviceInstanceID)
77 String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiId")
79 msg = "Input nsiId is null"
81 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
84 execution.setVariable("nsiId", nsiId)
87 String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
88 if (isBlank(networkType)) {
89 msg = "Input networkType is null"
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 execution.setVariable("networkType", networkType.toUpperCase())
97 //requestParameters, subscriptionServiceType is 5G
98 String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
99 if (isBlank(subscriptionServiceType)) {
100 msg = "Input subscriptionServiceType is null"
102 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
104 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
107 String jobId = UUID.randomUUID().toString()
108 execution.setVariable("jobId", jobId)
110 String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
111 execution.setVariable("sliceParams", sliceParams)
113 } catch(BpmnError e) {
115 } catch(Exception ex) {
116 msg = "Exception in DeAllocateSliceSubnet.preProcessRequest " + ex.getMessage()
118 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120 logger.debug(Prefix + "preProcessRequest Exit")
125 * create operation status in request db
127 * Init the Operation Status
129 def prepareInitOperationStatus = { DelegateExecution execution ->
130 logger.debug(Prefix + "prepareInitOperationStatus Start")
132 String serviceId = execution.getVariable("serviceInstanceID")
133 String jobId = execution.getVariable("jobId")
134 String nsiId = execution.getVariable("nsiId")
135 logger.debug("Generated new job for Service Instance serviceId:" + serviceId + " jobId:" + jobId)
137 ResourceOperationStatus initStatus = new ResourceOperationStatus()
138 initStatus.setServiceId(serviceId)
139 initStatus.setOperationId(jobId)
140 initStatus.setResourceTemplateUUID(nsiId)
141 initStatus.setOperType("Deallocate")
142 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
144 logger.debug(Prefix + "prepareInitOperationStatus Exit")
150 * return sync response
152 def sendSyncResponse = { DelegateExecution execution ->
153 logger.debug(Prefix + "sendSyncResponse Start")
155 String jobId = execution.getVariable("jobId")
156 String deAllocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""".trim().replaceAll(" ", "")
158 logger.debug("sendSyncResponse to APIH:" + "\n" + deAllocateSyncResponse)
159 sendWorkflowResponse(execution, 202, deAllocateSyncResponse)
161 execution.setVariable("sentSyncResponse", true)
162 } catch (Exception ex) {
163 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
165 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
167 logger.debug(Prefix + "sendSyncResponse Exit")