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="DeAllocateSliceSubnet_"
36 ExceptionUtil exceptionUtil = new ExceptionUtil()
37 JsonUtils jsonUtil = new JsonUtils()
38 RequestDBUtil requestDBUtil = new RequestDBUtil()
39 AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
41 private static final Logger logger = LoggerFactory.getLogger(DeAllocateSliceSubnet.class)
44 void preProcessRequest(DelegateExecution execution) {
45 logger.debug(Prefix + "preProcessRequest Start")
46 execution.setVariable("prefix", Prefix)
47 execution.setVariable("startTime", System.currentTimeMillis())
51 String subnetInstanceReq = execution.getVariable("bpmnRequest")
52 logger.debug(subnetInstanceReq)
54 String requestId = execution.getVariable("mso-request-id")
55 execution.setVariable("msoRequestId", requestId)
56 logger.debug("Input Request:" + subnetInstanceReq + " reqId:" + requestId)
59 String globalSubscriberId = jsonUtil.getJsonValue(subnetInstanceReq, "globalSubscriberId")
60 if (isBlank(globalSubscriberId)) {
61 msg = "Input globalSubscriberId' is null"
62 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
64 execution.setVariable("globalSubscriberId", globalSubscriberId)
68 String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
69 if (isBlank(serviceInstanceID)) {
70 msg = "Input serviceInstanceID is null"
72 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
75 execution.setVariable("serviceInstanceID", serviceInstanceID)
78 String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiId")
80 msg = "Input nsiId is null"
82 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
85 execution.setVariable("nsiId", nsiId)
88 String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
89 if (isBlank(networkType)) {
90 msg = "Input networkType is null"
92 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
95 execution.setVariable("networkType", networkType.toUpperCase())
98 //requestParameters, subscriptionServiceType is 5G
99 String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
100 if (isBlank(subscriptionServiceType)) {
101 msg = "Input subscriptionServiceType is null"
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
105 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
108 String jobId = UUID.randomUUID().toString()
109 execution.setVariable("jobId", jobId)
111 String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
112 execution.setVariable("sliceParams", sliceParams)
114 } catch(BpmnError e) {
116 } catch(Exception ex) {
117 msg = "Exception in DeAllocateSliceSubnet.preProcessRequest " + ex.getMessage()
119 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
121 logger.debug(Prefix + "preProcessRequest Exit")
126 * create operation status in request db
128 * Init the Operation Status
130 def prepareInitOperationStatus = { DelegateExecution execution ->
131 logger.debug(Prefix + "prepareInitOperationStatus Start")
133 String nssiId = execution.getVariable("serviceInstanceID")
134 String jobId = execution.getVariable("jobId")
135 String nsiId = execution.getVariable("nsiId")
136 String modelUuid = anNssmfUtils.getModelUuid(execution, nssiId)
137 logger.debug("Generated new job for Service Instance serviceId:" + nsiId + " jobId:" + jobId)
139 ResourceOperationStatus initStatus = new ResourceOperationStatus()
140 initStatus.setServiceId(nsiId)
141 initStatus.setOperationId(jobId)
142 //initStatus.setResourceTemplateUUID(modelUuid)
143 initStatus.setResourceInstanceID(nssiId)
144 initStatus.setOperType("Deallocate")
145 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
147 logger.debug(Prefix + "prepareInitOperationStatus Exit")
153 * return sync response
155 def sendSyncResponse = { DelegateExecution execution ->
156 logger.debug(Prefix + "sendSyncResponse Start")
158 String jobId = execution.getVariable("jobId")
159 String deAllocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}""".trim().replaceAll(" ", "")
161 logger.debug("sendSyncResponse to APIH:" + "\n" + deAllocateSyncResponse)
162 sendWorkflowResponse(execution, 202, deAllocateSyncResponse)
164 execution.setVariable("sentSyncResponse", true)
165 } catch (Exception ex) {
166 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
168 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
170 logger.debug(Prefix + "sendSyncResponse Exit")