</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
- <property name="allowedAbbreviationLength" value="3"/>
+ <property name="allowedAbbreviationLength" value="20"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
/**
- * Create a delivery task for a given delivery queue and pub ID
+ * Create a delivery task for a given delivery queue and pub ID.
*
* @param deliveryTaskHelper The delivery task helper for the queue this task is in.
* @param pubid The publish ID for this file. This is used as the base for the file name in the spool directory and
- * is of the form <milliseconds since 1970>.<fqdn of initial data router node>
+ * is of the form (milliseconds since 1970).(fqdn of initial data router node)
*/
DeliveryTask(DeliveryTaskHelper deliveryTaskHelper, String pubid) {
this.deliveryTaskHelper = deliveryTaskHelper;
public class LogManager extends TimerTask {
+ private static final String EXCEPTION = "Exception";
private EELFLogger logger = EELFManager.getInstance().getLogger(LogManager.class);
private NodeConfigManager config;
private Matcher isnodelog;
private String uploaddir;
private String logdir;
- private static final String EXCEPTION = "Exception";
-
/**
* Construct a log manager
*
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import org.jetbrains.annotations.NotNull;
/**
* Processed configuration for this node.
for (ProvParam p : pd.getParams()) {
params.put(p.getName(), p.getValue());
}
+ ArrayList<DestInfo> destInfos = addDestInfoToNodeConfig(pd, myname, spooldir, port, nodeauthkey);
+ PathFinder pf = new PathFinder(myname, nodeinfo.keySet().toArray(new String[0]), pd.getHops());
+ HashMap<String, ArrayList<Redirection>> rdtab = addSubRedirInfoToNodeConfig(pd);
+ HashMap<String, HashMap<String, String>> pfutab = addFeedUsersToNodeConfig(pd);
+ HashMap<String, String> egrtab = addEgressRoutesToNodeConfig(pd, myname);
+ HashMap<String, ArrayList<SubnetMatcher>> pfstab = addFeedSubnetToNodeConfig(pd);
+ HashSet<String> allfeeds = addFeedsToNodeConfig(pd);
+ HashMap<String, StringBuilder> feedTargets = addSubsToNodeConfig(pd, spooldir, destInfos, pf, egrtab, allfeeds);
+ alldests = destInfos.toArray(new DestInfo[0]);
+ addFeedTargetsToNodeConfig(pd, rdtab, pfutab, pfstab, feedTargets);
+ }
+
+ @NotNull
+ private ArrayList<DestInfo> addDestInfoToNodeConfig(ProvData pd, String myname, String spooldir, int port,
+ String nodeauthkey) {
ArrayList<DestInfo> destInfos = new ArrayList<>();
myauth = NodeUtils.getNodeAuthHdr(myname, nodeauthkey);
for (ProvNode pn : pd.getNodes()) {
nodeinfo.put(commonName, di);
nodes.put(auth, new IsFrom(commonName));
}
- PathFinder pf = new PathFinder(myname, nodeinfo.keySet().toArray(new String[0]), pd.getHops());
+ return destInfos;
+ }
+
+ @NotNull
+ private HashMap<String, ArrayList<Redirection>> addSubRedirInfoToNodeConfig(ProvData pd) {
HashMap<String, ArrayList<Redirection>> rdtab = new HashMap<>();
for (ProvForceIngress pfi : pd.getForceIngress()) {
- ArrayList<Redirection> v = rdtab.get(pfi.getFeedId());
- if (v == null) {
- v = new ArrayList<>();
- rdtab.put(pfi.getFeedId(), v);
+ ArrayList<Redirection> redirections = rdtab.get(pfi.getFeedId());
+ if (redirections == null) {
+ redirections = new ArrayList<>();
+ rdtab.put(pfi.getFeedId(), redirections);
}
- Redirection r = new Redirection();
+ Redirection redirection = new Redirection();
if (pfi.getSubnet() != null) {
- r.snm = new SubnetMatcher(pfi.getSubnet());
+ redirection.snm = new SubnetMatcher(pfi.getSubnet());
}
- r.user = pfi.getUser();
- r.nodes = pfi.getNodes();
- v.add(r);
+ redirection.user = pfi.getUser();
+ redirection.nodes = pfi.getNodes();
+ redirections.add(redirection);
}
+ return rdtab;
+ }
+
+ @NotNull
+ private HashMap<String, HashMap<String, String>> addFeedUsersToNodeConfig(ProvData pd) {
HashMap<String, HashMap<String, String>> pfutab = new HashMap<>();
for (ProvFeedUser pfu : pd.getFeedUsers()) {
- HashMap<String, String> t = pfutab.get(pfu.getFeedId());
- if (t == null) {
- t = new HashMap<>();
- pfutab.put(pfu.getFeedId(), t);
+ HashMap<String, String> userInfo = pfutab.get(pfu.getFeedId());
+ if (userInfo == null) {
+ userInfo = new HashMap<>();
+ pfutab.put(pfu.getFeedId(), userInfo);
}
- t.put(pfu.getCredentials(), pfu.getUser());
+ userInfo.put(pfu.getCredentials(), pfu.getUser());
}
+ return pfutab;
+ }
+
+ @NotNull
+ private HashMap<String, String> addEgressRoutesToNodeConfig(ProvData pd, String myname) {
HashMap<String, String> egrtab = new HashMap<>();
for (ProvForceEgress pfe : pd.getForceEgress()) {
if (pfe.getNode().equals(myname) || nodeinfo.get(pfe.getNode()) == null) {
}
egrtab.put(pfe.getSubId(), pfe.getNode());
}
+ return egrtab;
+ }
+
+ @NotNull
+ private HashMap<String, ArrayList<SubnetMatcher>> addFeedSubnetToNodeConfig(ProvData pd) {
HashMap<String, ArrayList<SubnetMatcher>> pfstab = new HashMap<>();
for (ProvFeedSubnet pfs : pd.getFeedSubnets()) {
- ArrayList<SubnetMatcher> v = pfstab.get(pfs.getFeedId());
- if (v == null) {
- v = new ArrayList<>();
- pfstab.put(pfs.getFeedId(), v);
+ ArrayList<SubnetMatcher> subnetMatchers = pfstab.get(pfs.getFeedId());
+ if (subnetMatchers == null) {
+ subnetMatchers = new ArrayList<>();
+ pfstab.put(pfs.getFeedId(), subnetMatchers);
}
- v.add(new SubnetMatcher(pfs.getCidr()));
+ subnetMatchers.add(new SubnetMatcher(pfs.getCidr()));
}
- HashMap<String, StringBuilder> feedTargets = new HashMap<>();
+ return pfstab;
+ }
+
+ @NotNull
+ private HashSet<String> addFeedsToNodeConfig(ProvData pd) {
HashSet<String> allfeeds = new HashSet<>();
for (ProvFeed pfx : pd.getFeeds()) {
if (pfx.getStatus() == null) {
allfeeds.add(pfx.getId());
}
}
+ return allfeeds;
+ }
+
+ @NotNull
+ private HashMap<String, StringBuilder> addSubsToNodeConfig(ProvData pd, String spooldir,
+ ArrayList<DestInfo> destInfos, PathFinder pf, HashMap<String, String> egrtab, HashSet<String> allfeeds) {
+ HashMap<String, StringBuilder> feedTargets = new HashMap<>();
for (ProvSubscription provSubscription : pd.getSubscriptions()) {
String subId = provSubscription.getSubId();
String feedId = provSubscription.getFeedId();
}
sb.append(' ').append(subId);
}
- alldests = destInfos.toArray(new DestInfo[0]);
+ return feedTargets;
+ }
+
+ private void addFeedTargetsToNodeConfig(ProvData pd, HashMap<String, ArrayList<Redirection>> rdtab,
+ HashMap<String, HashMap<String, String>> pfutab, HashMap<String, ArrayList<SubnetMatcher>> pfstab,
+ HashMap<String, StringBuilder> feedTargets) {
for (ProvFeed pfx : pd.getFeeds()) {
String fid = pfx.getId();
- Feed f = feeds.get(fid);
- if (f != null) {
+ Feed feed = feeds.get(fid);
+ if (feed != null) {
continue;
}
- f = new Feed();
- feeds.put(fid, f);
- f.createdDate = pfx.getCreatedDate();
- f.loginfo = pfx.getLogData();
- f.status = pfx.getStatus();
+ feed = new Feed();
+ feeds.put(fid, feed);
+ feed.createdDate = pfx.getCreatedDate();
+ feed.loginfo = pfx.getLogData();
+ feed.status = pfx.getStatus();
/*
* AAF changes: TDP EPIC US# 307413
* Passing aafInstance from ProvFeed to identify legacy/AAF feeds
*/
- f.aafInstance = pfx.getAafInstance();
+ feed.aafInstance = pfx.getAafInstance();
ArrayList<SubnetMatcher> v1 = pfstab.get(fid);
if (v1 == null) {
- f.subnets = new SubnetMatcher[0];
+ feed.subnets = new SubnetMatcher[0];
} else {
- f.subnets = v1.toArray(new SubnetMatcher[0]);
+ feed.subnets = v1.toArray(new SubnetMatcher[0]);
}
HashMap<String, String> h1 = pfutab.get(fid);
if (h1 == null) {
h1 = new HashMap();
}
- f.authusers = h1;
+ feed.authusers = h1;
ArrayList<Redirection> v2 = rdtab.get(fid);
if (v2 == null) {
- f.redirections = new Redirection[0];
+ feed.redirections = new Redirection[0];
} else {
- f.redirections = v2.toArray(new Redirection[0]);
+ feed.redirections = v2.toArray(new Redirection[0]);
}
StringBuilder sb = feedTargets.get(fid);
if (sb == null) {
- f.targets = new Target[0];
+ feed.targets = new Target[0];
} else {
- f.targets = parseRouting(sb.toString());
+ feed.targets = parseRouting(sb.toString());
}
}
}
/**
- * Parse a target string into an array of targets
+ * Parse a target string into an array of targets.
*
* @param routing Target string
* @return Array of targets.
if ("".equals(routing)) {
return (new Target[0]);
}
- String[] xx = routing.split("\\s+");
+ String[] routingTable = routing.split("\\s+");
HashMap<String, Target> tmap = new HashMap<>();
HashSet<String> subset = new HashSet<>();
- ArrayList<Target> tv = new ArrayList<>();
- for (int i = 0; i < xx.length; i++) {
- String t = xx[i];
- int j = t.indexOf('/');
- if (j == -1) {
- addTarget(subset, tv, t);
+ ArrayList<Target> targets = new ArrayList<>();
+ for (int i = 0; i < routingTable.length; i++) {
+ String target = routingTable[i];
+ int index = target.indexOf('/');
+ if (index == -1) {
+ addTarget(subset, targets, target);
} else {
- addTargetWithRouting(tmap, tv, t, j);
+ addTargetWithRouting(tmap, targets, target, index);
}
}
- return (tv.toArray(new Target[0]));
+ return (targets.toArray(new Target[0]));
}
/**
- * Check whether this is a valid node-to-node transfer
+ * Check whether this is a valid node-to-node transfer.
*
* @param credentials Credentials offered by the supposed node
* @param ip IP address the request came from
*/
public boolean isAnotherNode(String credentials, String ip) {
- IsFrom n = nodes.get(credentials);
- return (n != null && n.isFrom(ip));
+ IsFrom node = nodes.get(credentials);
+ return (node != null && node.isFrom(ip));
}
/**
* @param ip The requesting IP address
*/
public String isPublishPermitted(String feedid, String credentials, String ip) {
- Feed f = feeds.get(feedid);
+ Feed feed = feeds.get(feedid);
String nf = "Feed does not exist";
- if (f != null) {
- nf = f.status;
+ if (feed != null) {
+ nf = feed.status;
}
if (nf != null) {
return (nf);
}
- String user = f.authusers.get(credentials);
+ String user = feed.authusers.get(credentials);
if (user == null) {
return (PUBLISHER_NOT_PERMITTED);
}
- if (f.subnets.length == 0) {
+ if (feed.subnets.length == 0) {
return (null);
}
byte[] addr = NodeUtils.getInetAddress(ip);
- for (SubnetMatcher snm : f.subnets) {
+ for (SubnetMatcher snm : feed.subnets) {
if (snm.matches(addr)) {
return (null);
}
return (PUBLISHER_NOT_PERMITTED);
}
- /**
- * Check whether delete file is allowed.
- *
- * @param subId The ID of the subscription being requested.
- */
- public boolean isDeletePermitted(String subId) {
- ProvSubscription provSubscription = provSubscriptions.get(subId);
- return provSubscription.isPrivilegedSubscriber();
- }
-
/**
* Check whether publication is allowed for AAF Feed.
*
* @param ip The requesting IP address
*/
public String isPublishPermitted(String feedid, String ip) {
- Feed f = feeds.get(feedid);
+ Feed feed = feeds.get(feedid);
String nf = "Feed does not exist";
- if (f != null) {
- nf = f.status;
+ if (feed != null) {
+ nf = feed.status;
}
if (nf != null) {
return nf;
}
- if (f.subnets.length == 0) {
+ if (feed.subnets.length == 0) {
return null;
}
byte[] addr = NodeUtils.getInetAddress(ip);
- for (SubnetMatcher snm : f.subnets) {
+ for (SubnetMatcher snm : feed.subnets) {
if (snm.matches(addr)) {
return null;
}
}
/**
- * Get authenticated user
+ * Check whether delete file is allowed.
+ *
+ * @param subId The ID of the subscription being requested.
+ */
+ public boolean isDeletePermitted(String subId) {
+ ProvSubscription provSubscription = provSubscriptions.get(subId);
+ return provSubscription.isPrivilegedSubscriber();
+ }
+
+ /**
+ * Get authenticated user.
*/
public String getAuthUser(String feedid, String credentials) {
return (feeds.get(feedid).authusers.get(credentials));
}
/**
- * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID
+ * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID.
*
* @param feedid The ID of the feed specified
*/
public String getAafInstance(String feedid) {
- Feed f = feeds.get(feedid);
- return f.aafInstance;
+ Feed feed = feeds.get(feedid);
+ return feed.aafInstance;
}
/**
- * Check if the request should be redirected to a different ingress node
+ * Check if the request should be redirected to a different ingress node.
*/
public String getIngressNode(String feedid, String user, String ip) {
- Feed f = feeds.get(feedid);
- if (f.redirections.length == 0) {
+ Feed feed = feeds.get(feedid);
+ if (feed.redirections.length == 0) {
return (null);
}
byte[] addr = NodeUtils.getInetAddress(ip);
- for (Redirection r : f.redirections) {
+ for (Redirection r : feed.redirections) {
if ((r.user != null && !user.equals(r.user)) || (r.snm != null && !r.snm.matches(addr))) {
continue;
}
}
/**
- * Get a provisioned configuration parameter
+ * Get a provisioned configuration parameter.
*/
public String getProvParam(String name) {
return (params.get(name));
}
/**
- * Get all the DestInfos
+ * Get all the DestInfos.
*/
public DestInfo[] getAllDests() {
return (alldests);
}
/**
- * Get the targets for a feed
+ * Get the targets for a feed.
*
* @param feedid The feed ID
* @return The targets this feed should be delivered to
if (feedid == null) {
return (new Target[0]);
}
- Feed f = feeds.get(feedid);
- if (f == null) {
+ Feed feed = feeds.get(feedid);
+ if (feed == null) {
return (new Target[0]);
}
- return (f.targets);
+ return (feed.targets);
}
/**
- * Get the creation date for a feed
+ * Get the creation date for a feed.
*
* @param feedid The feed ID
* @return the timestamp of creation date of feed id passed
*/
public String getCreatedDate(String feedid) {
- Feed f = feeds.get(feedid);
- return (f.createdDate);
+ Feed feed = feeds.get(feedid);
+ return (feed.createdDate);
}
/**
- * Get the feed ID for a subscription
+ * Get the feed ID for a subscription.
*
* @param subid The subscription ID
* @return The feed ID
}
/**
- * Get the spool directory for a subscription
+ * Get the spool directory for a subscription.
*
* @param subid The subscription ID
* @return The spool directory
}
/**
- * Get the Authorization value this node uses
+ * Get the Authorization value this node uses.
*
* @return The Authorization header value for this node
*/
return !allfeeds.contains(feedId) || subinfo.get(subId) != null;
}
- private void addTargetWithRouting(HashMap<String, Target> tmap, ArrayList<Target> tv, String t, int j) {
- String node = t.substring(0, j);
- String rtg = t.substring(j + 1);
+ private void addTargetWithRouting(HashMap<String, Target> tmap, ArrayList<Target> targets, String target,
+ int index) {
+ String node = target.substring(0, index);
+ String rtg = target.substring(index + 1);
DestInfo di = nodeinfo.get(node);
if (di == null) {
- tv.add(new Target(null, t));
+ targets.add(new Target(null, target));
} else {
Target tt = tmap.get(node);
if (tt == null) {
tt = new Target(di, rtg);
tmap.put(node, tt);
- tv.add(tt);
+ targets.add(tt);
} else {
tt.addRouting(rtg);
}
}
}
- private void addTarget(HashSet<String> subset, ArrayList<Target> tv, String t) {
- DestInfo di = subinfo.get(t);
- if (di == null) {
- tv.add(new Target(null, t));
+ private void addTarget(HashSet<String> subset, ArrayList<Target> targets, String target) {
+ DestInfo destInfo = subinfo.get(target);
+ if (destInfo == null) {
+ targets.add(new Target(null, target));
} else {
- if (!subset.contains(t)) {
- subset.add(t);
- tv.add(new Target(di, null));
+ if (!subset.contains(target)) {
+ subset.add(target);
+ targets.add(new Target(destInfo, null));
}
}
}
/**
- * Raw configuration entry for a data router node
+ * Raw configuration entry for a data router node.
*/
public static class ProvNode {
}
/**
- * Get the cname of the node
+ * Get the cname of the node.
*/
public String getCName() {
return (cname);
}
/**
- * Raw configuration entry for a provisioning parameter
+ * Raw configuration entry for a provisioning parameter.
*/
public static class ProvParam {
* @param id The feed ID of the entry.
* @param logdata String for log entries about the entry.
* @param status The reason why this feed cannot be used (Feed has been deleted, Feed has been suspended) or
- * null if it is valid.
+ * null if it is valid.
*/
public ProvFeed(String id, String logdata, String status, String createdDate, String aafInstance) {
this.id = id;
private String credentials;
/**
- * Construct a feed user configuration entry
+ * Construct a feed user configuration entry.
*
* @param feedid The feed id.
* @param user The user that will publish to the feed.
}
/**
- * Raw configuration entry for a feed subnet
+ * Raw configuration entry for a feed subnet.
*/
public static class ProvFeedSubnet {
private String cidr;
/**
- * Construct a feed subnet configuration entry
+ * Construct a feed subnet configuration entry.
*
* @param feedid The feed ID
* @param cidr The CIDR allowed to publish to the feed.
}
/**
- * Raw configuration entry for a subscription
+ * Raw configuration entry for a subscription.
*/
public static class ProvSubscription {
private boolean decompress;
/**
- * Construct a subscription configuration entry
+ * Construct a subscription configuration entry.
*
* @param subid The subscription ID
* @param feedid The feed ID
* @param url The base delivery URL (not including the fileid)
* @param authuser The user in the credentials used to deliver
* @param credentials The credentials used to authenticate to the delivery URL exactly as they go in the
- * Authorization header.
+ * Authorization header.
* @param metaonly Is this a meta data only subscription?
* @param use100 Should we send Expect: 100-continue?
* @param privilegedSubscriber Can we wait to receive a delete file call before deleting file
}
/**
- * Get the subscription ID
+ * Get the subscription ID.
*/
public String getSubId() {
return (subid);
}
/**
- * Get the feed ID
+ * Get the feed ID.
*/
public String getFeedId() {
return (feedid);
}
/**
- * Get the delivery URL
+ * Get the delivery URL.
*/
public String getURL() {
return (url);
}
/**
- * Get the user
+ * Get the user.
*/
public String getAuthUser() {
return (authuser);
}
/**
- * Get the delivery credentials
+ * Get the delivery credentials.
*/
public String getCredentials() {
return (credentials);
}
/**
- * Is this a meta data only subscription?
+ * Is this a meta data only subscription.
*/
public boolean isMetaDataOnly() {
return (metaonly);
}
/**
- * Should we send Expect: 100-continue?
+ * Should we send Expect: 100-continue.
*/
public boolean isUsing100() {
return (use100);
}
/**
- * Can we wait to receive a delete file call before deleting file
+ * Can we wait to receive a delete file call before deleting file.
*/
public boolean isPrivilegedSubscriber() {
return (privilegedSubscriber);
}
/**
- * Should i decompress the file before sending it on
+ * Should I decompress the file before sending it on.
*/
public boolean isDecompress() {
return (decompress);
/**
* New field is added - FOLLOW_REDIRECTS feature iTrack:DATARTR-17 - 1706 Get the followRedirect of this
- * destination
+ * destination.
*/
boolean getFollowRedirect() {
return (followRedirect);
}
/**
- * Raw configuration entry for controlled ingress to the data router node
+ * Raw configuration entry for controlled ingress to the data router node.
*/
public static class ProvForceIngress {
private String[] nodes;
/**
- * Construct a forced ingress configuration entry
+ * Construct a forced ingress configuration entry.
*
* @param feedid The feed ID that this entry applies to
* @param subnet The CIDR for which publisher IP addresses this entry applies to or "" if it applies to all
- * publisher IP addresses
+ * publisher IP addresses
* @param user The publishing user this entry applies to or "" if it applies to all publishing users.
* @param nodes The array of FQDNs of the data router nodes to redirect publication attempts to.
*/
}
/**
- * Get the feed ID
+ * Get the feed ID.
*/
public String getFeedId() {
return (feedid);
}
/**
- * Get the subnet
+ * Get the subnet.
*/
public String getSubnet() {
return (subnet);
}
/**
- * Get the user
+ * Get the user.
*/
public String getUser() {
return (user);
}
/**
- * Get the node
+ * Get the node.
*/
public String[] getNodes() {
return (nodes);
}
/**
- * Raw configuration entry for controlled egress from the data router
+ * Raw configuration entry for controlled egress from the data router.
*/
public static class ProvForceEgress {
private String node;
/**
- * Construct a forced egress configuration entry
+ * Construct a forced egress configuration entry.
*
* @param subid The subscription ID the subscription with forced egress
* @param node The node handling deliveries for this subscription
}
/**
- * Get the subscription ID
+ * Get the subscription ID.
*/
public String getSubId() {
return (subid);
}
/**
- * Get the node
+ * Get the node.
*/
public String getNode() {
return (node);
}
/**
- * Raw configuration entry for routing within the data router network
+ * Raw configuration entry for routing within the data router network.
*/
public static class ProvHop {
private String via;
/**
- * Construct a hop entry
+ * Construct a hop entry.
*
* @param from The FQDN of the node with the data to be delivered
* @param to The FQDN of the node that will deliver to the subscriber
}
/**
- * A human readable description of this entry
+ * A human readable description of this entry.
*/
public String toString() {
return ("Hop " + from + "->" + to + " via " + via);
}
/**
- * Get the from node
+ * Get the from node.
*/
public String getFrom() {
return (from);
}
/**
- * Get the to node
+ * Get the to node.
*/
public String getTo() {
return (to);
}
/**
- * Get the next intermediate node
+ * Get the next intermediate node.
*/
public String getVia() {
return (via);
/**
* Maintain the configuration of a Data Router node
- * <p>
- * The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
+ *
+ * <p>The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
* subsystems to access configuration information.
- * <p>
- * There are two basic sets of configuration data. The static local configuration data, stored in a local configuration
- * file (created as part of installation by SWM), and the dynamic global configuration data fetched from the data router
- * provisioning server.
+ *
+ * <p>There are two basic sets of configuration data. The static local configuration data, stored in a local
+ * configuration file (created as part of installation by SWM), and the dynamic global configuration data fetched from
+ * the data router provisioning server.
*/
public class NodeConfigManager implements DeliveryQueueHelper {
/**
- * Initialize the configuration of a Data Router node
+ * Initialize the configuration of a Data Router node.
*/
private NodeConfigManager() {
gfport = Integer.parseInt(drNodeProperties.getProperty("IntHttpPort", "8080"));
svcport = Integer.parseInt(drNodeProperties.getProperty("IntHttpsPort", "8443"));
port = Integer.parseInt(drNodeProperties.getProperty("ExtHttpsPort", "443"));
- long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000"));
- long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000"));
spooldir = drNodeProperties.getProperty("SpoolDir", "spool");
File fdir = new File(spooldir + "/f");
fdir.mkdirs();
}
eelfLogger.info("NODE0304 My certificate says my name is " + myname);
pid = new PublishId(myname);
+ long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000"));
+ long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000"));
rdmgr = new RedirManager(redirfile, minrsinterval, timer);
pfetcher = new RateLimitedOperation(minpfinterval, timer) {
public void run() {
}
/**
- * Get the default node configuration manager
+ * Get the default node configuration manager.
*/
public static NodeConfigManager getInstance() {
return base;
private void fetchconfig() {
try {
eelfLogger.info("NodeConfigMan.fetchConfig: provurl:: " + provurl);
- Reader r = new InputStreamReader((new URL(provurl)).openStream());
- config = new NodeConfig(new ProvData(r), myname, spooldir, port, nak);
+ Reader reader = new InputStreamReader((new URL(provurl)).openStream());
+ config = new NodeConfig(new ProvData(reader), myname, spooldir, port, nak);
localconfig();
configtasks.startRun();
runTasks();
}
/**
- * Am I configured?
+ * Am I configured.
*/
public boolean isConfigured() {
return (config != null);
}
/**
- * Am I shut down?
+ * Am I shut down.
*/
public boolean isShutdown() {
return (quiesce.exists());
}
/**
- * Given a set of credentials and an IP address, is this request from another node?
+ * Given a set of credentials and an IP address, is this request from another node.
*
* @param credentials Credentials offered by the supposed node
* @param ip IP address the request came from
return (config.isPublishPermitted(feedid, credentials, ip));
}
- /**
- * Check whether delete file is allowed.
- *
- * @param subId The ID of the subscription being requested
- * @return True if the delete file is permitted for the subscriber.
- */
- public boolean isDeletePermitted(String subId) {
- return (config.isDeletePermitted(subId));
- }
-
/**
* Check whether publication is allowed for AAF Feed.
*
return (config.isPublishPermitted(feedid, ip));
}
+ /**
+ * Check whether delete file is allowed.
+ *
+ * @param subId The ID of the subscription being requested
+ * @return True if the delete file is permitted for the subscriber.
+ */
+ public boolean isDeletePermitted(String subId) {
+ return (config.isDeletePermitted(subId));
+ }
+
/**
* Check who the user is given the feed ID and the offered credentials.
*
}
/**
- * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID in NodeConfig
+ * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID in NodeConfig.
*
* @param feedid The ID of the feed specified
*/
return (config.getAafInstance(feedid));
}
+ public String getAafInstance() {
+ return aafInstance;
+ }
+
/**
* Check if the publish request should be sent to another node based on the feedid, user, and source IP address.
*
}
/**
- * Get a provisioned configuration parameter (from the provisioning server configuration)
+ * Get a provisioned configuration parameter (from the provisioning server configuration).
*
* @param name The name of the parameter
* @return The value of the parameter or null if it is not defined.
}
/**
- * Get a provisioned configuration parameter (from the provisioning server configuration)
+ * Get a provisioned configuration parameter (from the provisioning server configuration).
*
* @param name The name of the parameter
* @param defaultValue The value to use if the parameter is not defined
}
/**
- * Generate a publish ID
+ * Generate a publish ID.
*/
public String getPublishId() {
return (pid.next());
}
/**
- * Register a task to run whenever the configuration changes
+ * Register a task to run whenever the configuration changes.
*/
public void registerConfigTask(Runnable task) {
configtasks.addTask(task);
}
/**
- * Deregister a task to run whenever the configuration changes
+ * Deregister a task to run whenever the configuration changes.
*/
public void deregisterConfigTask(Runnable task) {
configtasks.removeTask(task);
}
/**
- * Is a destination redirected?
+ * Is a destination redirected.
*/
public boolean isDestRedirected(DestInfo destinfo) {
return (followredirects && rdmgr.isRedirected(destinfo.getSubId()));
}
/**
- * Set up redirection on receipt of a 3XX from a target URL
+ * Set up redirection on receipt of a 3XX from a target URL.
*/
public boolean handleRedirection(DestInfo destinationInfo, String redirto, String fileid) {
fileid = "/" + fileid;
}
/**
- * Set up redirection on receipt of a 3XX from a target URL
+ * Set up redirection on receipt of a 3XX from a target URL.
*/
public boolean handleRedirectionSubLevel(DeliveryTask task, DestInfo destinfo, String redirto, String fileid) {
fileid = "/" + fileid;
}
/**
- * Handle unreachable target URL
+ * Handle unreachable target URL.
*/
public void handleUnreachable(DestInfo destinationInfo) {
String subid = destinationInfo.getSubId();
}
/**
- * Get the timeout before retrying after an initial delivery failure
+ * Get the timeout before retrying after an initial delivery failure.
*/
public long getInitFailureTimer() {
return (initfailuretimer);
}
/**
- * Get the timeout before retrying after delivery and wait for file processing
+ * Get the timeout before retrying after delivery and wait for file processing.
*/
public long getWaitForFileProcessFailureTimer() {
return (waitForFileProcessFailureTimer);
}
/**
- * Get the maximum timeout between delivery attempts
+ * Get the maximum timeout between delivery attempts.
*/
public long getMaxFailureTimer() {
return (maxfailuretimer);
}
/**
- * Get the ratio between consecutive delivery attempts
+ * Get the ratio between consecutive delivery attempts.
*/
public double getFailureBackoff() {
return (failurebackoff);
}
/**
- * Get the expiration timer for deliveries
+ * Get the expiration timer for deliveries.
*/
public long getExpirationTimer() {
return (expirationtimer);
}
/**
- * Get the targets for a feed
+ * Get the targets for a feed.
*
* @param feedid The feed ID
* @return The targets this feed should be delivered to
}
/**
- * Get the creation date for a feed
+ * Get the creation date for a feed.
*
* @param feedid The feed ID
* @return the timestamp of creation date of feed id passed
}
/**
- * Get the spool directory for temporary files
+ * Get the spool directory for temporary files.
*/
public String getSpoolDir() {
return (spooldir + "/f");
}
/**
- * Get the base directory for spool directories
+ * Get the spool directory for a subscription.
+ */
+ public String getSpoolDir(String subid, String remoteaddr) {
+ if (provcheck.isFrom(remoteaddr)) {
+ String sdir = config.getSpoolDir(subid);
+ if (sdir != null) {
+ eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
+ + " from provisioning server " + remoteaddr);
+ } else {
+ eelfLogger.info("NODE0311 Received subscription reset request for unknown subscription " + subid
+ + " from provisioning server " + remoteaddr);
+ }
+ return (sdir);
+ } else {
+ eelfLogger.info("NODE0312 Received subscription reset request from unexpected server " + remoteaddr);
+ return (null);
+ }
+ }
+
+ /**
+ * Get the base directory for spool directories.
*/
public String getSpoolBase() {
return (spooldir);
}
/**
- * Get the key store type
+ * Get the key store type.
*/
public String getKSType() {
return (kstype);
}
/**
- * Get the key store file
+ * Get the key store file.
*/
public String getKSFile() {
return (ksfile);
}
/**
- * Get the key store password
+ * Get the key store password.
*/
public String getKSPass() {
return (kspass);
}
/**
- * Get the key password
+ * Get the key password.
*/
public String getKPass() {
return (kpass);
}
/**
- * Get the http port
+ * Get the http port.
*/
public int getHttpPort() {
return (gfport);
}
/**
- * Get the https port
+ * Get the https port.
*/
public int getHttpsPort() {
return (svcport);
}
/**
- * Get the externally visible https port
+ * Get the externally visible https port.
*/
public int getExtHttpsPort() {
return (port);
}
/**
- * Get the external name of this machine
+ * Get the external name of this machine.
*/
public String getMyName() {
return (myname);
}
/**
- * Get the number of threads to use for delivery
+ * Get the number of threads to use for delivery.
*/
public int getDeliveryThreads() {
return (deliverythreads);
}
/**
- * Get the URL for uploading the event log data
+ * Get the URL for uploading the event log data.
*/
public String getEventLogUrl() {
return (eventlogurl);
}
/**
- * Get the prefix for the names of event log files
+ * Get the prefix for the names of event log files.
*/
public String getEventLogPrefix() {
return (eventlogprefix);
}
/**
- * Get the suffix for the names of the event log files
+ * Get the suffix for the names of the event log files.
*/
public String getEventLogSuffix() {
return (eventlogsuffix);
}
/**
- * Get the interval between event log file rollovers
+ * Get the interval between event log file rollovers.
*/
public String getEventLogInterval() {
return (eventloginterval);
}
/**
- * Should I follow redirects from subscribers?
+ * Should I follow redirects from subscribers.
*/
public boolean isFollowRedirects() {
return (followredirects);
}
/**
- * Get the directory where the event and node log files live
+ * Get the directory where the event and node log files live.
*/
public String getLogDir() {
return (logdir);
}
/**
- * How long do I keep log files (in milliseconds)
+ * How long do I keep log files (in milliseconds).
*/
public long getLogRetention() {
return (logretention);
}
/**
- * Get the timer
+ * Get the timer.
*/
public Timer getTimer() {
return (timer);
}
/**
- * Get the feed ID for a subscription
+ * Get the feed ID for a subscription.
*
* @param subid The subscription ID
* @return The feed ID
}
/**
- * Get the authorization string this node uses
+ * Get the authorization string this node uses.
*
* @return The Authorization string for this node
*/
}
/**
- * Disable and enable protocols
+ * Disable and enable protocols.
*/
public String[] getEnabledprotocols() {
return enabledprotocols;
this.enabledprotocols = enabledprotocols.clone();
}
- /**
- * Get the spool directory for a subscription
- */
- public String getSpoolDir(String subid, String remoteaddr) {
- if (provcheck.isFrom(remoteaddr)) {
- String sdir = config.getSpoolDir(subid);
- if (sdir != null) {
- eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
- + " from provisioning server " + remoteaddr);
- } else {
- eelfLogger.info("NODE0311 Received subscription reset request for unknown subscription " + subid
- + " from provisioning server " + remoteaddr);
- }
- return (sdir);
- } else {
- eelfLogger.info("NODE0312 Received subscription reset request from unexpected server " + remoteaddr);
- return (null);
- }
- }
-
public String getAafType() {
return aafType;
}
this.aafType = aafType;
}
- public String getAafInstance() {
- return aafInstance;
- }
-
public void setAafInstance(String aafInstance) {
this.aafInstance = aafInstance;
}
}
/**
- * Builds the permissions string to be verified
+ * Builds the permissions string to be verified.
*
* @param aafInstance The aaf instance
* @return The permissions
package org.onap.dmaap.datarouter.node;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import org.onap.aaf.cadi.PropAccess;
/**
- * The main starting point for the Data Router node
+ * The main starting point for the Data Router node.
*/
public class NodeMain {
}
/**
- * Reset the retry timer for a subscription
+ * Reset the retry timer for a subscription.
*/
static void resetQueue(String subid, String ip) {
delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
/**
* Start the data router.
- * <p>
- * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties system
- * property. By default, it is "/opt/app/datartr/etc/node.properties".
+ *
+ * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
+ * system property. By default, it is "/opt/app/datartr/etc/node.properties".
*/
public static void main(String[] args) throws Exception {
nodeMainLogger.info("NODE0001 Data Router Node Starting");
sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
- //SP-6 : Fixes for SDV scan to exclude/remove DES/3DES ciphers are taken care by upgrading jdk in descriptor.xml
+ //SP-6: Fixes for SDV scan to exclude/remove DES/3DES
+ // ciphers are taken care by upgrading jdk in descriptor.xml
sslContextFactory.setExcludeCipherSuites(
"SSL_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
sslContextFactory.addExcludeProtocols("SSLv3");
sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
- nodeMainLogger.info("NODE00004 Unsupported protocols node server:-" +
- String.join(",", sslContextFactory.getExcludeProtocols()));
- nodeMainLogger.info("NODE00004 Supported protocols node server:-" +
- String.join(",", sslContextFactory.getIncludeProtocols()));
- nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-" +
- String.join(",", sslContextFactory.getExcludeCipherSuites()));
+ nodeMainLogger.info("NODE00004 Unsupported protocols node server:-"
+ + String.join(",", sslContextFactory.getExcludeProtocols()));
+ nodeMainLogger.info("NODE00004 Supported protocols node server:-"
+ + String.join(",", sslContextFactory.getIncludeProtocols()));
+ nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-"
+ + String.join(",", sslContextFactory.getExcludeCipherSuites()));
HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
httpsConfiguration.setRequestHeaderSize(8192);
server.start();
nodeMainLogger.info("NODE00006 Node Server started-" + server.getState());
} catch (Exception e) {
- nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable", e.getMessage());
+ nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
}
server.join();
nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState());
InputStream in = obj.getCadiProps();
cadiProperties.load(in);
} catch (IOException e1) {
- nodeMainLogger.error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage());
+ nodeMainLogger
+ .error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage(), e1);
}
cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
nodeMainLogger.info("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
import org.slf4j.MDC;
/**
- * Servlet for handling all http and https requests to the data router node
- * <p>
- * Handled requests are:
+ * Servlet for handling all http and https requests to the data router node.
+ *
+ * <p>Handled requests are:
* <br>
* GET http://<i>node</i>/internal/fetchProv - fetch the provisioning data
* <br>
}
/**
- * Get the NodeConfigurationManager
+ * Get the NodeConfigurationManager.
*/
@Override
public void init() {
}
/**
- * Handle a GET for /internal/fetchProv
+ * Handle a GET for /internal/fetchProv.
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
}
/**
- * Handle all PUT requests
+ * Handle all PUT requests.
*/
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
}
/**
- * Handle all DELETE requests
+ * Handle all DELETE requests.
*/
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
}
if (fileid.startsWith(PUBLISH)) {
fileid = fileid.substring(9);
- int i = fileid.indexOf('/');
- if (i == -1 || i == fileid.length() - 1) {
+ int index = fileid.indexOf('/');
+ if (index == -1 || index == fileid.length() - 1) {
eelfLogger.error("NODE0205 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
eelfLogger.info(EelfMsgs.EXIT);
return;
}
- feedid = fileid.substring(0, i);
+ feedid = fileid.substring(0, index);
if (config.getCadiEnabled()) {
String path = req.getPathInfo();
}
}
- fileid = fileid.substring(i + 1);
+ fileid = fileid.substring(index + 1);
pubid = config.getPublishId();
targets = config.getTargets(feedid);
} else if (fileid.startsWith(INTERNAL_PUBLISH)) {
while (hnames.hasMoreElements()) {
String hn = (String) hnames.nextElement();
String hnlc = hn.toLowerCase();
- if ((isput && ("content-type".equals(hnlc) ||
- "content-language".equals(hnlc) ||
- "content-md5".equals(hnlc) ||
- "content-range".equals(hnlc))) ||
- "x-dmaap-dr-meta".equals(hnlc) ||
- (feedid == null && "x-dmaap-dr-received".equals(hnlc)) ||
- (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
+ if ((isput && ("content-type".equals(hnlc)
+ || "content-language".equals(hnlc)
+ || "content-md5".equals(hnlc)
+ || "content-range".equals(hnlc)))
+ || "x-dmaap-dr-meta".equals(hnlc)
+ || (feedid == null && "x-dmaap-dr-received".equals(hnlc))
+ || (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
Enumeration hvals = req.getHeaders(hn);
while (hvals.hasMoreElements()) {
String hv = (String) hvals.nextElement();
private String writeInputStreamToFile(HttpServletRequest req, File data) {
byte[] buf = new byte[1024 * 1024];
- int i;
+ int bytesRead;
try (OutputStream dos = new FileOutputStream(data);
InputStream is = req.getInputStream()) {
- while ((i = is.read(buf)) > 0) {
- dos.write(buf, 0, i);
+ while ((bytesRead = is.read(buf)) > 0) {
+ dos.write(buf, 0, bytesRead);
}
} catch (IOException ioe) {
eelfLogger.error("NODE0530 Exception common: " + ioe, ioe);
final String FROM_DR_MESSAGE = ".M) from DR Node: ";
try {
fileid = fileid.substring(8);
- int i = fileid.indexOf('/');
- if (i == -1 || i == fileid.length() - 1) {
+ int index = fileid.indexOf('/');
+ if (index == -1 || index == fileid.length() - 1) {
eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + FROM + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
eelfLogger.info(EelfMsgs.EXIT);
return;
}
- String subscriptionId = fileid.substring(0, i);
+ String subscriptionId = fileid.substring(0, index);
int subId = Integer.parseInt(subscriptionId);
- pubid = fileid.substring(i + 1);
+ pubid = fileid.substring(index + 1);
String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
+ config.getMyName() + ".";
int subIdDir = subId - (subId % 100);
return false;
}
} catch (NullPointerException npe) {
- eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId +
- " does not exist", npe);
+ eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId
+ + " does not exist", npe);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
eelfLogger.info(EelfMsgs.EXIT);
return false;
import org.slf4j.MDC;
/**
- * Utility functions for the data router node
+ * Utility functions for the data router node.
*/
public class NodeUtils {
}
/**
- * Base64 encode a byte array
+ * Base64 encode a byte array.
*
* @param raw The bytes to be encoded
* @return The encoded string
}
/**
- * Given a user and password, generate the credentials
+ * Given a user and password, generate the credentials.
*
* @param user User name
* @param password User password
}
/**
- * Given a node name, generate the credentials
+ * Given a node name, generate the credentials.
*
* @param node Node name
*/
}
/**
- * Given a string representation of an IP address, get the corresponding byte array
+ * Given a string representation of an IP address, get the corresponding byte array.
*
* @param ip The IP address as a string
* @return The IP address as a byte array or null if the address is invalid
}
/**
- * Given a uri with parameters, split out the feed ID and file ID
+ * Given a uri with parameters, split out the feed ID and file ID.
*/
public static String[] getFeedAndFileID(String uriandparams) {
int end = uriandparams.length();
- int i = uriandparams.indexOf('#');
- if (i != -1 && i < end) {
- end = i;
+ int index = uriandparams.indexOf('#');
+ if (index != -1 && index < end) {
+ end = index;
}
- i = uriandparams.indexOf('?');
- if (i != -1 && i < end) {
- end = i;
+ index = uriandparams.indexOf('?');
+ if (index != -1 && index < end) {
+ end = index;
}
end = uriandparams.lastIndexOf('/', end);
if (end < 2) {
return (null);
}
- i = uriandparams.lastIndexOf('/', end - 1);
- if (i == -1) {
+ index = uriandparams.lastIndexOf('/', end - 1);
+ if (index == -1) {
return (null);
}
- return (new String[]{uriandparams.substring(i + 1, end), uriandparams.substring(end + 1)});
+ return (new String[]{uriandparams.substring(index + 1, end), uriandparams.substring(end + 1)});
}
/**
* Escape fields that might contain vertical bar, backslash, or newline by replacing them with backslash p,
* backslash e and backslash n.
*/
- public static String loge(String s) {
- if (s == null) {
- return (s);
+ public static String loge(String string) {
+ if (string == null) {
+ return (string);
}
- return (s.replaceAll("\\\\", "\\\\e").replaceAll("\\|", "\\\\p").replaceAll("\n", "\\\\n"));
+ return (string.replaceAll("\\\\", "\\\\e").replaceAll("\\|", "\\\\p").replaceAll("\n", "\\\\n"));
}
/**
* Undo what loge does.
*/
- public static String unloge(String s) {
- if (s == null) {
- return (s);
+ public static String unloge(String string) {
+ if (string == null) {
+ return (string);
}
- return (s.replaceAll("\\\\p", "\\|").replaceAll("\\\\n", "\n").replaceAll("\\\\e", "\\\\"));
+ return (string.replaceAll("\\\\p", "\\|").replaceAll("\\\\n", "\n").replaceAll("\\\\e", "\\\\"));
}
/**
return (logDate.format(when));
}
- /* Method prints method name, server FQDN and IP Address of the machine in EELF logs
- * @Method - setIpAndFqdnForEelf - Rally:US664892
- * @Params - method, prints method name in EELF log.
+ /** Method prints method name, server FQDN and IP Address of the machine in EELF logs.
+ *
+ * @param method Prints method name in EELF log.
*/
public static void setIpAndFqdnForEelf(String method) {
MDC.clear();
}
- /* Method sets RequestIs and InvocationId for se in EELF logs
- * @Method - setIpAndFqdnForEelf
- * @Params - Req, Request used to get RequestId and InvocationId
+ /** Method sets RequestIs and InvocationId for se in EELF logs.
+ *
+ * @param req Request used to get RequestId and InvocationId.
*/
public static void setRequestIdAndInvocationId(HttpServletRequest req) {
String reqId = req.getHeader("X-ONAP-RequestID");
MDC.put("InvocationId", invId);
}
+ /**
+ * Sends error as response with error code input.
+ */
public static void sendResponseError(HttpServletResponse response, int errorCode, EELFLogger intlogger) {
try {
response.sendError(errorCode);
}
/**
- * Method to check to see if file is of type gzip
+ * Method to check to see if file is of type gzip.
*
* @param file The name of the file to be checked
* @return True if the file is of type gzip
private static String getNameFromSubject(KeyStore ks, Enumeration<String> aliases) throws KeyStoreException {
- String s = aliases.nextElement();
- if (ks.entryInstanceOf(s, KeyStore.PrivateKeyEntry.class)) {
- X509Certificate c = (X509Certificate) ks.getCertificate(s);
- if (c != null) {
- String subject = c.getSubjectX500Principal().getName();
+ String alias = aliases.nextElement();
+ if (ks.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
+ X509Certificate cert = (X509Certificate) ks.getCertificate(alias);
+ if (cert != null) {
+ String subject = cert.getSubjectX500Principal().getName();
String[] parts = subject.split(",");
if (parts.length < 1) {
return null;
/**
* Given a set of node names and next hops, identify and ignore any cycles and figure out the sequence of next hops to
- * get from this node to any other node
+ * get from this node to any other node.
*/
public class PathFinder {
ht.put(n, new HashMap<>());
}
for (NodeConfig.ProvHop ph : hops) {
- Hop h = getHop(known, ht, ph);
- if (h == null) {
+ Hop hop = getHop(known, ht, ph);
+ if (hop == null) {
continue;
}
if (ph.getVia().equals(ph.getTo())) {
errors.add(ph + " gives destination as via");
- h.bad = true;
+ hop.bad = true;
}
}
for (String n : known) {
}
/**
- * Get list of errors encountered while finding paths
+ * Get list of errors encountered while finding paths.
*
* @return array of error descriptions
*/
}
/**
- * Get the route from this node to the specified node
+ * Get the route from this node to the specified node.
*
* @param destination node
* @return list of node names separated by and ending with "/"
return (to);
}
nh.mark = true;
- String x = plot(nh.basis.getVia(), to, info);
+ String route = plot(nh.basis.getVia(), to, info);
nh.mark = false;
if (nh.bad) {
return (to);
}
- return (nh.basis.getVia() + "/" + x);
+ return (nh.basis.getVia() + "/" + route);
}
@Nullable
return null;
}
HashMap<String, Hop> ht2 = ht.get(ph.getTo());
- Hop h = ht2.get(ph.getFrom());
- if (h != null) {
- h.bad = true;
- errors.add(ph + " gives duplicate next hop - previous via was " + h.basis.getVia());
+ Hop hop = ht2.get(ph.getFrom());
+ if (hop != null) {
+ hop.bad = true;
+ errors.add(ph + " gives duplicate next hop - previous via was " + hop.basis.getVia());
return null;
}
- h = new Hop();
- h.basis = ph;
- ht2.put(ph.getFrom(), h);
+ hop = new Hop();
+ hop.basis = ph;
+ ht2.put(ph.getFrom(), hop);
if (!known.contains(ph.getVia())) {
errors.add(ph + " references unknown via node");
- h.bad = true;
+ hop.bad = true;
return null;
}
- return h;
+ return hop;
}
private static class Hop {
package org.onap.dmaap.datarouter.node;\r
\r
/**\r
- * FORTIFY SCAN FIXES\r
+ * FORTIFY SCAN FIXES.\r
* <p>This Utility is used for Fortify fixes. It Validates the path url formed from\r
* the string passed in the request parameters.</p>\r
*/\r
/**\r
* This method takes String as the parameter and return the filtered path string.\r
*\r
- * @param aString String to clean\r
+ * @param string String to clean\r
* @return A cleaned String\r
*/\r
- static String cleanString(String aString) {\r
- if (aString == null) {\r
+ static String cleanString(String string) {\r
+ if (string == null) {\r
return null;\r
}\r
StringBuilder cleanString = new StringBuilder();\r
- for (int i = 0; i < aString.length(); ++i) {\r
- cleanString.append(cleanChar(aString.charAt(i)));\r
+ for (int i = 0; i < string.length(); ++i) {\r
+ cleanString.append(cleanChar(string.charAt(i)));\r
}\r
return cleanString.toString();\r
}\r
/**\r
* This method filters the valid special characters in path string.\r
*\r
- * @param aChar The char to be cleaned\r
+ * @param character The char to be cleaned\r
* @return The cleaned char\r
*/\r
- private static char cleanChar(char aChar) {\r
+ private static char cleanChar(char character) {\r
// 0 - 9\r
for (int i = 48; i < 58; ++i) {\r
- if (aChar == i) {\r
+ if (character == i) {\r
return (char) i;\r
}\r
}\r
// 'A' - 'Z'\r
for (int i = 65; i < 91; ++i) {\r
- if (aChar == i) {\r
+ if (character == i) {\r
return (char) i;\r
}\r
}\r
// 'a' - 'z'\r
for (int i = 97; i < 123; ++i) {\r
- if (aChar == i) {\r
+ if (character == i) {\r
return (char) i;\r
}\r
}\r
- return getValidCharacter(aChar);\r
+ return getValidCharacter(character);\r
}\r
\r
- private static char getValidCharacter(char aChar) {\r
+ private static char getValidCharacter(char character) {\r
// other valid characters\r
- switch (aChar) {\r
+ switch (character) {\r
case '/':\r
return '/';\r
case '.':\r
/**
* Parser for provisioning data from the provisioning server.
- * <p>
- * The ProvData class uses a Reader for the text configuration from the provisioning server to construct arrays of raw
- * configuration entries.
+ *
+ * <p>The ProvData class uses a Reader for the text configuration from the provisioning server to construct arrays of
+ * raw configuration entries.
*/
public class ProvData {
private static final String FEED_ID = "feedid";
private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(ProvData.class);
- private NodeConfig.ProvNode[] provNodes;
- private NodeConfig.ProvParam[] provParams;
- private NodeConfig.ProvFeed[] provFeeds;
- private NodeConfig.ProvFeedUser[] provFeedUsers;
- private NodeConfig.ProvFeedSubnet[] provFeedSubnets;
- private NodeConfig.ProvSubscription[] provSubscriptions;
- private NodeConfig.ProvForceIngress[] provForceIngresses;
- private NodeConfig.ProvForceEgress[] provForceEgresses;
- private NodeConfig.ProvHop[] provHops;
+ private NodeConfig.ProvNode[] pn;
+ private NodeConfig.ProvParam[] pp;
+ private NodeConfig.ProvFeed[] pf;
+ private NodeConfig.ProvFeedUser[] pfu;
+ private NodeConfig.ProvFeedSubnet[] pfsn;
+ private NodeConfig.ProvSubscription[] ps;
+ private NodeConfig.ProvForceIngress[] pfi;
+ private NodeConfig.ProvForceEgress[] pfe;
+ private NodeConfig.ProvHop[] ph;
/**
* Construct raw provisioing data entries from the text (JSON) provisioning document received from the provisioning
- * server
+ * server.
*
- * @param r The reader for the JSON text.
+ * @param reader The reader for the JSON text.
*/
- public ProvData(Reader r) throws IOException {
- ArrayList<ProvNode> provNodes1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvParam> provParams1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvFeed> provFeeds1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvFeedUser> provFeedUsers1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvFeedSubnet> provFeedSubnets1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvSubscription> provSubscriptions1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvForceIngress> provForceIngresses1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvForceEgress> provForceEgresses1 = new ArrayList<>();
- ArrayList<NodeConfig.ProvHop> provHops1 = new ArrayList<>();
+ public ProvData(Reader reader) throws IOException {
+ ArrayList<ProvNode> pnv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvParam> ppv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvFeed> pfv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvFeedUser> pfuv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvFeedSubnet> pfsnv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvSubscription> psv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvForceIngress> pfiv = new ArrayList<>();
+ ArrayList<NodeConfig.ProvForceEgress> pfev = new ArrayList<>();
+ ArrayList<NodeConfig.ProvHop> phv = new ArrayList<>();
try {
- JSONTokener jtx = new JSONTokener(r);
+ JSONTokener jtx = new JSONTokener(reader);
JSONObject jcfg = new JSONObject(jtx);
char c = jtx.nextClean();
if (c != '\0') {
throw new JSONException("Spurious characters following configuration");
}
- r.close();
- addJSONFeeds(provFeeds1, provFeedUsers1, provFeedSubnets1, jcfg);
- addJSONSubs(provSubscriptions1, jcfg);
- addJSONParams(provNodes1, provParams1, jcfg);
- addJSONRoutingInformation(provForceIngresses1, provForceEgresses1, provHops1, jcfg);
+ reader.close();
+ addJSONFeeds(pfv, pfuv, pfsnv, jcfg);
+ addJSONSubs(psv, jcfg);
+ addJSONParams(pnv, ppv, jcfg);
+ addJSONRoutingInformation(pfiv, pfev, phv, jcfg);
} catch (JSONException jse) {
NodeUtils.setIpAndFqdnForEelf("ProvData");
eelfLogger.error(EelfMsgs.MESSAGE_PARSING_ERROR, jse.toString());
.error("NODE0201 Error parsing configuration data from provisioning server " + jse.toString(), jse);
throw new IOException(jse.toString(), jse);
}
- provNodes = provNodes1.toArray(new NodeConfig.ProvNode[provNodes1.size()]);
- provParams = provParams1.toArray(new NodeConfig.ProvParam[provParams1.size()]);
- provFeeds = provFeeds1.toArray(new NodeConfig.ProvFeed[provFeeds1.size()]);
- provFeedUsers = provFeedUsers1.toArray(new NodeConfig.ProvFeedUser[provFeedUsers1.size()]);
- provFeedSubnets = provFeedSubnets1.toArray(new NodeConfig.ProvFeedSubnet[provFeedSubnets1.size()]);
- provSubscriptions = provSubscriptions1.toArray(new NodeConfig.ProvSubscription[provSubscriptions1.size()]);
- provForceIngresses = provForceIngresses1.toArray(new NodeConfig.ProvForceIngress[provForceIngresses1.size()]);
- provForceEgresses = provForceEgresses1.toArray(new NodeConfig.ProvForceEgress[provForceEgresses1.size()]);
- provHops = provHops1.toArray(new NodeConfig.ProvHop[provHops1.size()]);
+ pn = pnv.toArray(new NodeConfig.ProvNode[pnv.size()]);
+ pp = ppv.toArray(new NodeConfig.ProvParam[ppv.size()]);
+ pf = pfv.toArray(new NodeConfig.ProvFeed[pfv.size()]);
+ pfu = pfuv.toArray(new NodeConfig.ProvFeedUser[pfuv.size()]);
+ pfsn = pfsnv.toArray(new NodeConfig.ProvFeedSubnet[pfsnv.size()]);
+ ps = psv.toArray(new NodeConfig.ProvSubscription[psv.size()]);
+ pfi = pfiv.toArray(new NodeConfig.ProvForceIngress[pfiv.size()]);
+ pfe = pfev.toArray(new NodeConfig.ProvForceEgress[pfev.size()]);
+ ph = phv.toArray(new NodeConfig.ProvHop[phv.size()]);
}
- private static String[] gvasa(JSONObject o, String key) {
- return (gvasa(o.opt(key)));
+ private static String[] gvasa(JSONObject object, String key) {
+ return (gvasa(object.opt(key)));
}
- private static String[] gvasa(Object o) {
- if (o instanceof JSONArray) {
- JSONArray a = (JSONArray) o;
- ArrayList<String> v = new ArrayList<>();
- for (int i = 0; i < a.length(); i++) {
- String s = gvas(a, i);
- if (s != null) {
- v.add(s);
+ private static String[] gvasa(Object object) {
+ if (object instanceof JSONArray) {
+ JSONArray jsonArray = (JSONArray) object;
+ ArrayList<String> array = new ArrayList<>();
+ for (int i = 0; i < jsonArray.length(); i++) {
+ String string = gvas(jsonArray, i);
+ if (string != null) {
+ array.add(string);
}
}
- return (v.toArray(new String[v.size()]));
+ return (array.toArray(new String[array.size()]));
} else {
- String s = gvas(o);
- if (s == null) {
+ String string = gvas(object);
+ if (string == null) {
return (new String[0]);
} else {
- return (new String[]{s});
+ return (new String[]{string});
}
}
}
- private static String gvas(JSONArray a, int index) {
- return (gvas(a.get(index)));
+ private static String gvas(JSONArray array, int index) {
+ return (gvas(array.get(index)));
}
- private static String gvas(JSONObject o, String key) {
- return (gvas(o.opt(key)));
+ private static String gvas(JSONObject object, String key) {
+ return (gvas(object.opt(key)));
}
- private static String gvas(Object o) {
- if (o instanceof Boolean || o instanceof Number || o instanceof String) {
- return (o.toString());
+ private static String gvas(Object object) {
+ if (object instanceof Boolean || object instanceof Number || object instanceof String) {
+ return (object.toString());
}
return (null);
}
* Get the raw node configuration entries
*/
public NodeConfig.ProvNode[] getNodes() {
- return (provNodes);
+ return (pn);
}
/**
- * Get the raw parameter configuration entries
+ * Get the raw parameter configuration entries.
*/
public NodeConfig.ProvParam[] getParams() {
- return (provParams);
+ return (pp);
}
/**
- * Ge the raw feed configuration entries
+ * Ge the raw feed configuration entries.
*/
public NodeConfig.ProvFeed[] getFeeds() {
- return (provFeeds);
+ return (pf);
}
/**
- * Get the raw feed user configuration entries
+ * Get the raw feed user configuration entries.
*/
public NodeConfig.ProvFeedUser[] getFeedUsers() {
- return (provFeedUsers);
+ return (pfu);
}
/**
- * Get the raw feed subnet configuration entries
+ * Get the raw feed subnet configuration entries.
*/
public NodeConfig.ProvFeedSubnet[] getFeedSubnets() {
- return (provFeedSubnets);
+ return (pfsn);
}
/**
- * Get the raw subscription entries
+ * Get the raw subscription entries.
*/
public NodeConfig.ProvSubscription[] getSubscriptions() {
- return (provSubscriptions);
+ return (ps);
}
/**
- * Get the raw forced ingress entries
+ * Get the raw forced ingress entries.
*/
public NodeConfig.ProvForceIngress[] getForceIngress() {
- return (provForceIngresses);
+ return (pfi);
}
/**
- * Get the raw forced egress entries
+ * Get the raw forced egress entries.
*/
public NodeConfig.ProvForceEgress[] getForceEgress() {
- return (provForceEgresses);
+ return (pfe);
}
/**
- * Get the raw next hop entries
+ * Get the raw next hop entries.
*/
public NodeConfig.ProvHop[] getHops() {
- return (provHops);
+ return (ph);
}
@Nullable
return stat;
}
- private void addJSONFeeds(ArrayList<ProvFeed> provFeeds1, ArrayList<ProvFeedUser> provFeedUsers1,
- ArrayList<ProvFeedSubnet> provFeedSubnets1,
- JSONObject jsonConfig) {
- JSONArray jfeeds = jsonConfig.optJSONArray("feeds");
+ private void addJSONFeeds(ArrayList<ProvFeed> pfv, ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv,
+ JSONObject jcfg) {
+ JSONArray jfeeds = jcfg.optJSONArray("feeds");
if (jfeeds != null) {
for (int fx = 0; fx < jfeeds.length(); fx++) {
- addJSONFeed(provFeeds1, provFeedUsers1, provFeedSubnets1, jfeeds, fx);
+ addJSONFeed(pfv, pfuv, pfsnv, jfeeds, fx);
}
}
}
- private void addJSONFeed(ArrayList<ProvFeed> provFeeds1, ArrayList<ProvFeedUser> provFeedUsers1,
- ArrayList<ProvFeedSubnet> provFeedSubnets1, JSONArray jfeeds, int feedIndex) {
- JSONObject jfeed = jfeeds.getJSONObject(feedIndex);
+ private void addJSONFeed(ArrayList<ProvFeed> pfv, ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv,
+ JSONArray jfeeds, int fx) {
+ JSONObject jfeed = jfeeds.getJSONObject(fx);
String stat = getFeedStatus(jfeed);
String fid = gvas(jfeed, FEED_ID);
String fname = gvas(jfeed, "name");
* Passing aafInstance to ProvFeed from feeds json passed by prov to identify legacy/AAF feeds
*/
String aafInstance = gvas(jfeed, "aaf_instance");
- provFeeds1.add(new ProvFeed(fid, fname + "//" + fver, stat, createdDate, aafInstance));
+ pfv.add(new ProvFeed(fid, fname + "//" + fver, stat, createdDate, aafInstance));
/*
* END - AAF changes
*/
- addJSONFeedAuthArrays(provFeedUsers1, provFeedSubnets1, jfeed, fid);
+ addJSONFeedAuthArrays(pfuv, pfsnv, jfeed, fid);
}
- private void addJSONFeedAuthArrays(ArrayList<ProvFeedUser> provFeedUsers1,
- ArrayList<ProvFeedSubnet> provFeedSubnets1, JSONObject jfeed, String fid) {
+ private void addJSONFeedAuthArrays(ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv, JSONObject jfeed,
+ String fid) {
JSONObject jauth = jfeed.optJSONObject("authorization");
if (jauth == null) {
return;
JSONObject ju = jeids.getJSONObject(ux);
String login = gvas(ju, "id");
String password = gvas(ju, "password");
- provFeedUsers1.add(new ProvFeedUser(fid, login, NodeUtils.getAuthHdr(login, password)));
+ pfuv.add(new ProvFeedUser(fid, login, NodeUtils.getAuthHdr(login, password)));
}
}
JSONArray jeips = jauth.optJSONArray("endpoint_addrs");
if (jeips != null) {
for (int ix = 0; ix < jeips.length(); ix++) {
String sn = gvas(jeips, ix);
- provFeedSubnets1.add(new ProvFeedSubnet(fid, sn));
+ pfsnv.add(new ProvFeedSubnet(fid, sn));
}
}
}
- private void addJSONSubs(ArrayList<ProvSubscription> provSubscriptions1, JSONObject jsonConfig) {
- JSONArray jsubs = jsonConfig.optJSONArray("subscriptions");
+ private void addJSONSubs(ArrayList<ProvSubscription> psv, JSONObject jcfg) {
+ JSONArray jsubs = jcfg.optJSONArray("subscriptions");
if (jsubs != null) {
for (int sx = 0; sx < jsubs.length(); sx++) {
- addJSONSub(provSubscriptions1, jsubs, sx);
+ addJSONSub(psv, jsubs, sx);
}
}
}
- private void addJSONSub(ArrayList<ProvSubscription> provSubscriptions1, JSONArray jsubs, int sx) {
+ private void addJSONSub(ArrayList<ProvSubscription> psv, JSONArray jsubs, int sx) {
JSONObject jsub = jsubs.getJSONObject(sx);
if (jsub.optBoolean("suspend", false)) {
return;
boolean privilegedSubscriber = jsub.getBoolean("privilegedSubscriber");
boolean decompress = jsub.getBoolean("decompress");
boolean followRedirect = jsub.getBoolean("follow_redirect");
- provSubscriptions1
- .add(new ProvSubscription(sid, fid, delurl, id, NodeUtils.getAuthHdr(id, password), monly, use100,
- privilegedSubscriber, followRedirect, decompress));
+ psv.add(new ProvSubscription(sid, fid, delurl, id, NodeUtils.getAuthHdr(id, password), monly, use100,
+ privilegedSubscriber, followRedirect, decompress));
}
- private void addJSONParams(ArrayList<ProvNode> provNodes1, ArrayList<ProvParam> provParams1,
- JSONObject jsonconfig) {
- JSONObject jparams = jsonconfig.optJSONObject("parameters");
+ private void addJSONParams(ArrayList<ProvNode> pnv, ArrayList<ProvParam> ppv, JSONObject jcfg) {
+ JSONObject jparams = jcfg.optJSONObject("parameters");
if (jparams != null) {
for (String pname : JSONObject.getNames(jparams)) {
- addJSONParam(provParams1, jparams, pname);
+ addJSONParam(ppv, jparams, pname);
}
- addJSONNodesToParams(provNodes1, jparams);
+ addJSONNodesToParams(pnv, jparams);
}
}
- private void addJSONParam(ArrayList<ProvParam> provParams1, JSONObject jparams, String pname) {
+ private void addJSONParam(ArrayList<ProvParam> ppv, JSONObject jparams, String pname) {
String pvalue = gvas(jparams, pname);
if (pvalue != null) {
- provParams1.add(new ProvParam(pname, pvalue));
+ ppv.add(new ProvParam(pname, pvalue));
}
}
- private void addJSONNodesToParams(ArrayList<ProvNode> provNodes1, JSONObject jparams) {
+ private void addJSONNodesToParams(ArrayList<ProvNode> pnv, JSONObject jparams) {
String sfx = gvas(jparams, "PROV_DOMAIN");
JSONArray jnodes = jparams.optJSONArray("NODES");
if (jnodes != null) {
for (int nx = 0; nx < jnodes.length(); nx++) {
String nn = gvas(jnodes, nx);
- if (nn == null) {
- continue;
- }
if (nn.indexOf('.') == -1) {
nn = nn + "." + sfx;
}
- provNodes1.add(new ProvNode(nn));
+ pnv.add(new ProvNode(nn));
}
}
}
- private void addJSONRoutingInformation(ArrayList<ProvForceIngress> provForceIngresses1,
- ArrayList<ProvForceEgress> provForceEgresses1, ArrayList<ProvHop> provHops1, JSONObject jsonConfig) {
- JSONArray jingresses = jsonConfig.optJSONArray("ingress");
+ private void addJSONRoutingInformation(ArrayList<ProvForceIngress> pfiv, ArrayList<ProvForceEgress> pfev,
+ ArrayList<ProvHop> phv, JSONObject jcfg) {
+ JSONArray jingresses = jcfg.optJSONArray("ingress");
if (jingresses != null) {
for (int fx = 0; fx < jingresses.length(); fx++) {
- addJSONIngressRoute(provForceIngresses1, jingresses, fx);
+ addJSONIngressRoute(pfiv, jingresses, fx);
}
}
- JSONObject jegresses = jsonConfig.optJSONObject("egress");
+ JSONObject jegresses = jcfg.optJSONObject("egress");
if (jegresses != null && JSONObject.getNames(jegresses) != null) {
for (String esid : JSONObject.getNames(jegresses)) {
- addJSONEgressRoute(provForceEgresses1, jegresses, esid);
+ addJSONEgressRoute(pfev, jegresses, esid);
}
}
- JSONArray jhops = jsonConfig.optJSONArray("routing");
+ JSONArray jhops = jcfg.optJSONArray("routing");
if (jhops != null) {
for (int fx = 0; fx < jhops.length(); fx++) {
- addJSONRoutes(provHops1, jhops, fx);
+ addJSONRoutes(phv, jhops, fx);
}
}
}
- private void addJSONIngressRoute(ArrayList<ProvForceIngress> provForceIngresses1, JSONArray jingresses, int fx) {
+ private void addJSONIngressRoute(ArrayList<ProvForceIngress> pfiv, JSONArray jingresses, int fx) {
JSONObject jingress = jingresses.getJSONObject(fx);
String fid = gvas(jingress, FEED_ID);
String subnet = gvas(jingress, "subnet");
String user = gvas(jingress, "user");
- String[] nodes = gvasa(jingress, "node");
if (fid == null || "".equals(fid)) {
return;
}
if ("".equals(user)) {
user = null;
}
- provForceIngresses1.add(new ProvForceIngress(fid, subnet, user, nodes));
+ String[] nodes = gvasa(jingress, "node");
+ pfiv.add(new ProvForceIngress(fid, subnet, user, nodes));
}
- private void addJSONEgressRoute(ArrayList<ProvForceEgress> provForceEgresses1, JSONObject jegresses, String esid) {
+ private void addJSONEgressRoute(ArrayList<ProvForceEgress> pfev, JSONObject jegresses, String esid) {
String enode = gvas(jegresses, esid);
if (esid != null && enode != null && !"".equals(esid) && !"".equals(enode)) {
- provForceEgresses1.add(new ProvForceEgress(esid, enode));
+ pfev.add(new ProvForceEgress(esid, enode));
}
}
- private void addJSONRoutes(ArrayList<ProvHop> provHops1, JSONArray jhops, int fx) {
+ private void addJSONRoutes(ArrayList<ProvHop> phv, JSONArray jhops, int fx) {
JSONObject jhop = jhops.getJSONObject(fx);
String from = gvas(jhop, "from");
String to = gvas(jhop, "to");
if (from == null || to == null || via == null || "".equals(from) || "".equals(to) || "".equals(via)) {
return;
}
- provHops1.add(new ProvHop(from, to, via));
+ phv.add(new ProvHop(from, to, via));
}
}
package org.onap.dmaap.datarouter.node;
/**
- * Generate publish IDs
+ * Generate publish IDs.
*/
public class PublishId {
private String myname;
/**
- * Generate publish IDs for the specified name
+ * Generate publish IDs for the specified name.
*
* @param myname Unique identifier for this publish ID generator (usually fqdn of server)
*/
import java.util.TimerTask;
/**
- * Execute an operation no more frequently than a specified interval
+ * Execute an operation no more frequently than a specified interval.
*/
public abstract class RateLimitedOperation implements Runnable {
private long mininterval;
/**
- * Create a rate limited operation
+ * Create a rate limited operation.
*
* @param mininterval The minimum number of milliseconds after the last execution starts before a new execution can
- * begin
+ * begin
* @param timer The timer used to perform deferred executions
*/
public RateLimitedOperation(long mininterval, Timer timer) {
}
/**
- * Request that the operation be performed by this thread or at a later time by the timer
+ * Request that the operation be performed by this thread or at a later time by the timer.
*/
public void request() {
if (premark()) {
}
do {
run();
- } while (demark());
+ }
+ while (demark());
}
private synchronized boolean premark() {
import java.util.Timer;
/**
- * Track redirections of subscriptions
+ * Track redirections of subscriptions.
*/
public class RedirManager {
try {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : sid2primary.entrySet()) {
- String s = entry.getKey();
+ String key = entry.getKey();
String value = entry.getValue();
- sb.append(s).append(' ').append(value).append(' ')
- .append(sid2secondary.get(s)).append('\n');
+ sb.append(key).append(' ').append(value).append(' ')
+ .append(sid2secondary.get(key)).append('\n');
}
try (OutputStream os = new FileOutputStream(RedirManager.this.redirfile)) {
os.write(sb.toString().getBytes());
}
};
try {
- String s;
+ String line;
try (BufferedReader br = new BufferedReader(new FileReader(redirfile))) {
- while ((s = br.readLine()) != null) {
- addSubRedirInfo(s);
+ while ((line = br.readLine()) != null) {
+ addSubRedirInfo(line);
}
}
} catch (Exception e) {
}
/**
- * Is a subscription redirected?
+ * Is a subscription redirected.
*/
public synchronized boolean isRedirected(String sid) {
return (sid != null && sid2secondary.get(sid) != null);
}
- private void addSubRedirInfo(String s) {
- s = s.trim();
- String[] sx = s.split(" ");
- if (s.startsWith("#") || sx.length != 3) {
+ private void addSubRedirInfo(String subRedirInfo) {
+ subRedirInfo = subRedirInfo.trim();
+ String[] sx = subRedirInfo.split(" ");
+ if (subRedirInfo.startsWith("#") || sx.length != 3) {
return;
}
sid2primary.put(sx[0], sx[1]);
import java.util.regex.Pattern;
/**
- * Logging for data router delivery events (PUB/DEL/EXP)
+ * Logging for data router delivery events (PUB/DEL/EXP).
*/
public class StatusLog {
*/
public static long parseInterval(String interval, int def) {
try {
- Matcher m = Pattern.compile("(?:(\\d+)[Hh])?(?:(\\d+)[Mm])?(?:(\\d+)[Ss]?)?").matcher(interval);
- if (m.matches()) {
- int dur = getDur(m);
+ Matcher matcher = Pattern.compile("(?:(\\d+)[Hh])?(?:(\\d+)[Mm])?(?:(\\d+)[Ss]?)?").matcher(interval);
+ if (matcher.matches()) {
+ int dur = getDur(matcher);
int best = 86400;
int dist = best - dur;
if (dur > best) {
return best;
}
- private static int getDur(Matcher m) {
+ private static int getDur(Matcher matcher) {
int dur = 0;
- String x = m.group(1);
- if (x != null) {
- dur += 3600 * Integer.parseInt(x);
+ String match = matcher.group(1);
+ if (match != null) {
+ dur += 3600 * Integer.parseInt(match);
}
- x = m.group(2);
- if (x != null) {
- dur += 60 * Integer.parseInt(x);
+ match = matcher.group(2);
+ if (match != null) {
+ dur += 60 * Integer.parseInt(match);
}
- x = m.group(3);
- if (x != null) {
- dur += Integer.parseInt(x);
+ match = matcher.group(3);
+ if (match != null) {
+ dur += Integer.parseInt(match);
}
if (dur < 60) {
dur = 60;
}
/**
- * Get the name of the current log file
+ * Get the name of the current log file.
*
* @return The full path name of the current event log file
*/
}
/**
- * Log a data transfer error receiving a publication attempt
+ * Log a data transfer error receiving a publication attempt.
*
* @param pubid The publish ID assigned by the node
* @param feedid The feed id given by the publisher
}
/**
- * Log delivery attempts expired
+ * Log delivery attempts expired.
*
* @param pubid The publish ID assigned by the node
* @param feedid The feed ID
* @param subid The (space delimited list of) subscription ID
* @param clen The content length
* @param sent The # of bytes sent or -1 if subscriber returned an error instead of 100 Continue, otherwise, the
- * number of bytes sent before an error occurred.
+ * number of bytes sent before an error occurred.
*/
public static void logDelExtra(String pubid, String feedid, String subid, long clen, long sent) {
if (feedid == null) {
}
}
- private synchronized void log(String s) {
+ private synchronized void log(String string) {
try {
long now = System.currentTimeMillis();
checkRoll(now);
(new File(plainfile)).delete();
Files.createLink(Paths.get(plainfile), Paths.get(curfile));
}
- os.write((NodeUtils.logts(new Date(now)) + '|' + s + '\n').getBytes());
+ os.write((NodeUtils.logts(new Date(now)) + '|' + string + '\n').getBytes());
os.flush();
} catch (IOException ioe) {
eelfLogger.error("IOException", ioe);
package org.onap.dmaap.datarouter.node;
/**
- * Compare IP addresses as byte arrays to a subnet specified as a CIDR
+ * Compare IP addresses as byte arrays to a subnet specified as a CIDR.
*/
public class SubnetMatcher {
private int mask;
/**
- * Construct a subnet matcher given a CIDR
+ * Construct a subnet matcher given a CIDR.
*
* @param subnet The CIDR to match
*/
public SubnetMatcher(String subnet) {
- int i = subnet.lastIndexOf('/');
- if (i == -1) {
+ int index = subnet.lastIndexOf('/');
+ if (index == -1) {
sn = NodeUtils.getInetAddress(subnet);
len = sn.length;
} else {
- len = Integer.parseInt(subnet.substring(i + 1));
- sn = NodeUtils.getInetAddress(subnet.substring(0, i));
+ len = Integer.parseInt(subnet.substring(index + 1));
+ sn = NodeUtils.getInetAddress(subnet.substring(0, index));
mask = ((0xff00) >> (len % 8)) & 0xff;
len /= 8;
}
}
/**
- * Is the IP address in the CIDR?
+ * Is the IP address in the CIDR.
*
* @param addr the IP address as bytes in network byte order
* @return true if the IP address matches.
package org.onap.dmaap.datarouter.node;
/**
- * A destination to deliver a message
+ * A destination to deliver a message.
*/
public class Target {
private String routing;
/**
- * A destination to deliver a message
+ * A destination to deliver a message.
*
* @param destinfo Either info for a subscription ID or info for a node-to-node transfer
* @param routing For a node-to-node transfer, what to do when it gets there.
}
/**
- * Add additional routing
+ * Add additional routing.
*/
public void addRouting(String routing) {
this.routing = this.routing + " " + routing;
}
/**
- * Get the destination information for this target
+ * Get the destination information for this target.
*/
public DestInfo getDestInfo() {
return (destinfo);
}
/**
- * Get the next hop information for this target
+ * Get the next hop information for this target.
*/
public String getRouting() {
return (routing);
}
/**
- * Get the next task to execute
+ * Get the next task to execute.
*/
public synchronized Runnable next() {
while (runlist != null) {