package org.onap.dmaap.datarouter.node;
-import java.util.*;
-import java.io.*;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Vector;
/**
* Processed configuration for this node.
* <p>
- * The NodeConfig represents a processed configuration from the Data Router
- * provisioning server. Each time configuration data is received from the
- * provisioning server, a new NodeConfig is created and the previous one
+ * The NodeConfig represents a processed configuration from the Data Router provisioning server. Each time
+ * configuration data is received from the provisioning server, a new NodeConfig is created and the previous one
* discarded.
*/
public class NodeConfig {
+
/**
* Raw configuration entry for a data router node
*/
public static class ProvNode {
+
private String cname;
/**
* Raw configuration entry for a provisioning parameter
*/
public static class ProvParam {
+
private String name;
private String value;
/**
* Construct a provisioning parameter configuration entry.
*
- * @param name The name of the parameter.
- * @param value The value of the parameter.
+ * @param name The name of the parameter.
+ * @param value The value of the parameter.
*/
public ProvParam(String name, String value) {
this.name = name;
* Raw configuration entry for a data feed.
*/
public static class ProvFeed {
+
private String id;
private String logdata;
private String status;
/**
* Construct a feed configuration entry.
*
- * @param id The feed ID of the entry.
+ * @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.
+ * @param status The reason why this feed cannot be used (Feed has been deleted, Feed has been suspended) or
+ * null if it is valid.
*/
public ProvFeed(String id, String logdata, String status) {
this.id = id;
* Raw configuration entry for a feed user.
*/
public static class ProvFeedUser {
+
private String feedid;
private String user;
private String credentials;
/**
* Construct a feed user configuration entry
*
- * @param feedid The feed id.
- * @param user The user that will publish to the feed.
+ * @param feedid The feed id.
+ * @param user The user that will publish to the feed.
* @param credentials The Authorization header the user will use to publish.
*/
public ProvFeedUser(String feedid, String user, String credentials) {
* Raw configuration entry for a feed subnet
*/
public static class ProvFeedSubnet {
+
private String feedid;
private String cidr;
* Construct a feed subnet configuration entry
*
* @param feedid The feed ID
- * @param cidr The CIDR allowed to publish to the feed.
+ * @param cidr The CIDR allowed to publish to the feed.
*/
public ProvFeedSubnet(String feedid, String cidr) {
this.feedid = feedid;
* Raw configuration entry for a subscription
*/
public static class ProvSubscription {
+
private String subid;
private String feedid;
private String url;
private String credentials;
private boolean metaonly;
private boolean use100;
+ private boolean privilegedSubscriber;
+ private boolean decompress;
/**
* 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.
- * @param metaonly Is this a meta data only subscription?
- * @param use100 Should we send Expect: 100-continue?
- */
- public ProvSubscription(String subid, String feedid, String url, String authuser, String credentials, boolean metaonly, boolean use100) {
+ * @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.
+ * @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
+ * @param decompress To see if they want their information compressed or decompressed
+ */
+ public ProvSubscription(String subid, String feedid, String url, String authuser, String credentials,
+ boolean metaonly, boolean use100, boolean privilegedSubscriber, boolean decompress) {
this.subid = subid;
this.feedid = feedid;
this.url = url;
this.credentials = credentials;
this.metaonly = metaonly;
this.use100 = use100;
+ this.privilegedSubscriber = privilegedSubscriber;
+ this.decompress = decompress;
}
/**
public boolean isUsing100() {
return (use100);
}
+
+ /**
+ * 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
+ */
+ public boolean isDecompress() {
+ return (decompress);
+ }
}
/**
* Raw configuration entry for controlled ingress to the data router node
*/
public static class ProvForceIngress {
+
private String feedid;
private String subnet;
private String user;
* 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
- * @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.
+ * @param subnet The CIDR for which publisher IP addresses this entry applies to or "" if it applies to all
+ * 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.
*/
public ProvForceIngress(String feedid, String subnet, String user, String[] nodes) {
this.feedid = feedid;
* Raw configuration entry for controlled egress from the data router
*/
public static class ProvForceEgress {
+
private String subid;
private String node;
* 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
+ * @param node The node handling deliveries for this subscription
*/
public ProvForceEgress(String subid, String node) {
this.subid = subid;
* Raw configuration entry for routing within the data router network
*/
public static class ProvHop {
+
private String from;
private String to;
private String via;
* 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
- * @param via The FQDN of the node where the from node should send the data
+ * @param to The FQDN of the node that will deliver to the subscriber
+ * @param via The FQDN of the node where the from node should send the data
*/
public ProvHop(String from, String to, String via) {
this.from = from;
}
private static class Redirection {
+
SubnetMatcher snm;
String user;
String[] nodes;
}
private static class Feed {
+
String loginfo;
String status;
SubnetMatcher[] subnets;
Target[] targets;
}
- private Hashtable<String, String> params = new Hashtable<String, String>();
- private Hashtable<String, Feed> feeds = new Hashtable<String, Feed>();
- private Hashtable<String, DestInfo> nodeinfo = new Hashtable<String, DestInfo>();
- private Hashtable<String, DestInfo> subinfo = new Hashtable<String, DestInfo>();
- private Hashtable<String, IsFrom> nodes = new Hashtable<String, IsFrom>();
+ private Hashtable<String, String> params = new Hashtable<>();
+ private Hashtable<String, Feed> feeds = new Hashtable<>();
+ private Hashtable<String, DestInfo> nodeinfo = new Hashtable<>();
+ private Hashtable<String, DestInfo> subinfo = new Hashtable<>();
+ private Hashtable<String, IsFrom> nodes = new Hashtable<>();
+ private Hashtable<String, ProvSubscription> provSubscriptions = new Hashtable<>();
private String myname;
private String myauth;
private DestInfo[] alldests;
/**
* Process the raw provisioning data to configure this node
*
- * @param pd The parsed provisioning data
- * @param myname My name as seen by external systems
- * @param spooldir The directory where temporary files live
- * @param port The port number for URLs
+ * @param pd The parsed provisioning data
+ * @param myname My name as seen by external systems
+ * @param spooldir The directory where temporary files live
+ * @param port The port number for URLs
* @param nodeauthkey The keying string used to generate node authentication credentials
*/
public NodeConfig(ProvData pd, String myname, String spooldir, int port, String nodeauthkey) {
for (ProvParam p : pd.getParams()) {
params.put(p.getName(), p.getValue());
}
- Vector<DestInfo> div = new Vector<DestInfo>();
+ Vector<DestInfo> destInfos = new Vector<>();
myauth = NodeUtils.getNodeAuthHdr(myname, nodeauthkey);
for (ProvNode pn : pd.getNodes()) {
String cn = pn.getCName();
continue;
}
String auth = NodeUtils.getNodeAuthHdr(cn, nodeauthkey);
- DestInfo di = new DestInfo("n:" + cn, spooldir + "/n/" + cn, null, "n2n-" + cn, "https://" + cn + ":" + port + "/internal/publish", cn, myauth, false, true);
+ DestInfo di = new DestInfo("n:" + cn, spooldir + "/n/" + cn, null, "n2n-" + cn,
+ "https://" + cn + ":" + port + "/internal/publish", cn, myauth, false, true, false, false);
(new File(di.getSpool())).mkdirs();
- div.add(di);
+ destInfos.add(di);
nodeinfo.put(cn, di);
nodes.put(auth, new IsFrom(cn));
}
}
egrtab.put(pfe.getSubId(), pfe.getNode());
}
- Hashtable<String, Vector<SubnetMatcher>> pfstab = new Hashtable<String, Vector<SubnetMatcher>>();
+ Hashtable<String, Vector<SubnetMatcher>> pfstab = new Hashtable<>();
for (ProvFeedSubnet pfs : pd.getFeedSubnets()) {
Vector<SubnetMatcher> v = pfstab.get(pfs.getFeedId());
if (v == null) {
}
v.add(new SubnetMatcher(pfs.getCidr()));
}
- Hashtable<String, StringBuffer> ttab = new Hashtable<String, StringBuffer>();
- HashSet<String> allfeeds = new HashSet<String>();
+ Hashtable<String, StringBuffer> feedTargets = new Hashtable<>();
+ HashSet<String> allfeeds = new HashSet<>();
for (ProvFeed pfx : pd.getFeeds()) {
if (pfx.getStatus() == null) {
allfeeds.add(pfx.getId());
}
}
- for (ProvSubscription ps : pd.getSubscriptions()) {
- String sid = ps.getSubId();
- String fid = ps.getFeedId();
- if (!allfeeds.contains(fid)) {
+ for (ProvSubscription provSubscription : pd.getSubscriptions()) {
+ String subId = provSubscription.getSubId();
+ String feedId = provSubscription.getFeedId();
+ if (!allfeeds.contains(feedId)) {
continue;
}
- if (subinfo.get(sid) != null) {
+ if (subinfo.get(subId) != null) {
continue;
}
int sididx = 999;
try {
- sididx = Integer.parseInt(sid);
+ sididx = Integer.parseInt(subId);
sididx -= sididx % 100;
} catch (Exception e) {
}
- String siddir = sididx + "/" + sid;
- DestInfo di = new DestInfo("s:" + sid, spooldir + "/s/" + siddir, sid, fid, ps.getURL(), ps.getAuthUser(), ps.getCredentials(), ps.isMetaDataOnly(), ps.isUsing100());
- (new File(di.getSpool())).mkdirs();
- div.add(di);
- subinfo.put(sid, di);
- String egr = egrtab.get(sid);
+ String subscriptionDirectory = sididx + "/" + subId;
+ DestInfo destinationInfo = new DestInfo("s:" + subId,
+ spooldir + "/s/" + subscriptionDirectory, provSubscription);
+ (new File(destinationInfo.getSpool())).mkdirs();
+ destInfos.add(destinationInfo);
+ provSubscriptions.put(subId, provSubscription);
+ subinfo.put(subId, destinationInfo);
+ String egr = egrtab.get(subId);
if (egr != null) {
- sid = pf.getPath(egr) + sid;
+ subId = pf.getPath(egr) + subId;
}
- StringBuffer sb = ttab.get(fid);
+ StringBuffer sb = feedTargets.get(feedId);
if (sb == null) {
sb = new StringBuffer();
- ttab.put(fid, sb);
+ feedTargets.put(feedId, sb);
}
- sb.append(' ').append(sid);
+ sb.append(' ').append(subId);
}
- alldests = div.toArray(new DestInfo[div.size()]);
+ alldests = destInfos.toArray(new DestInfo[destInfos.size()]);
for (ProvFeed pfx : pd.getFeeds()) {
String fid = pfx.getId();
Feed f = feeds.get(fid);
} else {
f.redirections = v2.toArray(new Redirection[v2.size()]);
}
- StringBuffer sb = ttab.get(fid);
+ StringBuffer sb = feedTargets.get(fid);
if (sb == null) {
f.targets = new Target[0];
} else {
* 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
+ * @param ip IP address the request came from
*/
public boolean isAnotherNode(String credentials, String ip) {
IsFrom n = nodes.get(credentials);
/**
* Check whether publication is allowed.
*
- * @param feedid The ID of the feed being requested.
+ * @param feedid The ID of the feed being requested.
* @param credentials The offered credentials
- * @param ip The requesting IP address
+ * @param ip The requesting IP address
*/
public String isPublishPermitted(String feedid, String credentials, String ip) {
Feed f = feeds.get(feedid);
return ("Publisher not permitted for this feed");
}
+ /**
+ * 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
*/