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 {
36 String Prefix="AllocateSliceSubnet_"
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 sST = jsonUtil.getJsonValue(subnetInstanceReq, "sst")
98 execution.setVariable("sst", sST)
100 String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiInfo.nsiId")
101 if (isBlank(nsiId)) {
102 msg = "Input nsiId is null"
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
107 execution.setVariable("nsiId", nsiId)
110 String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
111 if (isBlank(networkType)) {
112 msg = "Input networkType is null"
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 execution.setVariable("networkType", networkType.toUpperCase())
120 //requestParameters, subscriptionServiceType is 5G
121 String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
122 if (isBlank(subscriptionServiceType)) {
123 msg = "Input subscriptionServiceType is null"
125 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
127 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
130 String jobId = UUID.randomUUID().toString()
131 execution.setVariable("jobId", jobId)
133 String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
134 execution.setVariable("sliceParams", sliceParams)
136 } catch(BpmnError e) {
138 } catch(Exception ex) {
139 msg = "Exception in AllocateSliceSubnet.preProcessRequest " + ex.getMessage()
141 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
143 logger.debug(Prefix + "preProcessRequest Exit")
148 * create operation status in request db
150 * Init the Operation Status
152 def prepareInitOperationStatus = { DelegateExecution execution ->
153 logger.debug(Prefix + "prepareInitOperationStatus Start")
155 String modelUuid = execution.getVariable("modelUuid")
156 String jobId = execution.getVariable("jobId")
157 String nsiId = execution.getVariable("nsiId")
158 logger.debug("Generated new job for Service Instance serviceId:" + modelUuid + " jobId:" + jobId)
160 ResourceOperationStatus initStatus = new ResourceOperationStatus()
161 initStatus.setServiceId(nsiId) // set nsiId to this field
162 initStatus.setOperationId(jobId) // set jobId to this field
163 initStatus.setResourceTemplateUUID(modelUuid) // set modelUuid to this field
164 initStatus.setOperType("ALLOCATE")
165 //initStatus.setResourceInstanceID() // set nssiId to this field
166 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
168 logger.debug(Prefix + "prepareInitOperationStatus Exit")
173 * return sync response
175 def sendSyncResponse = { DelegateExecution execution ->
176 logger.debug(Prefix + "sendSyncResponse Start")
178 String jobId = execution.getVariable("jobId")
179 String allocateSyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
180 .trim().replaceAll(" ", "").trim().replaceAll(" ", "")
182 logger.debug("sendSyncResponse to APIH:" + "\n" + allocateSyncResponse)
183 sendWorkflowResponse(execution, 202, allocateSyncResponse)
185 execution.setVariable("sentSyncResponse", true)
186 } catch (Exception ex) {
187 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
189 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
191 logger.debug(Prefix + "sendSyncResponse Exit")