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.rest.APIResponse
38 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
40 import java.util.UUID;
42 import org.camunda.bpm.engine.delegate.BpmnError
43 import org.camunda.bpm.engine.delegate.DelegateExecution
44 import org.apache.commons.lang3.*
45 import org.apache.commons.codec.binary.Base64;
46 import org.springframework.web.util.UriUtils
47 import org.onap.so.rest.RESTClient
48 import org.onap.so.rest.RESTConfig
49 import org.onap.so.rest.APIResponse;
50 import org.onap.so.bpmn.common.scripts.AaiUtil
53 * This groovy class supports the <class>CreateDeviceResource.bpmn</class> process.
54 * flow for Device Resource Create
56 public class CreateDeviceResource extends AbstractServiceTaskProcessor {
58 String Prefix="CREDEVRES_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
62 JsonUtils jsonUtil = new JsonUtils()
64 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CreateDeviceResource.class)
66 public void preProcessRequest(DelegateExecution execution){
67 msoLogger.info(" ***** Started preProcessRequest *****")
71 //get bpmn inputs from resource request.
72 String requestId = execution.getVariable("mso-request-id")
73 String requestAction = execution.getVariable("requestAction")
74 msoLogger.info("The requestAction is: " + requestAction)
75 String recipeParamsFromRequest = execution.getVariable("recipeParams")
76 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
77 String resourceInput = execution.getVariable("resourceInput")
78 msoLogger.info("The resourceInput is: " + resourceInput)
79 //Get ResourceInput Object
80 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
81 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
83 String resourceInputPrameters = resourceInputObj.getResourceParameters()
84 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
85 JSONObject inputParameters = new JSONObject(inputParametersJson)
86 execution.setVariable(Prefix + "ResourceRequestInputs", inputParameters)
88 // String incomingRequest = resourceInputObj.getRequestsInputs()
89 // String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
90 // String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
91 // JSONObject serviceInputParameters = new JSONObject(requestInputs)
92 // execution.setVariable(Prefix + "ServiceParameters", serviceInputParameters)
94 //Deal with recipeParams
95 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
96 String resourceName = resourceInputObj.getResourceInstanceName()
97 if (isBlank(resourceName)) {
98 msg = "Input resourceName is null"
101 execution.setVariable("resourceName", resourceName)
102 msoLogger.info("resourceName:" + resourceName)
104 String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
105 if (isBlank(resourceModelInvariantUuid)) {
106 msg = "Input resourceModelInvariantUuid is null"
109 execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
110 msoLogger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
112 String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
113 if (isBlank(resourceModelUuid)) {
114 msg = "Input resourceModelUuid is null"
117 execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
118 msoLogger.info("resourceModelUuid:" + resourceModelUuid)
120 String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
121 if (isBlank(resourceModelCustomizationUuid)) {
122 msg = "Input resourceModelCustomizationUuid is null"
125 execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
126 msoLogger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
128 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
129 execution.setVariable("mso-request-id", requestId)
131 } catch (BpmnError e) {
133 } catch (Exception ex){
134 msg = "Exception in preProcessRequest " + ex.getMessage()
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 public void checkDevType(DelegateExecution execution){
141 msoLogger.info(" ***** Started checkDevType *****")
144 JSONObject resourceInputParameters = execution.getVariable(Prefix + "ResourceRequestInputs")
145 String devType = resourceInputParameters.get("device_class")
147 if(StringUtils.isBlank(devType)) {
150 // support VNF as PNF, to modify
151 else if(StringUtils.equalsIgnoreCase(devType, "VNF")) {
155 execution.setVariable("device_class", devType)
157 } catch (Exception ex){
158 String msg = "Exception in checkDevType " + ex.getMessage()
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
164 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
165 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
166 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
167 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
170 public void prepareUpdateProgress(DelegateExecution execution) {
171 msoLogger.info(" ***** Started prepareUpdateProgress *****")
172 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
173 String operType = resourceInputObj.getOperationType()
174 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
175 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
176 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
177 String operationId = resourceInputObj.getOperationId()
178 String progress = execution.getVariable("progress")
179 String status = execution.getVariable("status")
180 String statusDescription = execution.getVariable("statusDescription")
183 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
184 xmlns:ns="http://org.openecomp.mso/requestsdb">
187 <ns:updateResourceOperationStatus>
188 <operType>${operType}</operType>
189 <operationId>${operationId}</operationId>
190 <progress>${progress}</progress>
191 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
192 <serviceId>${ServiceInstanceId}</serviceId>
193 <status>${status}</status>
194 <statusDescription>${statusDescription}</statusDescription>
195 </ns:updateResourceOperationStatus>
197 </soapenv:Envelope>"""
199 setProgressUpdateVariables(execution, body)
200 msoLogger.info(" ***** Exit prepareUpdateProgress *****")
203 public void getVNFTemplatefromSDC(DelegateExecution execution){
204 msoLogger.info(" ***** Started getVNFTemplatefromSDC *****")
209 } catch (Exception ex){
210 String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
212 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
216 public void postVNFInfoProcess(DelegateExecution execution){
217 msoLogger.info(" ***** Started postVNFInfoProcess *****")
222 } catch (Exception ex){
223 String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
225 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
229 public void sendSyncResponse (DelegateExecution execution) {
230 msoLogger.debug(" *** sendSyncResponse *** ")
233 String operationStatus = "finished"
234 // RESTResponse for main flow
235 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
236 msoLogger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
237 sendWorkflowResponse(execution, 202, resourceOperationResp)
238 execution.setVariable("sentSyncResponse", true)
240 } catch (Exception ex) {
241 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
243 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
245 utils.log("DEBUG"," ***** Exit sendSyncResopnse *****")