3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
25 import static org.apache.commons.lang3.StringUtils.isBlank
27 import org.apache.commons.lang3.StringUtils
28 import org.apache.http.HttpResponse
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.json.JSONObject
32 import org.onap.so.bpmn.common.recipe.BpmnRestClient
33 import org.onap.so.bpmn.common.recipe.ResourceInput
34 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
35 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
36 import org.onap.so.bpmn.common.scripts.ExceptionUtil
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.core.domain.AllottedResource
39 import org.onap.so.bpmn.core.domain.NetworkResource
40 import org.onap.so.bpmn.core.domain.Resource
41 import org.onap.so.bpmn.core.domain.ServiceDecomposition
42 import org.onap.so.bpmn.core.domain.VnfResource
43 import org.onap.so.bpmn.core.json.JsonUtils
44 import org.onap.so.bpmn.core.UrnPropertiesReader
45 import org.onap.so.bpmn.infrastructure.properties.BPMNProperties
46 import org.onap.so.logger.MsoLogger
55 * URN_mso_workflow_sdncadapter_callback
64 public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor {
65 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteResourcesV1.class);
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
69 JsonUtils jsonUtil = new JsonUtils()
70 CatalogDbUtils catalogDbUtils = new CatalogDbUtilsFactory().create()
72 public void preProcessRequest (DelegateExecution execution) {
73 msoLogger.debug(" ***** preProcessRequest *****")
77 String requestId = execution.getVariable("msoRequestId")
78 execution.setVariable("prefix",Prefix)
81 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
82 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
83 if (globalSubscriberId == null) {
84 execution.setVariable("globalSubscriberId", "")
87 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
88 String serviceType = execution.getVariable("serviceType")
89 if (serviceType == null)
91 execution.setVariable("serviceType", "")
94 //Generated in parent for AAI PUT
95 String serviceInstanceId = execution.getVariable("serviceInstanceId")
96 if (isBlank(serviceInstanceId)){
97 msg = "Input serviceInstanceId is null"
99 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 String sdncCallbackUrl = UrnPropertiesReader.getVariable('URN_mso_workflow_sdncadapter_callback', execution)
103 if (isBlank(sdncCallbackUrl)) {
104 msg = "URN_mso_workflow_sdncadapter_callback is null"
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
109 msoLogger.debug("SDNC Callback URL: " + sdncCallbackUrl)
111 StringBuilder sbParams = new StringBuilder()
112 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
113 if (paramsMap != null)
115 sbParams.append("<service-input-parameters>")
116 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
118 String paramName = entry.getKey()
119 String paramValue = entry.getValue()
122 <name>${MsoUtils.xmlEscape(paramName)}</name>
123 <value>${MsoUtils.xmlEscape(paramValue)}</value>
126 sbParams.append(paramsXml)
128 sbParams.append("</service-input-parameters>")
130 String siParamsXml = sbParams.toString()
131 if (siParamsXml == null)
133 execution.setVariable("siParamsXml", siParamsXml)
135 } catch (BpmnError e) {
137 } catch (Exception ex){
138 msg = "Exception in preProcessRequest " + ex.getMessage()
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
142 msoLogger.debug(" ***** Exit preProcessRequest *****",)
145 public void sequenceResource(DelegateExecution execution){
146 msoLogger.debug(" ======== STARTED sequenceResource Process ======== ")
147 List<Resource> sequencedResourceList = new ArrayList<Resource>()
148 List<Resource> wanResources = new ArrayList<Resource>()
150 // get delete resource list and order list
151 List<Resource> delResourceList = execution.getVariable("deleteResourceList")
153 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
154 String serviceModelName = serviceDecomposition.getModelInfo().getModelName();
156 def resourceSequence = BPMNProperties.getResourceSequenceProp(serviceModelName)
158 if(resourceSequence != null) {
159 for (resourceType in resourceSequence.reverse()) {
160 for (resource in delResourceList) {
161 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
162 sequencedResourceList.add(resource)
164 if (resource instanceof NetworkResource) {
165 wanResources.add(resource)
171 //define sequenced resource list, we deploy vf first and then network and then ar
172 //this is defaule sequence
173 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
174 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
175 for (Resource rc : delResourceList) {
176 if (rc instanceof VnfResource) {
177 vnfResourceList.add(rc)
178 } else if (rc instanceof NetworkResource) {
180 } else if (rc instanceof AllottedResource) {
181 arResourceList.add(rc)
185 sequencedResourceList.addAll(arResourceList)
186 sequencedResourceList.addAll(wanResources)
187 sequencedResourceList.addAll(vnfResourceList)
190 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
191 //if no networkResource, get SDNC config from properties file
192 if( "false".equals(isContainsWanResource)) {
193 String serviceNeedSDNC = "mso.workflow.custom." + serviceModelName + ".sdnc.need";
194 isContainsWanResource = BPMNProperties.getProperty(serviceNeedSDNC, isContainsWanResource)
196 execution.setVariable("isContainsWanResource", isContainsWanResource)
197 execution.setVariable("currentResourceIndex", 0)
198 execution.setVariable("sequencedResourceList", sequencedResourceList)
199 msoLogger.debug("resourceSequence: " + resourceSequence)
200 msoLogger.debug(" ======== END sequenceResource Process ======== ")
204 * prepare delete parameters
206 public void preResourceDelete(DelegateExecution execution){
207 msoLogger.debug(" ======== STARTED preResourceDelete Process ======== ")
209 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
211 int currentIndex = execution.getVariable("currentResourceIndex")
212 if(sequencedResourceList != null && sequencedResourceList.size() > currentIndex){
213 Resource curResource = sequencedResourceList.get(currentIndex);
215 String resourceInstanceUUID = curResource.getResourceId()
216 String resourceTemplateUUID = curResource.getModelInfo().getModelUuid()
217 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
218 execution.setVariable("currentResource", curResource)
219 msoLogger.debug("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
220 + resourceInstanceUUID + " resourceModelName: " + curResource.getModelInfo().getModelName())
223 execution.setVariable("resourceInstanceId", "")
226 msoLogger.debug(" ======== END preResourceDelete Process ======== ")
231 * Execute delete workflow for resource
233 public void executeResourceDelete(DelegateExecution execution) {
234 msoLogger.debug("======== Start executeResourceDelete Process ======== ")
236 String requestId = execution.getVariable("msoRequestId")
237 String serviceInstanceId = execution.getVariable("serviceInstanceId")
238 String serviceType = execution.getVariable("serviceType")
240 String resourceInstanceId = execution.getVariable("resourceInstanceId")
242 Resource currentResource = execution.getVariable("currentResource")
243 String action = "deleteInstance"
244 JSONObject resourceRecipe = catalogDbUtils.getResourceRecipe(execution, currentResource.getModelInfo().getModelUuid(), action)
245 String recipeUri = resourceRecipe.getString("orchestrationUri")
246 int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
247 String recipeParamXsd = resourceRecipe.get("paramXSD")
250 ResourceInput resourceInput = new ResourceInput();
251 resourceInput.setServiceInstanceId(serviceInstanceId)
252 resourceInput.setResourceInstanceName(currentResource.getResourceInstanceName())
253 resourceInput.setResourceInstancenUuid(currentResource.getResourceId())
254 resourceInput.setOperationId(execution.getVariable("operationId"))
255 resourceInput.setOperationType(execution.getVariable("operationType"))
256 String globalSubscriberId = execution.getVariable("globalSubscriberId")
257 resourceInput.setGlobalSubscriberId(globalSubscriberId)
258 resourceInput.setResourceModelInfo(currentResource.getModelInfo());
259 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
260 resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
261 resourceInput.setServiceType(serviceType)
263 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri
265 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeout, action, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
266 msoLogger.debug(" ======== END executeResourceDelete Process ======== ")
268 msoLogger.error("Rethrowing MSOWorkflowException")
271 msoLogger.error("Error occured within DoDeleteResourcesV1 executeResourceDelete method: " + e)
272 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, "Internal Error - Occured during DoDeleteResourcesV1 executeResourceDelete Catalog")
277 public void parseNextResource(DelegateExecution execution){
278 msoLogger.debug("======== Start parseNextResource Process ======== ")
279 def currentIndex = execution.getVariable("currentResourceIndex")
280 def nextIndex = currentIndex + 1
281 execution.setVariable("currentResourceIndex", nextIndex)
282 List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
283 if(nextIndex >= sequencedResourceList.size()){
284 execution.setVariable("allResourceFinished", "true")
286 execution.setVariable("allResourceFinished", "false")
288 msoLogger.debug("======== COMPLETED parseNextResource Process ======== ")
291 public void prepareFinishedProgressForResource(DelegateExecution execution) {
293 String serviceInstanceId = execution.getVariable("serviceInstanceId")
294 String serviceType = execution.getVariable("serviceType")
295 String resourceInstanceId = execution.getVariable("resourceInstanceId")
296 Resource currentResource = execution.getVariable("currentResource")
297 String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid()
298 String resourceModelName = currentResource.getModelInfo().getModelName()
299 String operationType = execution.getVariable("operationType")
300 String progress = "100"
301 String status = "finished"
302 String statusDescription = "The resource instance does not exist for " + resourceModelName
303 String operationId = execution.getVariable("operationId")
306 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
307 xmlns:ns="http://org.onap.so/requestsdb">
310 <ns:updateResourceOperationStatus>
311 <operType>${MsoUtils.xmlEscape(operationType)}</operType>
312 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
313 <progress>${MsoUtils.xmlEscape(progress)}</progress>
314 <resourceTemplateUUID>${MsoUtils.xmlEscape(resourceCustomizationUuid)}</resourceTemplateUUID>
315 <serviceId>${MsoUtils.xmlEscape(serviceInstanceId)}</serviceId>
316 <status>${MsoUtils.xmlEscape(status)}</status>
317 <statusDescription>${MsoUtils.xmlEscape(statusDescription)}</statusDescription>
318 </ns:updateResourceOperationStatus>
320 </soapenv:Envelope>""";
322 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
323 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
324 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
327 public void prepareSDNCServiceDeactivateRequest (DelegateExecution execution) {
328 prepareSDNCServiceRequest (execution, "deactivate")
331 public void prepareSDNCServiceDeleteRequest (DelegateExecution execution) {
332 prepareSDNCServiceRequest (execution, "delete")
335 public void prepareSDNCServiceRequest (DelegateExecution execution, String svcAction) {
336 msoLogger.debug(" ***** Started prepareSDNCServiceRequest for " + svcAction + "*****")
340 String sdnc_svcAction = svcAction
341 String sdncCallback = execution.getVariable("URN_mso_workflow_sdncadapter_callback")
342 String hdrRequestId = execution.getVariable("msoRequestId")
343 String serviceInstanceId = execution.getVariable("serviceInstanceId")
344 String source = execution.getVariable("source")
345 String sdnc_service_id = serviceInstanceId
346 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
347 String serviceType = execution.getVariable("serviceType")
348 String globalCustomerId = execution.getVariable("globalSubscriberId")
349 String serviceModelInvariantUuid = serviceDecomposition.getModelInfo().getModelInvariantUuid()
350 String serviceModelUuid = serviceDecomposition.getModelInfo().getModelUuid()
351 String serviceModelVersion = serviceDecomposition.getModelInfo().getModelVersion()
352 String serviceModelName = serviceDecomposition.getModelInfo().getModelName()
354 // 1. prepare assign topology via SDNC Adapter SUBFLOW call
355 String sndcTopologyDeleteRequest =
356 """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
357 xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1"
358 xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1">
359 <sdncadapter:RequestHeader>
360 <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId>
361 <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId>
362 <sdncadapter:SvcAction>${MsoUtils.xmlEscape(sdnc_svcAction)}</sdncadapter:SvcAction>
363 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
364 <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl>
365 <sdncadapter:MsoAction>generic-resource</sdncadapter:MsoAction>
366 </sdncadapter:RequestHeader>
367 <sdncadapterworkflow:SDNCRequestData>
368 <request-information>
369 <request-id>${MsoUtils.xmlEscape(hdrRequestId)}</request-id>
370 <request-action>DeleteServiceInstance</request-action>
371 <source>${MsoUtils.xmlEscape(source)}</source>
372 <notification-url></notification-url>
373 <order-number></order-number>
374 <order-version></order-version>
375 </request-information>
376 <service-information>
377 <service-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-id>
378 <subscription-service-type>${MsoUtils.xmlEscape(serviceType)}</subscription-service-type>
379 <onap-model-information>
380 <model-invariant-uuid>${MsoUtils.xmlEscape(serviceModelInvariantUuid)}</model-invariant-uuid>
381 <model-uuid>${MsoUtils.xmlEscape(serviceModelUuid)}</model-uuid>
382 <model-version>${MsoUtils.xmlEscape(serviceModelVersion)}</model-version>
383 <model-name>${MsoUtils.xmlEscape(serviceModelName)}</model-name>
384 </onap-model-information>
385 <service-instance-id>${MsoUtils.xmlEscape(serviceInstanceId)}</service-instance-id>
386 <global-customer-id>${MsoUtils.xmlEscape(globalCustomerId)}</global-customer-id>
387 </service-information>
388 <service-request-input>
389 </service-request-input>
390 </sdncadapterworkflow:SDNCRequestData>
391 </aetgt:SDNCAdapterWorkflowRequest>""".trim()
393 String sndcTopologyDeleteRequesAsString = utils.formatXml(sndcTopologyDeleteRequest)
394 msoLogger.debug(sndcTopologyDeleteRequesAsString)
395 execution.setVariable("sdncAdapterWorkflowRequest", sndcTopologyDeleteRequesAsString)
396 msoLogger.debug("sdncAdapterWorkflowRequest - " + "\n" + sndcTopologyDeleteRequesAsString)
398 } catch (Exception ex) {
399 String exceptionMessage = " Bpmn error encountered in DoDeleteResourcesV1 flow. prepareSDNCServiceRequest() - " + ex.getMessage()
400 msoLogger.debug(exceptionMessage)
401 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
404 msoLogger.debug("***** Exit prepareSDNCServiceRequest for " + svcAction + "*****")