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 ActivateSliceSubnet extends AbstractServiceTaskProcessor {
35 String Prefix="ActivateSliceSubnet_"
36 ExceptionUtil exceptionUtil = new ExceptionUtil()
37 JsonUtils jsonUtil = new JsonUtils()
38 AnNssmfUtils anNssmfUtils = new AnNssmfUtils()
39 RequestDBUtil requestDBUtil = new RequestDBUtil()
41 private static final Logger logger = LoggerFactory.getLogger(ActivateSliceSubnet.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)
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)
86 String networkType = jsonUtil.getJsonValue(subnetInstanceReq, "networkType")
87 if (isBlank(networkType)) {
88 msg = "Input networkType is null"
90 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 execution.setVariable("networkType", networkType.toUpperCase())
95 //requestParameters, subscriptionServiceType is 5G
96 String subscriptionServiceType = jsonUtil.getJsonValue(subnetInstanceReq, "subscriptionServiceType")
97 if (isBlank(subscriptionServiceType)) {
98 msg = "Input subscriptionServiceType is null"
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
105 //operationType = deactivateInstance/activateInstance
106 String operationType = execution.getVariable("requestAction")
107 if (isBlank(operationType)) {
108 msg = "Input operationType is null"
110 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
112 execution.setVariable("operationType", operationType)
115 String jobId = UUID.randomUUID().toString()
116 execution.setVariable("jobId", jobId)
118 String sliceParams = jsonUtil.getJsonValue(subnetInstanceReq, "additionalProperties")
119 execution.setVariable("sliceParams", sliceParams)
121 } catch(BpmnError e) {
123 } catch(Exception ex) {
124 msg = "Exception in ActivateSliceSubnet.preProcessRequest " + ex.getMessage()
126 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
128 logger.debug(Prefix + "preProcessRequest Exit")
133 * create operation status in request db
135 * Init the Operation Status
137 def prepareInitOperationStatus = { DelegateExecution execution ->
138 logger.debug(Prefix + "prepareInitOperationStatus Start")
140 String nssiId = execution.getVariable("serviceInstanceID")
141 String jobId = execution.getVariable("jobId")
142 String nsiId = execution.getVariable("nsiId")
143 String operationType = execution.getVariable("operationType")
144 String modelUuid = anNssmfUtils.getModelUuid(execution, nssiId)
145 logger.debug("Generated new job for Service Instance serviceId:" + nsiId + " jobId:" + jobId)
147 ResourceOperationStatus initStatus = new ResourceOperationStatus()
149 initStatus.setServiceId(nsiId)
150 initStatus.setOperationId(jobId)
151 initStatus.setResourceTemplateUUID(modelUuid)
152 initStatus.setResourceInstanceID(nssiId)
153 initStatus.setOperType(operationType)
154 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
156 logger.debug(Prefix + "prepareInitOperationStatus Exit")
161 * return sync response
163 def sendSyncResponse = { DelegateExecution execution ->
164 logger.debug(Prefix + "sendSyncResponse Start")
166 String jobId = execution.getVariable("jobId")
167 String activateSyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
168 .trim().replaceAll(" ", "")
170 logger.debug("sendSyncResponse to APIH:" + "\n" + activateSyncResponse)
171 sendWorkflowResponse(execution, 202, activateSyncResponse)
173 execution.setVariable("sentSyncResponse", true)
174 } catch (Exception ex) {
175 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
177 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
179 logger.debug(Prefix + "sendSyncResponse Exit")