diff options
author | amitjai <amitjai@amdocs.com> | 2018-04-27 13:28:57 +0530 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-04-30 06:05:27 +0000 |
commit | 42c920baf4dbb9fe8775843a6d4c9f70fa29f064 (patch) | |
tree | ac2aff977e2b129e61d2166c4832842676e4f5c3 /common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli | |
parent | f487427a32f410ab5c97a4092865d32beb88ee27 (diff) |
Rename packages from openecomp to onap.
This task is all about package name space change also make changes to pom for common module
Change-Id: Ie9bda0f958a9a05826c0374830cc9cb7d6d196b6
Issue-ID: SDC-1272
Signed-off-by: amitjai <amitjai@amdocs.com>
Diffstat (limited to 'common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli')
-rw-r--r-- | common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli/app/Configuration.java | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli/app/Configuration.java b/common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli/app/Configuration.java new file mode 100644 index 0000000000..d1a93f0041 --- /dev/null +++ b/common/onap-common-configuration-management/onap-configuration-management-cli/src/main/java/org/onap/config/cli/app/Configuration.java @@ -0,0 +1,119 @@ +package org.onap.config.cli.app; + +import org.onap.config.api.ConfigurationChangeListener; +import org.onap.config.api.ConfigurationManager; + +import java.util.HashMap; +import java.util.Map; + +import javax.management.JMX; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +/** + * The type Configuration. + */ +public class Configuration { + + /** + * The entry point of application. + * + * @param args the input arguments + * @throws Exception the exception + */ + public static void main(String[] args) throws Exception { + + String host = getValueFor("host", args); + String port = getValueFor("port", args); + + if (host == null) { + host = "127.0.0.1"; + } + if (port == null) { + port = "9999"; + } + JMXServiceURL url = + new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); + Map<String, String[]> env = new HashMap<>(); + //populate dummy value. need to be changed as per impl. + String[] credentials = {"principal", "password"}; + env.put(JMXConnector.CREDENTIALS, credentials); + + try (JMXConnector jmxc = JMXConnectorFactory.connect(url, env)) { + + boolean isUpdate = isKeyPresent("update", args); + + Map<String, Object> input = new HashMap<>(); + input.put("ImplClass", isUpdate ? "org.onap.config.type.ConfigurationUpdate" + : "org.onap.config.type.ConfigurationQuery"); + input.put("externalLookup", isKeyPresent("lookup", args)); + input.put("nodeOverride", isKeyPresent("nodeOverride", args)); + input.put("nodeSpecific", isKeyPresent("nodeSpecific", args)); + input.put("fallback", isKeyPresent("fallback", args)); + input.put("latest", isKeyPresent("latest", args)); + input.put("tenant", getValueFor("tenant", args)); + input.put("namespace", getValueFor("namespace", args)); + input.put("key", getValueFor("key", args)); + input.put("value", getValueFor("value", args)); + + + if (!isKeyPresent("list", args) && getValueFor("key", args) == null) { + throw new RuntimeException("Key is missing."); + } + if (isKeyPresent("update", args) && getValueFor("value", args) == null) { + throw new RuntimeException("Value is missing."); + } + + + MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); + ObjectName mbeanName = new ObjectName("org.openecomp.jmx:name=SystemConfig"); + org.onap.config.api.ConfigurationManager conf = + JMX.newMBeanProxy(mbsc, mbeanName, org.onap.config.api.ConfigurationManager.class, + true); + + boolean isGet = isKeyPresent("get", args); + boolean isList = isKeyPresent("list", args); + if (isGet) { + System.out.println(conf.getConfigurationValue(input)); + } else if (isList) { + Map<String, String> map = conf.listConfiguration(input); + for (Map.Entry<String, String> entry : map.entrySet()) { + System.out.println(entry.getKey() + " : " + entry.getValue()); + } + } else if (isUpdate) { + conf.updateConfigurationValue(input); + } + } + } + + private static boolean isSwitch(String key) { + return key.startsWith("-"); + } + + private static String getValueFor(String key, String[] args) { + for (int i = 0; i < args.length; i++) { + if (isSwitch(args[i])) { + String node = args[i].substring(1); + if (node.equalsIgnoreCase(key) && i < args.length - 1) { + return args[i + 1].trim().length() == 0 ? null : args[i + 1].trim(); + } + } + } + return null; + } + + private static boolean isKeyPresent(String key, String[] args) { + for (int i = 0; i < args.length; i++) { + if (isSwitch(args[i])) { + String node = args[i].substring(1); + if (node.equalsIgnoreCase(key)) { + return true; + } + } + } + return false; + } +} |