X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-node%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fnode%2FProvData.java;h=c436076f116d938646196c1d0b6d50a6d7d10c9e;hb=refs%2Fchanges%2F56%2F88856%2F2;hp=bb9ddc3b52dde4b1083229cff562e5a92526dcb6;hpb=5a55b790e8afa3131fd5f894e5d1b1e036dc4cd1;p=dmaap%2Fdatarouter.git
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
index bb9ddc3b..c436076f 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
@@ -47,52 +47,52 @@ import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
/**
* Parser for provisioning data from the provisioning server.
- *
- * The ProvData class uses a Reader for the text configuration from the provisioning server to construct arrays of raw
- * configuration entries.
+ *
+ *
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 provNodes1 = new ArrayList<>();
- ArrayList provParams1 = new ArrayList<>();
- ArrayList provFeeds1 = new ArrayList<>();
- ArrayList provFeedUsers1 = new ArrayList<>();
- ArrayList provFeedSubnets1 = new ArrayList<>();
- ArrayList provSubscriptions1 = new ArrayList<>();
- ArrayList provForceIngresses1 = new ArrayList<>();
- ArrayList provForceEgresses1 = new ArrayList<>();
- ArrayList provHops1 = new ArrayList<>();
+ public ProvData(Reader reader) throws IOException {
+ ArrayList pnv = new ArrayList<>();
+ ArrayList ppv = new ArrayList<>();
+ ArrayList pfv = new ArrayList<>();
+ ArrayList pfuv = new ArrayList<>();
+ ArrayList pfsnv = new ArrayList<>();
+ ArrayList psv = new ArrayList<>();
+ ArrayList pfiv = new ArrayList<>();
+ ArrayList pfev = new ArrayList<>();
+ ArrayList 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());
@@ -100,53 +100,53 @@ public class ProvData {
.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 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 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);
}
@@ -155,63 +155,63 @@ public class ProvData {
* 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
@@ -226,20 +226,19 @@ public class ProvData {
return stat;
}
- private void addJSONFeeds(ArrayList provFeeds1, ArrayList provFeedUsers1,
- ArrayList provFeedSubnets1,
- JSONObject jsonConfig) {
- JSONArray jfeeds = jsonConfig.optJSONArray("feeds");
+ private void addJSONFeeds(ArrayList pfv, ArrayList pfuv, ArrayList 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 provFeeds1, ArrayList provFeedUsers1,
- ArrayList provFeedSubnets1, JSONArray jfeeds, int feedIndex) {
- JSONObject jfeed = jfeeds.getJSONObject(feedIndex);
+ private void addJSONFeed(ArrayList pfv, ArrayList pfuv, ArrayList 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");
@@ -251,15 +250,15 @@ public class ProvData {
* 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 provFeedUsers1,
- ArrayList provFeedSubnets1, JSONObject jfeed, String fid) {
+ private void addJSONFeedAuthArrays(ArrayList pfuv, ArrayList pfsnv, JSONObject jfeed,
+ String fid) {
JSONObject jauth = jfeed.optJSONObject("authorization");
if (jauth == null) {
return;
@@ -270,28 +269,28 @@ public class ProvData {
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 provSubscriptions1, JSONObject jsonConfig) {
- JSONArray jsubs = jsonConfig.optJSONArray("subscriptions");
+ private void addJSONSubs(ArrayList 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 provSubscriptions1, JSONArray jsubs, int sx) {
+ private void addJSONSub(ArrayList psv, JSONArray jsubs, int sx) {
JSONObject jsub = jsubs.getJSONObject(sx);
if (jsub.optBoolean("suspend", false)) {
return;
@@ -307,74 +306,68 @@ public class ProvData {
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 provNodes1, ArrayList provParams1,
- JSONObject jsonconfig) {
- JSONObject jparams = jsonconfig.optJSONObject("parameters");
+ private void addJSONParams(ArrayList pnv, ArrayList 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 provParams1, JSONObject jparams, String pname) {
+ private void addJSONParam(ArrayList 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 provNodes1, JSONObject jparams) {
+ private void addJSONNodesToParams(ArrayList 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 provForceIngresses1,
- ArrayList provForceEgresses1, ArrayList provHops1, JSONObject jsonConfig) {
- JSONArray jingresses = jsonConfig.optJSONArray("ingress");
+ private void addJSONRoutingInformation(ArrayList pfiv, ArrayList pfev,
+ ArrayList 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 provForceIngresses1, JSONArray jingresses, int fx) {
+ private void addJSONIngressRoute(ArrayList 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;
}
@@ -384,17 +377,18 @@ public class ProvData {
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 provForceEgresses1, JSONObject jegresses, String esid) {
+ private void addJSONEgressRoute(ArrayList 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 provHops1, JSONArray jhops, int fx) {
+ private void addJSONRoutes(ArrayList phv, JSONArray jhops, int fx) {
JSONObject jhop = jhops.getJSONObject(fx);
String from = gvas(jhop, "from");
String to = gvas(jhop, "to");
@@ -402,6 +396,6 @@ public class ProvData {
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));
}
}