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
52 * URN_mso_workflow_sdncadapter_callback
61 public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor {
64 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 JsonUtils jsonUtil = new JsonUtils()
66 CatalogDbUtils cutils = new CatalogDbUtils()
68 public void preProcessRequest (DelegateExecution execution) {
69 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
70 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
74 String requestId = execution.getVariable("msoRequestId")
75 execution.setVariable("prefix",Prefix)
78 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
79 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
80 if (globalSubscriberId == null)
82 execution.setVariable("globalSubscriberId", "")
85 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
86 String serviceType = execution.getVariable("serviceType")
87 if (serviceType == null)
89 execution.setVariable("serviceType", "")
92 //Generated in parent for AAI PUT
93 String serviceInstanceId = execution.getVariable("serviceInstanceId")
94 if (isBlank(serviceInstanceId)){
95 msg = "Input serviceInstanceId is null"
96 utils.log("INFO", msg, isDebugEnabled)
97 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
100 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
101 if (isBlank(sdncCallbackUrl)) {
102 msg = "URN_mso_workflow_sdncadapter_callback is null"
103 utils.log("INFO", msg, isDebugEnabled)
104 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
107 utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
109 StringBuilder sbParams = new StringBuilder()
110 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
111 if (paramsMap != null)
113 sbParams.append("<service-input-parameters>")
114 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
116 String paramName = entry.getKey()
117 String paramValue = entry.getValue()
120 <name>${paramName}</name>
121 <value>${paramValue}</value>
124 sbParams.append(paramsXml)
126 sbParams.append("</service-input-parameters>")
128 String siParamsXml = sbParams.toString()
129 if (siParamsXml == null)
131 execution.setVariable("siParamsXml", siParamsXml)
133 } catch (BpmnError e) {
135 } catch (Exception ex){
136 msg = "Exception in preProcessRequest " + ex.getMessage()
137 utils.log("INFO", msg, isDebugEnabled)
138 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
140 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
143 public void sequenceResource(execution){
144 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
146 utils.log("INFO", " ======== STARTED sequenceResource Process ======== ", isDebugEnabled)
147 List<String> nsResources = new ArrayList<String>()
148 List<String> wanResources = new ArrayList<String>()
149 List<String> resourceSequence = new ArrayList<String>()
151 // get delete resource list and order list
152 List<Resource> delResourceList = execution.getVariable("deleteResourceList")
153 // existing resource list
154 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
156 for(ServiceInstance rc_e : existResourceList){
158 String muuid = rc_e.getModelInfo().getModelUuid()
159 String mIuuid = rc_e.getModelInfo().getModelInvariantUuid()
160 String mCuuid = rc_e.getModelInfo().getModelCustomizationUuid()
161 rcType = rc_e.getInstanceName()
163 for(Resource rc_d : delResourceList){
165 if(rc_d.getModelInfo().getModelUuid() == muuid
166 && rc_d.getModelInfo().getModelInvariantUuid() == mIuuid
167 && rc_d.getModelInfo().getModelCustomizationUuid() == mCuuid) {
169 if(StringUtils.containsIgnoreCase(rcType, "overlay")
170 || StringUtils.containsIgnoreCase(rcType, "underlay")){
171 wanResources.add(rcType)
173 nsResources.add(rcType)
181 resourceSequence.addAll(wanResources)
182 resourceSequence.addAll(nsResources)
183 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
184 execution.setVariable("isContainsWanResource", isContainsWanResource)
185 execution.setVariable("currentResourceIndex", 0)
186 execution.setVariable("resourceSequence", resourceSequence)
187 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
188 execution.setVariable("wanResources", wanResources)
189 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
193 * prepare delete parameters
195 public void preResourceDelete(execution, resourceName){
197 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
199 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
201 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
203 for(ServiceInstance rc_e : existResourceList){
205 if(StringUtils.containsIgnoreCase(rc_e.getInstanceName(), resourceName)) {
207 String resourceInstanceUUID = rc_e.getInstanceId()
208 String resourceTemplateUUID = rc_e.getModelInfo().getModelUuid()
209 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
210 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
211 execution.setVariable("resourceType", resourceName)
212 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
213 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
217 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
222 * Execute delete workflow for resource
224 public void executeResourceDelete(execution) {
225 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
226 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
227 String requestId = execution.getVariable("msoRequestId")
228 String serviceInstanceId = execution.getVariable("serviceInstanceId")
229 String serviceType = execution.getVariable("serviceType")
230 ResourceInput resourceInput = execution.getVariable("resourceInput")
231 String requestAction = resourceInput.getOperationType()
232 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceUuid(), requestAction)
233 String recipeUri = resourceRecipe.getString("orchestrationUri")
234 String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
235 String recipeParamXsd = resourceRecipe.get("paramXSD")
236 HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
237 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
241 public void parseNextResource(execution){
242 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
243 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
244 def currentIndex = execution.getVariable("currentResourceIndex")
245 def nextIndex = currentIndex + 1
246 execution.setVariable("currentResourceIndex", nextIndex)
247 List<String> resourceSequence = execution.getVariable("resourceSequence")
248 if(nextIndex >= resourceSequence.size()){
249 execution.setVariable("allResourceFinished", "true")
251 execution.setVariable("allResourceFinished", "false")
253 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)