From 4d3624549f41aeda68b8626270fc491ea99e5ee0 Mon Sep 17 00:00:00 2001 From: VENKATESH KUMAR Date: Wed, 14 Feb 2018 17:45:04 +0000 Subject: Fix keystore alais config and TC Change-Id: I8e0349f411dc05625b14536afc0acb1fac9a55c2 Signed-off-by: VENKATESH KUMAR Issue-ID: DCAEGEN2-227 --- .../onap/dcae/controller/FetchDynamicConfig.java | 54 +++++++++++----- .../onap/dcae/controller/LoadDynamicConfig.java | 73 +++++++++++++--------- 2 files changed, 83 insertions(+), 44 deletions(-) (limited to 'src/main/java/org/onap/dcae/controller') diff --git a/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java b/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java index 82d4bba3..95e95747 100644 --- a/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java +++ b/src/main/java/org/onap/dcae/controller/FetchDynamicConfig.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PROJECT * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ public class FetchDynamicConfig { private static final Logger log = LoggerFactory.getLogger(FetchDynamicConfig.class); - static String configFile = "/opt/app/KV-Configuration.json"; + public static String configFile = "/opt/app/KV-Configuration.json"; static String url; static String retString; @@ -49,8 +49,8 @@ public class FetchDynamicConfig { log.info("%s=%s%n", entry.getKey(), entry.getValue()); } - if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE") - && env.containsKey("HOSTNAME")) { + if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE")) { +// && env.containsKey("HOSTNAME")) { log.info(">>>Dynamic configuration to be fetched from ConfigBindingService"); url = env.get("CONSUL_HOST") + ":8500/v1/catalog/service/" + env.get("CONFIG_BINDING_SERVICE"); @@ -65,23 +65,47 @@ public class FetchDynamicConfig { } log.info("CONFIG_BINDING_SERVICE DNS RESOLVED:" + urlPart1); - url = urlPart1 + "/service_component/" + env.get("HOSTNAME"); - retString = executecurl(url); - - JSONObject jsonObject = new JSONObject(new JSONTokener(retString)); - try (FileWriter file = new FileWriter(configFile)) { - file.write(jsonObject.toString()); - - log.info("Successfully Copied JSON Object to file /opt/app/KV-Configuration.json"); - } catch (IOException e) { - log.error("Error in writing configuration into file /opt/app/KV-Configuration.json " + jsonObject, e); - e.printStackTrace(); + FetchDynamicConfig fc= new FetchDynamicConfig(); + if (env.containsKey("HOSTNAME")) + { + url = urlPart1 + "/service_component/" + env.get("HOSTNAME"); + retString = executecurl(url); + } + else if (env.containsKey("SERVICE_NAME")) + { + url = urlPart1 + "/service_component/" + env.get("SERVICE_NAME"); + retString = executecurl(url); + } + else + { + log.error("Service name environment variable - HOSTNAME/SERVICE_NAME not found within container "); } + fc.writefile(retString); + + } else { log.info(">>>Static configuration to be used"); } } + + public void writefile (String retString) + { + log.info("URL to fetch configuration:" + url + " Return String:" + retString); + + + String indentedretstring=(new JSONObject(retString)).toString(4); + + try (FileWriter file = new FileWriter(FetchDynamicConfig.configFile)) { + file.write(indentedretstring); + + log.info("Successfully Copied JSON Object to file /opt/app/KV-Configuration.json"); + } catch (IOException e) { + log.error("Error in writing configuration into file /opt/app/KV-Configuration.json " + retString, e); + e.printStackTrace(); + } + + } public static String executecurl(String url) { diff --git a/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java b/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java index 2db4ff42..9184c3e7 100644 --- a/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java +++ b/src/main/java/org/onap/dcae/controller/LoadDynamicConfig.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PROJECT * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,7 @@ public class LoadDynamicConfig { public String configFile = "/opt/app/KV-Configuration.json"; static String url; static String retString; + public String dmaapoutputfile = "./etc/DmaapConfig.json"; public LoadDynamicConfig() { @@ -59,35 +60,10 @@ public class LoadDynamicConfig { LoadDynamicConfig lc = new LoadDynamicConfig(); String jsonData = readFile(lc.configFile); JSONObject jsonObject = new JSONObject(jsonData); + lc.writeconfig(jsonObject); + - PropertiesConfiguration conf; - conf = new PropertiesConfiguration(lc.propFile); - conf.setEncoding(null); - - // update properties based on consul dynamic configuration - Iterator keys = jsonObject.keys(); - - while (keys.hasNext()) { - String key = (String) keys.next(); - // check if any configuration is related to dmaap - // and write into dmaapconfig.json - if (key.startsWith("streams_publishes")) { - // VESCollector only have publish streams - try (FileWriter file = new FileWriter("./etc/DmaapConfig.json")) { - file.write(jsonObject.get(key).toString()); - log.info("Successfully written JSON Object to DmaapConfig.json"); - file.close(); - } catch (IOException e) { - log.info("Error in writing dmaap configuration into DmaapConfig.json", e); - } - } else { - conf.setProperty(key, jsonObject.get(key).toString()); - } - - } - conf.save(); - - } catch (ConfigurationException e) { + } catch (Exception e) { log.error(e.getLocalizedMessage(), e); e.printStackTrace(); @@ -98,6 +74,45 @@ public class LoadDynamicConfig { } } + + public void writeconfig (JSONObject jsonObject) + { + + PropertiesConfiguration conf; + try { + conf = new PropertiesConfiguration(propFile); + + conf.setEncoding(null); + + // update properties based on consul dynamic configuration + Iterator keys = jsonObject.keys(); + + while (keys.hasNext()) { + String key = (String) keys.next(); + // check if any configuration is related to dmaap + // and write into dmaapconfig.json + if (key.startsWith("streams_publishes")) { + // VESCollector only have publish streams + try (FileWriter file = new FileWriter(dmaapoutputfile)) { + + String indentedretstring=(new JSONObject(jsonObject.get(key).toString())).toString(4); + file.write(indentedretstring); + log.info("Successfully written JSON Object to DmaapConfig.json"); + file.close(); + } catch (IOException e) { + log.info("Error in writing dmaap configuration into DmaapConfig.json", e); + } + } else { + conf.setProperty(key, jsonObject.get(key).toString()); + } + + } + conf.save(); + } catch (ConfigurationException e) { + log.error(e.getLocalizedMessage(), e); + e.printStackTrace(); + } + } public static String readFile(String filename) { String result = ""; -- cgit 1.2.3-korg