1 package org.openecomp.config.cli.app;
3 import org.openecomp.config.api.ConfigurationChangeListener;
4 import org.openecomp.config.api.ConfigurationManager;
6 import java.util.HashMap;
9 import javax.management.JMX;
10 import javax.management.MBeanServerConnection;
11 import javax.management.ObjectName;
12 import javax.management.remote.JMXConnector;
13 import javax.management.remote.JMXConnectorFactory;
14 import javax.management.remote.JMXServiceURL;
17 * The type Configuration.
19 public class Configuration {
22 * The entry point of application.
24 * @param args the input arguments
25 * @throws Exception the exception
27 public static void main(String[] args) throws Exception {
29 String host = getValueFor("host", args);
30 String port = getValueFor("port", args);
39 new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi");
40 Map<String, String[]> env = new HashMap<>();
41 //populate dummy value. need to be changed as per impl.
42 String[] credentials = {"principal", "password"};
43 env.put(JMXConnector.CREDENTIALS, credentials);
45 try (JMXConnector jmxc = JMXConnectorFactory.connect(url, env)) {
47 boolean isUpdate = isKeyPresent("update", args);
49 Map<String, Object> input = new HashMap<>();
50 input.put("ImplClass", isUpdate ? "org.openecomp.config.type.ConfigurationUpdate"
51 : "org.openecomp.config.type.ConfigurationQuery");
52 input.put("externalLookup", isKeyPresent("lookup", args));
53 input.put("nodeOverride", isKeyPresent("nodeOverride", args));
54 input.put("nodeSpecific", isKeyPresent("nodeSpecific", args));
55 input.put("fallback", isKeyPresent("fallback", args));
56 input.put("latest", isKeyPresent("latest", args));
57 input.put("tenant", getValueFor("tenant", args));
58 input.put("namespace", getValueFor("namespace", args));
59 input.put("key", getValueFor("key", args));
60 input.put("value", getValueFor("value", args));
63 if (!isKeyPresent("list", args) && getValueFor("key", args) == null) {
64 throw new RuntimeException("Key is missing.");
66 if (isKeyPresent("update", args) && getValueFor("value", args) == null) {
67 throw new RuntimeException("Value is missing.");
71 MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
72 ObjectName mbeanName = new ObjectName("org.openecomp.jmx:name=SystemConfig");
73 org.openecomp.config.api.ConfigurationManager conf =
74 JMX.newMBeanProxy(mbsc, mbeanName, org.openecomp.config.api.ConfigurationManager.class,
77 boolean isGet = isKeyPresent("get", args);
78 boolean isList = isKeyPresent("list", args);
80 System.out.println(conf.getConfigurationValue(input));
82 Map<String, String> map = conf.listConfiguration(input);
83 for (Map.Entry<String, String> entry : map.entrySet()) {
84 System.out.println(entry.getKey() + " : " + entry.getValue());
86 } else if (isUpdate) {
87 conf.updateConfigurationValue(input);
92 private static boolean isSwitch(String key) {
93 return key.startsWith("-");
96 private static String getValueFor(String key, String[] args) {
97 for (int i = 0; i < args.length; i++) {
98 if (isSwitch(args[i])) {
99 String node = args[i].substring(1);
100 if (node.equalsIgnoreCase(key) && i < args.length - 1) {
101 return args[i + 1].trim().length() == 0 ? null : args[i + 1].trim();
108 private static boolean isKeyPresent(String key, String[] args) {
109 for (int i = 0; i < args.length; i++) {
110 if (isSwitch(args[i])) {
111 String node = args[i].substring(1);
112 if (node.equalsIgnoreCase(key)) {