X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FParameters.java;h=e89cfd4757bfbdc17714b448fcc0400bcb55aad4;hp=b2378218b26f47dcfc18de00b7907d1af28cbf63;hb=bc1df610cddfb558cf6bde90c269b4af59768648;hpb=1298e6487340fcb1644c4a0a7e06026d156bdf8f diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java index b2378218..e89cfd47 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java @@ -23,25 +23,31 @@ package org.onap.dmaap.datarouter.provisioning.beans; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.*; - -import org.apache.log4j.Logger; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; /** - * Methods to provide access to Provisioning parameters in the DB. - * This class also provides constants of the standard parameters used by the Data Router. + * Methods to provide access to Provisioning parameters in the DB. This class also provides constants of the standard + * parameters used by the Data Router. * * @author Robert Eby * @version $Id: Parameters.java,v 1.11 2014/03/12 19:45:41 eby Exp $ */ + public class Parameters extends Syncable { + public static final String PROV_REQUIRE_SECURE = "PROV_REQUIRE_SECURE"; public static final String PROV_REQUIRE_CERT = "PROV_REQUIRE_CERT"; public static final String PROV_AUTH_ADDRESSES = "PROV_AUTH_ADDRESSES"; @@ -55,6 +61,7 @@ public class Parameters extends Syncable { public static final String PROV_POKETIMER2 = "PROV_POKETIMER2"; public static final String PROV_SPECIAL_SUBNET = "PROV_SPECIAL_SUBNET"; public static final String PROV_LOG_RETENTION = "PROV_LOG_RETENTION"; + public static final String DEFAULT_LOG_RETENTION = "DEFAULT_LOG_RETENTION"; public static final String NODES = "NODES"; public static final String ACTIVE_POD = "ACTIVE_POD"; public static final String STANDBY_POD = "STANDBY_POD"; @@ -64,44 +71,56 @@ public class Parameters extends Syncable { public static final String DELIVERY_RETRY_RATIO = "DELIVERY_RETRY_RATIO"; public static final String DELIVERY_MAX_AGE = "DELIVERY_MAX_AGE"; public static final String THROTTLE_FILTER = "THROTTLE_FILTER"; - public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610 + public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); + private static final String SQLEXCEPTION = "SQLException: "; private String keyname; private String value; + public Parameters(String key, String val) { + this.keyname = key; + this.value = val; + } + + public Parameters(ResultSet rs) throws SQLException { + this.keyname = rs.getString("KEYNAME"); + this.value = rs.getString("VALUE"); + } + /** * Get all parameters in the DB as a Map. * * @return the Map of keynames/values from the DB. */ public static Map getParameters() { - Map props = new HashMap(); + Map props = new HashMap<>(); for (Parameters p : getParameterCollection()) { props.put(p.getKeyname(), p.getValue()); } return props; } + /** + * Method to get parameters. + * @return collection of parameters + */ public static Collection getParameterCollection() { - Collection coll = new ArrayList(); - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - String sql = "select * from PARAMETERS"; - try(ResultSet rs = stmt.executeQuery(sql)) { - while (rs.next()) { - Parameters p = new Parameters(rs); - coll.add(p); - } + Collection coll = new ArrayList<>(); + DB db = new DB(); + String sql = "select * from PARAMETERS"; + try (Connection conn = db.getConnection(); + Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery(sql)) { + while (rs.next()) { + Parameters param = new Parameters(rs); + coll.add(param); } } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } return coll; } @@ -109,52 +128,32 @@ public class Parameters extends Syncable { /** * Get a specific parameter value from the DB. * - * @param k the key to lookup + * @param key the key to lookup * @return the value, or null if non-existant */ - public static Parameters getParameter(String k) { - Parameters v = null; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try(PreparedStatement stmt = conn.prepareStatement("select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?")) { - stmt.setString(1, k); - try(ResultSet rs = stmt.executeQuery()) { - if (rs.next()) { - v = new Parameters(rs); - } + public static Parameters getParameter(String key) { + Parameters val = null; + DB db = new DB(); + String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?"; + try (Connection conn = db.getConnection(); + PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, key); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + val = new Parameters(rs); } } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } - return v; - } - - public Parameters() { - this("", ""); - } - - public Parameters(String k, String v) { - this.keyname = k; - this.value = v; - } - - public Parameters(ResultSet rs) throws SQLException { - this.keyname = rs.getString("KEYNAME"); - this.value = rs.getString("VALUE"); + return val; } public String getKeyname() { return keyname; } - public void setKeyname(String keyname) { - this.keyname = keyname; - } - public String getValue() { return value; } @@ -172,81 +171,45 @@ public class Parameters extends Syncable { } @Override - public boolean doInsert(Connection c) { + public boolean doInsert(Connection conn) { boolean rv = true; - PreparedStatement ps = null; - try { - // Create the SUBSCRIPTIONS row - String sql = "insert into PARAMETERS values (?, ?)"; - ps = c.prepareStatement(sql); + String sql = "insert into PARAMETERS values (?, ?)"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, getKeyname()); ps.setString(2, getValue()); ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - if(ps!=null) { - ps.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e); } return rv; } @Override - public boolean doUpdate(Connection c) { + public boolean doUpdate(Connection conn) { boolean rv = true; - PreparedStatement ps = null; - try { - // Update the PARAMETERS row - String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?"; - ps = c.prepareStatement(sql); + String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, getValue()); ps.setString(2, getKeyname()); ps.executeUpdate(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - if(ps!=null) { - ps.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(),e); } return rv; } @Override - public boolean doDelete(Connection c) { + public boolean doDelete(Connection conn) { boolean rv = true; - PreparedStatement ps = null; - try { - // Create the SUBSCRIPTIONS row - String sql = "delete from PARAMETERS where KEYNAME = ?"; - ps = c.prepareStatement(sql); + String sql = "delete from PARAMETERS where KEYNAME = ?"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, getKeyname()); ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - if(ps!=null) { - ps.close(); - } - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e); } return rv; } @@ -258,14 +221,11 @@ public class Parameters extends Syncable { @Override public boolean equals(Object obj) { - if (!(obj instanceof Parameters)) + if (!(obj instanceof Parameters)) { return false; + } Parameters of = (Parameters) obj; - if (!keyname.equals(of.keyname)) - return false; - if (!value.equals(of.value)) - return false; - return true; + return (!value.equals(of.value)) && (!keyname.equals(of.keyname)); } @Override