2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
23 import static org.apache.commons.lang3.StringUtils.*;
24 import groovy.xml.XmlUtil
27 import org.openecomp.mso.bpmn.core.json.JsonUtils
28 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
31 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
32 import org.openecomp.mso.bpmn.core.RollbackData
33 import org.openecomp.mso.bpmn.core.WorkflowException
34 import org.openecomp.mso.rest.APIResponse;
35 import org.openecomp.mso.rest.RESTClient
36 import org.openecomp.mso.rest.RESTConfig
38 import java.util.UUID;
40 import org.camunda.bpm.engine.delegate.BpmnError
41 import org.camunda.bpm.engine.delegate.DelegateExecution
42 import org.json.JSONObject;
43 import org.apache.commons.lang3.*
44 import org.apache.commons.codec.binary.Base64;
45 import org.springframework.web.util.UriUtils;
47 * This groovy class supports the <class>DoUpdateE2EServiceInstanceRollback.bpmn</class> process.
50 * @param - msoRequestId
51 * @param - rollbackData with
53 * subscriptionServiceType
62 * @param - rollbackError
63 * @param - rolledBack (no localRB->null, localRB F->false, localRB S->true)
66 public class DoUpdateE2EServiceInstanceRollback extends AbstractServiceTaskProcessor{
68 String Prefix="DUPDSIRB_"
69 ExceptionUtil exceptionUtil = new ExceptionUtil()
71 public void preProcessRequest(DelegateExecution execution) {
72 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
73 execution.setVariable("prefix",Prefix)
75 utils.log("DEBUG"," ***** preProcessRequest *****", isDebugEnabled)
76 execution.setVariable("rollbackAAI",false)
77 execution.setVariable("rollbackAdded",false)
78 execution.setVariable("rollbackDeleted",false)
80 List addResourceList = execution.getVariable("addResourceList")
81 List delResourceList = execution.getVariable("delResourceList")
82 execution.setVariable("addResourceList_o", addResourceList)
83 execution.setVariable("delResourceList_o", delResourceList)
84 //exchange add and delete resource list
85 execution.setVariable("addResourceList", delResourceList)
86 execution.setVariable("delResourceList", addResourceList)
89 def rollbackData = execution.getVariable("rollbackData")
90 utils.log("DEBUG", "RollbackData:" + rollbackData, isDebugEnabled)
92 if (rollbackData != null) {
93 if (rollbackData.hasType("SERVICEINSTANCE")) {
95 def serviceInstanceId = rollbackData.get("SERVICEINSTANCE", "serviceInstanceId")
96 execution.setVariable("serviceInstanceId", serviceInstanceId)
98 def subscriptionServiceType = rollbackData.get("SERVICEINSTANCE", "subscriptionServiceType")
99 execution.setVariable("subscriptionServiceType", subscriptionServiceType)
101 def globalSubscriberId = rollbackData.get("SERVICEINSTANCE", "globalSubscriberId")
102 execution.setVariable("globalSubscriberId", globalSubscriberId)
104 def rollbackAAI = rollbackData.get("SERVICEINSTANCE", "rollbackAAI")
105 if ("true".equals(rollbackAAI))
107 execution.setVariable("rollbackAAI",true)
110 def rollbackAdded = rollbackData.get("SERVICEINSTANCE", "rollbackAdded")
111 if ("true".equals(rollbackAdded))
113 execution.setVariable("rollbackAdded", true)
116 def rollbackDeleted = rollbackData.get("SERVICEINSTANCE", "rollbackDeleted")
117 if ("true".equals(rollbackDeleted))
119 execution.setVariable("rollbackDeleted", true)
122 if (execution.getVariable("rollbackAAI") != true && execution.getVariable("rollbackAdded") != true
123 && execution.getVariable("rollbackDeleted") != true)
125 execution.setVariable("skipRollback", true)
130 execution.setVariable("skipRollback", true)
134 execution.setVariable("skipRollback", true)
136 if (execution.getVariable("disableRollback").equals("true" ))
138 execution.setVariable("skipRollback", true)
141 } catch (BpmnError e) {
143 } catch (Exception ex){
144 msg = "Exception in Update ServiceInstance Rollback preProcessRequest " + ex.getMessage()
145 utils.log("DEBUG", msg, isDebugEnabled)
146 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
148 utils.log("DEBUG"," ***** Exit preProcessRequest *****", isDebugEnabled)
151 public void postProcessRequest(DelegateExecution execution) {
152 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
153 utils.log("DEBUG"," ***** postProcessRequest ***** ", isDebugEnabled)
156 execution.setVariable("rollbackData", null)
157 String serviceInstanceId = execution.getVariable("serviceInstanceId")
158 boolean rollbackAAI = execution.getVariable("rollbackAAI")
159 boolean rollbackAdded = execution.getVariable("rollbackAdded")
160 boolean rollbackDeleted = execution.getVariable("rollbackDeleted")
162 List addResourceList = execution.getVariable("addResourceList_o")
163 List delResourceList = execution.getVariable("delResourceList_o")
164 execution.setVariable("addResourceList", addResourceList)
165 execution.setVariable("delResourceList", delResourceList)
167 if (rollbackAAI || rollbackAdded || rollbackDeleted)
169 execution.setVariable("rolledBack", true)
173 boolean succInAAI = execution.getVariable("GENDS_SuccessIndicator")
175 execution.setVariable("rolledBack", false) //both sdnc and aai must be successful to declare rollback Succesful
176 execution.setVariable("rollbackError", "Error deleting service-instance in AAI for rollback")
177 utils.log("DEBUG","Error deleting service-instance in AAI for rollback", + serviceInstanceId, isDebugEnabled)
180 utils.log("DEBUG","*** Exit postProcessRequest ***", isDebugEnabled)
182 } catch (BpmnError e) {
183 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + e.getMessage()
184 utils.log("DEBUG", msg, isDebugEnabled)
185 } catch (Exception ex) {
186 msg = "Exception in Create ServiceInstance Rollback postProcessRequest. " + ex.getMessage()
187 utils.log("DEBUG", msg, isDebugEnabled)
192 public void preProcessForAddResource(DelegateExecution execution) {
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
196 public void postProcessForAddResource(DelegateExecution execution) {
197 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
201 public void preProcessForDeleteResource(DelegateExecution execution) {
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
206 public void postProcessForDeleteResource(DelegateExecution execution) {
207 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
211 public void preProcessAAIGET(DelegateExecution execution) {
212 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
215 public void postProcessAAIGET(DelegateExecution execution) {
216 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
217 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
221 String serviceInstanceName = execution.getVariable("serviceInstanceName")
222 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
224 utils.log("INFO","Error getting Service-instance from AAI in postProcessAAIGET", + serviceInstanceName, isDebugEnabled)
225 WorkflowException workflowException = execution.getVariable("WorkflowException")
226 utils.logAudit("workflowException: " + workflowException)
227 if(workflowException != null){
228 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
232 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
233 utils.log("INFO", msg, isDebugEnabled)
234 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
239 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
241 String aaiService = execution.getVariable("GENGS_service")
242 if (!isBlank(aaiService) && (utils.nodeExists(aaiService, "resource-version"))) {
243 execution.setVariable("serviceInstanceVersion_n", utils.getNodeText1(aaiService, "resource-version"))
244 utils.log("INFO","Found Service-instance in AAI.serviceInstanceName:" + execution.getVariable("serviceInstanceName"), isDebugEnabled)
248 } catch (BpmnError e) {
250 } catch (Exception ex) {
251 msg = "Exception in DoCreateServiceInstance.postProcessAAIGET " + ex.getMessage()
252 utils.log("INFO", msg, isDebugEnabled)
253 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
255 utils.log("INFO"," *** Exit postProcessAAIGET *** ", isDebugEnabled)
258 public void preProcessAAIPUT(DelegateExecution execution) {
259 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
260 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
261 utils.log("INFO","Entered " + method, isDebugEnabled)
263 utils.log("INFO"," ***** preProcessAAIPUT *****", isDebugEnabled)
265 String serviceInstanceVersion = execution.getVariable("serviceInstanceVersion_n")
266 // execution.setVariable("GENPS_serviceResourceVersion", serviceInstanceVersion)
268 //requestDetails.modelInfo.for AAI PUT servieInstanceData
269 //requestDetails.requestInfo. for AAI GET/PUT serviceInstanceData
270 String serviceInstanceName = execution.getVariable("serviceInstanceName")
271 String serviceInstanceId = execution.getVariable("serviceInstanceId")
272 //aai serviceType and Role can be setted as fixed value now.
273 String aaiServiceType = "E2E Service"
274 String aaiServiceRole = "E2E Service"
275 String modelInvariantUuid = execution.getVariable("modelInvariantUuid")
276 String modelUuid = execution.getVariable("model-version-id-original")
279 AaiUtil aaiUriUtil = new AaiUtil(this)
280 utils.log("INFO","start create aai uri: " + aaiUriUtil, isDebugEnabled)
281 String aai_uri = aaiUriUtil.getBusinessCustomerUri(execution)
282 utils.log("INFO","aai_uri: " + aai_uri, isDebugEnabled)
283 String namespace = aaiUriUtil.getNamespaceFromUri(aai_uri)
284 utils.log("INFO","namespace: " + namespace, isDebugEnabled)
286 String serviceInstanceData =
287 """<service-instance xmlns=\"${namespace}\">
288 <service-instance-id>${serviceInstanceId}</service-instance-id>
289 <service-instance-name>${serviceInstanceName}</service-instance-name>
290 <service-type>${aaiServiceType}</service-type>
291 <service-role>${aaiServiceRole}</service-role>
292 <resource-version>${serviceInstanceVersion}</resource-version>
293 <model-invariant-id>${modelInvariantUuid}</model-invariant-id>
294 <model-version-id>${modelUuid}</model-version-id>
295 </service-instance>""".trim()
297 execution.setVariable("serviceInstanceData", serviceInstanceData)
298 utils.log("INFO","serviceInstanceData: " + serviceInstanceData, isDebugEnabled)
299 utils.logAudit(serviceInstanceData)
300 utils.log("INFO", " aai_uri " + aai_uri + " namespace:" + namespace, isDebugEnabled)
301 utils.log("INFO", " 'payload' to update Service Instance in AAI - " + "\n" + serviceInstanceData, isDebugEnabled)
303 utils.log("INFO", "Exited " + method, isDebugEnabled)
306 public void postProcessAAIPUT(DelegateExecution execution) {
307 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
308 utils.log("INFO"," ***** postProcessAAIPUT ***** ", isDebugEnabled)
311 String serviceInstanceId = execution.getVariable("serviceInstanceId")
312 boolean succInAAI = execution.getVariable("GENPS_SuccessIndicator")
314 utils.log("INFO","Error putting Service-instance in AAI", + serviceInstanceId, isDebugEnabled)
315 WorkflowException workflowException = execution.getVariable("WorkflowException")
316 utils.logAudit("workflowException: " + workflowException)
317 if(workflowException != null){
318 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
326 } catch (BpmnError e) {
328 } catch (Exception ex) {
329 msg = "Exception in DoCreateServiceInstance.postProcessAAIDEL. " + ex.getMessage()
330 utils.log("INFO", msg, isDebugEnabled)
331 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
333 utils.log("INFO"," *** Exit postProcessAAIPUT *** ", isDebugEnabled)
336 public void processRollbackException(DelegateExecution execution){
337 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
338 utils.log("DEBUG"," ***** processRollbackException ***** ", isDebugEnabled)
340 utils.log("DEBUG", "Caught an Exception in DoUpdateE2EServiceInstanceRollback", isDebugEnabled)
341 execution.setVariable("rollbackData", null)
342 execution.setVariable("rollbackError", "Caught exception in ServiceInstance Update Rollback")
343 execution.setVariable("WorkflowException", null)
346 utils.log("DEBUG", "BPMN Error during processRollbackExceptions Method: ", isDebugEnabled)
348 utils.log("DEBUG", "Caught Exception during processRollbackExceptions Method: " + e.getMessage(), isDebugEnabled)
351 utils.log("DEBUG", " Exit processRollbackException", isDebugEnabled)
354 public void processRollbackJavaException(DelegateExecution execution){
355 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
356 utils.log("DEBUG"," ***** processRollbackJavaException ***** ", isDebugEnabled)
358 execution.setVariable("rollbackData", null)
359 execution.setVariable("rollbackError", "Caught Java exception in ServiceInstance Update Rollback")
360 utils.log("DEBUG", "Caught Exception in processRollbackJavaException", isDebugEnabled)
363 utils.log("DEBUG", "Caught Exception in processRollbackJavaException " + e.getMessage(), isDebugEnabled)
365 utils.log("DEBUG", "***** Exit processRollbackJavaException *****", isDebugEnabled)