diff options
author | 2017-11-05 01:16:22 +0800 | |
---|---|---|
committer | 2017-11-05 01:16:22 +0800 | |
commit | e8643ee7b7fb72f55df742dd7e075469fbca43c8 (patch) | |
tree | 38dfd810865aaf1073732e9eec264275d2bbd5c8 /holmes-actions/src/main/java/org/onap | |
parent | 17308d4bb9cb15422958c0b7adfb7297a0d7a7ab (diff) |
Add Logic for Parsing Sub Info from DCAE
Change-Id: Ie74415afb700eec60b43543834d5ca97218ce8bf
Issue-ID: HOLMES-81
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java/org/onap')
3 files changed, 31 insertions, 30 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java index a0bb943..597e879 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java @@ -28,22 +28,7 @@ public class DcaeConfigurationQuery { public static DcaeConfigurations getDcaeConfigurations(String hostname) throws CorrelationException { - String serviceAddrInfo = MicroServiceConfig.getServiceConfigInfoFromCBS(hostname); - String response; - try { - response = getDcaeResponse(serviceAddrInfo); - } catch (Exception e) { - throw new CorrelationException("Failed to connect to DCAE. ", e); - } - DcaeConfigurations dcaeConfigurations = null; - dcaeConfigurations = DcaeConfigurationParser.parse(response); - return dcaeConfigurations; - } - - private static String getDcaeResponse(String serviceAddrInfo) { - Client client = ClientBuilder.newClient(new ClientConfig()); - WebTarget webTarget = client.target(serviceAddrInfo); - return webTarget.request("application/json").get() - .readEntity(String.class); + String serviceConfig = MicroServiceConfig.getServiceConfigInfoFromCBS(hostname); + return DcaeConfigurationParser.parse(serviceConfig); } } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/SecurityInfo.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/SecurityInfo.java index 6c6fa56..eeab5a7 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/SecurityInfo.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/SecurityInfo.java @@ -35,5 +35,6 @@ public class SecurityInfo { private String clientId;
private String clientRole;
private String topicUrl;
+ private String type;
}
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java index 9284dd8..1143263 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java @@ -16,7 +16,6 @@ package org.onap.holmes.common.dcae.utils;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
@@ -38,7 +37,7 @@ public class DcaeConfigurationParser { public static DcaeConfigurations parse(String jsonStr) throws CorrelationException {
if (StringUtils.isEmpty(jsonStr)) {
throw new CorrelationException(
- "Can not resolve configurations from DCAE. The configuration string is empty");
+ "Can not resolve configurations from DCAE. The configuration string is empty.");
}
DcaeConfigurations ret = new DcaeConfigurations();
@@ -52,10 +51,7 @@ public class DcaeConfigurationParser { fillInRules(ret, jsonObject);
fillInPublishesInfo(ret, jsonObject);
-
- if (jsonObject.containsKey("streams_subscribes")) {
-
- }
+ fillInSubscribesInfo(ret, jsonObject);
JSONObject finalJsonObject = jsonObject;
Stream.of(jsonObject.keySet().toArray(new String[0]))
@@ -74,13 +70,25 @@ public class DcaeConfigurationParser { }
}
+ private static void fillInSubscribesInfo(DcaeConfigurations ret, JSONObject jsonObject) {
+ if (jsonObject.containsKey("streams_subscribes")) {
+ JSONObject subscribes = jsonObject.getJSONObject("streams_subscribes");
+ for (Object key : subscribes.keySet()) {
+ ret.addSubSecInfo((String) key,
+ createSecurityInfo((String) key, subscribes.getJSONObject((String) key)));
+ }
+ }
+ }
+
private static SecurityInfo createSecurityInfo(String key, JSONObject entity) {
SecurityInfo securityInfo = new SecurityInfo();
- securityInfo.setType(entity.getString("type"));
- if (!entity.get("aaf_password").equals("null")) {
+ if (entity.containsKey("type")) {
+ securityInfo.setType(entity.getString("type"));
+ }
+ if (entity.containsKey("aaf_password")) {
securityInfo.setAafPassword(entity.getString("aaf_password"));
}
- if (!entity.get("aaf_username").equals("null")) {
+ if (entity.containsKey("aaf_username")) {
securityInfo.setAafUsername(entity.getString("aaf_username"));
}
securityInfo.setSecureTopic(!key.endsWith("unsecure"));
@@ -90,14 +98,21 @@ public class DcaeConfigurationParser { private static void fillInDmaapInfo(SecurityInfo securityInfo, JSONObject jsonDmaapInfo) {
SecurityInfo.DmaapInfo dmaapInfo = securityInfo.getDmaapInfo();
- dmaapInfo.setLocation(jsonDmaapInfo.getString("location"));
- dmaapInfo.setTopicUrl(jsonDmaapInfo.getString("topic_url"));
- if (!jsonDmaapInfo.get("client_id").equals("null")) {
+ if (jsonDmaapInfo.containsKey("location")){
+ dmaapInfo.setLocation(jsonDmaapInfo.getString("location"));
+ }
+ if (jsonDmaapInfo.containsKey("topic_url")) {
+ dmaapInfo.setTopicUrl(jsonDmaapInfo.getString("topic_url"));
+ }
+ if (jsonDmaapInfo.containsKey("client_id")) {
dmaapInfo.setClientId(jsonDmaapInfo.getString("client_id"));
}
- if (!jsonDmaapInfo.get("client_role").equals("null")) {
+ if (jsonDmaapInfo.containsKey("client_role")) {
dmaapInfo.setClientRole(jsonDmaapInfo.getString("client_role"));
}
+ if (jsonDmaapInfo.containsKey("type")) {
+ dmaapInfo.setType(jsonDmaapInfo.getString("type"));
+ }
}
private static void fillInRules(DcaeConfigurations ret, JSONObject jsonObject) {
|