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.openecomp.mso.bpmn.infrastructure.scripts
23 import groovy.json.JsonSlurper
24 import org.apache.commons.lang3.StringUtils
25 import org.apache.http.HttpResponse
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.json.JSONObject
29 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
30 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
31 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
34 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
35 import org.openecomp.mso.bpmn.core.domain.AllottedResource
36 import org.openecomp.mso.bpmn.core.domain.ModelInfo
37 import org.openecomp.mso.bpmn.core.domain.NetworkResource
38 import org.openecomp.mso.bpmn.core.domain.Resource
39 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
40 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
41 import org.openecomp.mso.bpmn.core.domain.VnfResource
42 import org.openecomp.mso.bpmn.core.json.JsonUtils
43 import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties
45 import static org.apache.commons.lang3.StringUtils.isBlank
54 * URN_mso_workflow_sdncadapter_callback
63 public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor {
66 ExceptionUtil exceptionUtil = new ExceptionUtil()
67 JsonUtils jsonUtil = new JsonUtils()
68 CatalogDbUtils cutils = new CatalogDbUtils()
70 public void preProcessRequest (DelegateExecution execution) {
71 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
72 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
76 String requestId = execution.getVariable("msoRequestId")
77 execution.setVariable("prefix",Prefix)
80 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
81 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
82 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"
98 utils.log("INFO", msg, isDebugEnabled)
99 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
102 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
103 if (isBlank(sdncCallbackUrl)) {
104 msg = "URN_mso_workflow_sdncadapter_callback is null"
105 utils.log("INFO", msg, isDebugEnabled)
106 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
109 utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
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>${paramName}</name>
123 <value>${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()
139 utils.log("INFO", msg, isDebugEnabled)
140 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
142 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
145 public void sequenceResource(DelegateExecution execution){
146 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
148 utils.log("INFO", " ======== STARTED sequenceResource Process ======== ", isDebugEnabled)
149 List<Resource> sequencedResourceList = new ArrayList<Resource>()
150 List<Resource> wanResources = new ArrayList<Resource>()
152 // get delete resource list and order list
153 List<Resource> delResourceList = execution.getVariable("deleteResourceList")
155 def resourceSequence = BPMNProperties.getResourceSequenceProp()
157 if(resourceSequence != null) {
158 for (resourceType in resourceSequence.reverse()) {
159 for (resource in delResourceList) {
160 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
161 sequencedResourceList.add(resource)
163 if (resource instanceof NetworkResource) {
164 wanResources.add(resource)
170 //define sequenced resource list, we deploy vf first and then network and then ar
171 //this is defaule sequence
172 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
173 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
174 for (Resource rc : delResourceList) {
175 if (rc instanceof VnfResource) {
176 vnfResourceList.add(rc)
177 } else if (rc instanceof NetworkResource) {
179 } else if (rc instanceof AllottedResource) {
180 arResourceList.add(rc)
184 sequencedResourceList.addAll(arResourceList)
185 sequencedResourceList.addAll(wanResources)
186 sequencedResourceList.addAll(vnfResourceList)
189 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
190 execution.setVariable("isContainsWanResource", isContainsWanResource)
191 execution.setVariable("currentResourceIndex", 0)
192 execution.setVariable("sequencedResourceList", sequencedResourceList)
193 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
194 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
198 * prepare delete parameters
200 public void preResourceDelete(DelegateExecution execution){
202 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
204 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
206 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
208 int currentIndex = execution.getVariable("currentResourceIndex")
209 Resource curResource = sequencedResourceList.get(currentIndex);
211 String resourceInstanceUUID = curResource.getResourceId()
212 String resourceTemplateUUID = curResource.getModelInfo().getModelUuid()
213 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
214 execution.setVariable("currentResource", curResource)
215 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
216 + resourceInstanceUUID + " resourceModelName: " + curResource.getModelInfo().getModelName(), isDebugEnabled)
218 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
223 * Execute delete workflow for resource
225 public void executeResourceDelete(DelegateExecution execution) {
226 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
227 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
228 String requestId = execution.getVariable("msoRequestId")
229 String serviceInstanceId = execution.getVariable("serviceInstanceId")
230 String serviceType = execution.getVariable("serviceType")
232 String resourceInstanceId = execution.getVariable("resourceInstanceId")
234 Resource currentResource = execution.getVariable("currentResource")
235 String action = "deleteInstance"
236 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, currentResource.getModelInfo().getModelUuid(), action)
237 String recipeUri = resourceRecipe.getString("orchestrationUri")
238 int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
239 String recipeParamXsd = resourceRecipe.get("paramXSD")
242 ResourceInput resourceInput = new ResourceInput();
243 resourceInput.setServiceInstanceId(serviceInstanceId)
244 resourceInput.setResourceInstanceName(currentResource.getResourceInstanceName())
245 resourceInput.setResourceInstancenUuid(currentResource.getResourceId())
246 resourceInput.setOperationId(execution.getVariable("operationId"))
247 String globalSubscriberId = execution.getVariable("globalSubscriberId")
248 resourceInput.setGlobalSubscriberId(globalSubscriberId)
249 resourceInput.setResourceModelInfo(currentResource.getModelInfo());
250 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
251 resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
252 resourceInput.setServiceType(serviceType)
254 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri
256 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeout, action, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
257 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
261 public void parseNextResource(DelegateExecution execution){
262 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
263 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
264 def currentIndex = execution.getVariable("currentResourceIndex")
265 def nextIndex = currentIndex + 1
266 execution.setVariable("currentResourceIndex", nextIndex)
267 List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
268 if(nextIndex >= sequencedResourceList.size()){
269 execution.setVariable("allResourceFinished", "true")
271 execution.setVariable("allResourceFinished", "false")
273 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)
276 public void prepareFinishedProgressForResource(execution) {
278 String serviceInstanceId = execution.getVariable("serviceInstanceId")
279 String serviceType = execution.getVariable("serviceType")
280 String resourceInstanceId = execution.getVariable("resourceInstanceId")
281 Resource currentResource = execution.getVariable("currentResource")
282 String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid()
283 String resourceModelName = currentResource.getModelInfo().getModelName()
284 String operationType = execution.getVariable("operationType")
285 String progress = "100"
286 String status = "finished"
287 String statusDescription = "The resource instance does not exist for " + resourceModelName
288 String operationId = execution.getVariable("operationId")
291 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
292 xmlns:ns="http://org.openecomp.mso/requestsdb">
295 <ns:updateResourceOperationStatus>
296 <operType>${operationType}</operType>
297 <operationId>${operationId}</operationId>
298 <progress>${progress}</progress>
299 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
300 <serviceId>${ServiceInstanceId}</serviceId>
301 <status>${status}</status>
302 <statusDescription>${statusDescription}</statusDescription>
303 </ns:updateResourceOperationStatus>
305 </soapenv:Envelope>""";
307 def dbAdapterEndpoint = execution.getVariable("URN_mso_adapters_openecomp_db_endpoint")
308 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
309 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
312 public void prepareServiceTopologyDeletion(DelegateExecution execution) {
313 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
314 utils.log("INFO"," ***** prepareServiceTopologyDeletion " + " *****", isDebugEnabled)
316 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
317 execution.setVariable("modelInvariantUuid", serviceDecomposition.getModelInfo().getModelInvariantUuid())
318 execution.setVariable("modelVersion", serviceDecomposition.getModelInfo().getModelVersion())
319 execution.setVariable("modelUuid", serviceDecomposition.getModelInfo().getModelUuid())
320 execution.setVariable("serviceModelName", serviceDecomposition.getModelInfo().getModelName())
322 // set operation type and resource type is required to form request body
323 execution.setVariable("operationType", "DELETE")
324 execution.setVariable("resourceType", "SDNC-SERVICE-TOPOLOGY")
326 utils.log("INFO"," ***** prepareServiceTopologyDeletion " + " *****", isDebugEnabled)