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.ModelInfo
36 import org.openecomp.mso.bpmn.core.domain.NetworkResource
37 import org.openecomp.mso.bpmn.core.domain.Resource
38 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
39 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
40 import org.openecomp.mso.bpmn.core.json.JsonUtils
41 import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties
43 import static org.apache.commons.lang3.StringUtils.isBlank
44 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(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 for (resourceType in resourceSequence.reverse()) {
160 for (resource in delResourceList) {
161 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
162 sequencedResourceList.add(resource)
164 if (resource instanceof NetworkResource) {
165 wanResources.add(resource)
171 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
172 execution.setVariable("isContainsWanResource", isContainsWanResource)
173 execution.setVariable("currentResourceIndex", 0)
174 execution.setVariable("resourceSequence", resourceSequence)
175 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
176 execution.setVariable("wanResources", wanResources)
177 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
181 * prepare delete parameters
183 public void preResourceDelete(execution, resourceName){
185 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
187 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
189 List<Resource> existResourceList = execution.getVariable("deleteResourceList")
191 int currentIndex = execution.getVariable("currentResourceIndex")
192 Resource curResource = existResourceList.get(currentIndex);
194 String resourceInstanceUUID = curResource.getResourceId()
195 String resourceTemplateUUID = curResource.getModelInfo().getModelUuid()
196 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
197 execution.setVariable("resourceUuid", resourceTemplateUUID)
198 execution.setVariable("resourceType", curResource.getModelInfo().getModelName())
199 execution.setVariable("currentResource", curResource)
200 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
201 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
203 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
208 * Execute delete workflow for resource
210 public void executeResourceDelete(execution, resourceName) {
211 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
212 utils.log("INFO", "======== Start executeResourceDelete Process ======== ", isDebugEnabled)
213 String requestId = execution.getVariable("msoRequestId")
214 String serviceInstanceId = execution.getVariable("serviceInstanceId")
215 String serviceType = execution.getVariable("serviceType")
217 String resourceInstanceId = execution.getVariable("resourceInstanceId")
218 String resourceUuid = execution.getVariable("resourceUuid")
220 String requestAction = execution.getVariable("operationType")
221 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceUuid, requestAction)
222 String recipeUri = resourceRecipe.getString("orchestrationUri")
223 int recipeTimeout = resourceRecipe.getInt("recipeTimeout")
224 String recipeParamXsd = resourceRecipe.get("paramXSD")
226 Resource currentResource = execution.getVariable("currentResource")
228 ResourceInput resourceInput = new ResourceInput();
229 resourceInput.setServiceInstanceId(serviceInstanceId)
230 resourceInput.setResourceInstanceName(currentResource.getResourceInstanceName())
231 resourceInput.setGlobalSubscriberId("globalSubscriberId")
232 ModelInfo modelInfo = new ModelInfo()
233 modelInfo.setModelCustomizationUuid(currentResource.getModelInfo().getModelCustomizationUuid())
234 modelInfo.setModelUuid(currentResource.getModelInfo().getModelCustomizationUuid())
235 modelInfo.setModelInvariantUuid(currentResource.getModelInfo().getModelInvariantUuid())
236 resourceInput.setServiceModelInfo(modelInfo)
237 resourceInput.setServiceType(serviceType)
239 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + recipeUri
241 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
242 utils.log("INFO", " ======== END executeResourceDelete Process ======== ", isDebugEnabled)
246 public void parseNextResource(execution){
247 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
248 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
249 def currentIndex = execution.getVariable("currentResourceIndex")
250 def nextIndex = currentIndex + 1
251 execution.setVariable("currentResourceIndex", nextIndex)
252 List<String> resourceSequence = execution.getVariable("resourceSequence")
253 if(nextIndex >= resourceSequence.size()){
254 execution.setVariable("allResourceFinished", "true")
256 execution.setVariable("allResourceFinished", "false")
258 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)