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 DeleteDeviceResource extends AbstractServiceTaskProcessor {
58 String Prefix="DELDEVRES_"
60 ExceptionUtil exceptionUtil = new ExceptionUtil()
62 JsonUtils jsonUtil = new JsonUtils()
64 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteDeviceResource.class)
66 public void preProcessRequest(DelegateExecution execution){
67 msoLogger.info(" ***** Started preProcessRequest *****")
70 //get bpmn inputs from resource request.
71 String requestId = execution.getVariable("mso-request-id")
72 String requestAction = execution.getVariable("requestAction")
73 msoLogger.info("The requestAction is: " + requestAction)
74 String recipeParamsFromRequest = execution.getVariable("recipeParams")
75 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
76 String resourceInput = execution.getVariable("resourceInput")
77 msoLogger.info("The resourceInput is: " + resourceInput)
78 //Get ResourceInput Object
79 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
80 execution.setVariable(Prefix + "resourceInput", resourceInputObj)
81 String resourceInputPrameters = resourceInputObj.getResourceParameters()
82 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
83 JSONObject inputParameters = new JSONObject(customizeResourceParam(inputParametersJson))
84 execution.setVariable(Prefix + "resourceRequestInputs", inputParameters)
86 //Deal with recipeParams
87 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
88 String resourceName = resourceInputObj.getResourceInstanceName()
89 //For sdnc requestAction default is "createNetworkInstance"
90 String operationType = "Network"
91 if(!StringUtils.isBlank(recipeParamsFromRequest)){
92 //the operationType from worflow(first node) is second priority.
93 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
95 if(!StringUtils.isBlank(recipeParamsFromWf)){
96 //the operationType from worflow(first node) is highest priority.
97 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
100 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
101 execution.setVariable("mso-request-id", requestId)
103 } catch (BpmnError e) {
105 } catch (Exception ex){
106 String msg = "Exception in preProcessRequest " + ex.getMessage()
107 msoLogger.debug( msg)
108 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
112 String customizeResourceParam(String networkInputParametersJson) {
113 List<Map<String, Object>> paramList = new ArrayList();
114 JSONObject jsonObject = new JSONObject(networkInputParametersJson);
115 Iterator iterator = jsonObject.keys();
116 while (iterator.hasNext()) {
117 String key = iterator.next();
118 HashMap<String, String> hashMap = new HashMap();
119 hashMap.put("name", key);
120 hashMap.put("value", jsonObject.get(key))
121 paramList.add(hashMap)
123 Map<String, List<Map<String, Object>>> paramMap = new HashMap();
124 paramMap.put("param", paramList);
126 return new JSONObject(paramMap).toString();
129 public void checkDevType(DelegateExecution execution){
130 utils.log("INFO"," ***** Started checkDevType *****")
133 JSONObject inputParameters = execution.getVariable(Prefix + "resourceRequestInputs")
135 String devType = inputParameters.get("device_class")
137 if(StringUtils.isBlank(devType)) {
141 execution.setVariable("device_class", devType)
143 } catch (Exception ex){
144 String msg = "Exception in checkDevType " + ex.getMessage()
145 msoLogger.debug( msg)
146 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
150 public void getVNFTemplatefromSDC(DelegateExecution execution){
151 utils.log("INFO"," ***** Started getVNFTemplatefromSDC *****")
156 } catch (Exception ex){
157 String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
158 msoLogger.debug( msg)
159 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
163 public void postVNFInfoProcess(DelegateExecution execution){
164 utils.log("INFO"," ***** Started postVNFInfoProcess *****")
169 } catch (Exception ex){
170 String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
171 msoLogger.debug( msg)
172 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
176 public void sendSyncResponse (DelegateExecution execution) {
177 msoLogger.debug( " *** sendSyncResponse *** ")
180 String operationStatus = "finished"
181 // RESTResponse for main flow
182 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
183 msoLogger.debug( " sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
184 sendWorkflowResponse(execution, 202, resourceOperationResp)
185 execution.setVariable("sentSyncResponse", true)
187 } catch (Exception ex) {
188 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
189 msoLogger.debug( msg)
190 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
192 msoLogger.debug(" ***** Exit sendSyncResopnse *****")