2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
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.json.JSONObject
26 import static org.apache.commons.lang3.StringUtils.*;
27 import groovy.xml.XmlUtil
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.onap.so.bpmn.common.recipe.ResourceInput;
32 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.json.JsonUtils
35 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
36 import org.onap.so.logger.MsoLogger
37 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
39 import java.util.UUID;
41 import org.camunda.bpm.engine.delegate.BpmnError
42 import org.camunda.bpm.engine.delegate.DelegateExecution
43 import org.apache.commons.lang3.*
44 import org.apache.commons.codec.binary.Base64;
45 import org.springframework.web.util.UriUtils
46 import org.onap.so.bpmn.common.scripts.AaiUtil
49 * This groovy class supports the <class>CreateDeviceResource.bpmn</class> process.
50 * flow for Device Resource Create
52 public class CreateDeviceResource extends AbstractServiceTaskProcessor {
54 String Prefix="CREDEVRES_"
56 ExceptionUtil exceptionUtil = new ExceptionUtil()
58 JsonUtils jsonUtil = new JsonUtils()
60 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateDeviceResource.class)
62 public void preProcessRequest(DelegateExecution execution){
63 msoLogger.info(" ***** Started preProcessRequest *****")
67 //get bpmn inputs from resource request.
68 String requestId = execution.getVariable("mso-request-id")
69 String requestAction = execution.getVariable("requestAction")
70 msoLogger.info("The requestAction is: " + requestAction)
71 String recipeParamsFromRequest = execution.getVariable("recipeParams")
72 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
73 String resourceInput = execution.getVariable("resourceInput")
74 msoLogger.info("The resourceInput is: " + resourceInput)
75 //Get ResourceInput Object
76 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
77 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
79 String resourceInputPrameters = resourceInputObj.getResourceParameters()
80 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
81 JSONObject inputParameters = new JSONObject(inputParametersJson)
82 execution.setVariable(Prefix + "ResourceRequestInputs", inputParameters)
84 // String incomingRequest = resourceInputObj.getRequestsInputs()
85 // String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
86 // String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
87 // JSONObject serviceInputParameters = new JSONObject(requestInputs)
88 // execution.setVariable(Prefix + "ServiceParameters", serviceInputParameters)
90 //Deal with recipeParams
91 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
92 String resourceName = resourceInputObj.getResourceInstanceName()
93 if (isBlank(resourceName)) {
94 msg = "Input resourceName is null"
97 execution.setVariable("resourceName", resourceName)
98 msoLogger.info("resourceName:" + resourceName)
100 String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
101 if (isBlank(resourceModelInvariantUuid)) {
102 msg = "Input resourceModelInvariantUuid is null"
105 execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
106 msoLogger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
108 String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
109 if (isBlank(resourceModelUuid)) {
110 msg = "Input resourceModelUuid is null"
113 execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
114 msoLogger.info("resourceModelUuid:" + resourceModelUuid)
116 String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
117 if (isBlank(resourceModelCustomizationUuid)) {
118 msg = "Input resourceModelCustomizationUuid is null"
121 execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
122 msoLogger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
124 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
125 execution.setVariable("mso-request-id", requestId)
127 } catch (BpmnError e) {
129 } catch (Exception ex){
130 msg = "Exception in preProcessRequest " + ex.getMessage()
132 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
136 public void checkDevType(DelegateExecution execution){
137 msoLogger.info(" ***** Started checkDevType *****")
140 JSONObject resourceInputParameters = execution.getVariable(Prefix + "ResourceRequestInputs")
141 String devType = resourceInputParameters.get("device_class")
143 if(StringUtils.isBlank(devType)) {
146 // support VNF as PNF, to modify
147 else if(StringUtils.equalsIgnoreCase(devType, "VNF")) {
151 execution.setVariable("device_class", devType)
153 } catch (Exception ex){
154 String msg = "Exception in checkDevType " + ex.getMessage()
156 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
160 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
161 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
162 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
163 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
166 public void prepareUpdateProgress(DelegateExecution execution) {
167 msoLogger.info(" ***** Started prepareUpdateProgress *****")
168 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
169 String operType = resourceInputObj.getOperationType()
170 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
171 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
172 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
173 String operationId = resourceInputObj.getOperationId()
174 String progress = execution.getVariable("progress")
175 String status = execution.getVariable("status")
176 String statusDescription = execution.getVariable("statusDescription")
179 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
180 xmlns:ns="http://org.openecomp.mso/requestsdb">
183 <ns:updateResourceOperationStatus>
184 <operType>${operType}</operType>
185 <operationId>${operationId}</operationId>
186 <progress>${progress}</progress>
187 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
188 <serviceId>${ServiceInstanceId}</serviceId>
189 <status>${status}</status>
190 <statusDescription>${statusDescription}</statusDescription>
191 </ns:updateResourceOperationStatus>
193 </soapenv:Envelope>"""
195 setProgressUpdateVariables(execution, body)
196 msoLogger.info(" ***** Exit prepareUpdateProgress *****")
199 public void getVNFTemplatefromSDC(DelegateExecution execution){
200 msoLogger.info(" ***** Started getVNFTemplatefromSDC *****")
205 } catch (Exception ex){
206 String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
208 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
212 public void postVNFInfoProcess(DelegateExecution execution){
213 msoLogger.info(" ***** Started postVNFInfoProcess *****")
218 } catch (Exception ex){
219 String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
221 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
225 public void sendSyncResponse (DelegateExecution execution) {
226 msoLogger.debug(" *** sendSyncResponse *** ")
229 String operationStatus = "finished"
230 // RESTResponse for main flow
231 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
232 msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
233 sendWorkflowResponse(execution, 202, resourceOperationResp)
234 execution.setVariable("sentSyncResponse", true)
236 } catch (Exception ex) {
237 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
239 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
241 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****")