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 ModifySliceSubnet extends AbstractServiceTaskProcessor {
35 String Prefix="ModifySliceSubnet_"
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(ModifySliceSubnet.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 servicename = jsonUtil.getJsonValue(subnetInstanceReq, "name")
79 execution.setVariable("servicename", servicename)
81 String nsiId = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties.nsiInfo.nsiId")
83 msg = "Input nsiId is null"
85 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
88 execution.setVariable("nsiId", nsiId)
91 String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
92 if (isBlank(networkType)) {
93 msg = "Input networkType is null"
95 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
98 execution.setVariable("networkType", networkType.toUpperCase())
101 //requestParameters, subscriptionServiceType is 5G
102 String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
103 if (isBlank(subscriptionServiceType)) {
104 msg = "Input subscriptionServiceType is null"
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
111 String jobId = UUID.randomUUID().toString()
112 execution.setVariable("jobId", jobId)
114 String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
115 execution.setVariable("sliceParams", sliceParams)
117 } catch(BpmnError e) {
119 } catch(Exception ex) {
120 msg = "Exception in ModifySliceSubnet.preProcessRequest " + ex.getMessage()
122 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
124 logger.debug(Prefix + "preProcessRequest Exit")
129 * create operation status in request db
131 * Init the Operation Status
133 def prepareInitOperationStatus = { DelegateExecution execution ->
134 logger.debug(Prefix + "prepareInitOperationStatus Start")
136 String nssiId = execution.getVariable("serviceInstanceID")
137 String jobId = execution.getVariable("jobId")
138 String nsiId = execution.getVariable("nsiId")
139 String modelUuid = anNssmfUtils.getModelUuid(execution, nssiId)
140 logger.debug("Generated new job for Service Instance serviceId:" + nsiId + "jobId:" + jobId)
142 ResourceOperationStatus initStatus = new ResourceOperationStatus()
143 initStatus.setServiceId(nsiId)
144 initStatus.setOperationId(jobId)
145 //initStatus.setResourceTemplateUUID(modelUuid)
146 initStatus.setResourceInstanceID(nssiId)
147 initStatus.setOperType("Modify")
148 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
150 logger.debug(Prefix + "prepareInitOperationStatus Exit")
156 * return sync response
158 def sendSyncResponse = { DelegateExecution execution ->
159 logger.debug(Prefix + "sendSyncResponse Start")
161 String jobId = execution.getVariable("jobId")
162 String modifySyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
163 .trim().replaceAll(" ", "")
164 logger.debug("sendSyncResponse to APIH:" + "\n" + modifySyncResponse)
165 sendWorkflowResponse(execution, 202, modifySyncResponse)
167 execution.setVariable("sentSyncResponse", true)
168 } catch (Exception ex) {
169 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
171 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
173 logger.debug(Prefix + "sendSyncResponse Exit")