2 * ============LICENSE_START=======================================================
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
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.common.scripts;
22 import static org.apache.commons.lang3.StringUtils.*;
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
35 import com.att.ecomp.mso.bpmn.core.domain.*
40 * This groovy class supports the <class>DecomposeService.bpmn</class> process.
45 * @param - msoRequestId
46 * @param - isDebugLogEnabled
47 * @param - serviceInstanceId
48 * @param - serviceModelInfo
49 * @param - requestParameters (may be null)
52 * @param - rollbackData (null)
53 * @param - rolledBack (null)
54 * @param - WorkflowException
55 * @param - serviceDecomposition
58 public class DecomposeService extends AbstractServiceTaskProcessor {
61 ExceptionUtil exceptionUtil = new ExceptionUtil()
62 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
63 JsonUtils jsonUtils = new JsonUtils()
65 public void preProcessRequest (Execution execution) {
66 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
68 utils.log("DEBUG"," ***** preProcessRequest of DecomposeService *****", isDebugEnabled)
69 setBasicDBAuthHeader(execution, isDebugEnabled)
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) {
81 } catch (Exception ex){
82 msg = "Exception in preProcessRequest " + ex.getMessage()
83 utils.log("DEBUG", msg, isDebugEnabled)
84 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
86 utils.log("DEBUG"," ***** Exit preProcessRequest of DecomposeService *****", isDebugEnabled)
89 public void queryCatalogDb (Execution execution) {
90 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
92 utils.log("DEBUG"," ***** queryCatalogDB of DecomposeService *****", isDebugEnabled)
97 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
98 String modelVersion = execution.getVariable("DDS_modelVersion")
100 utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
101 utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled)
103 JSONObject catalogDbResponse = null
105 if (modelVersion != null && modelVersion.length() > 0)
106 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2")
108 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuid(execution, serviceModelInvariantId, "v2")
109 String catalogDbResponseString = catalogDbResponse.toString()
111 execution.setVariable("DDS_catalogDbResponse", catalogDbResponseString)
112 utils.log("DEBUG", "catalog DB response string: "+ catalogDbResponseString, isDebugEnabled)
114 } catch (BpmnError e) {
116 } catch (Exception ex){
117 msg = "Exception in queryCatalogDb " + ex.getMessage()
118 utils.log("DEBUG", msg, isDebugEnabled)
119 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
121 utils.log("DEBUG"," ***** Exit queryCatalogDb of DecomposeService *****", isDebugEnabled)
126 public void actuallyDecomposeService (Execution execution) {
127 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
129 utils.log("DEBUG"," ***** actuallyDecomposeService of DecomposeService *****", isDebugEnabled)
134 String requestId = execution.getVariable("msoRequestId")
135 String serviceInstanceId = execution.getVariable("serviceInstanceId")
136 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
138 utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
140 utils.log("DEBUG", "getting service decomposition", isDebugEnabled)
142 String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse")
143 ServiceDecomposition serviceDecomposition = new ServiceDecomposition(catalogDbResponse, serviceInstanceId)
145 execution.setVariable("serviceDecomposition", serviceDecomposition)
146 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
148 utils.log("DEBUG", "service decomposition: "+ serviceDecomposition.toJsonString(), isDebugEnabled)
150 } catch (BpmnError e) {
152 } catch (Exception ex){
153 msg = "Exception in actuallyDecomposeService " + ex.getMessage()
154 utils.log("DEBUG", msg, isDebugEnabled)
155 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157 utils.log("DEBUG"," ***** Exit actuallyDecomposeService of DecomposeService *****", isDebugEnabled)