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.onap.so.logger.MsoLogger
25 import static org.apache.commons.lang3.StringUtils.*;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.onap.so.bpmn.common.recipe.ResourceInput;
31 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.MsoUtils
35 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
36 import org.onap.so.bpmn.core.json.JsonUtils
41 * This groovy class supports the <class>DeleteSDNCCNetworkResource.bpmn</class> process.
42 * flow for SDNC Network Resource
44 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
45 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
46 CreateSDNCNetworkResource.class);
48 String Prefix="DELSDNCRES_"
50 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
54 SDNCAdapterUtils sdncAdapterUtils = new SDNCAdapterUtils()
56 public void preProcessRequest(DelegateExecution execution){
57 msoLogger.info("***** Started preProcessRequest *****")
60 //get bpmn inputs from resource request.
61 String requestId = execution.getVariable("mso-request-id")
62 String requestAction = execution.getVariable("requestAction")
63 msoLogger.info("The requestAction is: " + requestAction)
64 String recipeParamsFromRequest = execution.getVariable("recipeParams")
65 msoLogger.info("The recipeParams is: " + recipeParamsFromRequest)
66 String resourceInput = execution.getVariable("resourceInput")
67 msoLogger.info("The resourceInput is: " + resourceInput)
68 //Get ResourceInput Object
69 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
70 execution.setVariable(Prefix + "resourceInput", resourceInputObj)
72 //Deal with recipeParams
73 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
74 String resourceModelName = resourceInputObj.getResourceModelInfo().getModelName()
75 //For sdnc requestAction default is "NetworkInstance"
76 String operationType = "Network"
77 if(!StringUtils.isBlank(recipeParamsFromRequest) && "null" != recipeParamsFromRequest){
78 //the operationType from worflow(first node) is second priority.
79 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
81 if(!StringUtils.isBlank(recipeParamsFromWf)){
82 //the operationType from worflow(first node) is highest priority.
83 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
87 //For sdnc, generate svc_action and request_action
88 String sdnc_svcAction = "delete"
89 if(StringUtils.containsIgnoreCase(resourceModelName, "overlay")){
90 //This will be resolved in R3.
91 sdnc_svcAction ="deactivate"
92 operationType = "NCINetwork"
94 if(StringUtils.containsIgnoreCase(resourceModelName, "underlay")){
95 //This will be resolved in R3.
96 operationType ="Network"
98 String sdnc_requestAction = StringUtils.capitalize(sdnc_svcAction) + operationType +"Instance"
99 execution.setVariable(Prefix + "svcAction", sdnc_svcAction)
100 execution.setVariable(Prefix + "requestAction", sdnc_requestAction)
101 execution.setVariable(Prefix + "serviceInstanceId", resourceInputObj.getServiceInstanceId())
102 execution.setVariable("mso-request-id", requestId)
103 execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
104 //TODO Here build networkrequest
106 } catch (BpmnError e) {
108 } catch (Exception ex){
109 msg = "Exception in preProcessRequest " + ex.getMessage()
111 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
116 * Pre Process the BPMN Flow Request
118 * generate the nsOperationKey
119 * generate the nsParameters
121 public void prepareSDNCRequest (DelegateExecution execution) {
122 msoLogger.info("***** Started prepareSDNCRequest *****")
126 String sdnc_svcAction = execution.getVariable(Prefix + "svcAction")
127 String sdnc_requestAction = execution.getVariable(Prefix + "requestAction")
128 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
129 String deleteNetworkInput = execution.getVariable(Prefix + "networkRequest")
131 String hdrRequestId = execution.getVariable("mso-request-id")
132 String serviceInstanceId = execution.getVariable(Prefix + "serviceInstanceId")
133 String source = execution.getVariable("source")
134 String sdnc_service_id = execution.getVariable(Prefix + "sdncServiceId")
135 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
136 String serviceType = resourceInputObj.getServiceType()
137 String serviceModelInvariantUuid = resourceInputObj.getServiceModelInfo().getModelInvariantUuid()
138 String serviceModelUuid = resourceInputObj.getServiceModelInfo().getModelUuid()
139 String serviceModelVersion = resourceInputObj.getServiceModelInfo().getModelVersion()
140 String serviceModelName = resourceInputObj.getServiceModelInfo().getModelName()
141 String globalCustomerId = resourceInputObj.getGlobalSubscriberId()
142 String modelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid();
143 String modelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
144 String modelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
145 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
146 String modelVersion = resourceInputObj.getResourceModelInfo().getModelVersion()
147 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
148 String sndcTopologyDeleteRequest = ""
152 sndcTopologyDeleteRequest = """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
153 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1"
154 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
155 <sdncadapter:RequestHeader>
156 <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId>
157 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
158 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(sdnc_svcAction)}</sdncadapter:SvcAction>
159 <sdncadapter:SvcOperation>network-topology-operation</sdncadapter:SvcOperation>
160 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
161 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
162 </sdncadapter:RequestHeader>
163 <sdncadapterworkflow:SDNCRequestData>
164 <request-information>
165 <request-id>${MsoUtils.xmlEscape(hdrRequestId)}</request-id>
166 <request-action>${MsoUtils.xmlEscape(sdnc_requestAction)}</request-action>
167 <source>${MsoUtils.xmlEscape(source)}</source>
168 <notification-url></notification-url>
169 <order-number></order-number>
170 <order-version></order-version>
171 </request-information>
172 <service-information>
173 <service-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-id>
174 <subscription-service-type>${MsoUtils.xmlEscape(serviceType)}</subscription-service-type>
175 <onap-model-information>
176 <model-invariant-uuid>${MsoUtils.xmlEscape(serviceModelInvariantUuid)}</model-invariant-uuid>
177 <model-uuid>${MsoUtils.xmlEscape(serviceModelUuid)}</model-uuid>
178 <model-version>${MsoUtils.xmlEscape(serviceModelVersion)}</model-version>
179 <model-name>${MsoUtils.xmlEscape(serviceModelName)}</model-name>
180 </onap-model-information>
181 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
182 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
183 <subscriber-name></subscriber-name>
184 </service-information>
186 <!-- TODO: to be filled as per the request input -->
188 <vnf-type></vnf-type>
189 <onap-model-information>
190 <model-invariant-uuid>${MsoUtils.xmlEscape(modelInvariantUuid)}</model-invariant-uuid>
191 <model-customization-uuid>${MsoUtils.xmlEscape(modelCustomizationUuid)}</model-customization-uuid>
192 <model-uuid>${MsoUtils.xmlEscape(modelUuid)}</model-uuid>
193 <model-version>${MsoUtils.xmlEscape(modelVersion)}</model-version>
194 <model-name>${MsoUtils.xmlEscape(modelName)}</model-name>
195 </onap-model-information>
198 <request-version></request-version>
199 <vnf-name></vnf-name>
202 <network-role></network-role>
203 <network-name></network-name>
204 <neutron-id></neutron-id>
205 <network-id></network-id>
206 <contrail-network-fqdn></contrail-network-fqdn>
209 <ip-version></ip-version>
210 <subnet-id></subnet-id>
216 <vnf-input-parameters>
218 </vnf-input-parameters>
219 </sdncadapterworkflow:SDNCRequestData>
220 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
226 sndcTopologyDeleteRequest = ""
229 String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
230 utils.logAudit(sndcTopologyDeleteRequesAsString)
231 execution.setVariable("sdncAdapterWorkflowRequest", sndcTopologyDeleteRequesAsString)
232 msoLogger.info("sdncAdapterWorkflowRequest - " + "\n" + sndcTopologyDeleteRequesAsString)
234 } catch (Exception ex) {
235 String exceptionMessage = " Bpmn error encountered in DeleteSDNCCNetworkResource flow. prepareSDNCRequest() - " + ex.getMessage()
236 msoLogger.debug(exceptionMessage)
237 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
240 msoLogger.info(" ***** Exit prepareSDNCRequest *****")
243 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
244 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
245 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
246 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
249 public void prepareUpdateBeforeDeleteSDNCResource(DelegateExecution execution) {
250 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
251 String operType = resourceInputObj.getOperationType()
252 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
253 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
254 String operationId = resourceInputObj.getOperationId()
255 String progress = "20"
256 String status = "processing"
257 String statusDescription = "SDCN resource delete invoked"
259 //String operationId = execution.getVariable("operationId")
262 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
263 xmlns:ns="http://org.onap.so/requestsdb">
266 <ns:updateResourceOperationStatus>
267 <operType>${MsoUtils.xmlEscape(operType)}</operType>
268 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
269 <progress>${MsoUtils.xmlEscape(progress)}</progress>
270 <resourceTemplateUUID>${MsoUtils.xmlEscape(resourceCustomizationUuid)}</resourceTemplateUUID>
271 <serviceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceId>
272 <status>${MsoUtils.xmlEscape(status)}</status>
273 <statusDescription>${MsoUtils.xmlEscape(statusDescription)}</statusDescription>
274 </ns:updateResourceOperationStatus>
276 </soapenv:Envelope>""";
278 setProgressUpdateVariables(execution, body)
282 public void prepareUpdateAfterDeleteSDNCResource(DelegateExecution execution) {
283 ResourceInput resourceInputObj = execution.getVariable(Prefix + "resourceInput")
284 String operType = resourceInputObj.getOperationType()
285 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
286 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
287 String operationId = resourceInputObj.getOperationId()
288 String progress = "100"
289 String status = "finished"
290 String statusDescription = "SDCN resource delete completed"
292 //String operationId = execution.getVariable("operationId")
295 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
296 xmlns:ns="http://org.onap.so/requestsdb">
299 <ns:updateResourceOperationStatus>
300 <operType>${MsoUtils.xmlEscape(operType)}</operType>
301 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
302 <progress>${MsoUtils.xmlEscape(progress)}</progress>
303 <resourceTemplateUUID>${MsoUtils.xmlEscape(resourceCustomizationUuid)}</resourceTemplateUUID>
304 <serviceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceId>
305 <status>${MsoUtils.xmlEscape(status)}</status>
306 <statusDescription>${MsoUtils.xmlEscape(statusDescription)}</statusDescription>
307 </ns:updateResourceOperationStatus>
309 </soapenv:Envelope>""";
311 setProgressUpdateVariables(execution, body)
314 public void postDeleteSDNCCall(DelegateExecution execution){
315 msoLogger.info(" ***** Started prepareSDNCRequest *****")
316 String responseCode = execution.getVariable(Prefix + "sdncDeleteReturnCode")
317 String responseObj = execution.getVariable(Prefix + "SuccessIndicator")
319 msoLogger.info("response from sdnc, response code :" + responseCode + " response object :" + responseObj)
320 msoLogger.info(" ***** Exit prepareSDNCRequest *****")
323 public void sendSyncResponse (DelegateExecution execution) {
324 msoLogger.info(" *** sendSyncResponse *** ")
327 String operationStatus = "finished"
328 // RESTResponse for main flow
329 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
330 utils.log("DEBUG", " sendSyncResponse to APIH:" + "\n" + resourceOperationResp, isDebugEnabled)
331 sendWorkflowResponse(execution, 202, resourceOperationResp)
332 execution.setVariable("sentSyncResponse", true)
334 } catch (Exception ex) {
335 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
337 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
339 msoLogger.info(" ***** Exit sendSyncResopnse *****")