Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / main / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateServiceInstanceV2.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 static org.apache.commons.lang3.StringUtils.*;
24
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.core.domain.ServiceDecomposition
30 import org.onap.so.client.orchestration.AAIServiceInstanceResources
31 import org.onap.so.client.orchestration.SDNCServiceInstanceResources
32 import org.onap.so.logger.MsoLogger
33 import org.onap.so.logger.MessageEnum
34
35 import groovy.json.*
36
37 /**
38  * This groovy class supports the <class>DoCreateServiceInstanceV2.bpmn</class> process.
39  *
40 */
41
42 public class DoCreateServiceInstanceV2 extends AbstractServiceTaskProcessor {
43         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoCreateServiceInstanceV2.class);
44         AAIServiceInstanceResources aaiO = new AAIServiceInstanceResources()
45         SDNCServiceInstanceResources sdncO = new SDNCServiceInstanceResources()
46         
47         @Override
48         public void preProcessRequest(DelegateExecution execution) {
49         }
50
51         public void createServiceInstance(DelegateExecution execution) { 
52                 execution.setVariable("callSDNC",true)
53                 if(execution.getVariable("serviceType").equalsIgnoreCase("PORT-MIRROR")== false){
54                                 if(execution.getVariable("sdncVersion").equals("1610")){
55                                         execution.setVariable("callSDNC",false);                                
56                                 }
57                 }
58                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
59                 try{
60                         aaiO.createServiceInstance(serviceDecomp)
61                 } catch (BpmnError e) {
62                         throw e
63                 }
64         }
65         
66         public void createProject(DelegateExecution execution) {
67                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
68                 if (serviceDecomp.getServiceInstance() != null && serviceDecomp.getProject() != null) { 
69                         try{
70                                 aaiO.createProjectandConnectServiceInstance(serviceDecomp)
71                         } catch (BpmnError e) {
72                                 throw e
73                         }
74                 }
75         }
76         
77         public void createOwningEntity(DelegateExecution execution) {
78                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
79                 if (serviceDecomp.getServiceInstance() != null && serviceDecomp.getOwningEntity() != null) {
80                         try{
81                                 aaiO.createOwningEntityandConnectServiceInstance(serviceDecomp)
82                         } catch (BpmnError e) {
83                                 throw e
84                         }       
85                 }                       
86         }
87         
88         public void sdncAssignRequest(DelegateExecution execution) {
89                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")
90                 if (serviceDecomp != null) {
91                         try {
92                                 sdncO.sendSyncResponse(serviceDecomp)
93                         } catch (BpmnError e) {
94                                 throw e
95                         }
96                 }
97
98         }
99         
100         public void rollback(DelegateExecution execution) {
101                 //TODO
102         }
103         
104 }