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.onap.so.bpmn.infrastructure.scripts
22 import org.json.JSONArray;
24 import static org.apache.commons.lang3.StringUtils.*;
25 import groovy.xml.XmlUtil
28 import org.onap.so.bpmn.core.domain.ModelInfo
29 import org.onap.so.bpmn.core.domain.Resource
30 import org.onap.so.bpmn.core.domain.ServiceInstance
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
35 import org.onap.so.bpmn.core.WorkflowException
36 import org.onap.so.rest.APIResponse;
37 import org.onap.so.rest.RESTClient
38 import org.onap.so.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;
59 import org.onap.so.logger.MessageEnum
60 import org.onap.so.logger.MsoLogger
63 * This groovy class supports the <class>DoDeleteResources.bpmn</class> process.
66 * @param - msoRequestId
67 * @param - globalSubscriberId - O
68 * @param - subscriptionServiceType - O
69 * @param - serviceInstanceId
70 * @param - serviceInstanceName - O
71 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
72 * @param - sdncVersion
73 * @param - failNotFound - TODO
74 * @param - serviceInputParams - TODO
76 * @param - delResourceList
77 * @param - serviceRelationShip
80 * @param - WorkflowException
84 public class DoDeleteResources extends AbstractServiceTaskProcessor {
85 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoDeleteResources.class);
87 String Prefix="DDELR_"
88 ExceptionUtil exceptionUtil = new ExceptionUtil()
89 JsonUtils jsonUtil = new JsonUtils()
91 public void preProcessRequest (DelegateExecution execution) {
92 msoLogger.trace("preProcessRequest ")
95 List<ServiceInstance> realNSRessources = new ArrayList<ServiceInstance>()
97 // related ns from AAI
98 String serviceRelationShip = execution.getVariable("serviceRelationShip")
99 def jsonSlurper = new JsonSlurper()
100 def jsonOutput = new JsonOutput()
101 List<String> nsSequence = new ArrayList<String>()
102 List relationShipList = jsonSlurper.parseText(serviceRelationShip)
103 if (relationShipList != null) {
104 relationShipList.each {
105 String resourceType = it.resourceType
106 nsSequence.add(resourceType)
110 execution.setVariable("currentNSIndex", 0)
111 execution.setVariable("nsSequence", nsSequence)
112 execution.setVariable("realNSRessources", realNSRessources)
113 msoLogger.info("nsSequence: " + nsSequence)
115 msoLogger.trace("Exit preProcessRequest ")
118 public void getCurrentNS(execution){
119 msoLogger.trace("Start getCurrentNS Process ")
121 def currentIndex = execution.getVariable("currentNSIndex")
122 List<String> nsSequence = execution.getVariable("nsSequence")
123 String nsResourceType = nsSequence.get(currentIndex)
125 // GET AAI by Name, not ID, for process convenient
126 execution.setVariable("GENGS_type", "service-instance")
127 execution.setVariable("GENGS_serviceInstanceId", "")
128 execution.setVariable("GENGS_serviceInstanceName", nsResourceType)
130 msoLogger.trace("COMPLETED getCurrentNS Process ")
133 public void postProcessAAIGET(DelegateExecution execution) {
134 msoLogger.trace("postProcessAAIGET2 ")
138 String nsResourceName = execution.getVariable("GENGS_serviceInstanceName")
139 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
141 msoLogger.info("Error getting Service-instance from AAI in postProcessAAIGET", + nsResourceName)
142 WorkflowException workflowException = execution.getVariable("WorkflowException")
143 msoLogger.debug("workflowException: " + workflowException)
144 if(workflowException != null){
145 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
149 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
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.getNodeText(aaiService, "service-instance-id")
161 //String mn = utils.getNodeText(aaiService, "model-name")
162 String mIuuid = utils.getNodeText(aaiService, "model-invariant-id")
163 String muuid = utils.getNodeText(aaiService, "model-version-id")
164 String mCuuid = utils.getNodeText(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 msoLogger.info("Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"))
183 } catch (BpmnError e) {
185 } catch (Exception ex) {
186 msg = "Exception in DoDeleteResources.postProcessAAIGET " + ex.getMessage()
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
190 msoLogger.trace("Exit postProcessAAIGET ")
193 public void parseNextNS(execution){
194 msoLogger.trace("Start parseNextNS Process ")
195 def currentIndex = execution.getVariable("currentNSIndex")
196 def nextIndex = currentIndex + 1
197 execution.setVariable("currentNSIndex", nextIndex)
198 List<String> nsSequence = execution.getVariable("nsSequence")
199 if(nextIndex >= nsSequence.size()){
200 execution.setVariable("allNsFinished", "true")
202 execution.setVariable("allNsFinished", "false")
204 msoLogger.trace("COMPLETED parseNextNS Process ")
208 public void sequenceResource(execution){
209 msoLogger.trace("STARTED sequenceResource Process ")
210 List<String> nsResources = new ArrayList<String>()
211 List<String> wanResources = new ArrayList<String>()
212 List<String> resourceSequence = new ArrayList<String>()
214 // get delete resource list and order list
215 List<Resource> delResourceList = execution.getVariable("delResourceList")
216 // existing resource list
217 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
219 for(ServiceInstance rc_e : existResourceList){
221 String muuid = rc_e.getModelInfo().getModelUuid()
222 String mIuuid = rc_e.getModelInfo().getModelInvariantUuid()
223 String mCuuid = rc_e.getModelInfo().getModelCustomizationUuid()
224 rcType = rc_e.getInstanceName()
226 for(Resource rc_d : delResourceList){
228 if(rc_d.getModelInfo().getModelUuid() == muuid
229 && rc_d.getModelInfo().getModelInvariantUuid() == mIuuid
230 && rc_d.getModelInfo().getModelCustomizationUuid() == mCuuid) {
232 if(StringUtils.containsIgnoreCase(rcType, "overlay")
233 || StringUtils.containsIgnoreCase(rcType, "underlay")){
234 wanResources.add(rcType)
236 nsResources.add(rcType)
244 resourceSequence.addAll(wanResources)
245 resourceSequence.addAll(nsResources)
246 String isContainsWanResource = wanResources.isEmpty() ? "false" : "true"
247 execution.setVariable("isContainsWanResource", isContainsWanResource)
248 execution.setVariable("currentResourceIndex", 0)
249 execution.setVariable("resourceSequence", resourceSequence)
250 msoLogger.info("resourceSequence: " + resourceSequence)
251 execution.setVariable("wanResources", wanResources)
252 msoLogger.trace("END sequenceResource Process ")
255 public void getCurrentResource(execution){
256 msoLogger.trace("Start getCurrentResoure Process ")
257 def currentIndex = execution.getVariable("currentResourceIndex")
258 List<String> resourceSequence = execution.getVariable("resourceSequence")
259 List<String> wanResources = execution.getVariable("wanResources")
260 String resourceName = resourceSequence.get(currentIndex)
261 execution.setVariable("resourceType",resourceName)
262 if(wanResources.contains(resourceName)){
263 execution.setVariable("controllerInfo", "SDN-C")
265 execution.setVariable("controllerInfo", "VF-C")
267 msoLogger.trace("COMPLETED getCurrentResoure Process ")
271 * prepare delete parameters
273 public void preResourceDelete(execution, resourceName){
275 msoLogger.trace("STARTED preResourceDelete Process ")
277 List<ServiceInstance> existResourceList = execution.getVariable("realNSRessources")
279 for(ServiceInstance rc_e : existResourceList){
281 if(StringUtils.containsIgnoreCase(rc_e.getInstanceName(), resourceName)) {
283 String resourceInstanceUUID = rc_e.getInstanceId()
284 String resourceTemplateUUID = rc_e.getModelInfo().getModelUuid()
285 execution.setVariable("resourceInstanceId", resourceInstanceUUID)
286 execution.setVariable("resourceTemplateId", resourceTemplateUUID)
287 execution.setVariable("resourceType", resourceName)
288 msoLogger.info("Delete Resource Info resourceTemplate Id :" + resourceTemplateUUID + " resourceInstanceId: " + resourceInstanceUUID + " resourceType: " + resourceName)
292 msoLogger.trace("END preResourceDelete Process ")
295 public void parseNextResource(execution){
296 msoLogger.trace("Start parseNextResource Process ")
297 def currentIndex = execution.getVariable("currentResourceIndex")
298 def nextIndex = currentIndex + 1
299 execution.setVariable("currentResourceIndex", nextIndex)
300 List<String> resourceSequence = execution.getVariable("resourceSequence")
301 if(nextIndex >= resourceSequence.size()){
302 execution.setVariable("allResourceFinished", "true")
304 execution.setVariable("allResourceFinished", "false")
306 msoLogger.trace("COMPLETED parseNextResource Process ")
310 * post config request.
312 public void postConfigRequest(execution){