9358537448155c1833d20a72cd45c282ccd109b8
[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.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
33 import static org.apache.commons.lang3.StringUtils.*;
34 import groovy.xml.XmlUtil
35 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
36 import groovy.json.*
37
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
48
49 import java.util.List;
50 import java.util.UUID;
51 import javax.xml.parsers.DocumentBuilder
52 import javax.xml.parsers.DocumentBuilderFactory
53
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
65
66 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP.Def;
67
68 public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor {
69     String Prefix="DDELSDNNS_"
70
71
72     public void preProcessRequest (DelegateExecution execution) {
73         def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
74         utils.log("INFO"," ***** preProcessSDNCDelete *****", isDebugEnabled)
75         String msg = ""
76
77         try {
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 = ""
89             String modelUuid = ""
90             String modelName = ""
91
92             if (!isBlank(serviceModelInfo))
93             {
94                 modelInvariantUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelInvariantUuid")
95                 modelVersion = jsonUtil.getJsonValue(serviceModelInfo, "modelVersion")
96                 modelUuid = jsonUtil.getJsonValue(serviceModelInfo, "modelUuid")
97                 modelName = jsonUtil.getJsonValue(serviceModelInfo, "modelName")
98
99                 if (modelInvariantUuid == null) {
100                     modelInvariantUuid = ""
101                 }
102                 if (modelVersion == null) {
103                     modelVersion = ""
104                 }
105                 if (modelUuid == null) {
106                     modelUuid = ""
107                 }
108                 if (modelName == null) {
109                     modelName = ""
110                 }
111             }
112             if (serviceInstanceName == null) {
113                 serviceInstanceName = ""
114             }
115             if (serviceId == null) {
116                 serviceId = ""
117             }
118
119             def siParamsXml = execution.getVariable("siParamsXml")
120             def serviceType = execution.getVariable("serviceType")
121             if (serviceType == null)
122             {
123                 serviceType = ""
124             }
125
126             String sdncRequestId = UUID.randomUUID().toString()
127
128             String recipeParamsFromWf = execution.getVariable("recipeParamXsd")
129
130             String operationType = "Network"
131             String sdnc_svcAction = "delete"
132
133             if(!StringUtils.isBlank(recipeParamsFromRequest)){
134                 //the operationType from worflow(first node) is second priority.
135                 operationType = jsonUtil.getJsonValue(recipeParamsFromRequest, "operationType")
136             }
137             if(!StringUtils.isBlank(recipeParamsFromWf)){
138                 //the operationType from worflow(first node) is highest priority.
139                 operationType = jsonUtil.getJsonValue(recipeParamsFromWf, "operationType")
140             }
141
142             operationType = "delete" + operationType + "Instance"
143
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"
149             }
150             if(StringUtils.containsIgnoreCase(resourceInput.getResourceModelInfo().getModelName(), "underlay")){
151                 //This will be resolved in R3.
152                 operationType ="DeleteNetworkInstance"
153             }
154
155             String sdncDelete =
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>
170                                                 <source>MSO</source>
171                                                 <notification-url/>
172                                                 <order-number/>
173                                                 <order-version/>
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>
186                                                 <subscriber-name/>
187                                                 <global-customer-id>${globalSubscriberId}</global-customer-id>
188                                         </service-information>
189                                         <service-request-input>
190                                                 <service-instance-name>${serviceInstanceName}</service-instance-name>
191                                                 ${siParamsXml}
192                                         </service-request-input>
193                                 </sdncadapterworkflow:SDNCRequestData>
194                                 </sdncadapterworkflow:SDNCAdapterWorkflowRequest>"""
195
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)
203
204         } catch (BpmnError e) {
205             throw 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())
210         }
211         utils.log("INFO"," *****Exit preProcessSDNCDelete *****", isDebugEnabled)
212     }
213
214
215     public void postProcessSDNCDelete(DelegateExecution execution, String response) {
216
217         def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
218         utils.log("INFO"," ***** postProcessSDNC "  + " *****", isDebugEnabled)
219         String msg = ""
220         utils.log("INFO"," response " + response, isDebugEnabled)
221         utils.log("INFO"," *** Exit postProcessSDNC " + " ***", isDebugEnabled)
222     }
223
224 }