2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
22 import org.json.JSONArray;
24 import static org.apache.commons.lang3.StringUtils.*;
25 import groovy.xml.XmlUtil
28 import org.openecomp.mso.bpmn.core.domain.ModelInfo
29 import org.openecomp.mso.bpmn.core.domain.Resource
30 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
31 import org.openecomp.mso.bpmn.core.json.JsonUtils
32 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
34 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
35 import org.openecomp.mso.bpmn.core.WorkflowException
36 import org.openecomp.mso.rest.APIResponse;
37 import org.openecomp.mso.rest.RESTClient
38 import org.openecomp.mso.rest.RESTConfig
40 import java.util.List;
41 import java.util.UUID;
42 import javax.xml.parsers.DocumentBuilder
43 import javax.xml.parsers.DocumentBuilderFactory
45 import org.camunda.bpm.engine.delegate.BpmnError
46 import org.camunda.bpm.engine.delegate.DelegateExecution
47 import org.camunda.bpm.engine.runtime.Execution
48 import org.json.JSONObject;
49 import org.apache.commons.lang3.*
50 import org.apache.commons.codec.binary.Base64;
51 import org.springframework.web.util.UriUtils;
52 import org.w3c.dom.Document
53 import org.w3c.dom.Element
54 import org.w3c.dom.Node
55 import org.w3c.dom.NodeList
56 import org.xml.sax.InputSource
58 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def;
61 * This groovy class supports the <class>DoDeleteResources.bpmn</class> process.
64 * @param - msoRequestId
65 * @param - globalSubscriberId - O
66 * @param - subscriptionServiceType - O
67 * @param - serviceInstanceId
68 * @param - serviceInstanceName - O
69 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
70 * @param - sdncVersion
71 * @param - failNotFound - TODO
72 * @param - serviceInputParams - TODO
74 * @param - delResourceList
75 * @param - serviceRelationShip
78 * @param - WorkflowException
82 public class DoDeleteResources extends AbstractServiceTaskProcessor {
84 String Prefix="DDELR_"
85 ExceptionUtil exceptionUtil = new ExceptionUtil()
86 JsonUtils jsonUtil = new JsonUtils()
88 public void preProcessRequest (DelegateExecution execution) {
89 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
90 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
93 List<ServiceInstance> realNSRessources = new ArrayList<ServiceInstance>()
95 // related ns from AAI
96 String serviceRelationShip = execution.getVariable("serviceRelationShip")
97 def jsonSlurper = new JsonSlurper()
98 def jsonOutput = new JsonOutput()
99 List<String> nsSequence = new ArrayList<String>()
100 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
101 if (relationShipList != null) {
102 relationShipList.each {
103 String resourceType = it.resourceType
104 nsSequence.add(resourceType)
108 execution.setVariable("currentNSIndex", 0)
109 execution.setVariable("nsSequence", nsSequence)
110 execution.setVariable("realNSRessources", realNSRessources)
111 utils.log("INFO", "nsSequence: " + nsSequence, isDebugEnabled)
113 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
116 public void getCurrentNS(execution){
117 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
118 utils.log("INFO", "======== Start getCurrentNS Process ======== ", isDebugEnabled)
120 def currentIndex = execution.getVariable("currentNSIndex")
121 List<String> nsSequence = execution.getVariable("nsSequence")
122 String nsResourceType = nsSequence.get(currentIndex)
124 // GET AAI by Name, not ID, for process convenient
125 execution.setVariable("GENGS_type", "service-instance")
126 execution.setVariable("GENGS_serviceInstanceId", "")
127 execution.setVariable("GENGS_serviceInstanceName", nsResourceType)
129 utils.log("INFO", "======== COMPLETED getCurrentNS Process ======== ", isDebugEnabled)
132 public void postProcessAAIGET(DelegateExecution execution) {
133 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
134 utils.log("INFO"," ***** postProcessAAIGET2 ***** ", isDebugEnabled)
138 String nsResourceName = execution.getVariable("GENGS_serviceInstanceName")
139 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
141 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + nsResourceName, isDebugEnabled)
142 WorkflowException workflowException = execution.getVariable("WorkflowException")
143 utils.logAudit("workflowException: " + workflowException)
144 if(workflowException != null){
145 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
149 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
150 utils.log("INFO", msg, isDebugEnabled)
151 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
156 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
158 String aaiService = execution.getVariable("GENGS_service")
159 if (!isBlank(aaiService)) {
160 String svcId = utils.getNodeText1(aaiService, "service-instance-id")
161 //String mn = utils.getNodeText1(aaiService, "model-name")
162 String mIuuid = utils.getNodeText1(aaiService, "model-invariant-id")
163 String muuid = utils.getNodeText1(aaiService, "model-version-id")
164 String mCuuid = utils.getNodeText1(aaiService, "model-customization-uuid")
165 ServiceInstance rc = new ServiceInstance()
166 ModelInfo modelInfo = new ModelInfo()
167 //modelInfo.setModelName(mn)
168 modelInfo.setModelUuid(muuid)
169 modelInfo.setModelInvariantUuid(mIuuid)
170 modelInfo.getModelCustomizationUuid(mCuuid)
171 rc.setModelInfo(modelInfo)
172 rc.setInstanceId(svcId)
173 rc.setInstanceName(nsResourceName)
175 List<ServiceInstance> realNSRessources = execution.getVariable("realNSRessources")
176 realNSRessources.add(rc)
177 execution.setVariable("realNSRessources", realNSRessources)
179 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
183 } catch (BpmnError e) {
185 } catch (Exception ex) {
186 msg = "Exception in DoDeleteResources.postProcessAAIGET " + ex.getMessage()
187 utils.log("INFO", msg, isDebugEnabled)
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
193 public void parseNextNS(execution){
194 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
195 utils.log("INFO", "======== Start parseNextNS Process ======== ", isDebugEnabled)
196 def currentIndex = execution.getVariable("currentNSIndex")
197 def nextIndex = currentIndex + 1
198 execution.setVariable("currentNSIndex", nextIndex)
199 List<String> nsSequence = execution.getVariable("nsSequence")
200 if(nextIndex >= nsSequence.size()){
201 execution.setVariable("allNsFinished", "true")
203 execution.setVariable("allNsFinished", "false")
205 utils.log("INFO", "======== COMPLETED parseNextNS Process ======== ", isDebugEnabled)
209 public void sequenceResource(execution){
210 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
212 utils.log("INFO", " ======== STARTED sequenceResource Process ======== ", isDebugEnabled)
213 List<String> nsResources = new ArrayList<String>()
214 List<String> wanResources = new ArrayList<String>()
215 List<String> resourceSequence = new ArrayList<String>()
217 // get delete resource list and order list
218 List<Resource> delResourceList = execution.getVariable("delResourceList")
219 // existing resource list
220 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
222 for(ServiceInstance rc_e : existResourceList){
224 String muuid = rc_e.getModelInfo().getModelUuid()
225 String mIuuid = rc_e.getModelInfo().getModelInvariantUuid()
226 String mCuuid = rc_e.getModelInfo().getModelCustomizationUuid()
227 rcType = rc_e.getInstanceName()
229 for(Resource rc_d : delResourceList){
231 if(rc_d.getModelInfo().getModelUuid() == muuid
232 && rc_d.getModelInfo().getModelInvariantUuid() == mIuuid
233 && rc_d.getModelInfo().getModelCustomizationUuid() == mCuuid) {
235 if(StringUtils.containsIgnoreCase(rcType, "overlay")
236 || StringUtils.containsIgnoreCase(rcType, "underlay")){
237 wanResources.add(rcType)
239 nsResources.add(rcType)
247 resourceSequence.addAll(wanResources)
248 resourceSequence.addAll(nsResources)
249 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
250 execution.setVariable("isContainsWanResource", isContainsWanResource)
251 execution.setVariable("currentResourceIndex", 0)
252 execution.setVariable("resourceSequence", resourceSequence)
253 utils.log("INFO", "resourceSequence: " + resourceSequence, isDebugEnabled)
254 execution.setVariable("wanResources", wanResources)
255 utils.log("INFO", " ======== END sequenceResource Process ======== ", isDebugEnabled)
258 public void getCurrentResource(execution){
259 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
260 utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)
261 def currentIndex = execution.getVariable("currentResourceIndex")
262 List<String> resourceSequence = execution.getVariable("resourceSequence")
263 List<String> wanResources = execution.getVariable("wanResources")
264 String resourceName = resourceSequence.get(currentIndex)
265 execution.setVariable("resourceType",resourceName)
266 if(wanResources.contains(resourceName)){
267 execution.setVariable("controllerInfo", "SDN-C")
269 execution.setVariable("controllerInfo", "VF-C")
271 utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)
275 * prepare delete parameters
277 public void preResourceDelete(execution, resourceName){
279 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
281 utils.log("INFO", " ======== STARTED preResourceDelete Process ======== ", isDebugEnabled)
283 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
285 for(ServiceInstance rc_e : existResourceList){
287 if(StringUtils.containsIgnoreCase(rc_e.getInstanceName(), resourceName)) {
289 String resourceInstanceUUID = rc_e.getInstanceId()
290 String resourceTemplateUUID = rc_e.getModelInfo().getModelUuid()
291 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
292 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
293 execution.setVariable("resourceType", resourceName)
294 utils.log("INFO", "Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: "
295 + resourceInstanceUUID + " resourceType: " + resourceName, isDebugEnabled)
299 utils.log("INFO", " ======== END preResourceDelete Process ======== ", isDebugEnabled)
302 public void parseNextResource(execution){
303 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
304 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
305 def currentIndex = execution.getVariable("currentResourceIndex")
306 def nextIndex = currentIndex + 1
307 execution.setVariable("currentResourceIndex", nextIndex)
308 List<String> resourceSequence = execution.getVariable("resourceSequence")
309 if(nextIndex >= resourceSequence.size()){
310 execution.setVariable("allResourceFinished", "true")
312 execution.setVariable("allResourceFinished", "false")
314 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)
318 * post config request.
320 public void postConfigRequest(execution){