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<String> wanResources = new ArrayList<String>()
152 // get delete resource list and order list
153 List<Resource> delResourceList = execution.getVariable("deleteResourceList")
154 // existing resource list
155 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
157 def resourceSequence = BPMNProperties.getResourceSequenceProp()
159 if(resourceSequence != null) {
160 for (resourceType in resourceSequence.reverse()) {
161 for (resource in delResourceList) {
162 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
163 sequencedResourceList.add(resource)
165 if (resource instanceof NetworkResource) {
166 wanResources.add(resource)
172 //define sequenced resource list, we deploy vf first and then network and then ar
173 //this is defaule sequence
174 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
175 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
176 List<NetworkResource> networkResourceList = new ArrayList<NetworkResource>()
178 for (Resource rc : delResourceList) {
179 if (rc instanceof VnfResource) {
180 vnfResourceList.add(rc)
181 } else if (rc instanceof NetworkResource) {
182 networkResourceList.add(rc)
183 } else if (rc instanceof AllottedResource) {
184 arResourceList.add(rc)
188 sequencedResourceList.addAll(arResourceList)
189 sequencedResourceList.addAll(networkResourceList)
190 sequencedResourceList.addAll(vnfResourceList)
193 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
194 execution.setVariable("isContainsWanResource", isContainsWanResource)
195 execution.setVariable("currentResourceIndex", 0)
196 execution.setVariable("resourceSequence", resourceSequence)
197 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
198 execution.setVariable("wanResources", wanResources)
199 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
203 * prepare delete parameters
205 public void preResourceDelete(DelegateExecution execution, String resourceName){
207 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
209 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
211 List<Resource> existResourceList = execution.getVariable("deleteResourceList")
213 int currentIndex = execution.getVariable("currentResourceIndex")
214 Resource curResource = existResourceList.get(currentIndex);
216 String resourceInstanceUUID = curResource.getResourceId()
217 String resourceTemplateUUID = curResource.getModelInfo().getModelUuid()
218 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
219 execution.setVariable("resourceUuid", resourceTemplateUUID)
220 execution.setVariable("resourceType", curResource.getModelInfo().getModelName())
221 execution.setVariable("currentResource", curResource)
222 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
223 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
225 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
230 * Execute delete workflow for resource
232 public void executeResourceDelete(DelegateExecution execution, String resourceName) {
233 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
234 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
235 String requestId = execution.getVariable("msoRequestId")
236 String serviceInstanceId = execution.getVariable("serviceInstanceId")
237 String serviceType = execution.getVariable("serviceType")
239 String resourceInstanceId = execution.getVariable("resourceInstanceId")
240 String resourceUuid = execution.getVariable("resourceUuid")
242 String requestAction = execution.getVariable("operationType")
243 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, requestAction)
244 String recipeUri = resourceRecipe.getString("orchestrationUri")
245 int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
246 String recipeParamXsd = resourceRecipe.get("paramXSD")
248 Resource currentResource = execution.getVariable("currentResource")
250 ResourceInput resourceInput = new ResourceInput();
251 resourceInput.setServiceInstanceId(serviceInstanceId)
252 resourceInput.setResourceInstanceName(currentResource.getResourceInstanceName())
253 resourceInput.setGlobalSubscriberId("globalSubscriberId")
254 ModelInfo modelInfo = new ModelInfo()
255 modelInfo.setModelCustomizationUuid(currentResource.getModelInfo().getModelCustomizationUuid())
256 modelInfo.setModelUuid(currentResource.getModelInfo().getModelCustomizationUuid())
257 modelInfo.setModelInvariantUuid(currentResource.getModelInfo().getModelInvariantUuid())
258 resourceInput.setServiceModelInfo(modelInfo)
259 resourceInput.setServiceType(serviceType)
261 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri
263 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
264 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
268 public void parseNextResource(DelegateExecution execution){
269 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
270 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
271 def currentIndex = execution.getVariable("currentResourceIndex")
272 def nextIndex = currentIndex + 1
273 execution.setVariable("currentResourceIndex", nextIndex)
274 List<String> resourceSequence = execution.getVariable("resourceSequence")
275 if(nextIndex >= resourceSequence.size()){
276 execution.setVariable("allResourceFinished", "true")
278 execution.setVariable("allResourceFinished", "false")
280 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)