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
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.aai.domain.yang.Device
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.UrnPropertiesReader
34 import org.onap.so.bpmn.core.WorkflowException
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
37 import org.onap.so.client.HttpClient
38 import org.onap.so.client.aai.AAIObjectType
39 import org.onap.so.client.aai.AAIResourcesClient
40 import org.onap.so.client.aai.entities.uri.AAIResourceUri
41 import org.onap.so.client.aai.entities.uri.AAIUriFactory
42 import org.onap.so.logger.MsoLogger
43 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
45 import java.util.UUID;
46 import javax.ws.rs.core.Response
47 import org.camunda.bpm.engine.delegate.BpmnError
48 import org.camunda.bpm.engine.delegate.DelegateExecution
49 import org.apache.commons.lang3.*
50 import javax.ws.rs.core.MediaType
51 import org.apache.commons.codec.binary.Base64
52 import org.onap.so.utils.TargetEntity
56 * This groovy class supports the <class>DeleteDeviceResource.bpmn</class> process.
57 * flow for Device Resource Delete
59 public class DeleteDeviceResource extends AbstractServiceTaskProcessor {
61 String Prefix="DELDEVRES_"
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 JsonUtils jsonUtil = new JsonUtils()
67 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DeleteDeviceResource.class)
69 public void preProcessRequest(DelegateExecution execution){
70 msoLogger.info(" ***** Started preProcessRequest *****")
73 //get bpmn inputs from resource request.
74 String requestId = execution.getVariable("mso-request-id")
75 String requestAction = execution.getVariable("requestAction")
76 msoLogger.info("The requestAction is: " + requestAction)
77 String recipeParamsFromRequest = execution.getVariable("recipeParams")
78 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
79 String resourceInput = execution.getVariable("resourceInput")
80 msoLogger.info("The resourceInput is: " + resourceInput)
81 //Get ResourceInput Object
82 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
83 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
84 String resourceInputPrameters = resourceInputObj.getResourceParameters()
85 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
86 JSONObject inputParameters = new JSONObject(inputParametersJson)
87 execution.setVariable(Prefix + "ResourceRequestInputs", inputParameters)
89 //Deal with recipeParams
90 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
91 String resourceName = resourceInputObj.getResourceInstanceName()
93 String resourceInstanceId = resourceInputObj.getResourceInstancenUuid()
94 String deviceId = resourceInstanceId
95 execution.setVariable(Prefix + "DeviceId", deviceId)
97 getDeviceInAAI(execution)
99 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
100 execution.setVariable("mso-request-id", requestId)
102 } catch (Exception ex){
103 String msg = "Exception in preProcessRequest " + ex.getMessage()
105 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
109 private void getDeviceInAAI(DelegateExecution execution) {
110 msoLogger.info(" ***** Started getDeviceInAAI *****")
112 String deviceId = execution.getVariable(Prefix + "DeviceId")
114 AAIResourcesClient client = new AAIResourcesClient()
115 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.DEVICE, deviceId)
116 Device dev = client.get(uri).asBean(Device.class).get()
118 String devClass = dev.getClass ()
119 execution.setVariable(Prefix + "DeviceClass", devClass)
120 msoLogger.debug(" DeviceClass is: " + devClass)
122 } catch (Exception ex){
123 String msg = "Exception in getDeviceInAAI " + ex.getMessage()
125 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
128 msoLogger.info(" ***** Exit getDeviceInAAI *****")
131 public void checkDevType(DelegateExecution execution){
132 msoLogger.info(" ***** Started checkDevType *****")
135 String devType = execution.getVariable(Prefix + "DeviceClass")
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 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
151 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
152 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
153 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
156 public void prepareUpdateProgress(DelegateExecution execution) {
157 msoLogger.info(" ***** Started prepareUpdateProgress *****")
158 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
159 String operType = resourceInputObj.getOperationType()
160 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
161 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
162 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
163 String operationId = resourceInputObj.getOperationId()
164 String progress = execution.getVariable("progress")
165 String status = execution.getVariable("status")
166 String statusDescription = execution.getVariable("statusDescription")
169 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
170 xmlns:ns="http://org.openecomp.mso/requestsdb">
173 <ns:updateResourceOperationStatus>
174 <operType>${operType}</operType>
175 <operationId>${operationId}</operationId>
176 <progress>${progress}</progress>
177 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
178 <serviceId>${ServiceInstanceId}</serviceId>
179 <status>${status}</status>
180 <statusDescription>${statusDescription}</statusDescription>
181 </ns:updateResourceOperationStatus>
183 </soapenv:Envelope>"""
185 setProgressUpdateVariables(execution, body)
186 msoLogger.info(" ***** Exit prepareUpdateProgress *****")
189 public void getVNFTemplatefromSDC(DelegateExecution execution){
190 msoLogger.info(" ***** Started getVNFTemplatefromSDC *****")
195 } catch (Exception ex){
196 String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
197 msoLogger.debug( msg)
198 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
202 public void postVNFInfoProcess(DelegateExecution execution){
203 msoLogger.info(" ***** Started postVNFInfoProcess *****")
208 } catch (Exception ex){
209 String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
210 msoLogger.debug( msg)
211 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
215 public void sendSyncResponse (DelegateExecution execution) {
216 msoLogger.debug( " *** sendSyncResponse *** ")
219 String operationStatus = "finished"
220 // RESTResponse for main flow
221 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
222 msoLogger.debug( " sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
223 sendWorkflowResponse(execution, 202, resourceOperationResp)
224 execution.setVariable("sentSyncResponse", true)
226 } catch (Exception ex) {
227 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
228 msoLogger.debug( msg)
229 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
231 msoLogger.debug(" ***** Exit sendSyncResopnse *****")