X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FNodeConfig.java;h=d3d3d01b7d7e337b8792fe31b4b065a4be8deda4;hb=refs%2Fchanges%2F80%2F77780%2F10;hp=c40d29c389a1767c188c7b059715a76b76397b05;hpb=953dbd55595d28ecc7b65413b0edf910da6f45c0;p=dmaap%2Fdatarouter.git diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfig.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfig.java index c40d29c3..d3d3d01b 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfig.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfig.java @@ -231,6 +231,7 @@ public class NodeConfig { private String credentials; private boolean metaonly; private boolean use100; + private boolean privilegedSubscriber; /** * Construct a subscription configuration entry @@ -243,9 +244,10 @@ public class NodeConfig { * 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 */ public ProvSubscription(String subid, String feedid, String url, String authuser, String credentials, - boolean metaonly, boolean use100) { + boolean metaonly, boolean use100, boolean privilegedSubscriber) { this.subid = subid; this.feedid = feedid; this.url = url; @@ -253,6 +255,7 @@ public class NodeConfig { this.credentials = credentials; this.metaonly = metaonly; this.use100 = use100; + this.privilegedSubscriber = privilegedSubscriber; } /** @@ -303,6 +306,13 @@ public class NodeConfig { public boolean isUsing100() { return (use100); } + + /** + * Can we wait to receive a delete file call before deleting file + */ + public boolean isPrivilegedSubscriber() { + return (privilegedSubscriber); + } } /** @@ -462,11 +472,12 @@ public class NodeConfig { Target[] targets; } - private Hashtable params = new Hashtable(); - private Hashtable feeds = new Hashtable(); - private Hashtable nodeinfo = new Hashtable(); - private Hashtable subinfo = new Hashtable(); - private Hashtable nodes = new Hashtable(); + private Hashtable params = new Hashtable<>(); + private Hashtable feeds = new Hashtable<>(); + private Hashtable nodeinfo = new Hashtable<>(); + private Hashtable subinfo = new Hashtable<>(); + private Hashtable nodes = new Hashtable<>(); + private Hashtable provSubscriptions = new Hashtable<>(); private String myname; private String myauth; private DestInfo[] alldests; @@ -486,7 +497,7 @@ public class NodeConfig { for (ProvParam p : pd.getParams()) { params.put(p.getName(), p.getValue()); } - Vector div = new Vector(); + Vector destInfos = new Vector<>(); myauth = NodeUtils.getNodeAuthHdr(myname, nodeauthkey); for (ProvNode pn : pd.getNodes()) { String cn = pn.getCName(); @@ -495,9 +506,9 @@ public class NodeConfig { } 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); + "https://" + cn + ":" + port + "/internal/publish", cn, myauth, false, true, false); (new File(di.getSpool())).mkdirs(); - div.add(di); + destInfos.add(di); nodeinfo.put(cn, di); nodes.put(auth, new IsFrom(cn)); } @@ -533,7 +544,7 @@ public class NodeConfig { } egrtab.put(pfe.getSubId(), pfe.getNode()); } - Hashtable> pfstab = new Hashtable>(); + Hashtable> pfstab = new Hashtable<>(); for (ProvFeedSubnet pfs : pd.getFeedSubnets()) { Vector v = pfstab.get(pfs.getFeedId()); if (v == null) { @@ -542,46 +553,47 @@ public class NodeConfig { } v.add(new SubnetMatcher(pfs.getCidr())); } - Hashtable ttab = new Hashtable(); - HashSet allfeeds = new HashSet(); + Hashtable feedTargets = new Hashtable<>(); + HashSet 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); @@ -609,7 +621,7 @@ public class NodeConfig { } 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 { @@ -711,6 +723,16 @@ public class NodeConfig { 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 */