X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fconfiguration%2FApplicationConfigParser.java;h=ae83bc05f620978c4983fd45656d3f4c1fc3412d;hb=refs%2Fchanges%2F69%2F2369%2F3;hp=530ac98ba831f8eaf7358eb304806174b09ff505;hpb=ff56d2600d074ac0a4473c81b8193004a316c2f8;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java index 530ac98b..ae83bc05 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java @@ -34,8 +34,10 @@ import java.util.Set; import java.util.Vector; import javax.validation.constraints.NotNull; - +import lombok.Getter; +import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants; import org.oransc.policyagent.exceptions.ServiceException; +import org.springframework.http.MediaType; public class ApplicationConfigParser { @@ -45,25 +47,28 @@ public class ApplicationConfigParser { .serializeNulls() // .create(); // - private Vector ricConfig; + @Getter + private Vector ricConfigs; + @Getter + private Properties dmaapPublisherConfig; + @Getter private Properties dmaapConsumerConfig; - public ApplicationConfigParser() { - } - public void parse(JsonObject root) throws ServiceException { - JsonObject ricConfigJson = root.getAsJsonObject(CONFIG); - ricConfig = parseRics(ricConfigJson); - JsonObject dmaapConfigJson = root.getAsJsonObject("streams_subscribes"); - dmaapConsumerConfig = parseDmaapConsumerConfig(dmaapConfigJson); - } - - public Vector getRicConfigs() { - return this.ricConfig; - } - - public Properties getDmaapConsumerConfig() { - return dmaapConsumerConfig; + JsonObject agentConfigJson = root.getAsJsonObject(CONFIG); + ricConfigs = parseRics(agentConfigJson); + JsonObject dmaapPublisherConfigJson = agentConfigJson.getAsJsonObject("streams_publishes"); + if (dmaapPublisherConfigJson == null) { + dmaapPublisherConfig = new Properties(); + } else { + dmaapPublisherConfig = parseDmaapConfig(dmaapPublisherConfigJson); + } + JsonObject dmaapConsumerConfigJson = agentConfigJson.getAsJsonObject("streams_subscribes"); + if (dmaapConsumerConfigJson == null) { + dmaapConsumerConfig = new Properties(); + } else { + dmaapConsumerConfig = parseDmaapConfig(dmaapConsumerConfigJson); + } } private Vector parseRics(JsonObject config) throws ServiceException { @@ -86,13 +91,14 @@ public class ApplicationConfigParser { return get(obj, memberName).getAsJsonArray(); } - private Properties parseDmaapConsumerConfig(JsonObject consumerCfg) throws ServiceException { - Set> topics = consumerCfg.entrySet(); - if (topics.size() != 1) { - throw new ServiceException("Invalid configuration, number of topic must be one, config: " + topics); + private Properties parseDmaapConfig(JsonObject streamCfg) throws ServiceException { + Set> streamConfigEntries = streamCfg.entrySet(); + if (streamConfigEntries.size() != 1) { + throw new ServiceException( + "Invalid configuration. Number of streams must be one, config: " + streamConfigEntries); } - JsonObject topic = topics.iterator().next().getValue().getAsJsonObject(); - JsonObject dmaapInfo = get(topic, "dmaap_info").getAsJsonObject(); + JsonObject streamConfigEntry = streamConfigEntries.iterator().next().getValue().getAsJsonObject(); + JsonObject dmaapInfo = get(streamConfigEntry, "dmaap_info").getAsJsonObject(); String topicUrl = getAsString(dmaapInfo, "topic_url"); Properties dmaapProps = new Properties(); @@ -106,17 +112,19 @@ public class ApplicationConfigParser { passwd = userInfo[1]; } String urlPath = url.getPath(); - DmaapConsumerUrlPath path = parseDmaapUrlPath(urlPath); + DmaapUrlPath path = parseDmaapUrlPath(urlPath); - dmaapProps.put("port", url.getPort()); - dmaapProps.put("server", url.getHost()); + dmaapProps.put("ServiceName", url.getHost() + ":" + url.getPort() + "/events"); dmaapProps.put("topic", path.dmaapTopicName); - dmaapProps.put("consumerGroup", path.consumerGroup); - dmaapProps.put("consumerInstance", path.consumerId); - dmaapProps.put("fetchTimeout", 15000); - dmaapProps.put("fetchLimit", 1000); + dmaapProps.put("host", url.getHost() + ":" + url.getPort()); + dmaapProps.put("contenttype", MediaType.APPLICATION_JSON.toString()); dmaapProps.put("userName", userName); dmaapProps.put("password", passwd); + dmaapProps.put("group", path.consumerGroup); + dmaapProps.put("id", path.consumerId); + dmaapProps.put("TransportType", ProtocolTypeConstants.HTTPNOAUTH.toString()); + dmaapProps.put("timeout", 15000); + dmaapProps.put("limit", 1000); } catch (MalformedURLException e) { throw new ServiceException("Could not parse the URL", e); } @@ -128,27 +136,31 @@ public class ApplicationConfigParser { return get(obj, memberName).getAsString(); } - private class DmaapConsumerUrlPath { + private class DmaapUrlPath { final String dmaapTopicName; final String consumerGroup; final String consumerId; - DmaapConsumerUrlPath(String dmaapTopicName, String consumerGroup, String consumerId) { + DmaapUrlPath(String dmaapTopicName, String consumerGroup, String consumerId) { this.dmaapTopicName = dmaapTopicName; this.consumerGroup = consumerGroup; this.consumerId = consumerId; } } - private DmaapConsumerUrlPath parseDmaapUrlPath(String urlPath) throws ServiceException { + private DmaapUrlPath parseDmaapUrlPath(String urlPath) throws ServiceException { String[] tokens = urlPath.split("/"); // /events/A1-P/users/sdnc1 - if (tokens.length != 5) { + if (!(tokens.length == 3 ^ tokens.length == 5)) { throw new ServiceException("The path has incorrect syntax: " + urlPath); } - final String dmaapTopicName = tokens[1] + "/" + tokens[2]; // /events/A1-P - final String consumerGroup = tokens[3]; // users - final String consumerId = tokens[4]; // sdnc1 - return new DmaapConsumerUrlPath(dmaapTopicName, consumerGroup, consumerId); + final String dmaapTopicName = tokens[2]; // /events/A1-P + String consumerGroup = ""; // users + String consumerId = ""; // sdnc1 + if (tokens.length == 5) { + consumerGroup = tokens[3]; + consumerId = tokens[4]; + } + return new DmaapUrlPath(dmaapTopicName, consumerGroup, consumerId); } }