Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateServiceInstanceRollbackV2.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.camunda.bpm.engine.runtime.Execution
26 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.onap.so.bpmn.core.domain.ServiceDecomposition
28 import org.onap.so.client.orchestration.AAIServiceInstanceResources
29 import org.onap.so.logger.MsoLogger
30
31
32 public class DoCreateServiceInstanceRollbackV2 extends AbstractServiceTaskProcessor{
33         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstanceRollbackV2.class);
34         
35         @Override
36         public void preProcessRequest(DelegateExecution execution) {
37                 
38         }
39         
40         public void aaiServiceInstanceRollback (DelegateExecution execution) {
41                 def aaiServiceInstanceRollback = execution.getVariable("aaiServiceInstanceRollback")
42                 if(aaiServiceInstanceRollback){
43                         msoLogger.trace("Started aaiServiceInstanceRollback")
44                         try{
45                                 ServiceDecomposition serviceDecomp = execution.getVariable("ServiceDecomposition")
46                                 AAIServiceInstanceResources aaiO = new AAIServiceInstanceResources()
47                                 aaiO.deleteServiceInstance(serviceDecomp)
48                         }catch (Exception ex) {
49                                 String msg =  "Error Response from AAI for aaiServiceInstanceRollback"
50                                 execution.setVariable("rollbackError", msg)
51                                 msoLogger.debug(msg)
52                                 throw new BpmnError("MSOWorkflowException")
53                         }
54                         msoLogger.trace("Completed aaiServiceInstanceRollback")
55                 }else{
56                         msoLogger.trace("SKIPPING A&AI ROLLBACK")
57                 }
58         }
59         
60         public void rollbackError (DelegateExecution execution) {
61                 msoLogger.trace("rollbackError")
62                 try{
63                         msoLogger.debug("Caught an Exception in DoCreateServiceInstanceRollbackV2")
64                 }catch(BpmnError b){
65                         msoLogger.debug("BPMN Error during rollbackError: " + b.getMessage())
66                 }catch(Exception e){
67                         msoLogger.debug("Caught Exception during rollbackError: " + e.getMessage())
68                 }
69                 msoLogger.debug(" Exit processRollbackException")
70         }
71         
72 }