1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
24 package org.onap.dmaap.datarouter.provisioning.beans;
\r
26 import java.sql.Connection;
\r
27 import java.sql.PreparedStatement;
\r
28 import java.sql.ResultSet;
\r
29 import java.sql.SQLException;
\r
30 import java.sql.Statement;
\r
33 import com.att.eelf.configuration.EELFLogger;
\r
34 import com.att.eelf.configuration.EELFManager;
\r
35 import org.json.JSONObject;
\r
36 import org.onap.dmaap.datarouter.provisioning.utils.DB;
\r
39 * Methods to provide access to Provisioning parameters in the DB. This class also provides constants of the standard
\r
40 * parameters used by the Data Router.
\r
42 * @author Robert Eby
\r
43 * @version $Id: Parameters.java,v 1.11 2014/03/12 19:45:41 eby Exp $
\r
45 public class Parameters extends Syncable {
\r
47 public static final String PROV_REQUIRE_SECURE = "PROV_REQUIRE_SECURE";
\r
48 public static final String PROV_REQUIRE_CERT = "PROV_REQUIRE_CERT";
\r
49 public static final String PROV_AUTH_ADDRESSES = "PROV_AUTH_ADDRESSES";
\r
50 public static final String PROV_AUTH_SUBJECTS = "PROV_AUTH_SUBJECTS";
\r
51 public static final String PROV_NAME = "PROV_NAME";
\r
52 public static final String PROV_ACTIVE_NAME = "PROV_ACTIVE_NAME";
\r
53 public static final String PROV_DOMAIN = "PROV_DOMAIN";
\r
54 public static final String PROV_MAXFEED_COUNT = "PROV_MAXFEED_COUNT";
\r
55 public static final String PROV_MAXSUB_COUNT = "PROV_MAXSUB_COUNT";
\r
56 public static final String PROV_POKETIMER1 = "PROV_POKETIMER1";
\r
57 public static final String PROV_POKETIMER2 = "PROV_POKETIMER2";
\r
58 public static final String PROV_SPECIAL_SUBNET = "PROV_SPECIAL_SUBNET";
\r
59 public static final String PROV_LOG_RETENTION = "PROV_LOG_RETENTION";
\r
60 public static final String NODES = "NODES";
\r
61 public static final String ACTIVE_POD = "ACTIVE_POD";
\r
62 public static final String STANDBY_POD = "STANDBY_POD";
\r
63 public static final String LOGROLL_INTERVAL = "LOGROLL_INTERVAL";
\r
64 public static final String DELIVERY_INIT_RETRY_INTERVAL = "DELIVERY_INIT_RETRY_INTERVAL";
\r
65 public static final String DELIVERY_MAX_RETRY_INTERVAL = "DELIVERY_MAX_RETRY_INTERVAL";
\r
66 public static final String DELIVERY_RETRY_RATIO = "DELIVERY_RETRY_RATIO";
\r
67 public static final String DELIVERY_MAX_AGE = "DELIVERY_MAX_AGE";
\r
68 public static final String THROTTLE_FILTER = "THROTTLE_FILTER";
\r
69 public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610
\r
71 private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
\r
72 private static final String SQLEXCEPTION = "SQLException: ";
\r
74 private String keyname;
\r
75 private String value;
\r
78 * Get all parameters in the DB as a Map.
\r
80 * @return the Map of keynames/values from the DB.
\r
82 public static Map<String, String> getParameters() {
\r
83 Map<String, String> props = new HashMap<String, String>();
\r
84 for (Parameters p : getParameterCollection()) {
\r
85 props.put(p.getKeyname(), p.getValue());
\r
90 public static Collection<Parameters> getParameterCollection() {
\r
91 Collection<Parameters> coll = new ArrayList<Parameters>();
\r
94 @SuppressWarnings("resource")
\r
95 Connection conn = db.getConnection();
\r
96 try (Statement stmt = conn.createStatement()) {
\r
97 String sql = "select * from PARAMETERS";
\r
98 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
100 Parameters p = new Parameters(rs);
\r
106 } catch (SQLException e) {
\r
107 intlogger.error(SQLEXCEPTION + e.getMessage());
\r
113 * Get a specific parameter value from the DB.
\r
115 * @param k the key to lookup
\r
116 * @return the value, or null if non-existant
\r
118 public static Parameters getParameter(String k) {
\r
119 Parameters v = null;
\r
122 @SuppressWarnings("resource")
\r
123 Connection conn = db.getConnection();
\r
124 try (PreparedStatement stmt = conn
\r
125 .prepareStatement("select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?")) {
\r
126 stmt.setString(1, k);
\r
127 try (ResultSet rs = stmt.executeQuery()) {
\r
129 v = new Parameters(rs);
\r
134 } catch (SQLException e) {
\r
135 intlogger.error(SQLEXCEPTION + e.getMessage());
\r
140 public Parameters() {
\r
144 public Parameters(String k, String v) {
\r
149 public Parameters(ResultSet rs) throws SQLException {
\r
150 this.keyname = rs.getString("KEYNAME");
\r
151 this.value = rs.getString("VALUE");
\r
154 public String getKeyname() {
\r
158 public void setKeyname(String keyname) {
\r
159 this.keyname = keyname;
\r
162 public String getValue() {
\r
166 public void setValue(String value) {
\r
167 this.value = value;
\r
171 public JSONObject asJSONObject() {
\r
172 JSONObject jo = new JSONObject();
\r
173 jo.put("keyname", keyname);
\r
174 jo.put("value", value);
\r
179 public boolean doInsert(Connection c) {
\r
181 PreparedStatement ps = null;
\r
183 // Create the SUBSCRIPTIONS row
\r
184 String sql = "insert into PARAMETERS values (?, ?)";
\r
185 ps = c.prepareStatement(sql);
\r
186 ps.setString(1, getKeyname());
\r
187 ps.setString(2, getValue());
\r
189 } catch (SQLException e) {
\r
191 intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
\r
197 } catch (SQLException e) {
\r
198 intlogger.error(SQLEXCEPTION + e.getMessage());
\r
205 public boolean doUpdate(Connection c) {
\r
207 PreparedStatement ps = null;
\r
209 // Update the PARAMETERS row
\r
210 String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?";
\r
211 ps = c.prepareStatement(sql);
\r
212 ps.setString(1, getValue());
\r
213 ps.setString(2, getKeyname());
\r
214 ps.executeUpdate();
\r
215 } catch (SQLException e) {
\r
217 intlogger.warn("PROV0006 doUpdate: " + e.getMessage(),e);
\r
223 } catch (SQLException e) {
\r
224 intlogger.error(SQLEXCEPTION + e.getMessage(), e);
\r
231 public boolean doDelete(Connection c) {
\r
233 PreparedStatement ps = null;
\r
235 // Create the SUBSCRIPTIONS row
\r
236 String sql = "delete from PARAMETERS where KEYNAME = ?";
\r
237 ps = c.prepareStatement(sql);
\r
238 ps.setString(1, getKeyname());
\r
240 } catch (SQLException e) {
\r
242 intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
\r
248 } catch (SQLException e) {
\r
249 intlogger.error(SQLEXCEPTION + e.getMessage(), e);
\r
256 public String getKey() {
\r
257 return getKeyname();
\r
261 public boolean equals(Object obj) {
\r
262 if (!(obj instanceof Parameters)) {
\r
265 Parameters of = (Parameters) obj;
\r
266 if (!keyname.equals(of.keyname)) {
\r
269 if (!value.equals(of.value)) {
\r
276 public int hashCode() {
\r
277 return Objects.hash(keyname, value);
\r
281 public String toString() {
\r
282 return "PARAM: keyname=" + keyname + ", value=" + value;
\r