1 package org.onap.config.cli.app;
3 import org.onap.config.api.ConfigurationManager;
5 import javax.management.JMX;
6 import javax.management.MBeanServerConnection;
7 import javax.management.ObjectName;
8 import javax.management.remote.JMXConnector;
9 import javax.management.remote.JMXConnectorFactory;
10 import javax.management.remote.JMXServiceURL;
11 import java.util.HashMap;
15 * The type Configuration.
17 public class Configuration {
20 * The entry point of application.
22 * @param args the input arguments
23 * @throws Exception the exception
25 public static void main(String[] args) throws Exception {
27 String host = getValueFor("host", args);
28 String port = getValueFor("port", args);
37 new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
38 Map<String, String[]> env = new HashMap<>();
39 //populate dummy value. need to be changed as per impl.
40 String[] credentials = {"principal", "password"};
41 env.put(JMXConnector.CREDENTIALS, credentials);
43 try (JMXConnector jmxc = JMXConnectorFactory.connect(url, env)) {
45 boolean isUpdate = isKeyPresent("update", args);
47 Map<String, Object> input = new HashMap<>();
48 input.put("ImplClass", isUpdate ? "org.onap.config.type.ConfigurationUpdate"
49 : "org.onap.config.type.ConfigurationQuery");
50 input.put("externalLookup", isKeyPresent("lookup", args));
51 input.put("nodeOverride", isKeyPresent("nodeOverride", args));
52 input.put("nodeSpecific", isKeyPresent("nodeSpecific", args));
53 input.put("fallback", isKeyPresent("fallback", args));
54 input.put("latest", isKeyPresent("latest", args));
55 input.put("tenant", getValueFor("tenant", args));
56 input.put("namespace", getValueFor("namespace", args));
57 input.put("key", getValueFor("key", args));
58 input.put("value", getValueFor("value", args));
61 if (!isKeyPresent("list", args) && getValueFor("key", args) == null) {
62 throw new RuntimeException("Key is missing.");
64 if (isKeyPresent("update", args) && getValueFor("value", args) == null) {
65 throw new RuntimeException("Value is missing.");
69 MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
70 ObjectName mbeanName = new ObjectName("org.openecomp.jmx:name=SystemConfig");
71 org.onap.config.api.ConfigurationManager conf =
72 JMX.newMBeanProxy(mbsc, mbeanName, org.onap.config.api.ConfigurationManager.class,
75 boolean isGet = isKeyPresent("get", args);
76 boolean isList = isKeyPresent("list", args);
78 System.out.println(conf.getConfigurationValue(input));
80 Map<String, String> map = conf.listConfiguration(input);
81 for (Map.Entry<String, String> entry : map.entrySet()) {
82 System.out.println(entry.getKey() + " : " + entry.getValue());
84 } else if (isUpdate) {
85 conf.updateConfigurationValue(input);
90 private static boolean isSwitch(String key) {
91 return key.startsWith("-");
94 private static String getValueFor(String key, String[] args) {
95 for (int i = 0; i < args.length; i++) {
96 if (isSwitch(args[i])) {
97 String node = args[i].substring(1);
98 if (node.equalsIgnoreCase(key) && i < args.length - 1) {
99 return args[i + 1].trim().length() == 0 ? null : args[i + 1].trim();
106 private static boolean isKeyPresent(String key, String[] args) {
107 for (int i = 0; i < args.length; i++) {
108 if (isSwitch(args[i])) {
109 String node = args[i].substring(1);
110 if (node.equalsIgnoreCase(key)) {