1710 Rebase - Second Attempt
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / DecomposeService.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 package org.openecomp.mso.bpmn.common.scripts;
21
22 import static org.apache.commons.lang3.StringUtils.*;
23
24
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.runtime.Execution
28 import org.json.JSONObject;
29 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
32 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
33 import org.openecomp.mso.bpmn.core.json.JsonUtils
34
35 import com.att.ecomp.mso.bpmn.core.domain.*
36
37 import groovy.json.*
38
39 /**
40  * This groovy class supports the <class>DecomposeService.bpmn</class> process.
41  *
42  * @author
43  *
44  * Inputs:
45  * @param - msoRequestId
46  * @param - isDebugLogEnabled
47  * @param - serviceInstanceId
48  * @param - serviceModelInfo
49  * @param - requestParameters (may be null)
50  *
51  * Outputs:
52  * @param - rollbackData (null)
53  * @param - rolledBack (null)
54  * @param - WorkflowException
55  * @param - serviceDecomposition
56  *
57  */
58 public class DecomposeService extends AbstractServiceTaskProcessor {
59
60         String Prefix="DDS_"
61         ExceptionUtil exceptionUtil = new ExceptionUtil()
62         CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
63         JsonUtils jsonUtils = new JsonUtils()
64
65         public void preProcessRequest (Execution execution) {
66                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
67                 String msg = ""
68                 utils.log("DEBUG"," ***** preProcessRequest of DecomposeService *****",  isDebugEnabled)
69                 setBasicDBAuthHeader(execution, isDebugEnabled)
70
71                 try {
72                         execution.setVariable("prefix", Prefix)
73                         // check for required input
74                         String requestId = execution.getVariable("msoRequestId")
75                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
76                         String serviceModelInfo = execution.getVariable("serviceModelInfo")
77                         execution.setVariable("DDS_serviceModelInvariantId", jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantUuid"))
78                         execution.setVariable("DDS_modelVersion", jsonUtils.getJsonValue(serviceModelInfo, "modelVersion"))
79                 } catch (BpmnError e) {
80                         throw e;
81                 } catch (Exception ex){
82                         msg = "Exception in preProcessRequest " + ex.getMessage()
83                         utils.log("DEBUG", msg, isDebugEnabled)
84                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
85                 }
86                 utils.log("DEBUG"," ***** Exit preProcessRequest of DecomposeService *****",  isDebugEnabled)
87         }
88
89         public void queryCatalogDb (Execution execution) {
90                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
91                 String msg = ""
92                 utils.log("DEBUG"," ***** queryCatalogDB of DecomposeService *****",  isDebugEnabled)
93
94                 try {
95
96                         // check for input
97                         String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
98                         String modelVersion = execution.getVariable("DDS_modelVersion")
99                         
100                         utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
101                         utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled)                     
102                         
103                         JSONObject catalogDbResponse = null
104                         
105                         if (modelVersion != null && modelVersion.length() > 0)
106                                 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2")
107                         else
108                                 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuid(execution, serviceModelInvariantId, "v2")
109                         String catalogDbResponseString = catalogDbResponse.toString()
110
111                         execution.setVariable("DDS_catalogDbResponse", catalogDbResponseString)
112                         utils.log("DEBUG", "catalog DB response string: "+ catalogDbResponseString, isDebugEnabled)
113
114                 } catch (BpmnError e) {
115                         throw e;
116                 } catch (Exception ex){
117                         msg = "Exception in queryCatalogDb " + ex.getMessage()
118                         utils.log("DEBUG", msg, isDebugEnabled)
119                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120                 }
121                 utils.log("DEBUG"," ***** Exit queryCatalogDb of DecomposeService *****",  isDebugEnabled)
122         }
123
124
125
126         public void actuallyDecomposeService (Execution execution) {
127                 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
128                 String msg = ""
129                 utils.log("DEBUG"," ***** actuallyDecomposeService of DecomposeService *****",  isDebugEnabled)
130
131                 try {
132
133                         // check for input
134                         String requestId = execution.getVariable("msoRequestId")
135                         String serviceInstanceId = execution.getVariable("serviceInstanceId")
136                         String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
137
138                         utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
139
140                         utils.log("DEBUG", "getting service decomposition", isDebugEnabled)
141
142                         String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse")
143                         ServiceDecomposition serviceDecomposition = new ServiceDecomposition(catalogDbResponse, serviceInstanceId)
144
145                         execution.setVariable("serviceDecomposition", serviceDecomposition)
146                         execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
147
148                         utils.log("DEBUG", "service decomposition: "+ serviceDecomposition.toJsonString(), isDebugEnabled)
149
150                 } catch (BpmnError e) {
151                         throw e;
152                 } catch (Exception ex){
153                         msg = "Exception in actuallyDecomposeService " + ex.getMessage()
154                         utils.log("DEBUG", msg, isDebugEnabled)
155                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
156                 }
157                 utils.log("DEBUG"," ***** Exit actuallyDecomposeService of DecomposeService *****",  isDebugEnabled)
158         }
159
160 }