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.appc.flow.controller.dbervices;
25 import org.onap.appc.flow.controller.data.Transaction;
26 import org.onap.appc.flow.controller.utils.EscapeUtils;
27 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
32 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 public class FlowControlDBService {
39 private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlDBService.class);
40 private SvcLogicResource serviceLogic;
41 private static FlowControlDBService dgGeneralDBService = null;
42 public static FlowControlDBService initialise() {
43 if (dgGeneralDBService == null) {
44 dgGeneralDBService = new FlowControlDBService();
46 return dgGeneralDBService;
48 private FlowControlDBService() {
49 if (serviceLogic == null) {
50 serviceLogic = new SqlResource();
54 public void getFlowReferenceData(SvcLogicContext ctx, Map<String, String> inParams, SvcLogicContext localContext) throws SvcLogicException {
56 String fn = "DBService.getflowModelInfo";
57 // log.debug("Testing " + ctx.getAttribute(FlowExecutorConstants.VNF_TYPE) + " and " + ctx.getAttribute(FlowExecutorConstants.ACTION_LEVEL));
58 String whereClause = " where ACTION = $" +FlowControllerConstants.REQUEST_ACTION ;
60 if(ctx.getAttribute(FlowControllerConstants.VNF_TYPE) !=null)
61 whereClause = whereClause.concat(" and VNF_TYPE = $" + FlowControllerConstants.VNF_TYPE);
63 if(ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL) !=null)
64 whereClause = whereClause.concat(" and ACTION_LEVEL = $" + FlowControllerConstants.ACTION_LEVEL);
66 QueryStatus status = null;
67 if (serviceLogic != null && localContext != null) {
68 String key = "select SEQUENCE_TYPE, CATEGORY, GENERATION_NODE, EXECUTION_NODE from " + FlowControllerConstants.DB_MULTISTEP_FLOW_REFERENCE +
70 log.debug(fn + "Query String : " + key);
71 status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
72 if(status.toString().equals("FAILURE"))
73 throw new SvcLogicException("Error - while getting FlowReferenceData ");
76 public String getEndPointByAction(String action) {
77 // TODO Auto-generated method stub
80 public String getDesignTimeFlowModel(SvcLogicContext localContext) throws SvcLogicException {
81 String fn = "DBService.getDesignTimeFlowModel ";
82 QueryStatus status = null;
83 if (serviceLogic != null && localContext != null) {
84 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
85 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
86 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
87 " and vnfc_type = $" + FlowControllerConstants.VNFC_TYPE +
88 " and action = $" + FlowControllerConstants.REQUEST_ACTION +
89 " and file_category = $" + FlowControllerConstants.CATEGORY + " )" ;
92 log.debug(fn + "Query String : " + queryString);
93 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
95 if(status.toString().equals("FAILURE"))
96 throw new SvcLogicException("Error - while getting FlowReferenceData ");
98 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
99 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
101 log.debug(fn + "Query String : " + queryString1);
102 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
103 if(status.toString().equals("FAILURE"))
104 throw new SvcLogicException("Error - while getting FlowReferenceData ");
106 return localContext != null ? localContext.getAttribute("artifact-content") : null;
108 public QueryStatus loadSequenceIntoDB(SvcLogicContext localContext) throws SvcLogicException {
110 QueryStatus status = null;
112 if (localContext != null) {
113 String fn = "DBService.saveArtifacts";
115 localContext.setAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED,
116 EscapeUtils.escapeSql(localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT)));
117 log.debug("ESCAPED sequence for DB : " + localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED));
119 for (Object key : localContext.getAttributeKeySet()) {
120 String parmName = (String) key;
121 String parmValue = localContext.getAttribute(parmName);
122 log.debug(" loadSequenceIntoDB " + parmName + "=" + parmValue);
126 String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS +
127 " set request_id = $" + FlowControllerConstants.REQUEST_ID +
128 " , action = $" + FlowControllerConstants.REQUEST_ACTION +
129 " , action_level = $" + FlowControllerConstants.ACTION_LEVEL +
130 " , vnf_type = $" + FlowControllerConstants.VNF_TYPE +
131 " , category = $" + FlowControllerConstants.CATEGORY +
132 " , artifact_content = $" + FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED +
133 " , updated_date = sysdate() ";
135 log.debug(fn + "Query String : " + queryString);
136 status = serviceLogic.save("SQL", false, false, queryString, null, null, localContext);
137 if(status.toString().equals("FAILURE"))
138 throw new SvcLogicException("Error While processing storing Artifact: " +localContext.getAttribute(FlowControllerConstants.ARTIFACT_NAME));
143 public void populateModuleAndRPC(Transaction transaction, String vnf_type) throws SvcLogicException {
144 String fn = "FlowControlDBService.populateModuleAndRPC ";
145 QueryStatus status = null;
146 SvcLogicContext context = new SvcLogicContext();
148 String key = "select execution_type, execution_module, execution_rpc from " + FlowControllerConstants.DB_PROCESS_FLOW_REFERENCE +
149 " where action = '" + transaction.getAction() + "'" +
150 " and action_level = '" + transaction.getActionLevel() + "'" +
151 " and protocol in ( select protocol from " + FlowControllerConstants.DB_PROTOCOL_REFERENCE +
152 " where action = '" + transaction.getAction() + "'" ;
153 if(vnf_type !=null && !vnf_type.isEmpty())
154 key = key + " and vnf_type ='" + vnf_type + "' )" ;
157 log.debug(fn + "Query String : " + key);
158 status = serviceLogic.query("SQL", false, null, key, null, null, context);
159 if(status.toString().equals("FAILURE"))
160 throw new SvcLogicException("Error - while getting FlowReferenceData ");
162 transaction.setExecutionModule(context.getAttribute(FlowControllerConstants.EXECUTTION_MODULE));
163 transaction.setExecutionRPC(context.getAttribute(FlowControllerConstants.EXECUTION_RPC));
164 transaction.setExecutionType(context.getAttribute(FlowControllerConstants.EXECUTION_TYPE));
168 public String getDependencyInfo(SvcLogicContext localContext) throws SvcLogicException {
169 String fn = "DBService.getDependencyInfo ";
170 QueryStatus status = null;
171 if (serviceLogic != null && localContext != null) {
172 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
173 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
174 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
175 " and file_category = '" + FlowControllerConstants.DEPENDENCYMODEL +"' )" ;
177 log.debug(fn + "Query String : " + queryString);
178 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
180 if(status.toString().equals("FAILURE"))
181 throw new SvcLogicException("Error - while getting dependencydata ");
183 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
184 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
186 log.debug(fn + "Query String : " + queryString1);
187 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
188 if(status.toString().equals("FAILURE"))
189 throw new SvcLogicException("Error - while getting dependencyData ");
192 return localContext != null ? localContext.getAttribute("artifact-content") : null;
196 public String getCapabilitiesData(SvcLogicContext localContext) throws SvcLogicException {
197 String fn = "DBService.getCapabilitiesData ";
198 QueryStatus status = null;
199 if (serviceLogic != null && localContext != null) {
200 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
201 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
202 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
203 " and file_category = '" + FlowControllerConstants.CAPABILITY +"' )" ;
205 log.info(fn + "Query String : " + queryString);
206 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
208 if(status.toString().equals("FAILURE"))
209 throw new SvcLogicException("Error - while getting capabilitiesData ");
211 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
212 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
214 log.debug(fn + "Query String : " + queryString1);
215 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
216 if(status.toString().equals("FAILURE"))
217 throw new SvcLogicException("Error - while getting capabilitiesData ");
219 return localContext != null ? localContext.getAttribute("artifact-content") : null;