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=========================================================
21 package org.onap.so.bpmn.common.scripts
23 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.delegate.DelegateExecution
28 import org.json.JSONObject;
29 import org.onap.so.bpmn.core.domain.ServiceDecomposition
30 import org.onap.so.bpmn.core.json.DecomposeJsonUtil;
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.onap.so.logger.MsoLogger
35 * This groovy class supports the <class>DecomposeService.bpmn</class> process.
40 * @param - msoRequestId
41 * @param - isDebugLogEnabled
42 * @param - serviceInstanceId
43 * @param - serviceModelInfo
44 * @param - requestParameters (may be null)
47 * @param - rollbackData (null)
48 * @param - rolledBack (null)
49 * @param - WorkflowException
50 * @param - serviceDecomposition
53 public class DecomposeService extends AbstractServiceTaskProcessor {
54 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DecomposeService.class);
58 ExceptionUtil exceptionUtil = new ExceptionUtil()
59 CatalogDbUtils catalogDbUtils = new CatalogDbUtils()
60 JsonUtils jsonUtils = new JsonUtils()
62 public void preProcessRequest (DelegateExecution execution) {
64 msoLogger.trace("preProcessRequest of DecomposeService ")
65 setBasicDBAuthHeader(execution, execution.getVariable('isDebugLogEnabled'))
68 execution.setVariable("prefix", Prefix)
69 // check for required input
70 String requestId = execution.getVariable("msoRequestId")
71 String serviceInstanceId = execution.getVariable("serviceInstanceId")
72 String serviceModelInfo = execution.getVariable("serviceModelInfo")
74 if(jsonUtils.jsonElementExist(serviceModelInfo, "modelInvariantUuid")){
75 invariantId = jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantUuid")
76 }else if(jsonUtils.jsonElementExist(serviceModelInfo, "modelInvariantId")){
77 invariantId = jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantId")
79 execution.setVariable("DDS_serviceModelInvariantId", invariantId)
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()
87 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
89 msoLogger.trace("Exit preProcessRequest of DecomposeService ")
92 public void queryCatalogDb (DelegateExecution execution) {
94 msoLogger.trace("queryCatalogDB of DecomposeService ")
99 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
100 String serviceModelUuid = execution.getVariable("DDS_serviceModelUuid")
101 String modelVersion = execution.getVariable("DDS_modelVersion")
103 msoLogger.debug("serviceModelInvariantId: " + serviceModelInvariantId)
104 msoLogger.debug("modelVersion: " + modelVersion)
106 JSONObject catalogDbResponse = null
107 if(serviceModelUuid != null && serviceModelUuid.length() > 0)
108 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelUuid(execution, serviceModelUuid, "v2")
109 else if (modelVersion != null && modelVersion.length() > 0)
110 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2")
112 catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuid(execution, serviceModelInvariantId, "v2")
114 if (catalogDbResponse == null || catalogDbResponse.toString().equalsIgnoreCase("null")) {
115 msg = "No data found in Catalog DB"
117 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
120 String catalogDbResponseString = catalogDbResponse.toString()
122 execution.setVariable("DDS_catalogDbResponse", catalogDbResponseString)
123 msoLogger.debug("catalog DB response string: "+ catalogDbResponseString)
125 } catch (BpmnError e) {
127 } catch (Exception ex){
128 msg = "Exception in queryCatalogDb " + ex.getMessage()
130 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
132 msoLogger.trace("Exit queryCatalogDb of DecomposeService ")
137 public void actuallyDecomposeService (DelegateExecution execution) {
139 msoLogger.trace("actuallyDecomposeService of DecomposeService ")
144 String requestId = execution.getVariable("msoRequestId")
145 String serviceInstanceId = execution.getVariable("serviceInstanceId")
146 String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId")
148 msoLogger.debug("serviceModelInvariantId: " + serviceModelInvariantId)
150 msoLogger.debug("getting service decomposition")
152 String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse")
153 ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.jsonToServiceDecomposition(catalogDbResponse, serviceInstanceId)
155 execution.setVariable("serviceDecomposition", serviceDecomposition)
156 execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString())
158 msoLogger.debug("service decomposition: "+ serviceDecomposition.toJsonString())
160 } catch (BpmnError e) {
162 } catch (Exception ex){
163 msg = "Exception in actuallyDecomposeService " + ex.getMessage()
165 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
167 msoLogger.trace("Exit actuallyDecomposeService of DecomposeService ")