diff options
Diffstat (limited to 'src/main/java/org')
8 files changed, 157 insertions, 137 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java index 01d103d..b1d3871 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java @@ -40,7 +40,6 @@ import javax.net.ssl.SSLHandshakeException; import org.apache.commons.codec.binary.Base64; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; -import org.onap.dmaap.dbcapi.service.DmaapService; import org.onap.dmaap.dbcapi.util.DmaapConfig; @@ -73,11 +72,12 @@ public class AafConnection extends BaseLoggingClass { uc.setInstanceFollowRedirects(false); logger.info( "successful connect to " + pURL ); return(true); - } catch ( UnknownHostException uhe ) { + } catch ( UnknownHostException uhe ) { errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION, pURL, uhe.getMessage() ); - uhe.printStackTrace(); + logger.error("Error", uhe); return(false); } catch (Exception e) { + logger.error("Error", e); errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR, pURL, e.getMessage() ); e.printStackTrace(); return(false); @@ -137,21 +137,26 @@ public class AafConnection extends BaseLoggingClass { os.write( postData ); } catch (ProtocolException pe) { + logger.error("Error", pe); // Rcvd error instead of 100-Continue try { // work around glitch in Java 1.7.0.21 and likely others // without this, Java will connect multiple times to the server to run the same request uc.setDoOutput(false); } catch (Exception e) { + logger.error("Error", e); } } catch ( SSLHandshakeException she ) { + logger.error("Error", she); errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL); } catch ( UnknownHostException uhe ) { + logger.error("Error", uhe); errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION, pURL, uhe.getMessage() ); rc = 500; return rc; } catch ( ConnectException ce ) { - if ( unit_test.equals( "Yes" ) ) { + logger.error("Error", ce); + if ( "Yes".equals(unit_test) ) { rc = 201; return rc; } @@ -162,6 +167,7 @@ public class AafConnection extends BaseLoggingClass { try { rc = uc.getResponseCode(); } catch ( SSLHandshakeException she ) { + logger.error("Error", she); errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL); rc = 500; return rc; @@ -190,16 +196,16 @@ public class AafConnection extends BaseLoggingClass { } } catch (Exception e) { - System.err.println("Unable to read response " ); - e.printStackTrace(); + logger.error("Unable to read response "); + logger.error("Error", e); } finally { try { uc.disconnect(); - } catch ( Exception e ) {} - } - //return responseBody; - + } catch ( Exception e ) { + logger.error("Error", e); + } + } return rc; } @@ -239,12 +245,14 @@ public class AafConnection extends BaseLoggingClass { os.write( postData ); } catch (ProtocolException pe) { + logger.error("Error", pe); // Rcvd error instead of 100-Continue try { // work around glitch in Java 1.7.0.21 and likely others // without this, Java will connect multiple times to the server to run the same request uc.setDoOutput(false); } catch (Exception e) { + logger.error("Error", e); } } catch ( SSLHandshakeException she ) { errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL); @@ -252,6 +260,7 @@ public class AafConnection extends BaseLoggingClass { try { rc = uc.getResponseCode(); } catch ( SSLHandshakeException she ) { + logger.error("Error", she); errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL); rc = 500; return rc; @@ -280,11 +289,9 @@ public class AafConnection extends BaseLoggingClass { } } catch (Exception e) { - System.err.println("Unable to read response " ); - e.printStackTrace(); - } - //return responseBody; - + logger.error("Unable to read response "); + logger.error("Error", e); + } return rc; } diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java b/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java index 072c548..59d610c 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java @@ -24,7 +24,6 @@ import java.lang.reflect.*; import java.sql.*; import java.util.*; -import org.apache.log4j.Logger; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -33,7 +32,40 @@ import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; public class DBFieldHandler { - static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); + static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); + + public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception { + this(c, fieldname, fieldnum, null); + } + public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception { + this.fieldnum = fieldnum; + StringBuilder sb = new StringBuilder(); + for (String s: fieldname.split("_")) { + sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1)); + } + String camelcase = sb.toString(); + try { + objget = c.getMethod("is" + camelcase); + } catch (Exception e) { + errorLogger.error("Error", e); + objget = c.getMethod("get" + camelcase); + } + objset = c.getMethod("set" + camelcase, objget.getReturnType()); + sqlop = op; + if (sqlop != null) { + return; + } + Class<?> x = objget.getReturnType(); + if (x.isEnum()) { + sqlop = new EnumSql(x); + return; + } + sqlop = sqltypes.get(x.getName()); + if (sqlop != null) { + return; + } + errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER, c.getName(), fieldname, Integer.toString(fieldnum), x.getName()); + } public static interface SqlOp { public Object get(ResultSet rs, int index) throws Exception; @@ -121,7 +153,7 @@ public class DBFieldHandler { } private static Map<String, SqlOp> sqltypes; static { - sqltypes = new HashMap<String, SqlOp>(); + sqltypes = new HashMap<>(); sqltypes.put("[Ljava.lang.String;", new AofString()); sqltypes.put("java.util.Date", new SqlDate()); try { @@ -134,6 +166,7 @@ public class DBFieldHandler { new SqlType("Short"); new SqlType("String"); } catch (Exception e) { + errorLogger.error("Error", e); errorLogger.error(DmaapbcLogMessageEnum.DB_ACCESS_INIT_ERROR, e.getMessage() ); } } @@ -156,37 +189,6 @@ public class DBFieldHandler { public void fromSQL(ResultSet r, Object o) throws Exception { objset.invoke(o, sqlop.get(r, fieldnum)); } - public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception { - this(c, fieldname, fieldnum, null); - } - public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception { - this.fieldnum = fieldnum; - StringBuffer sb = new StringBuffer(); - for (String s: fieldname.split("_")) { - sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1)); - } - String camelcase = sb.toString(); - try { - objget = c.getMethod("is" + camelcase); - } catch (Exception e) { - objget = c.getMethod("get" + camelcase); - } - objset = c.getMethod("set" + camelcase, objget.getReturnType()); - sqlop = op; - if (sqlop != null) { - return; - } - Class<?> x = objget.getReturnType(); - if (x.isEnum()) { - sqlop = new EnumSql(x); - return; - } - sqlop = sqltypes.get(x.getName()); - if (sqlop != null) { - return; - } - errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER, c.getName(), fieldname, Integer.toString(fieldnum), x.getName()); - } public static String fesc(String s) { if (s == null) { return(s); diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java b/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java index f0a5582..11b0d15 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java @@ -57,10 +57,6 @@ public class DatabaseClass extends BaseLoggingClass { } List<String> rv = new ArrayList<String>(); for (String s: val.split(",")) { - //String[] f = s.split(";"); - //if (f.length < 3) { - // continue; - //} rv.add(new String(s)); } return(rv); @@ -72,7 +68,7 @@ public class DatabaseClass extends BaseLoggingClass { } @SuppressWarnings("unchecked") List<String> xv = (List<String>)val; - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); String sep = ""; for (Object o: xv) { String rv = (String)o; @@ -152,17 +148,17 @@ public class DatabaseClass extends BaseLoggingClass { } try { dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap"); - dcaeLocations = new DBMap<DcaeLocation>(DcaeLocation.class, "dcae_location", "dcae_location_name"); - dr_nodes = new DBMap<DR_Node>(DR_Node.class, "dr_node", "fqdn"); - dr_pubs = new DBMap<DR_Pub>(DR_Pub.class, "dr_pub", "pub_id"); - dr_subs = new DBMap<DR_Sub>(DR_Sub.class, "dr_sub", "sub_id"); - mr_clients = new DBMap<MR_Client>(MR_Client.class, "mr_client", "mr_client_id"); - mr_clusters = new DBMap<MR_Cluster>(MR_Cluster.class, "mr_cluster", "dcae_location_name"); - feeds = new DBMap<Feed>(Feed.class, "feed", "feed_id"); + dcaeLocations = new DBMap<>(DcaeLocation.class, "dcae_location", "dcae_location_name"); + dr_nodes = new DBMap<>(DR_Node.class, "dr_node", "fqdn"); + dr_pubs = new DBMap<>(DR_Pub.class, "dr_pub", "pub_id"); + dr_subs = new DBMap<>(DR_Sub.class, "dr_sub", "sub_id"); + mr_clients = new DBMap<>(MR_Client.class, "mr_client", "mr_client_id"); + mr_clusters = new DBMap<>(MR_Cluster.class, "mr_cluster", "dcae_location_name"); + feeds = new DBMap<>(Feed.class, "feed", "feed_id"); TableHandler.setSpecialCase("topic", "replication_case", new TopicReplicationTypeHandler()); - topics = new DBMap<Topic>(Topic.class, "topic", "fqtn"); + topics = new DBMap<>(Topic.class, "topic", "fqtn"); TableHandler.setSpecialCase("mirror_maker", "topics", new MirrorTopicsHandler()); - mirrors = new DBMap<MirrorMaker>(MirrorMaker.class, "mirror_maker", "mm_name"); + mirrors = new DBMap<>(MirrorMaker.class, "mirror_maker", "mm_name"); } catch (Exception e) { errorLogger.error("Error initializing database access " + e, e); System.exit(1); @@ -193,15 +189,15 @@ public class DatabaseClass extends BaseLoggingClass { dmaap.setAccessKeyOwner(nd.getAccessKeyOwner()); } }; - dcaeLocations = new HashMap<String, DcaeLocation>(); - dr_nodes = new HashMap<String, DR_Node>(); - dr_pubs = new HashMap<String, DR_Pub>(); - dr_subs = new HashMap<String, DR_Sub>(); - mr_clients = new HashMap<String, MR_Client>(); - mr_clusters = new HashMap<String, MR_Cluster>(); - feeds = new HashMap<String, Feed>(); - topics = new HashMap<String, Topic>(); - mirrors = new HashMap<String, MirrorMaker>(); + dcaeLocations = new HashMap<>(); + dr_nodes = new HashMap<>(); + dr_pubs = new HashMap<>(); + dr_subs = new HashMap<>(); + mr_clients = new HashMap<>(); + mr_clusters = new HashMap<>(); + feeds = new HashMap<>(); + topics = new HashMap<>(); + mirrors = new HashMap<>(); } dmaap.init(new Dmaap("0", "", "", "", "", "", "", "")); // check for, and set up initial data, if it isn't already there @@ -217,11 +213,12 @@ public class DatabaseClass extends BaseLoggingClass { dmaap.update(dmx); } } catch (Exception e) { + errorLogger.error("Error", e); errorLogger.error(DmaapbcLogMessageEnum.DB_UPDATE_ERROR, e.getMessage()); } } - public synchronized static String getNextClientId() { + public static synchronized String getNextClientId() { long id = System.currentTimeMillis(); if ( id <= lastTime ) { diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java index 2c52b0d..1f1b078 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java @@ -23,20 +23,12 @@ package org.onap.dmaap.dbcapi.database; import java.io.*; import java.sql.*; -import org.apache.log4j.Logger; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - -import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; +; public class LoadSchema { private static final EELFLogger logger = EELFManager.getInstance().getLogger(LoadSchema.class); - private static final EELFLogger appLogger = EELFManager.getInstance().getApplicationLogger(); - private static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - private static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger(); - private static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); - private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); static int getVer(Statement s) throws SQLException { ResultSet rs = null; @@ -66,6 +58,7 @@ public class LoadSchema { stmt.execute(cmd); logger.info("SCHEMA: " + cmd); } catch (SQLException sqle) { + logger.error("Error", sqle); throw sqle; } @@ -74,7 +67,9 @@ public class LoadSchema { int newver = -1; try { newver = getVer(stmt); - } catch (Exception e) {} + } catch (Exception e) { + logger.error("Error", e); + } logger.info("Database schema currently at version " + newver++); @@ -126,8 +121,20 @@ public class LoadSchema { } catch (IOException ioe) { throw new SQLException(ioe); } finally { - if (stmt != null) { try { stmt.close(); } catch (Exception e) {}} - if (c != null) { try { c.close(); } catch (Exception e) {}} + if (stmt != null) { + try { + stmt.close(); + } catch (Exception e) { + logger.error("Error", e); + } + } + if (c != null) { + try { + c.close(); + } catch (Exception e) { + logger.error("Error", e); + } + } } } public static void main(String[] args) throws Exception { diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java b/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java index c83b6be..fc68aa2 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java @@ -40,22 +40,10 @@ class TableHandler<C> { protected String initstmt; protected Class<C> cls; protected DBFieldHandler[] fields; - private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<String, Map<String, DBFieldHandler.SqlOp>>(); - public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) { - Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); - if (m == null) { - m = new HashMap<String, DBFieldHandler.SqlOp>(); - exceptions.put(dbtabname, m); - } - m.put(dbfldname, handler); - } - public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) { - Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); - if (m != null) { - return(m.get(dbfldname)); - } - return(null); - } + private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<>(); + private String select = "SELECT "; + private String from = " FROM "; + protected TableHandler(Class<C> cls, String tabname, String keyname) throws Exception { this(ConnectionFactory.getDefaultInstance(), cls, tabname, keyname); } @@ -71,14 +59,31 @@ class TableHandler<C> { } } } + + public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) { + Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); + if (m == null) { + m = new HashMap<>(); + exceptions.put(dbtabname, m); + } + m.put(dbfldname, handler); + } + public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) { + Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname); + if (m != null) { + return(m.get(dbfldname)); + } + return(null); + } + private void setup(DatabaseMetaData dmd, Class<C> cls, String tabname, String keyname) throws Exception { this.cls = cls; - Vector<DBFieldHandler> h = new Vector<DBFieldHandler>(); + Vector<DBFieldHandler> h = new Vector<>(); String qualifiedTableName = String.format( "%s.%s", cf.getSchema(), tabname ); ResultSet rs = dmd.getColumns("", cf.getSchema(), tabname, null); - StringBuffer sb1 = new StringBuffer(); - StringBuffer sb2 = new StringBuffer(); - StringBuffer sb3 = new StringBuffer(); + StringBuilder sb1 = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(); + StringBuilder sb3 = new StringBuilder(); int count = 0; while (rs.next()) { if (!rs.getString(3).equals(tabname)) { @@ -109,13 +114,13 @@ class TableHandler<C> { h.add(new DBFieldHandler(cls, keyname, count, getSpecialCase(tabname, keyname))); delstmt = "DELETE FROM " + qualifiedTableName + " WHERE " + keyname + " = ?"; insorreplstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ", " + keyname + ") VALUES (" + qlist + ", ?) ON CONFLICT(" + keyname + ") DO UPDATE SET (" + clist + ") = (" + elist + ")"; - getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName + " WHERE " + keyname + " = ?"; - liststmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName; + getstmt = select + clist + ", " + keyname + from + qualifiedTableName + " WHERE " + keyname + " = ?"; + liststmt = select + clist + ", " + keyname + from + qualifiedTableName; } else { delstmt = "DELETE FROM " + qualifiedTableName; initstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ") VALUES (" + qlist + ")"; insorreplstmt = "UPDATE " + qualifiedTableName + " SET (" + clist + ") = (" + qlist + ")"; - getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName; + getstmt = select + clist + ", " + keyname + from + qualifiedTableName; } fields = h.toArray(new DBFieldHandler[h.size()]); } diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java index 5a768c5..e089881 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java @@ -42,32 +42,6 @@ public class DR_Sub extends DmaapObject { private boolean use100; private boolean suspended; private String owner; - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public boolean isSuspended() { - return suspended; - } - - public void setSuspended(boolean suspended) { - this.suspended = suspended; - } - - - - public boolean isUse100() { - return use100; - } - - public void setUse100(boolean use100) { - this.use100 = use100; - } public DR_Sub() { @@ -125,6 +99,32 @@ public class DR_Sub extends DmaapObject { logger.info( "new DR_Sub returning"); } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public boolean isSuspended() { + return suspended; + } + + public void setSuspended(boolean suspended) { + this.suspended = suspended; + } + + + + public boolean isUse100() { + return use100; + } + + public void setUse100(boolean use100) { + this.use100 = use100; + } public String getDcaeLocationName() { return dcaeLocationName; diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DcaeLocation.java b/src/main/java/org/onap/dmaap/dbcapi/model/DcaeLocation.java index 8248ef1..b4b5e2e 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/DcaeLocation.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/DcaeLocation.java @@ -26,7 +26,7 @@ import org.apache.log4j.Logger; @XmlRootElement public class DcaeLocation extends DmaapObject { - static final Logger logger = Logger.getLogger(MR_Cluster.class); + static final Logger errorLogger = Logger.getLogger(MR_Cluster.class); private String clli; private String dcaeLayer; private String dcaeLocationName; diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java index 95f9d33..cab48ca 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java +++ b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java @@ -96,7 +96,7 @@ public class TopicResource extends BaseLoggingClass { public Response addTopic( Topic topic ) { - logger.info( "addTopic request: " + String.valueOf(topic) ); + logger.info( "addTopic request: " + topic ); ApiService check = new ApiService(); try { @@ -104,10 +104,10 @@ public class TopicResource extends BaseLoggingClass { check.required( "topicDescription", topic.getTopicDescription(), "" ); check.required( "owner", topic.getOwner(), "" ); } catch( RequiredFieldException rfe ) { + logger.error("Error", rfe); return check.error(); } - //String repReq = topic.getReplicationRequest(); ReplicationType t = topic.getReplicationCase(); if ( t == null || t == ReplicationType.REPLICATION_NOT_SPECIFIED ) { topic.setReplicationCase( mr_topicService.reviewTopic(topic)); @@ -163,6 +163,7 @@ public class TopicResource extends BaseLoggingClass { try { check.required( "fqtn", id, "" ); } catch( RequiredFieldException rfe ) { + logger.error("Error", rfe); return check.error(); } @@ -192,6 +193,7 @@ public class TopicResource extends BaseLoggingClass { try { check.required( "topicName", id, "^\\S+$" ); //no white space allowed in topicName } catch( RequiredFieldException rfe ) { + logger.error("Error", rfe); return check.error(); } Topic mrc = mr_topicService.getTopic( id, check.getErr() ); |