Example usage for org.apache.commons.configuration Configuration addProperty

List of usage examples for org.apache.commons.configuration Configuration addProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration addProperty.

Prototype

void addProperty(String key, Object value);

Source Link

Document

Add a property to the configuration.

Usage

From source file:fr.mby.portal.coreimpl.configuration.PropertiesConfigurationManagerTest.java

/**
 * test 3.//from   www . jav a  2  s.c om
 * 
 * @throws Exception
 */
@Test
public void testFlush() throws Exception {
    final Configuration config1 = this.configManager.initConfiguration(PropertiesConfigurationManagerTest.KEY2,
            PropertiesConfigurationManagerTest.TYPE2, PropertiesConfigurationManagerTest.TAG2);
    Assert.assertNotNull("Config not initialized !", config1);
    config1.addProperty("key2", "Value2");

    // Flush
    this.configManager.flushConfiguration(PropertiesConfigurationManagerTest.KEY2);

    final Configuration config2 = this.configManager.getConfiguration(PropertiesConfigurationManagerTest.KEY2);
    Assert.assertNotNull("Config cannot be retrieved !", config2);
    Assert.assertEquals("Bad property value in config !", "Value2", config2.getString("key2"));

    Assert.assertNotNull("Tags cannot be retrieved !", this.configManager.getConfigurationTags());
    Assert.assertEquals("Tags count bad !", 1, this.configManager.getConfigurationTags().size());
    final String configKey = this.configManager.getConfigurationTags().iterator().next();
    Assert.assertEquals("Tag name bad !", PropertiesConfigurationManagerTest.KEY2, configKey);

    Assert.assertNotNull("Empty collection not returned !",
            this.configManager.getConfigurationKeys("unknownTag"));
}

From source file:io.mindmaps.graql.internal.analytics.DegreeVertexProgram.java

@Override
public void storeState(final Configuration configuration) {
    configuration.setProperty(VERTEX_PROGRAM, DegreeVertexProgram.class.getName());
    Iterator iterator = selectedTypes.iterator();
    int count = 0;
    while (iterator.hasNext()) {
        configuration.addProperty(TYPE + "." + count, iterator.next());
        count++;/*  ww  w. j a  v  a  2 s  .co  m*/
    }
}

From source file:io.mindmaps.graql.internal.analytics.CountMapReduce.java

@Override
public void storeState(final Configuration configuration) {
    configuration.setProperty(COUNT_MEMORY_KEY, this.memoryKey);
    configuration.setProperty(MAP_REDUCE, CountMapReduce.class.getName());
    Iterator iterator = selectedTypes.iterator();
    int count = 0;
    while (iterator.hasNext()) {
        configuration.addProperty(TYPE + "." + count, iterator.next());
        count++;/*from w ww  . j  a  v  a2 s. c o  m*/
    }
}

From source file:com.linkedin.pinot.tools.perf.PerfBenchmarkDriver.java

private void startServer() throws Exception {
    if (!_conf.shouldStartServer()) {
        LOGGER.info("Skipping start server step. Assumes server is already started.");
        return;//from   w  ww .  j a v  a  2  s  .co m
    }
    Configuration serverConfiguration = new PropertiesConfiguration();
    serverConfiguration.addProperty(CommonConstants.Server.CONFIG_OF_INSTANCE_DATA_DIR, _serverInstanceDataDir);
    serverConfiguration.addProperty(CommonConstants.Server.CONFIG_OF_INSTANCE_SEGMENT_TAR_DIR,
            _serverInstanceSegmentTarDir);
    serverConfiguration.setProperty(CommonConstants.Server.CONFIG_OF_SEGMENT_FORMAT_VERSION,
            _segmentFormatVersion);
    serverConfiguration.setProperty("instanceId", _serverInstanceName);
    LOGGER.info("Starting server instance: {}", _serverInstanceName);
    new HelixServerStarter(_clusterName, _zkAddress, serverConfiguration);
}

From source file:io.mindmaps.graql.internal.analytics.DegreeAndPersistVertexProgram.java

@Override
public void storeState(final Configuration configuration) {
    configuration.setProperty(VERTEX_PROGRAM, DegreeAndPersistVertexProgram.class.getName());
    Iterator iterator = selectedTypes.iterator();
    int count = 0;
    while (iterator.hasNext()) {
        configuration.addProperty(TYPE + "." + count, iterator.next());
        count++;/*from   w ww. j  av a2  s. com*/
    }
    configuration.setProperty(KEYSPACE, keySpace);
}

From source file:com.linkedin.pinot.tools.admin.command.StartBrokerCommand.java

@Override
public boolean execute() throws Exception {
    if (_brokerHost == null) {
        _brokerHost = NetUtil.getHostAddress();
    }//from   w  w w .  j a v  a  2  s .  c om

    Configuration configuration = readConfigFromFile(_configFileName);
    if (configuration == null) {
        if (_configFileName != null) {
            LOGGER.error("Error: Unable to find file {}.", _configFileName);
            return false;
        }

        configuration = new PropertiesConfiguration();
        configuration.addProperty(CommonConstants.Helix.KEY_OF_BROKER_QUERY_PORT, _brokerPort);
        configuration.setProperty("pinot.broker.routing.table.builder.class", "random");
    }

    LOGGER.info("Executing command: " + toString());
    final HelixBrokerStarter pinotHelixBrokerStarter = new HelixBrokerStarter(_clusterName, _zkAddress,
            configuration);

    String pidFile = ".pinotAdminBroker-" + String.valueOf(System.currentTimeMillis()) + ".pid";
    savePID(System.getProperty("java.io.tmpdir") + File.separator + pidFile);
    return true;
}

From source file:ai.grakn.graql.internal.analytics.CommonOLAP.java

/**
 * Store <code>persistentProperties</code> and any hard coded fields in an apache config object for propagation to
 * spark executors./*from  w  w  w  . j av a  2  s  .  c o m*/
 *
 * @param configuration the apache config object that will be propagated
 */
public void storeState(final Configuration configuration) {
    // clear properties from vertex program
    Set<String> oldKeys = new HashSet<>();
    configuration.subset(PREFIX_SELECTED_TYPE_KEY).getKeys()
            .forEachRemaining(key -> oldKeys.add(PREFIX_SELECTED_TYPE_KEY + "." + key));
    oldKeys.forEach(configuration::clearProperty);

    // store selectedTypes
    selectedTypes.forEach(typeId -> configuration.addProperty(PREFIX_SELECTED_TYPE_KEY + "." + typeId, typeId));

    // store user specified properties
    persistentProperties.forEach(
            (key, value) -> configuration.addProperty(PREFIX_PERSISTENT_PROPERTIES + "." + key, value));
}

From source file:com.linkedin.pinot.tools.admin.command.StartServerCommand.java

@Override
public boolean execute() throws Exception {
    if (_serverHost == null) {
        _serverHost = NetUtil.getHostAddress();
    }/* w  w w.jav  a  2s  .c o m*/

    Configuration configuration = readConfigFromFile(_configFileName);
    if (configuration == null) {
        if (_configFileName != null) {
            LOGGER.error("Error: Unable to find file {}.", _configFileName);
            return false;
        }

        configuration = new PropertiesConfiguration();
        configuration.addProperty(CommonConstants.Helix.KEY_OF_SERVER_NETTY_HOST, _serverHost);
        configuration.addProperty(CommonConstants.Helix.KEY_OF_SERVER_NETTY_PORT, _serverPort);
        configuration.addProperty("pinot.server.instance.dataDir", _dataDir + _serverPort + "/index");
        configuration.addProperty("pinot.server.instance.segmentTarDir",
                _segmentDir + _serverPort + "/segmentTar");
    }

    LOGGER.info("Executing command: " + toString());
    final HelixServerStarter pinotHelixStarter = new HelixServerStarter(_clusterName, _zkAddress,
            configuration);
    String pidFile = ".pinotAdminServer-" + String.valueOf(System.currentTimeMillis()) + ".pid";
    savePID(System.getProperty("java.io.tmpdir") + File.separator + pidFile);
    return true;
}

From source file:com.linkedin.pinot.transport.common.routing.RoutingTableTest.java

@Test
public void testCombinedKafkaRouting() throws Exception {
    HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, NO_LLC_ROUTING);

    final long now = System.currentTimeMillis();
    final String tableName = "table";
    final String resourceName = tableName + "_REALTIME";
    final String group1 = resourceName + "_" + Long.toString(now) + "_0";
    final String group2 = resourceName + "_" + Long.toString(now) + "_1";
    final String online = "ONLINE";
    final String consuming = "CONSUMING";
    final int partitionId = 1;
    final String partitionRange = "JUNK";
    final int segId1 = 1;
    final int segId2 = 2;
    final int port1 = 1;
    final int port2 = 2;
    final String host = "host";
    final ServerInstance serverInstance1 = new ServerInstance(host, port1);
    final ServerInstance serverInstance2 = new ServerInstance(host, port2);
    final String helixInstance1 = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + serverInstance1;
    final String helixInstance2 = CommonConstants.Helix.PREFIX_OF_SERVER_INSTANCE + serverInstance2;
    final HLCSegmentName s1HlcSegment1 = new HLCSegmentName(group1, partitionRange, Integer.toString(segId1));
    final HLCSegmentName s1HlcSegment2 = new HLCSegmentName(group1, partitionRange, Integer.toString(segId2));
    final HLCSegmentName s2HlcSegment1 = new HLCSegmentName(group2, partitionRange, Integer.toString(segId1));
    final HLCSegmentName s2HlcSegment2 = new HLCSegmentName(group2, partitionRange, Integer.toString(segId2));
    final LLCSegmentName llcSegment1 = new LLCSegmentName(tableName, partitionId, segId1, now);
    final LLCSegmentName llcSegment2 = new LLCSegmentName(tableName, partitionId, segId2, now);

    final List<InstanceConfig> instanceConfigs = new ArrayList<>(2);
    instanceConfigs.add(new InstanceConfig(helixInstance1));
    instanceConfigs.add(new InstanceConfig(helixInstance2));
    ExternalView ev = new ExternalView(resourceName);
    ev.setState(s1HlcSegment1.getSegmentName(), helixInstance1, online);
    ev.setState(s1HlcSegment2.getSegmentName(), helixInstance1, online);
    ev.setState(llcSegment1.getSegmentName(), helixInstance2, online);
    ev.setState(llcSegment2.getSegmentName(), helixInstance2, consuming);
    routingTable.markDataResourceOnline(resourceName, ev, instanceConfigs);

    final RoutingTableLookupRequest request = new RoutingTableLookupRequest(resourceName);
    for (int i = 0; i < 100; i++) {
        Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
        Assert.assertEquals(routingMap.size(), 1);
        List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
        Assert.assertEquals(segments.size(), 2);
        Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
        Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
    }/*from   ww  w.j a va  2 s . co  m*/

    // Now change the percent value in the routing table selector to be 100, and we should get only LLC segments.
    Configuration configuration = new PropertiesConfiguration();
    configuration.addProperty("class", PercentageBasedRoutingTableSelector.class.getName());
    configuration.addProperty("table." + resourceName, new Integer(100));
    RoutingTableSelector selector = RoutingTableSelectorFactory.getRoutingTableSelector(configuration);
    selector.init(configuration);
    Field selectorField = HelixExternalViewBasedRouting.class.getDeclaredField("_routingTableSelector");
    selectorField.setAccessible(true);
    selectorField.set(routingTable, selector);

    // And we should find only LLC segments.
    for (int i = 0; i < 100; i++) {
        Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
        Assert.assertEquals(routingMap.size(), 1);
        List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
        Assert.assertEquals(segments.size(), 2);
        Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
        Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
    }

    // Now change it to 50, and we should find both (at least 10 times each).
    configuration = new PropertiesConfiguration();
    configuration.addProperty("table." + resourceName, new Integer(50));
    selector = new PercentageBasedRoutingTableSelector();
    selector.init(configuration);
    selectorField.set(routingTable, selector);

    int hlc = 0;
    int llc = 0;
    for (int i = 0; i < 100; i++) {
        Map<ServerInstance, SegmentIdSet> routingMap = routingTable.findServers(request);
        Assert.assertEquals(routingMap.size(), 1);
        if (routingMap.containsKey(serverInstance2)) {
            List<String> segments = routingMap.get(serverInstance2).getSegmentsNameList();
            Assert.assertEquals(segments.size(), 2);
            Assert.assertTrue(segments.contains(llcSegment1.getSegmentName()));
            Assert.assertTrue(segments.contains(llcSegment2.getSegmentName()));
            llc++;
        } else {
            List<String> segments = routingMap.get(serverInstance1).getSegmentsNameList();
            Assert.assertEquals(segments.size(), 2);
            Assert.assertTrue(segments.contains(s1HlcSegment1.getSegmentName()));
            Assert.assertTrue(segments.contains(s1HlcSegment2.getSegmentName()));
            hlc++;
        }
    }

    // If we do the above iteration 100 times, we should get at least 10 of each type of routing.
    // If this test fails
    Assert.assertTrue(hlc >= 10, "Got low values hlc=" + hlc + ",llc=" + llc);
    Assert.assertTrue(llc >= 10, "Got low values hlc=" + hlc + ",llc=" + llc);
}

From source file:com.linkedin.pinot.controller.api.resources.PinotTableRestletResource.java

@POST
@Produces(MediaType.APPLICATION_JSON)/*from  w  ww. j  a v  a 2s  .c o m*/
@Path("/tables/{tableName}/rebalance")
@ApiOperation(value = "Rebalances segments of a table across servers", notes = "Rebalances segments of a table across servers")
public String rebalance(
        @ApiParam(value = "Name of the table to rebalance") @Nonnull @PathParam("tableName") String tableName,
        @ApiParam(value = "offline|realtime") @Nonnull @QueryParam("type") String tableType,
        @ApiParam(value = "true|false") @Nonnull @QueryParam("dryrun") Boolean dryRun,
        @ApiParam(value = "true|false") @DefaultValue("false") @QueryParam("includeConsuming") Boolean includeConsuming) {

    if (tableType != null
            && !EnumUtils.isValidEnum(CommonConstants.Helix.TableType.class, tableType.toUpperCase())) {
        throw new ControllerApplicationException(LOGGER, "Illegal table type " + tableType,
                Response.Status.BAD_REQUEST);
    }

    Configuration rebalanceUserConfig = new PropertiesConfiguration();
    rebalanceUserConfig.addProperty(RebalanceUserConfigConstants.DRYRUN, dryRun);
    rebalanceUserConfig.addProperty(RebalanceUserConfigConstants.INCLUDE_CONSUMING, includeConsuming);

    JSONObject jsonObject = null;
    try {
        jsonObject = _pinotHelixResourceManager.rebalanceTable(tableName,
                CommonConstants.Helix.TableType.valueOf(tableType.toUpperCase()), rebalanceUserConfig);
    } catch (JSONException e) {
        throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
    } catch (InvalidConfigException e) {
        throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.BAD_REQUEST);
    }
    return jsonObject.toString();

}