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