2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.json.JSONObject
28 import static org.apache.commons.lang3.StringUtils.*;
29 import groovy.xml.XmlUtil
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.aai.domain.yang.Device
33 import org.onap.so.bpmn.common.recipe.ResourceInput;
34 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
35 import org.onap.so.bpmn.core.UrnPropertiesReader
36 import org.onap.so.bpmn.core.WorkflowException
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
39 import org.onap.so.client.HttpClient
40 import org.onap.aaiclient.client.aai.AAIObjectType
41 import org.onap.aaiclient.client.aai.AAIResourcesClient
42 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
43 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
44 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
45 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
46 import org.slf4j.Logger
47 import org.slf4j.LoggerFactory
48 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
50 import java.util.UUID;
51 import javax.ws.rs.core.Response
52 import org.camunda.bpm.engine.delegate.BpmnError
53 import org.camunda.bpm.engine.delegate.DelegateExecution
54 import org.apache.commons.lang3.*
55 import javax.ws.rs.core.MediaType
56 import org.apache.commons.codec.binary.Base64
57 import org.onap.logging.filter.base.ONAPComponents;
61 * This groovy class supports the <class>DeleteDeviceResource.bpmn</class> process.
62 * flow for Device Resource Delete
64 public class DeleteDeviceResource extends AbstractServiceTaskProcessor {
66 String Prefix="DELDEVRES_"
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
70 JsonUtils jsonUtil = new JsonUtils()
72 private static final Logger logger = LoggerFactory.getLogger( DeleteDeviceResource.class);
74 public void preProcessRequest(DelegateExecution execution){
75 logger.info(" ***** Started preProcessRequest *****")
78 //get bpmn inputs from resource request.
79 String requestId = execution.getVariable("mso-request-id")
80 String requestAction = execution.getVariable("requestAction")
81 logger.info("The requestAction is: " + requestAction)
82 String recipeParamsFromRequest = execution.getVariable("recipeParams")
83 logger.info("The recipeParams is: " + recipeParamsFromRequest)
84 String resourceInput = execution.getVariable("resourceInput")
85 logger.info("The resourceInput is: " + resourceInput)
86 //Get ResourceInput Object
87 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
88 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
89 String resourceInputPrameters = resourceInputObj.getResourceParameters()
90 String inputParametersJson = jsonUtil.getJsonValue(resourceInputPrameters, "requestInputs")
91 JSONObject inputParameters = new JSONObject(inputParametersJson)
92 execution.setVariable(Prefix + "ResourceRequestInputs", inputParameters)
94 //Deal with recipeParams
95 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
96 String resourceName = resourceInputObj.getResourceInstanceName()
98 String resourceInstanceId = resourceInputObj.getResourceInstancenUuid()
99 String deviceId = resourceInstanceId
100 execution.setVariable(Prefix + "DeviceId", deviceId)
102 getDeviceInAAI(execution)
104 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
105 execution.setVariable("mso-request-id", requestId)
107 } catch (Exception ex){
108 String msg = "Exception in preProcessRequest " + ex.getMessage()
110 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
114 private void getDeviceInAAI(DelegateExecution execution) {
115 logger.info(" ***** Started getDeviceInAAI *****")
117 String deviceId = execution.getVariable(Prefix + "DeviceId")
119 AAIResourcesClient client = new AAIResourcesClient()
120 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().device(deviceId))
121 Device dev = client.get(uri).asBean(Device.class).get()
123 String devClass = dev.getClass ()
124 execution.setVariable(Prefix + "DeviceClass", devClass)
125 logger.debug(" DeviceClass is: " + devClass)
127 } catch (Exception ex){
128 String msg = "Exception in getDeviceInAAI " + ex.getMessage()
130 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
133 logger.info(" ***** Exit getDeviceInAAI *****")
136 public void checkDevType(DelegateExecution execution){
137 logger.info(" ***** Started checkDevType *****")
140 String devType = execution.getVariable(Prefix + "DeviceClass")
142 if(StringUtils.isBlank(devType)) {
146 execution.setVariable("device_class", devType)
148 } catch (Exception ex){
149 String msg = "Exception in checkDevType " + ex.getMessage()
151 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
155 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
156 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
157 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
158 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
161 public void prepareUpdateProgress(DelegateExecution execution) {
162 logger.info(" ***** Started prepareUpdateProgress *****")
163 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
164 String operType = resourceInputObj.getOperationType()
165 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
166 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
167 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
168 String operationId = resourceInputObj.getOperationId()
169 String progress = execution.getVariable("progress")
170 String status = execution.getVariable("status")
171 String statusDescription = execution.getVariable("statusDescription")
174 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
175 xmlns:ns="http://org.onap.so/requestsdb">
178 <ns:updateResourceOperationStatus>
179 <operType>${operType}</operType>
180 <operationId>${operationId}</operationId>
181 <progress>${progress}</progress>
182 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
183 <serviceId>${ServiceInstanceId}</serviceId>
184 <status>${status}</status>
185 <statusDescription>${statusDescription}</statusDescription>
186 </ns:updateResourceOperationStatus>
188 </soapenv:Envelope>"""
190 setProgressUpdateVariables(execution, body)
191 logger.info(" ***** Exit prepareUpdateProgress *****")
194 public void getVNFTemplatefromSDC(DelegateExecution execution){
195 logger.info(" ***** Started getVNFTemplatefromSDC *****")
200 } catch (Exception ex){
201 String msg = "Exception in getVNFTemplatefromSDC " + ex.getMessage()
203 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
207 public void postVNFInfoProcess(DelegateExecution execution){
208 logger.info(" ***** Started postVNFInfoProcess *****")
213 } catch (Exception ex){
214 String msg = "Exception in postVNFInfoProcess " + ex.getMessage()
216 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
220 public void sendSyncResponse (DelegateExecution execution) {
221 logger.debug( " *** sendSyncResponse *** ")
224 String operationStatus = "finished"
225 // RESTResponse for main flow
226 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
227 logger.debug( " sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
228 sendWorkflowResponse(execution, 202, resourceOperationResp)
229 execution.setVariable("sentSyncResponse", true)
231 } catch (Exception ex) {
232 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
234 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
236 logger.debug(" ***** Exit sendSyncResopnse *****")