Creates a new ConfigArgP @param args The command line arguments
(String...args)
| 114 | * @param args The command line arguments |
| 115 | */ |
| 116 | public ConfigArgP(String...args) { |
| 117 | InputStream is = null; |
| 118 | commandLineArgs = Collections.unmodifiableSet(new LinkedHashSet<String>(Arrays.asList(args))); |
| 119 | try { |
| 120 | config = new NoLoadConfig(); |
| 121 | is = ConfigArgP.class.getClassLoader().getResourceAsStream("opentsdb.conf.json"); |
| 122 | ObjectMapper jsonMapper = new ObjectMapper(); |
| 123 | JsonNode root = jsonMapper.reader().readTree(is); |
| 124 | JsonNode configRoot = root.get("config-items"); |
| 125 | scriptEngine.eval("var config = " + configRoot.toString() + ";"); |
| 126 | processBindings(jsonMapper, root); |
| 127 | // Contains all the defaults |
| 128 | final ConfigurationItem[] loadedItems = jsonMapper.reader(ConfigurationItem[].class).readValue(configRoot); |
| 129 | // Contains all the defaults |
| 130 | final TreeSet<ConfigurationItem> items = new TreeSet<ConfigurationItem>(Arrays.asList(loadedItems)); |
| 131 | |
| 132 | Map<String, ConfigurationItem> tmpItems = new HashMap<String, ConfigurationItem>(items.size()); |
| 133 | for(Iterator<ConfigurationItem> iter = items.iterator(); iter.hasNext();) { |
| 134 | ConfigurationItem item = iter.next(); |
| 135 | if(tmpItems.containsKey(item.getKey())) throw new RuntimeException("opentsdb.conf.json contains duplicate key: [" + item.getKey() + "]"); |
| 136 | if(tmpItems.containsKey(item.getClOption())) throw new RuntimeException("opentsdb.conf.json contains duplicate clOption: [" + item.getClOption() + "]"); |
| 137 | tmpItems.put(item.getKey(), item); |
| 138 | tmpItems.put(item.getClOption(), item); |
| 139 | // if("BOOL".equals(item.getMeta())) iter.remove(); |
| 140 | } |
| 141 | defaultConfItems = Collections.unmodifiableMap(tmpItems); |
| 142 | LOG.debug("Loaded [{}] Configuration Items from opentsdb.conf.json", items.size()); |
| 143 | if(LOG.isDebugEnabled()) { |
| 144 | StringBuilder b = new StringBuilder("Configs:"); |
| 145 | for(ConfigurationItem ci: items) { |
| 146 | b.append("\n\t").append(ci.toString()); |
| 147 | } |
| 148 | b.append("\n"); |
| 149 | LOG.debug(b.toString()); |
| 150 | } |
| 151 | for(ConfigurationItem ci: items) { |
| 152 | LOG.debug("Processing CI [{}]", ci.getKey()); |
| 153 | if(ci.meta!=null) { |
| 154 | argp.addOption(ci.clOption, ci.meta, ci.description); |
| 155 | LOG.debug("Registered Meta ArgP cl:[{}], meta:[{}]", ci.clOption, ci.meta); |
| 156 | if("default".equals(ci.help)) dargp.addOption(ci.clOption, ci.meta, ci.description); |
| 157 | } else { |
| 158 | argp.addOption(ci.clOption, ci.description); |
| 159 | LOG.debug("Registered No Meta ArgP cl:[{}]", ci.clOption); |
| 160 | if("default".equals(ci.help)) dargp.addOption(ci.clOption, ci.description); |
| 161 | } |
| 162 | if(!configItemsByKey.add(ci)) { |
| 163 | throw new RuntimeException("Duplicate configuration key [" + ci.key + "] in opentsdb.conf.json. Programmer Error."); |
| 164 | } |
| 165 | if(!configItemsByCl.add(ci)) { |
| 166 | throw new RuntimeException("Duplicate configuration command line option [" + ci.clOption + "] in opentsdb.conf.json. Programmer Error."); |
| 167 | } |
| 168 | if(ci.getDefaultValue()!=null && !ci.getDefaultValue().trim().isEmpty()) { |
| 169 | ci.setValue(processConfigValue(ci.getDefaultValue())); |
| 170 | config.overrideConfig(ci.key, processConfigValue(ci.getValue())); |
| 171 | } |
| 172 | } |
| 173 | nonOptionArgs = applyArgs(args); |
nothing calls this directly
no test coverage detected