org.apache.commons.configuration.SubnodeConfiguration Java Examples
The following examples show how to use
org.apache.commons.configuration.SubnodeConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 7 votes |
@Override protected void notify(Parameters parameters) throws NotificationException { SubnodeConfiguration config = retrieveTeamInformation(); if (config == null) { throw new NotificationException("Invalid configuration"); } SlackWebApiClient slackClient = SlackClientFactory.createWebApiClient(config.getString("accessToken")); ChatPostMessageMethod chatPostMessageMethod = new ChatPostMessageMethod(channel, message); chatPostMessageMethod.setAs_user(true); slackClient.postMessage(chatPostMessageMethod); log.info("https://" + config.getString("teamName") + ".slack.com/messages/" + channel + "/"); }
Example #2
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 6 votes |
@Override protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException { String teamId = accessTokenData.get("teamId"); configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId); SubnodeConfiguration section = configuration.getSection(teamId); section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken()); for (Map.Entry<String, String> entry : accessTokenData.getData()) { section.setProperty(entry.getKey(), entry.getValue()); } try { configuration.save(); } catch (ConfigurationException e) { throw new NotificationException(e); } }
Example #3
Source File: LServerClientTest.java From development with Apache License 2.0 | 6 votes |
@Test public void getConfiguration() throws Exception { // given LPlatformClient lplatformClient = prepareLPlatformClient(); HashMap<String, String> request = prepareRequest("GetLServerConfiguration"); XMLConfiguration xMLConfiguration = mock(XMLConfiguration.class); SubnodeConfiguration config = mock(SubnodeConfiguration.class); when(config.getString(eq(VMTYPE))).thenReturn(VMTYPE); when(xMLConfiguration.configurationAt(eq("lserver"))) .thenReturn(config); when(vdcClient.execute(eq(request))).thenReturn(xMLConfiguration); // when prepareLServerClient(lplatformClient); LServerConfiguration result = lServerClient.getConfiguration(); // then assertEquals(result.getVmType(), VMTYPE); }
Example #4
Source File: ConfigurableIngestTopology.java From cognition with Apache License 2.0 | 6 votes |
void configure(HierarchicalConfiguration conf) throws Exception { this.stormConfig = new Config(); this.builder = new TopologyBuilder(); SubnodeConfiguration topologyConf = conf.configurationAt(TOPOLOGY); this.topologyName = getTopologyName(topologyConf); SubnodeConfiguration stormConf = topologyConf.configurationAt(STORM_CONF); configureStorm(stormConf, stormConfig); SubnodeConfiguration spoutConf = conf.configurationAt(SPOUT); String spout = configureSpout(builder, spoutConf); SubnodeConfiguration boltConfs = conf.configurationAt(BOLTS); configureBolts(builder, boltConfs, spout); }
Example #5
Source File: ModelConfig.java From modernmt with Apache License 2.0 | 6 votes |
public Map<LanguageDirection, File> getAvailableModels() { HashMap<LanguageDirection, File> result = new HashMap<>(); SubnodeConfiguration models; try { models = config.configurationAt("models"); } catch (IllegalArgumentException iex) { // the passed in key does not map to exactly one node return result; } Iterator<String> keyIterator = models.getKeys(); while (keyIterator.hasNext()) { String key = keyIterator.next(); String[] parts = key.split("__"); LanguageDirection language = new LanguageDirection(Language.fromString(parts[0]), Language.fromString(parts[1])); File model = new File(basePath, models.getString(key)); result.put(language, model); } return result; }
Example #6
Source File: EurostagImpactAnalysis.java From ipst with Mozilla Public License 2.0 | 6 votes |
private void writeWp43Configs(List<Contingency> contingencies, Path workingDir) throws IOException, ConfigurationException { Path baseWp43ConfigFile = PlatformConfig.defaultConfig().getConfigDir().resolve(WP43_CONFIGS_FILE_NAME); // generate one variant of the base config for all the contingency // this allow to add extra variables for some indexes HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(baseWp43ConfigFile.toFile()); SubnodeConfiguration node = configuration.getSection("smallsignal"); node.setProperty("f_instant", parameters.getFaultEventInstant()); for (int i = 0; i < contingencies.size(); i++) { Contingency contingency = contingencies.get(i); if (contingency.getElements().isEmpty()) { throw new AssertionError("Empty contingency " + contingency.getId()); } Iterator<ContingencyElement> it = contingency.getElements().iterator(); // compute the maximum fault duration double maxDuration = getFaultDuration(contingency, it.next()); while (it.hasNext()) { maxDuration = Math.max(maxDuration, getFaultDuration(contingency, it.next())); } node.setProperty("f_duration", maxDuration); Path wp43Config = workingDir.resolve(WP43_CONFIGS_PER_FAULT_FILE_NAME.replace(CommandConstants.EXECUTION_NUMBER_PATTERN, Integer.toString(i))); try (Writer writer = Files.newBufferedWriter(wp43Config, StandardCharsets.UTF_8)) { configuration.save(writer); } } }
Example #7
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 6 votes |
@Override protected void storeAccessTokenData(AccessTokenData accessTokenData, HierarchicalINIConfiguration configuration) throws NotificationException { String teamId = accessTokenData.get("teamId"); configuration.setProperty(KEY_DEFAULT_TEAM_ID, teamId); SubnodeConfiguration section = configuration.getSection(teamId); section.setProperty(KEY_ACCESS_TOKEN, accessTokenData.getAccessToken()); for (Map.Entry<String, String> entry : accessTokenData.getData()) { section.setProperty(entry.getKey(), entry.getValue()); } try { configuration.save(); } catch (ConfigurationException e) { throw new NotificationException(e); } }
Example #8
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 6 votes |
@Override protected void notify(Parameters parameters) throws NotificationException { SubnodeConfiguration config = retrieveTeamInformation(); if (config == null) { throw new NotificationException("Invalid configuration"); } SlackWebApiClient slackClient = SlackClientFactory.createWebApiClient(config.getString("accessToken")); ChatPostMessageMethod chatPostMessageMethod = new ChatPostMessageMethod(channel, message); chatPostMessageMethod.setAs_user(true); slackClient.postMessage(chatPostMessageMethod); log.info("https://" + config.getString("teamName") + ".slack.com/messages/" + channel + "/"); }
Example #9
Source File: ModelConfig.java From modernmt with Apache License 2.0 | 5 votes |
public int getSuggestionsLimit() { try { SubnodeConfiguration settings = config.configurationAt("settings"); return settings.getInt("memory_suggestions_limit", DEFAULT_SUGGESTIONS_LIMIT); } catch (IllegalArgumentException iex) { return DEFAULT_SUGGESTIONS_LIMIT; } }
Example #10
Source File: ConfigHandler.java From DDF with Apache License 2.0 | 5 votes |
/** * Load configuration from ddf.ini, or the file name specified by the environment variable DDF_INI. * * @return the {@link Configuration} object loaded * @throws Exception * @throws ConfigurationException , {@link IOException} */ @Override public Configuration loadConfig() throws ConfigurationException, IOException { Configuration resultConfig = new Configuration(); if (!Utils.localFileExists(this.getConfigFileName())) { // String configFileName = System.getenv(ConfigConstant.DDF_INI_ENV_VAR.getValue()); File file = new File(this.locateConfigFileName(this.getConfigDir(), this.getConfigFileName())); mConfigDir = file.getParentFile().getName(); mConfigFileName = file.getCanonicalPath(); } if (!Utils.localFileExists(this.getConfigFileName())) return null; HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(this.getConfigFileName()); @SuppressWarnings("unchecked") Set<String> sectionNames = config.getSections(); for (String sectionName : sectionNames) { SubnodeConfiguration section = config.getSection(sectionName); if (section != null) { Configuration.Section resultSection = resultConfig.getSection(sectionName); @SuppressWarnings("unchecked") Iterator<String> keys = section.getKeys(); while (keys.hasNext()) { String key = keys.next(); String value = section.getString(key); if (value != null) { resultSection.set(key, value); } } } } mConfig = resultConfig; return mConfig; }
Example #11
Source File: ConfigurableIngestTopologyTest.java From cognition with Apache License 2.0 | 5 votes |
@Test public void testConfigure( @Injectable HierarchicalConfiguration conf, @Injectable SubnodeConfiguration topologyConf, @Injectable SubnodeConfiguration stormConf, @Injectable SubnodeConfiguration spoutConf, @Injectable SubnodeConfiguration boltConfs, @Injectable String topologyName, @Injectable String spout) throws Exception { new Expectations(topology) {{ conf.configurationAt(TOPOLOGY); result = topologyConf; topology.getTopologyName(topologyConf); result = topologyName; topologyConf.configurationAt(STORM_CONF); result = stormConf; topology.configureStorm(stormConf, (Config) any); conf.configurationAt(SPOUT); result = spoutConf; topology.configureSpout((TopologyBuilder) any, spoutConf); result = spout; conf.configurationAt(BOLTS); result = boltConfs; topology.configureBolts((TopologyBuilder) any, boltConfs, spout); }}; topology.configure(conf); }
Example #12
Source File: ConfigurableIngestTopology.java From cognition with Apache License 2.0 | 5 votes |
/** * Gets a topology builder and set of storm bolt configurations. Initializes the bolts and sets them with the * topology builder. * * @param builder storm topology builder * @param boltsConf component configurations * @param spout type of storm component being added (spout/bolt) * @throws ConfigurationException */ void configureBolts(TopologyBuilder builder, SubnodeConfiguration boltsConf, String spout) throws ConfigurationException { String prevComponent = spout; // bolts subscribe to other bolts by number HashMap<Integer, String> boltNumberToId = new HashMap<>(); List<HierarchicalConfiguration> bolts = boltsConf.configurationsAt(BOLT); for (HierarchicalConfiguration bolt : bolts) { String boltType = bolt.getString(TYPE); Configuration boltConf = bolt.configurationAt(CONF); int boltNum = bolt.getInt(NUMBER_ATTRIBUTE); String boltId = String.format("%02d_%s", boltNum, boltType); boltNumberToId.put(boltNum, boltId); String subscribingToComponent = getSubscribingToComponent(prevComponent, boltNumberToId, boltConf); logger.info("{} subscribing to {}", boltId, subscribingToComponent); IComponent baseComponent = buildComponent(boltType, boltConf); StormParallelismConfig stormParallelismConfig = getStormParallelismConfig(boltConf); BoltDeclarer declarer = buildBoltDeclarer(builder, stormParallelismConfig, boltId, baseComponent); configureTickFrequency(boltConf, declarer); configureStreamGrouping(subscribingToComponent, boltConf, declarer); prevComponent = boltId; boltNum++; } }
Example #13
Source File: ModelConfig.java From modernmt with Apache License 2.0 | 5 votes |
public int getQueryMinimumResults() { try { SubnodeConfiguration settings = config.configurationAt("settings"); return settings.getInt("memory_query_min_results", DEFAULT_QUERY_MIN_RESULTS); } catch (IllegalArgumentException iex) { return DEFAULT_QUERY_MIN_RESULTS; } }
Example #14
Source File: LPlatformClientTest.java From development with Apache License 2.0 | 5 votes |
private void PrepareSubnodeConfiguration(HashMap<String, String> request) throws Exception { XMLConfiguration xMLConfiguration = mock(XMLConfiguration.class); SubnodeConfiguration config = mock(SubnodeConfiguration.class); when(config.getString(eq(LPLATFORMID))).thenReturn(LPLATFORMID); when(xMLConfiguration.configurationAt(eq(LPLATFORM))) .thenReturn(config); when(rorClient.execute(eq(request))).thenReturn(xMLConfiguration); }
Example #15
Source File: RORVSystemCommunicationTest.java From development with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void prepareLServerConfiguration(LPlatformClient platformClient) throws Exception { RORClient vdcClient = platformClient.getVdcClient(); HashMap<String, String> request = new HashMap<>(); doReturn(request).when(vdcClient).getBasicParameters(); XMLConfiguration xmlConfiguration = mock(XMLConfiguration.class); doReturn(xmlConfiguration).when(vdcClient).execute(any(HashMap.class)); SubnodeConfiguration config = mock(SubnodeConfiguration.class); doReturn(PRIVATE_IP).when(config).getString(NIC_PRIVATE_IP); doReturn(config).when(xmlConfiguration).configurationAt("lserver"); }
Example #16
Source File: DymolaAdaptersMatParamsWriter.java From ipst with Mozilla Public License 2.0 | 5 votes |
public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration) { if (configuration == null) { throw new RuntimeException("null config"); } this.configuration = configuration; //this below will simply log parameters .. for (String section : configuration.getSections()) { SubnodeConfiguration node = configuration.getSection(section); List<String> paramsSummary = StreamSupport.stream( Spliterators.spliteratorUnknownSize(node.getKeys(), Spliterator.ORDERED), false).map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList()); LOGGER.info("index {}: {}", section, paramsSummary); } }
Example #17
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 4 votes |
private SubnodeConfiguration retrieveTeamInformation() throws NotificationException { return getConfiguration().getSection(getTeamId()); }
Example #18
Source File: SlackNotifier.java From yfiton with Apache License 2.0 | 4 votes |
private SubnodeConfiguration retrieveTeamInformation() throws NotificationException { return getConfiguration().getSection(getTeamId()); }
Example #19
Source File: ConfigurableIngestTopologyTest.java From cognition with Apache License 2.0 | 4 votes |
@Test public void testConfigureBolts( @Injectable TopologyBuilder builder, @Injectable SubnodeConfiguration boltsConf, @Injectable HierarchicalConfiguration bolt, @Injectable SubnodeConfiguration boltConf, @Injectable IComponent baseComponent, @Injectable StormParallelismConfig stormParallelismConfig, @Injectable BoltDeclarer declarer) throws Exception { List<HierarchicalConfiguration> bolts = Arrays.asList(bolt); String spout = "spout_id"; new Expectations(topology) {{ boltsConf.configurationsAt(BOLT); result = bolts; bolt.getString(TYPE); result = "bolt_type"; bolt.configurationAt(CONF); result = boltConf; bolt.getInt(NUMBER_ATTRIBUTE); result = 0; topology.getSubscribingToComponent(spout, (HashMap<Integer, String>) any, boltConf); result = spout; topology.buildComponent("bolt_type", boltConf); result = baseComponent; topology.getStormParallelismConfig(boltConf); result = stormParallelismConfig; topology.buildBoltDeclarer(builder, stormParallelismConfig, "00_bolt_type", baseComponent); result = declarer; topology.configureTickFrequency(boltConf, declarer); topology.configureStreamGrouping(spout, boltConf, declarer); }}; topology.configureBolts(builder, boltsConf, spout); }