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.Resource
36 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
37 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
38 import org.openecomp.mso.bpmn.core.json.JsonUtils
39 import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties
41 import static org.apache.commons.lang3.StringUtils.isBlank
42 import static org.apache.commons.lang3.StringUtils.isBlank
44 public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor {
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
49 CatalogDbUtils cutils = new CatalogDbUtils()
51 public void preProcessRequest (DelegateExecution execution) {
52 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
53 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
57 String requestId = execution.getVariable("msoRequestId")
58 execution.setVariable("prefix",Prefix)
61 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
62 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
63 if (globalSubscriberId == null)
65 execution.setVariable("globalSubscriberId", "")
68 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
69 String serviceType = execution.getVariable("serviceType")
70 if (serviceType == null)
72 execution.setVariable("serviceType", "")
75 //Generated in parent for AAI PUT
76 String serviceInstanceId = execution.getVariable("serviceInstanceId")
77 if (isBlank(serviceInstanceId)){
78 msg = "Input serviceInstanceId is null"
79 utils.log("INFO", msg, isDebugEnabled)
80 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
83 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
84 if (isBlank(sdncCallbackUrl)) {
85 msg = "URN_mso_workflow_sdncadapter_callback is null"
86 utils.log("INFO", msg, isDebugEnabled)
87 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
89 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
90 utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
92 StringBuilder sbParams = new StringBuilder()
93 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
94 if (paramsMap != null)
96 sbParams.append("<service-input-parameters>")
97 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
99 String paramName = entry.getKey()
100 String paramValue = entry.getValue()
103 <name>${paramName}</name>
104 <value>${paramValue}</value>
107 sbParams.append(paramsXml)
109 sbParams.append("</service-input-parameters>")
111 String siParamsXml = sbParams.toString()
112 if (siParamsXml == null)
114 execution.setVariable("siParamsXml", siParamsXml)
116 } catch (BpmnError e) {
118 } catch (Exception ex){
119 msg = "Exception in preProcessRequest " + ex.getMessage()
120 utils.log("INFO", msg, isDebugEnabled)
121 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
123 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
126 public void sequenceResource(execution){
127 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
129 utils.log("INFO", " ======== STARTED sequenceResource Process ======== ", isDebugEnabled)
130 List<String> nsResources = new ArrayList<String>()
131 List<String> wanResources = new ArrayList<String>()
132 List<String> resourceSequence = new ArrayList<String>()
134 // get delete resource list and order list
135 List<Resource> delResourceList = execution.getVariable("delResourceList")
136 // existing resource list
137 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
139 for(ServiceInstance rc_e : existResourceList){
141 String muuid = rc_e.getModelInfo().getModelUuid()
142 String mIuuid = rc_e.getModelInfo().getModelInvariantUuid()
143 String mCuuid = rc_e.getModelInfo().getModelCustomizationUuid()
144 rcType = rc_e.getInstanceName()
146 for(Resource rc_d : delResourceList){
148 if(rc_d.getModelInfo().getModelUuid() == muuid
149 && rc_d.getModelInfo().getModelInvariantUuid() == mIuuid
150 && rc_d.getModelInfo().getModelCustomizationUuid() == mCuuid) {
152 if(StringUtils.containsIgnoreCase(rcType, "overlay")
153 || StringUtils.containsIgnoreCase(rcType, "underlay")){
154 wanResources.add(rcType)
156 nsResources.add(rcType)
164 resourceSequence.addAll(wanResources)
165 resourceSequence.addAll(nsResources)
166 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
167 execution.setVariable("isContainsWanResource", isContainsWanResource)
168 execution.setVariable("currentResourceIndex", 0)
169 execution.setVariable("resourceSequence", resourceSequence)
170 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
171 execution.setVariable("wanResources", wanResources)
172 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
176 * prepare delete parameters
178 public void preResourceDelete(execution, resourceName){
180 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
182 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
184 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
186 for(ServiceInstance rc_e : existResourceList){
188 if(StringUtils.containsIgnoreCase(rc_e.getInstanceName(), resourceName)) {
190 String resourceInstanceUUID = rc_e.getInstanceId()
191 String resourceTemplateUUID = rc_e.getModelInfo().getModelUuid()
192 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
193 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
194 execution.setVariable("resourceType", resourceName)
195 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
196 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
200 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
205 * Execute delete workflow for resource
207 public void executeResourceDelete(execution) {
208 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
209 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
210 String requestId = execution.getVariable("msoRequestId")
211 String serviceInstanceId = execution.getVariable("serviceInstanceId")
212 String serviceType = execution.getVariable("serviceType")
213 ResourceInput resourceInput = execution.getVariable("resourceInput")
214 String requestAction = resourceInput.getOperationType()
215 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceUuid(), requestAction)
216 String recipeUri = resourceRecipe.getString("orchestrationUri")
217 String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
218 String recipeParamXsd = resourceRecipe.get("paramXSD")
219 HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
220 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
224 public void parseNextResource(execution){
225 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
226 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
227 def currentIndex = execution.getVariable("currentResourceIndex")
228 def nextIndex = currentIndex + 1
229 execution.setVariable("currentResourceIndex", nextIndex)
230 List<String> resourceSequence = execution.getVariable("resourceSequence")
231 if(nextIndex >= resourceSequence.size()){
232 execution.setVariable("allResourceFinished", "true")
234 execution.setVariable("allResourceFinished", "false")
236 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)