3 * ============LICENSE_START=======================================================
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.openecomp.mso.bpmn.infrastructure.scripts
24 import org.json.JSONArray
25 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
26 import org.openecomp.mso.bpmn.core.domain.Resource
27 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
28 import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties;
29 import org.apache.http.HttpResponse
30 import org.json.JSONArray
31 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
32 import org.openecomp.mso.bpmn.common.recipe.ResourceInput;
34 import static org.apache.commons.lang3.StringUtils.*;
35 import groovy.xml.XmlUtil
36 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
39 import org.openecomp.mso.bpmn.core.json.JsonUtils
40 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
41 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
42 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
43 import org.openecomp.mso.bpmn.core.WorkflowException
44 import org.openecomp.mso.rest.APIResponse;
45 import org.openecomp.mso.rest.RESTClient
46 import org.openecomp.mso.rest.RESTConfig
48 import java.util.List;
49 import java.util.UUID;
50 import javax.xml.parsers.DocumentBuilder
51 import javax.xml.parsers.DocumentBuilderFactory
53 import org.camunda.bpm.engine.delegate.BpmnError
54 import org.camunda.bpm.engine.delegate.DelegateExecution
55 import org.json.JSONObject;
56 import org.apache.commons.lang3.*
57 import org.apache.commons.codec.binary.Base64;
58 import org.springframework.web.util.UriUtils;
59 import org.w3c.dom.Document
60 import org.w3c.dom.Element
61 import org.w3c.dom.Node
62 import org.w3c.dom.NodeList
63 import org.xml.sax.InputSource
65 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def;
67 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
68 String Prefix="DDELSDNNS_"
71 public void preProcessRequest (DelegateExecution execution) {
72 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
73 utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled)
77 serviceInstanceId = execution.getVariable("serviceInstanceId")
78 serviceInstanceName = execution.getVariable("serviceInstanceName")
79 callbackURL = execution.getVariable("sdncCallbackUrl")
80 requestId = execution.getVariable("msoRequestId")
81 serviceId = execution.getVariable("productFamilyId")
82 subscriptionServiceType = execution.getVariable("subscriptionServiceType")
83 globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
84 String recipeParamsFromRequest = execution.getVariable("recipeParams")
85 String serviceModelInfo = execution.getVariable("serviceModelInfo")
86 modelInvariantUuid = ""
91 if (!isBlank(serviceModelInfo))
93 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
94 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
95 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
96 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
98 if (modelInvariantUuid == null) {
99 modelInvariantUuid = ""
101 if (modelVersion == null) {
104 if (modelUuid == null) {
107 if (modelName == null) {
111 if (serviceInstanceName == null) {
112 serviceInstanceName = ""
114 if (serviceId == null) {
118 def siParamsXml = execution.getVariable("siParamsXml")
119 def serviceType = execution.getVariable("serviceType")
120 if (serviceType == null)
125 sdncRequestId = UUID.randomUUID().toString()
127 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
129 String operationType = "Network"
130 String sdnc_svcAction = "delete"
132 if(!StringUtils.isBlank(recipeParamsFromRequest)){
133 //the operationType from worflow(first node) is second priority.
134 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
136 if(!StringUtils.isBlank(recipeParamsFromWf)){
137 //the operationType from worflow(first node) is highest priority.
138 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
141 operationType = "delete" + operationType + "Instance"
143 if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "overlay")){
144 //This will be resolved in R3.
145 sdnc_svcAction ="deactivate"
146 operationType = "DeActivateDCINetworkInstance"
148 if(StringUtils.containsIgnoreCase(resourceInputObj.getResourceInstanceName(), "underlay")){
149 //This will be resolved in R3.
150 operationType ="DeleteNetworkInstance"
154 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
155 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
156 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
157 <sdncadapter:RequestHeader>
158 <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
159 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
160 <sdncadapter:SvcAction>${sdnc_svcAction}</sdncadapter:SvcAction>
161 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
162 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
163 <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
164 </sdncadapter:RequestHeader>
165 <sdncadapterworkflow:SDNCRequestData>
166 <request-information>
167 <request-id>${requestId}</request-id>
172 <request-action>${operationType}</request-action>
173 </request-information>
174 <service-information>
175 <service-id>${serviceId}</service-id>
176 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
177 <onap-model-information>
178 <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
179 <model-uuid>${modelUuid}</model-uuid>
180 <model-version>${modelVersion}</model-version>
181 <model-name>${modelName}</model-name>
182 </onap-model-information>
183 <service-instance-id>${serviceInstanceId}</service-instance-id>
185 <global-customer-id>${globalSubscriberId}</global-customer-id>
186 </service-information>
187 <service-request-input>
188 <service-instance-name>${serviceInstanceName}</service-instance-name>
190 </service-request-input>
191 </sdncadapterworkflow:SDNCRequestData>
192 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
194 sdncDelete = utils.formatXml(sdncDelete)
195 //def sdncRequestId2 = UUID.randomUUID().toString()
196 //String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
197 execution.setVariable("sdncDelete", sdncDelete)
198 execution.setVariable("sdncDeactivate", sdncDeactivate)
199 utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
200 utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled)
202 } catch (BpmnError e) {
204 } catch(Exception ex) {
205 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
206 utils.log("INFO", msg, isDebugEnabled)
207 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
209 utils.log("INFO"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
213 public void postProcessSDNCDelete(DelegateExecution execution, String response) {
215 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
216 utils.log("INFO"," ***** postProcessSDNC " + " *****", isDebugEnabled)
218 utils.log("INFO"," response " + response, isDebugEnabled)
219 utils.log("INFO"," *** Exit postProcessSDNC " + " ***", isDebugEnabled)