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
46 import static org.apache.commons.lang3.StringUtils.isBlank
56 * URN_mso_workflow_sdncadapter_callback
65 public class DoDeleteResourcesV1 extends AbstractServiceTaskProcessor {
68 ExceptionUtil exceptionUtil = new ExceptionUtil()
69 JsonUtils jsonUtil = new JsonUtils()
70 CatalogDbUtils cutils = new CatalogDbUtils()
72 public void preProcessRequest (DelegateExecution execution) {
73 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
74 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
78 String requestId = execution.getVariable("msoRequestId")
79 execution.setVariable("prefix",Prefix)
82 //requestDetails.subscriberInfo. for AAI GET & PUT & SDNC assignToplology
83 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
84 if (globalSubscriberId == null)
86 execution.setVariable("globalSubscriberId", "")
89 //requestDetails.requestParameters. for AAI PUT & SDNC assignTopology
90 String serviceType = execution.getVariable("serviceType")
91 if (serviceType == null)
93 execution.setVariable("serviceType", "")
96 //Generated in parent for AAI PUT
97 String serviceInstanceId = execution.getVariable("serviceInstanceId")
98 if (isBlank(serviceInstanceId)){
99 msg = "Input serviceInstanceId is null"
100 utils.log("INFO", msg, isDebugEnabled)
101 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
104 String sdncCallbackUrl = execution.getVariable('URN_mso_workflow_sdncadapter_callback')
105 if (isBlank(sdncCallbackUrl)) {
106 msg = "URN_mso_workflow_sdncadapter_callback is null"
107 utils.log("INFO", msg, isDebugEnabled)
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
110 execution.setVariable("sdncCallbackUrl", sdncCallbackUrl)
111 utils.log("INFO","SDNC Callback URL: " + sdncCallbackUrl, isDebugEnabled)
113 StringBuilder sbParams = new StringBuilder()
114 Map<String, String> paramsMap = execution.getVariable("serviceInputParams")
115 if (paramsMap != null)
117 sbParams.append("<service-input-parameters>")
118 for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
120 String paramName = entry.getKey()
121 String paramValue = entry.getValue()
124 <name>${paramName}</name>
125 <value>${paramValue}</value>
128 sbParams.append(paramsXml)
130 sbParams.append("</service-input-parameters>")
132 String siParamsXml = sbParams.toString()
133 if (siParamsXml == null)
135 execution.setVariable("siParamsXml", siParamsXml)
137 } catch (BpmnError e) {
139 } catch (Exception ex){
140 msg = "Exception in preProcessRequest " + ex.getMessage()
141 utils.log("INFO", msg, isDebugEnabled)
142 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
144 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
147 public void sequenceResource(execution){
148 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
150 utils.log("INFO", " ======== STARTED sequenceResource Process ======== ", isDebugEnabled)
151 List<Resource> sequencedResourceList = new ArrayList<Resource>()
152 List<String> wanResources = new ArrayList<String>()
154 // get delete resource list and order list
155 List<Resource> delResourceList = execution.getVariable("deleteResourceList")
156 // existing resource list
157 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
159 def resourceSequence = BPMNProperties.getResourceSequenceProp()
161 if(resourceSequence != null) {
162 for (resourceType in resourceSequence.reverse()) {
163 for (resource in delResourceList) {
164 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
165 sequencedResourceList.add(resource)
167 if (resource instanceof NetworkResource) {
168 wanResources.add(resource)
174 //define sequenced resource list, we deploy vf first and then network and then ar
175 //this is defaule sequence
176 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
177 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
179 for (Resource rc : delResourceList) {
180 if (rc instanceof VnfResource) {
181 vnfResourceList.add(rc)
182 } else if (rc instanceof NetworkResource) {
183 networkResourceList.add(rc)
184 } else if (rc instanceof AllottedResource) {
185 arResourceList.add(rc)
189 sequencedResourceList.addAll(arResourceList)
190 sequencedResourceList.addAll(networkResourceList)
191 sequencedResourceList.addAll(vnfResourceList)
194 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
195 execution.setVariable("isContainsWanResource", isContainsWanResource)
196 execution.setVariable("currentResourceIndex", 0)
197 execution.setVariable("resourceSequence", resourceSequence)
198 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
199 execution.setVariable("wanResources", wanResources)
200 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
204 * prepare delete parameters
206 public void preResourceDelete(execution, resourceName){
208 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
210 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
212 List<Resource> existResourceList = execution.getVariable("deleteResourceList")
214 int currentIndex = execution.getVariable("currentResourceIndex")
215 Resource curResource = existResourceList.get(currentIndex);
217 String resourceInstanceUUID = curResource.getResourceId()
218 String resourceTemplateUUID = curResource.getModelInfo().getModelUuid()
219 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
220 execution.setVariable("resourceUuid", resourceTemplateUUID)
221 execution.setVariable("resourceType", curResource.getModelInfo().getModelName())
222 execution.setVariable("currentResource", curResource)
223 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
224 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
226 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
231 * Execute delete workflow for resource
233 public void executeResourceDelete(execution, resourceName) {
234 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
235 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
236 String requestId = execution.getVariable("msoRequestId")
237 String serviceInstanceId = execution.getVariable("serviceInstanceId")
238 String serviceType = execution.getVariable("serviceType")
240 String resourceInstanceId = execution.getVariable("resourceInstanceId")
241 String resourceUuid = execution.getVariable("resourceUuid")
243 String requestAction = execution.getVariable("operationType")
244 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, requestAction)
245 String recipeUri = resourceRecipe.getString("orchestrationUri")
246 int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
247 String recipeParamXsd = resourceRecipe.get("paramXSD")
249 Resource currentResource = execution.getVariable("currentResource")
251 ResourceInput resourceInput = new ResourceInput();
252 resourceInput.setServiceInstanceId(serviceInstanceId)
253 resourceInput.setResourceInstanceName(currentResource.getResourceInstanceName())
254 resourceInput.setGlobalSubscriberId("globalSubscriberId")
255 ModelInfo modelInfo = new ModelInfo()
256 modelInfo.setModelCustomizationUuid(currentResource.getModelInfo().getModelCustomizationUuid())
257 modelInfo.setModelUuid(currentResource.getModelInfo().getModelCustomizationUuid())
258 modelInfo.setModelInvariantUuid(currentResource.getModelInfo().getModelInvariantUuid())
259 resourceInput.setServiceModelInfo(modelInfo)
260 resourceInput.setServiceType(serviceType)
262 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri
264 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
265 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
269 public void parseNextResource(execution){
270 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
271 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
272 def currentIndex = execution.getVariable("currentResourceIndex")
273 def nextIndex = currentIndex + 1
274 execution.setVariable("currentResourceIndex", nextIndex)
275 List<String> resourceSequence = execution.getVariable("resourceSequence")
276 if(nextIndex >= resourceSequence.size()){
277 execution.setVariable("allResourceFinished", "true")
279 execution.setVariable("allResourceFinished", "false")
281 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)