From 8280a5e1a6cfd155edfafe882439b8c04c6a4509 Mon Sep 17 00:00:00 2001 From: HelenaLydon Date: Thu, 22 Aug 2019 15:53:27 +0000 Subject: [PATCH] DMAAP-1195 [DR] Remove DR code smells Issue-ID: DMAAP-1195 Change-Id: I7c6117aa55d281fd0562c845a812107f9eb9581d Signed-off-by: HelenaLydon --- .../onap/dmaap/datarouter/node/DeliveryQueue.java | 22 +- .../dmaap/datarouter/provisioning/beans/Feed.java | 323 +++++++++++---------- .../datarouter/provisioning/beans/LogRecord.java | 99 ++++--- .../provisioning/beans/Subscription.java | 208 ++++++------- .../provisioning/utils/ThrottleFilter.java | 3 +- .../datarouter/provisioning/beans/FeedTest.java | 4 +- 6 files changed, 332 insertions(+), 327 deletions(-) diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java index e06ec5a8..4d336b73 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java @@ -82,6 +82,16 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { private File dir; private List todoList = new ArrayList<>(); + /** + * Create a delivery queue for a given destination info. + */ + DeliveryQueue(DeliveryQueueHelper deliveryQueueHelper, DestInfo destinationInfo) { + this.deliveryQueueHelper = deliveryQueueHelper; + this.destinationInfo = destinationInfo; + dir = new File(destinationInfo.getSpool()); + dir.mkdirs(); + } + /** * Try to cancel a delivery task. * @@ -227,16 +237,6 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { } } - /** - * Create a delivery queue for a given destination info. - */ - DeliveryQueue(DeliveryQueueHelper deliveryQueueHelper, DestInfo destinationInfo) { - this.deliveryQueueHelper = deliveryQueueHelper; - this.destinationInfo = destinationInfo; - dir = new File(destinationInfo.getSpool()); - dir.mkdirs(); - } - /** * Update the destination info for this delivery queue. */ @@ -449,4 +449,4 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { } return fname2; } -} +} \ No newline at end of file diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java index 4a14da2f..76b9e4b7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java @@ -57,8 +57,13 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; public class Feed extends Syncable { private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); - private static int next_feedid = getMaxFeedID() + 1; + private static int nextFeedID = getMaxFeedID() + 1; private static final String SQLEXCEPTION = "SQLException: "; + private static final String FEEDID = "FEEDID"; + private static final String feedIDStr = "feedid"; + private static final String deletedStr = "deleted"; + private static final String lastModStr = "last_mod"; + private static final String createdDateStr ="created_date"; private int feedid; private int groupid; //New field is added - Groups feature Rally:US708115 - 1610 @@ -75,6 +80,143 @@ public class Feed extends Syncable { private Date createdDate; private String aafInstance; + public Feed() { + this("", "", "", ""); + } + + /** + * Feed constructor. + * @param name feed name + * @param version feed version + * @param desc feed description + * @param businessDescription feed business description + */ + public Feed(String name, String version, String desc, String businessDescription) { + this.feedid = -1; + this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 + this.name = name; + this.version = version; + this.description = desc; + this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610 + this.authorization = new FeedAuthorization(); + this.publisher = ""; + this.links = new FeedLinks(); + this.deleted = false; + this.suspended = false; + this.lastMod = new Date(); + this.createdDate = new Date(); + this.aafInstance = ""; + } + + /** + * Feed Constructor from ResultSet. + * @param rs ResultSet + * @throws SQLException in case of SQL statement error + */ + public Feed(ResultSet rs) throws SQLException { + this.feedid = rs.getInt(FEEDID); + //New field is added - Groups feature Rally:US708115 - 1610 + this.groupid = rs.getInt("GROUPID"); + this.name = rs.getString("NAME"); + this.version = rs.getString("VERSION"); + this.description = rs.getString("DESCRIPTION"); + // New field is added - Groups feature Rally:US708102 - 1610 + this.businessDescription = rs.getString("BUSINESS_DESCRIPTION"); + this.authorization = new FeedAuthorization(); + this.authorization.setClassification(rs.getString("AUTH_CLASS")); + this.publisher = rs.getString("PUBLISHER"); + this.links = new FeedLinks(); + this.links.setSelf(rs.getString("SELF_LINK")); + this.links.setPublish(rs.getString("PUBLISH_LINK")); + this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK")); + this.links.setLog(rs.getString("LOG_LINK")); + this.deleted = rs.getBoolean("DELETED"); + this.suspended = rs.getBoolean("SUSPENDED"); + this.lastMod = rs.getDate("LAST_MOD"); + this.createdDate = rs.getTimestamp("CREATED_DATE"); + this.aafInstance = rs.getString("AAF_INSTANCE"); + } + + /** + * Feed constructor from JSONObject. + * @param jo JSONObject + * @throws InvalidObjectException in case of JSON error + */ + public Feed(JSONObject jo) throws InvalidObjectException { + this("", "", "", ""); + try { + // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation + this.feedid = jo.optInt(feedIDStr, -1); + this.groupid = jo.optInt("groupid"); + this.name = jo.getString("name"); + this.aafInstance = jo.optString("aaf_instance", "legacy"); + if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { + throw new InvalidObjectException("aaf_instance field is too long"); + } + if (name.length() > 255) { + throw new InvalidObjectException("name field is too long"); + } + try { + this.version = jo.getString("version"); + } catch (JSONException e) { + intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e); + this.version = null; + } + if (version != null && version.length() > 20) { + throw new InvalidObjectException("version field is too long"); + } + this.description = jo.optString("description"); + this.businessDescription = jo.optString("business_description"); + if (description.length() > 1000) { + throw new InvalidObjectException("technical description field is too long"); + } + if (businessDescription.length() > 1000) { + throw new InvalidObjectException("business description field is too long"); + } + this.authorization = new FeedAuthorization(); + JSONObject jauth = jo.getJSONObject("authorization"); + this.authorization.setClassification(jauth.getString("classification")); + if (this.authorization.getClassification().length() > 32) { + throw new InvalidObjectException("classification field is too long"); + } + JSONArray endPointIds = jauth.getJSONArray("endpoint_ids"); + for (int i = 0; i < endPointIds.length(); i++) { + JSONObject id = endPointIds.getJSONObject(i); + FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password")); + if (fid.getId().length() > 60) { + throw new InvalidObjectException("id field is too long (" + fid.getId() + ")"); + } + if (fid.getPassword().length() > 32) { + //Fortify scan fixes - Privacy Violation + throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")"); + } + this.authorization.getEndpointIDS().add(fid); + } + if (this.authorization.getEndpointIDS().isEmpty()) { + throw new InvalidObjectException("need to specify at least one endpoint_id"); + } + endPointIds = jauth.getJSONArray("endpoint_addrs"); + for (int i = 0; i < endPointIds.length(); i++) { + String addr = endPointIds.getString(i); + if (!JSONUtilities.validIPAddrOrSubnet(addr)) { + throw new InvalidObjectException("bad IP addr or subnet mask: " + addr); + } + this.authorization.getEndpointAddrs().add(addr); + } + + this.publisher = jo.optString("publisher", ""); + this.deleted = jo.optBoolean(deletedStr, false); + this.suspended = jo.optBoolean("suspend", false); + JSONObject jol = jo.optJSONObject("links"); + this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol)); + } catch (InvalidObjectException e) { + throw e; + } catch (Exception e) { + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); + } + } + /** * Check if a feed ID is valid. * @@ -196,7 +338,7 @@ public class Feed extends Syncable { String sql = "select * from FEED_ENDPOINT_IDS"; try (ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { - int id = rs.getInt("FEEDID"); + int id = rs.getInt(FEEDID); Feed feed = map.get(id); if (feed != null) { FeedEndpointID epi = new FeedEndpointID(rs); @@ -209,7 +351,7 @@ public class Feed extends Syncable { sql = "select * from FEED_ENDPOINT_ADDRS"; try (ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { - int id = rs.getInt("FEEDID"); + int id = rs.getInt(FEEDID); Feed feed = map.get(id); if (feed != null) { Collection acoll = feed.getAuthorization().getEndpointAddrs(); @@ -303,142 +445,7 @@ public class Feed extends Syncable { return feed; } - public Feed() { - this("", "", "", ""); - } - - /** - * Feed constructor. - * @param name feed name - * @param version feed version - * @param desc feed description - * @param businessDescription feed business description - */ - public Feed(String name, String version, String desc, String businessDescription) { - this.feedid = -1; - this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 - this.name = name; - this.version = version; - this.description = desc; - this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610 - this.authorization = new FeedAuthorization(); - this.publisher = ""; - this.links = new FeedLinks(); - this.deleted = false; - this.suspended = false; - this.lastMod = new Date(); - this.createdDate = new Date(); - this.aafInstance = ""; - } - /** - * Feed Constructor from ResultSet. - * @param rs ResultSet - * @throws SQLException in case of SQL statement error - */ - public Feed(ResultSet rs) throws SQLException { - this.feedid = rs.getInt("FEEDID"); - //New field is added - Groups feature Rally:US708115 - 1610 - this.groupid = rs.getInt("GROUPID"); - this.name = rs.getString("NAME"); - this.version = rs.getString("VERSION"); - this.description = rs.getString("DESCRIPTION"); - // New field is added - Groups feature Rally:US708102 - 1610 - this.businessDescription = rs.getString("BUSINESS_DESCRIPTION"); - this.authorization = new FeedAuthorization(); - this.authorization.setClassification(rs.getString("AUTH_CLASS")); - this.publisher = rs.getString("PUBLISHER"); - this.links = new FeedLinks(); - this.links.setSelf(rs.getString("SELF_LINK")); - this.links.setPublish(rs.getString("PUBLISH_LINK")); - this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK")); - this.links.setLog(rs.getString("LOG_LINK")); - this.deleted = rs.getBoolean("DELETED"); - this.suspended = rs.getBoolean("SUSPENDED"); - this.lastMod = rs.getDate("LAST_MOD"); - this.createdDate = rs.getTimestamp("CREATED_DATE"); - this.aafInstance = rs.getString("AAF_INSTANCE"); - } - - /** - * Feed constructor from JSONObject. - * @param jo JSONObject - * @throws InvalidObjectException in case of JSON error - */ - public Feed(JSONObject jo) throws InvalidObjectException { - this("", "", "", ""); - try { - // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation - this.feedid = jo.optInt("feedid", -1); - this.groupid = jo.optInt("groupid"); - this.name = jo.getString("name"); - this.aafInstance = jo.optString("aaf_instance", "legacy"); - if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { - throw new InvalidObjectException("aaf_instance field is too long"); - } - if (name.length() > 255) { - throw new InvalidObjectException("name field is too long"); - } - try { - this.version = jo.getString("version"); - } catch (JSONException e) { - intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e); - this.version = null; - } - if (version != null && version.length() > 20) { - throw new InvalidObjectException("version field is too long"); - } - this.description = jo.optString("description"); - this.businessDescription = jo.optString("business_description"); - if (description.length() > 1000) { - throw new InvalidObjectException("technical description field is too long"); - } - if (businessDescription.length() > 1000) { - throw new InvalidObjectException("business description field is too long"); - } - this.authorization = new FeedAuthorization(); - JSONObject jauth = jo.getJSONObject("authorization"); - this.authorization.setClassification(jauth.getString("classification")); - if (this.authorization.getClassification().length() > 32) { - throw new InvalidObjectException("classification field is too long"); - } - JSONArray endPointIds = jauth.getJSONArray("endpoint_ids"); - for (int i = 0; i < endPointIds.length(); i++) { - JSONObject id = endPointIds.getJSONObject(i); - FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password")); - if (fid.getId().length() > 60) { - throw new InvalidObjectException("id field is too long (" + fid.getId() + ")"); - } - if (fid.getPassword().length() > 32) { - //Fortify scan fixes - Privacy Violation - throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")"); - } - this.authorization.getEndpointIDS().add(fid); - } - if (this.authorization.getEndpointIDS().isEmpty()) { - throw new InvalidObjectException("need to specify at least one endpoint_id"); - } - endPointIds = jauth.getJSONArray("endpoint_addrs"); - for (int i = 0; i < endPointIds.length(); i++) { - String addr = endPointIds.getString(i); - if (!JSONUtilities.validIPAddrOrSubnet(addr)) { - throw new InvalidObjectException("bad IP addr or subnet mask: " + addr); - } - this.authorization.getEndpointAddrs().add(addr); - } - - this.publisher = jo.optString("publisher", ""); - this.deleted = jo.optBoolean("deleted", false); - this.suspended = jo.optBoolean("suspend", false); - JSONObject jol = jo.optJSONObject("links"); - this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol)); - } catch (InvalidObjectException e) { - throw e; - } catch (Exception e) { - intlogger.warn("Invalid JSON: " + e.getMessage(), e); - throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); - } - } public int getFeedid() { return feedid; @@ -463,7 +470,7 @@ public class Feed extends Syncable { return aafInstance; } - public void setAaf_instance(String aafInstance) { + public void setAafInstance(String aafInstance) { this.aafInstance = aafInstance; } @@ -501,11 +508,11 @@ public class Feed extends Syncable { } // New field is added - Groups feature Rally:US708102 - 1610 - public String getBusiness_description() { + public String getBusinessDescription() { return businessDescription; } - public void setBusiness_description(String businessDescription) { + public void setBusinessDescription(String businessDescription) { this.businessDescription = businessDescription; } @@ -561,7 +568,7 @@ public class Feed extends Syncable { @Override public JSONObject asJSONObject() { JSONObject jo = new JSONObject(); - jo.put("feedid", feedid); + jo.put(feedIDStr, feedid); //New field is added - Groups feature Rally:US708115 - 1610 jo.put("groupid", groupid); jo.put("name", name); @@ -572,10 +579,10 @@ public class Feed extends Syncable { jo.put("authorization", authorization.asJSONObject()); jo.put("publisher", publisher); jo.put("links", links.asJSONObject()); - jo.put("deleted", deleted); + jo.put(deletedStr, deleted); jo.put("suspend", suspended); - jo.put("last_mod", lastMod.getTime()); - jo.put("created_date", createdDate.getTime()); + jo.put(lastModStr, lastMod.getTime()); + jo.put(createdDateStr, createdDate.getTime()); jo.put("aaf_instance", aafInstance); return jo; } @@ -588,10 +595,10 @@ public class Feed extends Syncable { public JSONObject asJSONObject(boolean hidepasswords) { JSONObject jo = asJSONObject(); if (hidepasswords) { - jo.remove("feedid"); // we no longer hide passwords, however we do hide these - jo.remove("deleted"); - jo.remove("last_mod"); - jo.remove("created_date"); + jo.remove(feedIDStr); // we no longer hide passwords, however we do hide these + jo.remove(deletedStr); + jo.remove(lastModStr); + jo.remove(createdDateStr); } return jo; } @@ -602,10 +609,10 @@ public class Feed extends Syncable { */ public JSONObject asLimitedJSONObject() { JSONObject jo = asJSONObject(); - jo.remove("deleted"); - jo.remove("feedid"); - jo.remove("last_mod"); - jo.remove("created_date"); + jo.remove(deletedStr); + jo.remove(feedIDStr); + jo.remove(lastModStr); + jo.remove(createdDateStr); return jo; } @@ -640,11 +647,11 @@ public class Feed extends Syncable { boolean rv = true; try { if (feedid == -1) { - setFeedid(next_feedid++); + setFeedid(nextFeedID++); } // In case we insert a feed from synchronization - if (feedid > next_feedid) { - next_feedid = feedid + 1; + if (feedid > nextFeedID) { + nextFeedID = feedid + 1; } // Create FEED_ENDPOINT_IDS rows @@ -687,7 +694,7 @@ public class Feed extends Syncable { ps2.setString(10, getLinks().getLog()); ps2.setBoolean(11, isDeleted()); ps2.setBoolean(12, isSuspended()); - ps2.setString(13, getBusiness_description()); + ps2.setString(13, getBusinessDescription()); ps2.setInt(14, groupid); ps2.setString(15, getAafInstance()); ps2.executeUpdate(); @@ -768,7 +775,7 @@ public class Feed extends Syncable { ps.setString(2, getAuthorization().getClassification()); ps.setInt(3, deleted ? 1 : 0); ps.setInt(4, suspended ? 1 : 0); - ps.setString(5, getBusiness_description()); + ps.setString(5, getBusinessDescription()); ps.setInt(6, groupid); ps.setInt(7, feedid); ps.executeUpdate(); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java index 51c162ef..b26e551b 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java @@ -57,44 +57,13 @@ public class LogRecord extends BaseLogRecord { * @throws IOException in case of I/O error */ private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); - - /** - * Get Log Records. - * @param os outputstream - * @param bs RLEBitSet object - * @throws IOException in case of I/O error - */ - public static void printLogRecords(OutputStream os, RLEBitSet bs) throws IOException { - final String sql = "select * from LOG_RECORDS where RECORD_ID >= ? AND RECORD_ID <= ?"; - DB db = new DB(); - try (Connection conn = db.getConnection()) { - Iterator iter = bs.getRangeIterator(); - try (PreparedStatement ps = conn.prepareStatement(sql)) { - while (iter.hasNext()) { - Long[] nxt = iter.next(); - ps.setLong(1, nxt[0]); - ps.setLong(2, nxt[1]); - try (ResultSet rs = ps.executeQuery()) { - while (rs.next()) { - LogRecord lr = new LogRecord(rs); - os.write(lr.toString().getBytes()); - } - ps.clearParameters(); - } - } - } - } catch (SQLException e) { - intlogger.error("PROV0001 printLogRecords: " + e.getMessage(), e); - } - } - private final String type; - private final String feedFileid; + private final String feedFileID; private final String remoteAddr; private final String user; private final int status; - private final int subid; - private final String fileid; + private final int subID; + private final String fileID; private final int result; private final int attempts; private final String reason; @@ -110,13 +79,13 @@ public class LogRecord extends BaseLogRecord { public LogRecord(ResultSet rs) throws SQLException { super(rs); this.type = rs.getString("TYPE"); - this.feedFileid = rs.getString("FEED_FILEID"); + this.feedFileID = rs.getString("FEED_FILEID"); this.remoteAddr = rs.getString("REMOTE_ADDR"); this.user = rs.getString("USER"); this.status = rs.getInt("STATUS"); - this.subid = rs.getInt("DELIVERY_SUBID"); - this.fileid = rs.getString("DELIVERY_FILEID"); + this.subID = rs.getInt("DELIVERY_SUBID"); + this.fileID = rs.getString("DELIVERY_FILEID"); this.result = rs.getInt("RESULT"); this.attempts = rs.getInt("ATTEMPTS"); @@ -135,13 +104,13 @@ public class LogRecord extends BaseLogRecord { public LogRecord(String[] pp) throws ParseException { super(pp); this.type = pp[8]; - this.feedFileid = pp[9]; + this.feedFileID = pp[9]; this.remoteAddr = pp[10]; this.user = pp[11]; this.status = Integer.parseInt(pp[12]); - this.subid = Integer.parseInt(pp[13]); - this.fileid = pp[14]; + this.subID = Integer.parseInt(pp[13]); + this.fileID = pp[14]; this.result = Integer.parseInt(pp[15]); this.attempts = Integer.parseInt(pp[16]); @@ -152,6 +121,36 @@ public class LogRecord extends BaseLogRecord { this.fileName = pp[20]; } + /** + * Get Log Records. + * @param os outputstream + * @param bs RLEBitSet object + * @throws IOException in case of I/O error + */ + public static void printLogRecords(OutputStream os, RLEBitSet bs) throws IOException { + final String sql = "select * from LOG_RECORDS where RECORD_ID >= ? AND RECORD_ID <= ?"; + DB db = new DB(); + try (Connection conn = db.getConnection()) { + Iterator iter = bs.getRangeIterator(); + try (PreparedStatement ps = conn.prepareStatement(sql)) { + while (iter.hasNext()) { + Long[] nxt = iter.next(); + ps.setLong(1, nxt[0]); + ps.setLong(2, nxt[1]); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + LogRecord lr = new LogRecord(rs); + os.write(lr.toString().getBytes()); + } + ps.clearParameters(); + } + } + } + } catch (SQLException e) { + intlogger.error("PROV0001 printLogRecords: " + e.getMessage(), e); + } + } + public long getRecordId() { return recordId; } @@ -168,12 +167,12 @@ public class LogRecord extends BaseLogRecord { + getContentType() + "|" + getContentLength() + "|" + type + "|" - + feedFileid + "|" + + feedFileID + "|" + remoteAddr + "|" + user + "|" + status + "|" - + subid + "|" - + fileid + "|" + + subID + "|" + + fileID + "|" + result + "|" + attempts + "|" + reason + "|" @@ -187,7 +186,7 @@ public class LogRecord extends BaseLogRecord { ps.setString(1, type); super.load(ps); // loads fields 2-8 if (type.equals("pub")) { - ps.setString(9, feedFileid); + ps.setString(9, feedFileID); ps.setString(10, remoteAddr); ps.setString(11, user); ps.setInt(12, status); @@ -204,8 +203,8 @@ public class LogRecord extends BaseLogRecord { ps.setNull(10, Types.VARCHAR); ps.setString(11, user); ps.setNull(12, Types.INTEGER); - ps.setInt(13, subid); - ps.setString(14, fileid); + ps.setInt(13, subID); + ps.setString(14, fileID); ps.setInt(15, result); ps.setNull(16, Types.INTEGER); ps.setNull(17, Types.VARCHAR); @@ -217,8 +216,8 @@ public class LogRecord extends BaseLogRecord { ps.setNull(10, Types.VARCHAR); ps.setNull(11, Types.VARCHAR); ps.setNull(12, Types.INTEGER); - ps.setInt(13, subid); - ps.setString(14, fileid); + ps.setInt(13, subID); + ps.setString(14, fileID); ps.setNull(15, Types.INTEGER); ps.setInt(16, attempts); ps.setString(17, reason); @@ -226,7 +225,7 @@ public class LogRecord extends BaseLogRecord { ps.setNull(19, Types.BIGINT); ps.setString(20, fileName); } else if (type.equals("pbf")) { - ps.setString(9, feedFileid); + ps.setString(9, feedFileID); ps.setString(10, remoteAddr); ps.setString(11, user); ps.setNull(12, Types.INTEGER); @@ -243,7 +242,7 @@ public class LogRecord extends BaseLogRecord { ps.setNull(10, Types.VARCHAR); ps.setNull(11, Types.VARCHAR); ps.setNull(12, Types.INTEGER); - ps.setInt(13, subid); + ps.setInt(13, subID); ps.setNull(14, Types.VARCHAR); ps.setNull(15, Types.INTEGER); ps.setNull(16, Types.INTEGER); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java index 95f0a706..749980e5 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java @@ -75,6 +75,110 @@ public class Subscription extends Syncable { private String aafInstance; private boolean decompress; + public Subscription() { + this("", "", ""); + } + + /** + * Subscription constructor. + * @param url url string + * @param user user string + * @param password password string + */ + public Subscription(String url, String user, String password) { + this.subid = -1; + this.feedid = -1; + this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 + this.delivery = new SubDelivery(url, user, password, false); + this.metadataOnly = false; + this.followRedirect = false; + this.subscriber = ""; + this.links = new SubLinks(); + this.suspended = false; + this.lastMod = new Date(); + this.createdDate = new Date(); + this.privilegedSubscriber = false; + this.aafInstance = ""; + this.decompress = false; + } + + /** + * Subscription constructor. + * @param rs resultset from SQL + * @throws SQLException in case of SQL error + */ + public Subscription(ResultSet rs) throws SQLException { + this.subid = rs.getInt(SUBID_COL); + this.feedid = rs.getInt("FEEDID"); + this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610 + this.delivery = new SubDelivery(rs); + this.metadataOnly = rs.getBoolean("METADATA_ONLY"); + this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS"); + this.subscriber = rs.getString("SUBSCRIBER"); + this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), + rs.getString("LOG_LINK")); + this.suspended = rs.getBoolean("SUSPENDED"); + this.lastMod = rs.getDate("LAST_MOD"); + this.createdDate = rs.getDate("CREATED_DATE"); + this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER"); + this.aafInstance = rs.getString("AAF_INSTANCE"); + this.decompress = rs.getBoolean("DECOMPRESS"); + } + + /** + * Subscription constructor. + * @param jo JSONObject + * @throws InvalidObjectException in case of object error + */ + public Subscription(JSONObject jo) throws InvalidObjectException { + this("", "", ""); + try { + // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation + this.subid = jo.optInt(SUBID_KEY, -1); + this.feedid = jo.optInt(FEEDID_KEY, -1); + this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610 + this.aafInstance = jo.optString("aaf_instance", "legacy"); + if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { + throw new InvalidObjectException("aaf_instance field is too long"); + } + JSONObject jdeli = jo.getJSONObject("delivery"); + String url = jdeli.getString("url"); + String user = jdeli.getString("user"); + final String password = jdeli.getString("password"); + final boolean use100 = jdeli.getBoolean("use100"); + + //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. + Properties prop = (new DB()).getProperties(); + if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) { + throw new InvalidObjectException("delivery URL is not HTTPS"); + } + + if (url.length() > 256) { + throw new InvalidObjectException("delivery url field is too long"); + } + if (user.length() > 60) { + throw new InvalidObjectException("delivery user field is too long"); + } + if (password.length() > 32) { + throw new InvalidObjectException("delivery password field is too long"); + } + this.delivery = new SubDelivery(url, user, password, use100); + this.metadataOnly = jo.getBoolean("metadataOnly"); + this.followRedirect = jo.optBoolean("follow_redirect", false); + this.suspended = jo.optBoolean("suspend", false); + this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false); + this.decompress = jo.optBoolean("decompress", false); + this.subscriber = jo.optString("subscriber", ""); + JSONObject jol = jo.optJSONObject("links"); + this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol)); + } catch (InvalidObjectException e) { + throw e; + } catch (Exception e) { + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); + } + } + /** * Get specific subscription. * @param sub subscription object @@ -217,110 +321,6 @@ public class Subscription extends Syncable { return count; } - public Subscription() { - this("", "", ""); - } - - /** - * Subscription constructor. - * @param url url string - * @param user user string - * @param password password string - */ - public Subscription(String url, String user, String password) { - this.subid = -1; - this.feedid = -1; - this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 - this.delivery = new SubDelivery(url, user, password, false); - this.metadataOnly = false; - this.followRedirect = false; - this.subscriber = ""; - this.links = new SubLinks(); - this.suspended = false; - this.lastMod = new Date(); - this.createdDate = new Date(); - this.privilegedSubscriber = false; - this.aafInstance = ""; - this.decompress = false; - } - - /** - * Subscription constructor. - * @param rs resultset from SQL - * @throws SQLException in case of SQL error - */ - public Subscription(ResultSet rs) throws SQLException { - this.subid = rs.getInt(SUBID_COL); - this.feedid = rs.getInt("FEEDID"); - this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610 - this.delivery = new SubDelivery(rs); - this.metadataOnly = rs.getBoolean("METADATA_ONLY"); - this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS"); - this.subscriber = rs.getString("SUBSCRIBER"); - this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), - rs.getString("LOG_LINK")); - this.suspended = rs.getBoolean("SUSPENDED"); - this.lastMod = rs.getDate("LAST_MOD"); - this.createdDate = rs.getDate("CREATED_DATE"); - this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER"); - this.aafInstance = rs.getString("AAF_INSTANCE"); - this.decompress = rs.getBoolean("DECOMPRESS"); - } - - /** - * Subscription constructor. - * @param jo JSONObject - * @throws InvalidObjectException in case of object error - */ - public Subscription(JSONObject jo) throws InvalidObjectException { - this("", "", ""); - try { - // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation - this.subid = jo.optInt(SUBID_KEY, -1); - this.feedid = jo.optInt(FEEDID_KEY, -1); - this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610 - this.aafInstance = jo.optString("aaf_instance", "legacy"); - if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { - throw new InvalidObjectException("aaf_instance field is too long"); - } - JSONObject jdeli = jo.getJSONObject("delivery"); - String url = jdeli.getString("url"); - String user = jdeli.getString("user"); - final String password = jdeli.getString("password"); - final boolean use100 = jdeli.getBoolean("use100"); - - //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. - Properties prop = (new DB()).getProperties(); - if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) { - throw new InvalidObjectException("delivery URL is not HTTPS"); - } - - if (url.length() > 256) { - throw new InvalidObjectException("delivery url field is too long"); - } - if (user.length() > 60) { - throw new InvalidObjectException("delivery user field is too long"); - } - if (password.length() > 32) { - throw new InvalidObjectException("delivery password field is too long"); - } - this.delivery = new SubDelivery(url, user, password, use100); - this.metadataOnly = jo.getBoolean("metadataOnly"); - this.followRedirect = jo.optBoolean("follow_redirect", false); - this.suspended = jo.optBoolean("suspend", false); - this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false); - this.decompress = jo.optBoolean("decompress", false); - this.subscriber = jo.optString("subscriber", ""); - JSONObject jol = jo.optJSONObject("links"); - this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol)); - } catch (InvalidObjectException e) { - throw e; - } catch (Exception e) { - intlogger.warn("Invalid JSON: " + e.getMessage(), e); - throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); - } - } - private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties prop) { return prop.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo .has("sync"); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java index 659dbacd..f0f10671 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java @@ -104,6 +104,7 @@ public class ThrottleFilter extends TimerTask implements Filter { private static EELFLogger logger = EELFManager.getInstance().getLogger("InternalLog"); private static Map map = new HashMap<>(); + private Map> suspendedRequests = new HashMap<>(); private static final Timer rolex = new Timer(); @Override @@ -229,8 +230,6 @@ public class ThrottleFilter extends TimerTask implements Filter { } } - private Map> suspendedRequests = new HashMap<>(); - private void register(String id, Continuation continuation) { synchronized (suspendedRequests) { List list = suspendedRequests.get(id); diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java index 9db43223..37e69c84 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/FeedTest.java @@ -161,7 +161,7 @@ public class FeedTest { feed.setVersion("v1.0"); feed.setGroupid(1); feed.setDescription("test feed"); - feed.setBusiness_description("test feed"); + feed.setBusinessDescription("test feed"); feed.setSuspended(false); feed.setPublisher("publish"); @@ -169,7 +169,7 @@ public class FeedTest { Assert.assertEquals(feed.getVersion(), "v1.0"); Assert.assertEquals(feed.getGroupid(), 1); Assert.assertEquals(feed.getDescription(), "test feed"); - Assert.assertEquals(feed.getBusiness_description(), "test feed"); + Assert.assertEquals(feed.getBusinessDescription(), "test feed"); Assert.assertEquals(feed.isSuspended(), false); Assert.assertEquals(feed.getPublisher(), "publish"); } -- 2.16.6