72db6f358d8e5b6b33db6c14592c9ea82c5fd7e9
[so.git] /
1
2 /*-
3  * ============LICENSE_START=======================================================
4  * ONAP - SO
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22 package org.openecomp.mso.bpmn.infrastructure.scripts
23
24 import org.json.JSONArray
25 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
26 import org.openecomp.mso.bpmn.core.domain.ModelInfo
27 import org.openecomp.mso.bpmn.core.domain.Resource
28 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
29 import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties;
30 import org.apache.http.HttpResponse
31 import org.json.JSONArray
32 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
33
34 import static org.apache.commons.lang3.StringUtils.*;
35 import groovy.xml.XmlUtil
36 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
37 import groovy.json.*
38
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
47 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
48 import com.fasterxml.jackson.databind.ObjectMapper
49
50 import java.util.List;
51 import java.util.UUID;
52 import javax.xml.parsers.DocumentBuilder
53 import javax.xml.parsers.DocumentBuilderFactory
54
55 import org.camunda.bpm.engine.delegate.BpmnError
56 import org.camunda.bpm.engine.delegate.DelegateExecution
57 import org.json.JSONObject;
58 import org.apache.commons.lang3.*
59 import org.apache.commons.codec.binary.Base64;
60 import org.springframework.web.util.UriUtils;
61 import org.w3c.dom.Document
62 import org.w3c.dom.Element
63 import org.w3c.dom.Node
64 import org.w3c.dom.NodeList
65 import org.xml.sax.InputSource
66
67 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def;
68
69 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
70     String Prefix="DDELSDNNS_"
71
72
73     public void preProcessRequest (DelegateExecution execution) {
74         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
75         utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled)
76         String msg = ""
77
78         try {
79             ResourceInput resourceInput = new ObjectMapper().readValue(execution.getVariable("resourceInput"), ResourceInput.class)
80
81             ModelInfo resourceModelInfo = resourceInput.getResourceModelInfo()
82             execution.setVariable("resourceInvariantUUID", resourceModelInfo.getModelInvariantUuid())
83             execution.setVariable("modelVersion", resourceModelInfo.getModelVersion())
84             execution.setVariable("resourceUUID", resourceModelInfo.getModelUuid())
85             execution.setVariable("resourceType", resourceModelInfo.getModelType())
86
87             String serviceInstanceId = execution.getVariable("serviceInstanceId")
88             String serviceInstanceName = execution.getVariable("serviceInstanceName")
89             String callbackURL = execution.getVariable("sdncCallbackUrl")
90             String requestId = execution.getVariable("msoRequestId")
91             String subscriptionServiceType = execution.getVariable("serviceType")
92             String globalSubscriberId = resourceInput.getGlobalSubscriberId()
93             String recipeParamsFromRequest = execution.getVariable("recipeParams")
94             String serviceId = resourceInput.getServiceInstanceId()
95             ModelInfo serviceModelInfo = resourceInput.getServiceModelInfo()
96             String modelInvariantUuid = ""
97             String modelVersion = ""
98             String modelUuid = ""
99             String modelName = ""
100
101             if (serviceModelInfo != null)
102             {
103                 modelInvariantUuid = serviceModelInfo.getModelInvariantUuid()
104                 modelVersion = serviceModelInfo.getModelVersion()
105                 modelUuid = serviceModelInfo.getModelUuid()
106                 modelName = serviceModelInfo.getModelName()
107
108                 execution.setVariable("modelInvariantUuid", serviceModelInfo.getModelInvariantUuid())
109                 execution.setVariable("modelVersion", serviceModelInfo.getModelVersion())
110                 execution.setVariable("modelUuid", serviceModelInfo.getModelUuid())
111                 execution.setVariable("serviceModelName", serviceModelInfo.getModelName())
112
113                 if (modelInvariantUuid == null) {
114                     modelInvariantUuid = ""
115                 }
116                 if (modelVersion == null) {
117                     modelVersion = ""
118                 }
119                 if (modelUuid == null) {
120                     modelUuid = ""
121                 }
122                 if (modelName == null) {
123                     modelName = ""
124                 }
125             }
126             if (serviceInstanceName == null) {
127                 serviceInstanceName = ""
128             }
129             if (serviceId == null) {
130                 serviceId = ""
131             }
132
133             def siParamsXml = execution.getVariable("siParamsXml")
134             def serviceType = execution.getVariable("serviceType")
135             if (serviceType == null)
136             {
137                 serviceType = ""
138             }
139
140             String sdncRequestId = UUID.randomUUID().toString()
141
142             String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
143
144             String operationType = "Network"
145             String sdnc_svcAction = "delete"
146
147             if(!StringUtils.isBlank(recipeParamsFromRequest)){
148                 //the operationType from worflow(first node) is second priority.
149                 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
150             }
151             if(!StringUtils.isBlank(recipeParamsFromWf)){
152                 //the operationType from worflow(first node) is highest priority.
153                 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
154             }
155
156             operationType = "delete" + operationType + "Instance"
157
158             if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "overlay")){
159                 //This will be resolved in R3.
160                 sdnc_svcAction ="deactivate"
161                 operationType = "DeActivateDCINetworkInstance"
162             }
163             if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "underlay")){
164                 //This will be resolved in R3.
165                 operationType ="DeleteNetworkInstance"
166             }
167
168             String sdncDelete =
169                     """<sdncadapterworkflow:SDNCAdapterWorkflowRequest xmlns:ns5="http://org.openecomp/mso/request/types/v1"
170                                                                                                         xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
171                                                                                                         xmlns:sdncadapter="http://org.openecomp/workflow/sdnc/adapter/schema/v1">
172                                    <sdncadapter:RequestHeader>
173                                                         <sdncadapter:RequestId>${sdncRequestId}</sdncadapter:RequestId>
174                                                         <sdncadapter:SvcInstanceId>${serviceInstanceId}</sdncadapter:SvcInstanceId>
175                                                         <sdncadapter:SvcAction>${sdnc_svcAction}</sdncadapter:SvcAction>
176                                                         <sdncadapter:SvcOperation>service-topology-operation</sdncadapter:SvcOperation>
177                                                         <sdncadapter:CallbackUrl>${callbackURL}</sdncadapter:CallbackUrl>
178                                                         <sdncadapter:MsoAction>${serviceType}</sdncadapter:MsoAction>
179                                         </sdncadapter:RequestHeader>
180                                 <sdncadapterworkflow:SDNCRequestData>
181                                         <request-information>
182                                                 <request-id>${requestId}</request-id>
183                                                 <source>MSO</source>
184                                                 <notification-url/>
185                                                 <order-number/>
186                                                 <order-version/>
187                                                 <request-action>${operationType}</request-action>
188                                         </request-information>
189                                         <service-information>
190                                                 <service-id>${serviceId}</service-id>
191                                                 <subscription-service-type>${subscriptionServiceType}</subscription-service-type>
192                                                 <onap-model-information>
193                                                  <model-invariant-uuid>${modelInvariantUuid}</model-invariant-uuid>
194                                                  <model-uuid>${modelUuid}</model-uuid>
195                                                  <model-version>${modelVersion}</model-version>
196                                                  <model-name>${modelName}</model-name>
197                                             </onap-model-information>
198                                                 <service-instance-id>${serviceInstanceId}</service-instance-id>
199                                                 <subscriber-name/>
200                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>
201                                         </service-information>
202                                         <service-request-input>
203                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
204                                                 ${siParamsXml}
205                                         </service-request-input>
206                                 </sdncadapterworkflow:SDNCRequestData>
207                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
208
209             sdncDelete = utils.formatXml(sdncDelete)
210
211             // set operation type and resource type is required to form request body
212             execution.setVariable("operationType", "DELETE")
213             execution.setVariable("resourceType", resourceModelInfo.getModelName())
214
215             //def sdncRequestId2 = UUID.randomUUID().toString()
216             //String sdncDeactivate = sdncDelete.replace(">delete<", ">deactivate<").replace(">${sdncRequestId}<", ">${sdncRequestId2}<")
217             execution.setVariable("sdncDelete", sdncDelete)
218 //            execution.setVariable("sdncDeactivate", sdncDeactivate)
219 //            utils.log("INFO","sdncDeactivate:\n" + sdncDeactivate, isDebugEnabled)
220             utils.log("INFO","sdncDelete:\n" + sdncDelete, isDebugEnabled)
221
222         } catch (BpmnError e) {
223             throw e;
224         } catch(Exception ex) {
225             msg = "Exception in preProcessSDNCDelete. " + ex.getMessage()
226             utils.log("INFO", msg, isDebugEnabled)
227             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Exception Occured in preProcessSDNCDelete.\n" + ex.getMessage())
228         }
229         utils.log("INFO"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
230     }
231
232
233     public void postProcessSDNCDelete(DelegateExecution execution, String response) {
234
235         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
236         utils.log("INFO"," ***** postProcessSDNC "  + " *****", isDebugEnabled)
237         String msg = ""
238         utils.log("INFO"," response " + response, isDebugEnabled)
239         utils.log("INFO"," *** Exit postProcessSDNC " + " ***", isDebugEnabled)
240     }
241
242 }