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 org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
24 import static org.apache.commons.lang3.StringUtils.*;
27 import org.apache.commons.lang3.*
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.runtime.Execution
30 import org.json.JSONObject;
31 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
33 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
34 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
35 import org.openecomp.mso.bpmn.core.json.JsonUtils
37 import com.att.ecomp.mso.bpmn.core.domain.*
42 * This groovy class supports the <class>DecomposeService.bpmn</class> process.
47 * @param - msoRequestId
48 * @param - isDebugLogEnabled
49 * @param - serviceInstanceId
50 * @param - serviceModelInfo
51 * @param - requestParameters (may be null)
54 * @param - rollbackData (null)
55 * @param - rolledBack (null)
56 * @param - WorkflowException
57 * @param - serviceDecomposition
60 public class DecomposeService extends AbstractServiceTaskProcessor {
63 ExceptionUtil exceptionUtil = new ExceptionUtil()
64 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
65 JsonUtils jsonUtils = new JsonUtils()
67 public void preProcessRequest (Execution execution) {
68 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
70 utils.log("DEBUG"," ***** preProcessRequest of DecomposeService *****", isDebugEnabled)
71 setBasicDBAuthHeader(execution, isDebugEnabled)
74 execution.setVariable("prefix", Prefix)
75 // check for required input
76 String requestId = execution.getVariable("msoRequestId")
77 String serviceInstanceId = execution.getVariable("serviceInstanceId")
78 String serviceModelInfo = execution.getVariable("serviceModelInfo")
79 execution.setVariable("DDS_serviceModelInvariantId", jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantUuid"))
80 execution.setVariable("DDS_serviceModelUuid", jsonUtils.getJsonValue(serviceModelInfo, "modelUuid"))
81 execution.setVariable("DDS_modelVersion", jsonUtils.getJsonValue(serviceModelInfo, "modelVersion"))
82 } catch (BpmnError e) {
84 } catch (Exception ex){
85 msg = "Exception in preProcessRequest " + ex.getMessage()
86 utils.log("DEBUG", msg, isDebugEnabled)
87 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
89 utils.log("DEBUG"," ***** Exit preProcessRequest of DecomposeService *****", isDebugEnabled)
92 public void queryCatalogDb (Execution execution) {
93 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
95 utils.log("DEBUG"," ***** queryCatalogDB of DecomposeService *****", isDebugEnabled)
100 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
101 String serviceModelUuid = execution.getVariable("DDS_serviceModelUuid")
102 String modelVersion = execution.getVariable("DDS_modelVersion")
104 utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
105 utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled)
107 JSONObject catalogDbResponse = null
108 if(serviceModelUuid != null && serviceModelUuid.length() > 0)
109 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelUuid(execution, serviceModelUuid, "v2")
110 else if (modelVersion != null && modelVersion.length() > 0)
111 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2")
113 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuid(execution, serviceModelInvariantId, "v2")
114 String catalogDbResponseString = catalogDbResponse.toString()
116 execution.setVariable("DDS_catalogDbResponse", catalogDbResponseString)
117 utils.log("DEBUG", "catalog DB response string: "+ catalogDbResponseString, isDebugEnabled)
119 } catch (BpmnError e) {
121 } catch (Exception ex){
122 msg = "Exception in queryCatalogDb " + ex.getMessage()
123 utils.log("DEBUG", msg, isDebugEnabled)
124 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
126 utils.log("DEBUG"," ***** Exit queryCatalogDb of DecomposeService *****", isDebugEnabled)
131 public void actuallyDecomposeService (Execution execution) {
132 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
134 utils.log("DEBUG"," ***** actuallyDecomposeService of DecomposeService *****", isDebugEnabled)
139 String requestId = execution.getVariable("msoRequestId")
140 String serviceInstanceId = execution.getVariable("serviceInstanceId")
141 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
143 utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled)
145 utils.log("DEBUG", "getting service decomposition", isDebugEnabled)
147 String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse")
148 ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.jsonToServiceDecomposition(catalogDbResponse, serviceInstanceId)
150 execution.setVariable("serviceDecomposition", serviceDecomposition)
151 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
153 utils.log("DEBUG", "service decomposition: "+ serviceDecomposition.toJsonString(), isDebugEnabled)
155 } catch (BpmnError e) {
157 } catch (Exception ex){
158 msg = "Exception in actuallyDecomposeService " + ex.getMessage()
159 utils.log("DEBUG", msg, isDebugEnabled)
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
162 utils.log("DEBUG"," ***** Exit actuallyDecomposeService of DecomposeService *****", isDebugEnabled)