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
33 import static org.apache.commons.lang3.StringUtils.*;
34 import groovy.xml.XmlUtil
35 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
38 import org.openecomp.mso.bpmn.core.json.JsonUtils
39 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
40 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
41 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
42 import org.openecomp.mso.bpmn.core.WorkflowException
43 import org.openecomp.mso.rest.APIResponse;
44 import org.openecomp.mso.rest.RESTClient
45 import org.openecomp.mso.rest.RESTConfig
46 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
47 import com.fasterxml.jackson.databind.ObjectMapper
49 import java.util.List;
50 import java.util.UUID;
51 import javax.xml.parsers.DocumentBuilder
52 import javax.xml.parsers.DocumentBuilderFactory
54 import org.camunda.bpm.engine.delegate.BpmnError
55 import org.camunda.bpm.engine.delegate.DelegateExecution
56 import org.json.JSONObject;
57 import org.apache.commons.lang3.*
58 import org.apache.commons.codec.binary.Base64;
59 import org.springframework.web.util.UriUtils;
60 import org.w3c.dom.Document
61 import org.w3c.dom.Element
62 import org.w3c.dom.Node
63 import org.w3c.dom.NodeList
64 import org.xml.sax.InputSource
66 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def;
68 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
69 String Prefix="DDELSDNNS_"
72 public void preProcessRequest (DelegateExecution execution) {
73 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
74 utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled)
78 String serviceInstanceId = execution.getVariable("serviceInstanceId")
79 String serviceInstanceName = execution.getVariable("serviceInstanceName")
80 String callbackURL = execution.getVariable("sdncCallbackUrl")
81 String requestId = execution.getVariable("msoRequestId")
82 String serviceId = execution.getVariable("productFamilyId")
83 String subscriptionServiceType = execution.getVariable("subscriptionServiceType")
84 String globalSubscriberId = execution.getVariable("globalSubscriberId") //globalCustomerId
85 String recipeParamsFromRequest = execution.getVariable("recipeParams")
86 String serviceModelInfo = execution.getVariable("serviceModelInfo")
87 String modelInvariantUuid = ""
88 String modelVersion = ""
92 if (!isBlank(serviceModelInfo))
94 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
95 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
96 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
97 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
99 if (modelInvariantUuid == null) {
100 modelInvariantUuid = ""
102 if (modelVersion == null) {
105 if (modelUuid == null) {
108 if (modelName == null) {
112 if (serviceInstanceName == null) {
113 serviceInstanceName = ""
115 if (serviceId == null) {
119 def siParamsXml = execution.getVariable("siParamsXml")
120 def serviceType = execution.getVariable("serviceType")
121 if (serviceType == null)
126 String sdncRequestId = UUID.randomUUID().toString()
128 String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
130 String operationType = "Network"
131 String sdnc_svcAction = "delete"
133 if(!StringUtils.isBlank(recipeParamsFromRequest)){
134 //the operationType from worflow(first node) is second priority.
135 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
137 if(!StringUtils.isBlank(recipeParamsFromWf)){
138 //the operationType from worflow(first node) is highest priority.
139 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
142 operationType = "delete" + operationType + "Instance"
144 ResourceInput resourceInput = new ObjectMapper().readValue(execution.getVariable("resourceInput"), ResourceInput.class)
145 if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "overlay")){
146 //This will be resolved in R3.
147 sdnc_svcAction ="deactivate"
148 operationType = "DeActivateDCINetworkInstance"
150 if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "underlay")){
151 //This will be resolved in R3.
152 operationType ="DeleteNetworkInstance"
156 """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
157 xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
158 xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
159 <sdncadapter:RequestHeader>
160 <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
161 <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
162 <sdncadapter:SvcAction>${sdnc_svcAction}</sdncadapter:SvcAction>
163 <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
164 <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
165 <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
166 </sdncadapter:RequestHeader>
167 <sdncadapterworkflow:SDNCRequestData>
168 <request-information>
169 <request-id>${requestId}</request-id>
174 <request-action>${operationType}</request-action>
175 </request-information>
176 <service-information>
177 <service-id>${serviceId}</service-id>
178 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
179 <onap-model-information>
180 <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
181 <model-uuid>${modelUuid}</model-uuid>
182 <model-version>${modelVersion}</model-version>
183 <model-name>${modelName}</model-name>
184 </onap-model-information>
185 <service-instance-id>${serviceInstanceId}</service-instance-id>
187 <global-customer-id>${globalSubscriberId}</global-customer-id>
188 </service-information>
189 <service-request-input>
190 <service-instance-name>${serviceInstanceName}</service-instance-name>
192 </service-request-input>
193 </sdncadapterworkflow:SDNCRequestData>
194 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
196 sdncDelete = utils.formatXml(sdncDelete)
197 //def sdncRequestId2 = UUID.randomUUID().toString()
198 //String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
199 execution.setVariable("sdncDelete", sdncDelete)
200 // execution.setVariable("sdncDeactivate", sdncDeactivate)
201 // utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
202 utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled)
204 } catch (BpmnError e) {
206 } catch(Exception ex) {
207 msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
208 utils.log("INFO", msg, isDebugEnabled)
209 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
211 utils.log("INFO"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
215 public void postProcessSDNCDelete(DelegateExecution execution, String response) {
217 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
218 utils.log("INFO"," ***** postProcessSDNC " + " *****", isDebugEnabled)
220 utils.log("INFO"," response " + response, isDebugEnabled)
221 utils.log("INFO"," *** Exit postProcessSDNC " + " ***", isDebugEnabled)