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.openecomp.appc.flow.controller.dbervices;
23 import java.util.HashMap;
26 import org.openecomp.appc.flow.controller.data.Transaction;
27 import org.openecomp.appc.flow.controller.utils.EscapeUtils;
28 import org.openecomp.appc.flow.controller.utils.FlowControllerConstants;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
33 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
38 public class FlowControlDBService {
40 private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlDBService.class);
41 private SvcLogicResource serviceLogic;
42 private static FlowControlDBService dgGeneralDBService = null;
43 public static FlowControlDBService initialise() {
44 if (dgGeneralDBService == null) {
45 dgGeneralDBService = new FlowControlDBService();
47 return dgGeneralDBService;
49 private FlowControlDBService() {
50 if (serviceLogic == null) {
51 serviceLogic = new SqlResource();
55 public void getFlowReferenceData(SvcLogicContext ctx, Map<String, String> inParams, SvcLogicContext localContext) throws SvcLogicException {
57 String fn = "DBService.getflowModelInfo";
58 // log.debug("Testing " + ctx.getAttribute(FlowExecutorConstants.VNF_TYPE) + " and " + ctx.getAttribute(FlowExecutorConstants.ACTION_LEVEL));
59 String whereClause = " where ACTION = $" +FlowControllerConstants.REQUEST_ACTION ;
61 if(ctx.getAttribute(FlowControllerConstants.VNF_TYPE) !=null)
62 whereClause = whereClause.concat(" and VNF_TYPE = $" + FlowControllerConstants.VNF_TYPE);
64 if(ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL) !=null)
65 whereClause = whereClause.concat(" and ACTION_LEVEL = $" + FlowControllerConstants.ACTION_LEVEL);
67 QueryStatus status = null;
68 if (serviceLogic != null && localContext != null) {
69 String key = "select SEQUENCE_TYPE, CATEGORY, GENERATION_NODE, EXECUTION_NODE from " + FlowControllerConstants.DB_MULTISTEP_FLOW_REFERENCE +
71 log.debug(fn + "Query String : " + key);
72 status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
73 if(status.toString().equals("FAILURE"))
74 throw new SvcLogicException("Error - while getting FlowReferenceData ");
77 public String getEndPointByAction(String action) {
78 // TODO Auto-generated method stub
81 public String getDesignTimeFlowModel(SvcLogicContext localContext) throws SvcLogicException {
82 String fn = "DBService.getDesignTimeFlowModel ";
83 QueryStatus status = null;
84 if (serviceLogic != null && localContext != null) {
85 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
86 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
87 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
88 " and vnfc_type = $" + FlowControllerConstants.VNFC_TYPE +
89 " and action = $" + FlowControllerConstants.REQUEST_ACTION +
90 " and file_category = $" + FlowControllerConstants.CATEGORY + " )" ;
93 log.debug(fn + "Query String : " + queryString);
94 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
96 if(status.toString().equals("FAILURE"))
97 throw new SvcLogicException("Error - while getting FlowReferenceData ");
99 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
100 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
102 log.debug(fn + "Query String : " + queryString1);
103 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
104 if(status.toString().equals("FAILURE"))
105 throw new SvcLogicException("Error - while getting FlowReferenceData ");
108 return localContext.getAttribute("artifact-content");
110 public QueryStatus loadSequenceIntoDB(SvcLogicContext localContext) throws SvcLogicException {
111 String fn = "DBService.saveArtifacts";
112 localContext.setAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED, EscapeUtils.escapeSql(localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT)));
113 log.debug("ESCAPED sequence for DB : " + localContext.getAttribute(FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED));
115 for (Object key : localContext.getAttributeKeySet()) {
116 String parmName = (String) key;
117 String parmValue = localContext.getAttribute(parmName);
118 log.debug(" loadSequenceIntoDB " + parmName + "=" + parmValue);
123 QueryStatus status = null;
124 if (serviceLogic != null && localContext != null) {
125 String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS +
126 " set request_id = $" + FlowControllerConstants.REQUEST_ID +
127 " , action = $" + FlowControllerConstants.REQUEST_ACTION +
128 " , action_level = $" + FlowControllerConstants.ACTION_LEVEL +
129 " , vnf_type = $" + FlowControllerConstants.VNF_TYPE +
130 " , category = $" + FlowControllerConstants.CATEGORY +
131 " , artifact_content = $" + FlowControllerConstants.ARTIFACT_CONTENT_ESCAPED +
132 " , updated_date = sysdate() ";
134 status = serviceLogic.save("SQL", false, false, queryString, null, null, localContext);
135 if(status.toString().equals("FAILURE"))
136 throw new SvcLogicException("Error While processing storing Artifact: " +localContext.getAttribute(FlowControllerConstants.ARTIFACT_NAME));
141 public void populateModuleAndRPC(Transaction transaction, String vnf_type) throws SvcLogicException {
142 String fn = "FlowControlDBService.populateModuleAndRPC ";
143 QueryStatus status = null;
144 SvcLogicContext context = new SvcLogicContext();
145 if (serviceLogic != null && context != null) {
146 String key = "select execution_type, execution_module, execution_rpc from " + FlowControllerConstants.DB_PROCESS_FLOW_REFERENCE +
147 " where action = '" + transaction.getAction() + "'" +
148 " and action_level = '" + transaction.getActionLevel() + "'" +
149 " and protocol in ( select protocol from " + FlowControllerConstants.DB_PROTOCOL_REFERENCE +
150 " where action = '" + transaction.getAction() + "'" ;
151 if(vnf_type !=null && !vnf_type.isEmpty())
152 key = key + " and vnf_type ='" + vnf_type + "' )" ;
155 log.debug(fn + "Query String : " + key);
156 status = serviceLogic.query("SQL", false, null, key, null, null, context);
157 if(status.toString().equals("FAILURE"))
158 throw new SvcLogicException("Error - while getting FlowReferenceData ");
160 transaction.setExecutionModule(context.getAttribute(FlowControllerConstants.EXECUTTION_MODULE));
161 transaction.setExecutionRPC(context.getAttribute(FlowControllerConstants.EXECUTION_RPC));
162 transaction.setExecutionType(context.getAttribute(FlowControllerConstants.EXECUTION_TYPE));
167 public String getDependencyInfo(SvcLogicContext localContext) throws SvcLogicException {
168 String fn = "DBService.getDependencyInfo ";
169 QueryStatus status = null;
170 if (serviceLogic != null && localContext != null) {
171 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
172 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
173 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
174 " and file_category = '" + FlowControllerConstants.DEPENDENCYMODEL +"' )" ;
176 log.debug(fn + "Query String : " + queryString);
177 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
179 if(status.toString().equals("FAILURE"))
180 throw new SvcLogicException("Error - while getting dependencydata ");
182 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
183 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
185 log.debug(fn + "Query String : " + queryString1);
186 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
187 if(status.toString().equals("FAILURE"))
188 throw new SvcLogicException("Error - while getting dependencyData ");
191 return localContext.getAttribute("artifact-content");
194 public String getCapabilitiesData(SvcLogicContext localContext) throws SvcLogicException {
195 String fn = "DBService.getCapabilitiesData ";
196 QueryStatus status = null;
197 if (serviceLogic != null && localContext != null) {
198 String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + FlowControllerConstants.DB_SDC_ARTIFACTS
199 + " where artifact_name in (select artifact_name from " + FlowControllerConstants.DB_SDC_REFERENCE +
200 " where vnf_type= $" + FlowControllerConstants.VNF_TYPE +
201 " and file_category = '" + FlowControllerConstants.CAPABILITY +"' )" ;
203 log.info(fn + "Query String : " + queryString);
204 status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext);
206 if(status.toString().equals("FAILURE"))
207 throw new SvcLogicException("Error - while getting capabilitiesData ");
209 String queryString1 = "select artifact_content from " + FlowControllerConstants.DB_SDC_ARTIFACTS +
210 " where artifact_name = $artifactName and internal_version = $maxInternalVersion ";
212 log.debug(fn + "Query String : " + queryString1);
213 status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext);
214 if(status.toString().equals("FAILURE"))
215 throw new SvcLogicException("Error - while getting capabilitiesData ");
218 return localContext.getAttribute("artifact-content");