Example usage for org.apache.commons.configuration PropertiesConfiguration setProperty

List of usage examples for org.apache.commons.configuration PropertiesConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Document

Sets a new value for the specified property.

Usage

From source file:com.linkedin.pinot.core.segment.creator.impl.SegmentColumnarIndexCreator.java

void writeMetadata() throws ConfigurationException {
    PropertiesConfiguration properties = new PropertiesConfiguration(
            new File(file, V1Constants.MetadataKeys.METADATA_FILE_NAME));

    properties.setProperty(SEGMENT_CREATOR_VERSION, config.getCreatorVersion());
    properties.setProperty(SEGMENT_PADDING_CHARACTER,
            StringEscapeUtils.escapeJava(Character.toString(config.getPaddingCharacter())));
    properties.setProperty(SEGMENT_NAME, segmentName);
    properties.setProperty(TABLE_NAME, config.getTableName());
    properties.setProperty(DIMENSIONS, config.getDimensions());
    properties.setProperty(METRICS, config.getMetrics());
    properties.setProperty(TIME_COLUMN_NAME, config.getTimeColumnName());
    properties.setProperty(TIME_INTERVAL, "not_there");
    properties.setProperty(SEGMENT_TOTAL_RAW_DOCS, String.valueOf(totalRawDocs));
    properties.setProperty(SEGMENT_TOTAL_AGGREGATE_DOCS, String.valueOf(totalAggDocs));
    properties.setProperty(SEGMENT_TOTAL_DOCS, String.valueOf(totalDocs));
    properties.setProperty(STAR_TREE_ENABLED, String.valueOf(config.isEnableStarTreeIndex()));
    properties.setProperty(SEGMENT_TOTAL_ERRORS, String.valueOf(totalErrors));
    properties.setProperty(SEGMENT_TOTAL_NULLS, String.valueOf(totalNulls));
    properties.setProperty(SEGMENT_TOTAL_CONVERSIONS, String.valueOf(totalConversions));
    properties.setProperty(SEGMENT_TOTAL_NULL_COLS, String.valueOf(totalNullCols));

    StarTreeIndexSpec starTreeIndexSpec = config.getStarTreeIndexSpec();
    if (starTreeIndexSpec != null) {
        properties.setProperty(STAR_TREE_SPLIT_ORDER, starTreeIndexSpec.getDimensionsSplitOrder());
        properties.setProperty(STAR_TREE_MAX_LEAF_RECORDS, starTreeIndexSpec.getMaxLeafRecords());
        properties.setProperty(STAR_TREE_SKIP_STAR_NODE_CREATION_FOR_DIMENSIONS,
                starTreeIndexSpec.getSkipStarNodeCreationForDimensions());
        properties.setProperty(STAR_TREE_SKIP_MATERIALIZATION_CARDINALITY,
                starTreeIndexSpec.getskipMaterializationCardinalityThreshold());
        properties.setProperty(STAR_TREE_SKIP_MATERIALIZATION_FOR_DIMENSIONS,
                starTreeIndexSpec.getskipMaterializationForDimensions());
    }/*from w ww .j  av  a2  s .  c o m*/

    HllConfig hllConfig = config.getHllConfig();
    Map<String, String> derivedHllFieldToOriginMap = null;
    if (hllConfig != null) {
        properties.setProperty(SEGMENT_HLL_LOG2M, hllConfig.getHllLog2m());
        derivedHllFieldToOriginMap = hllConfig.getDerivedHllFieldToOriginMap();
    }

    String timeColumn = config.getTimeColumnName();
    if (indexCreationInfoMap.get(timeColumn) != null) {
        properties.setProperty(SEGMENT_START_TIME, indexCreationInfoMap.get(timeColumn).getMin());
        properties.setProperty(SEGMENT_END_TIME, indexCreationInfoMap.get(timeColumn).getMax());
        properties.setProperty(TIME_UNIT, config.getSegmentTimeUnit());
    }

    if (config.containsCustomProperty(SEGMENT_START_TIME)) {
        properties.setProperty(SEGMENT_START_TIME, config.getStartTime());
    }
    if (config.containsCustomProperty(SEGMENT_END_TIME)) {
        properties.setProperty(SEGMENT_END_TIME, config.getEndTime());
    }
    if (config.containsCustomProperty(TIME_UNIT)) {
        properties.setProperty(TIME_UNIT, config.getSegmentTimeUnit());
    }

    for (Map.Entry<String, String> entry : config.getCustomProperties().entrySet()) {
        properties.setProperty(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<String, ColumnIndexCreationInfo> entry : indexCreationInfoMap.entrySet()) {
        String column = entry.getKey();
        ColumnIndexCreationInfo columnIndexCreationInfo = entry.getValue();
        int dictionaryElementSize = dictionaryCreatorMap.get(column).getStringColumnMaxLength();

        // TODO: after fixing the server-side dependency on HAS_INVERTED_INDEX and deployed, set HAS_INVERTED_INDEX properly
        // The hasInvertedIndex flag in segment metadata is picked up in ColumnMetadata, and will be used during the query
        // plan phase. If it is set to false, then inverted indexes are not used in queries even if they are created via table
        // configs on segment load. So, we set it to true here for now, until we fix the server to update the value inside
        // ColumnMetadata, export information to the query planner that the inverted index available is current and can be used.
        //
        //    boolean hasInvertedIndex = invertedIndexCreatorMap.containsKey();
        boolean hasInvertedIndex = true;

        String hllOriginColumn = null;
        if (derivedHllFieldToOriginMap != null) {
            hllOriginColumn = derivedHllFieldToOriginMap.get(column);
        }

        addColumnMetadataInfo(properties, column, columnIndexCreationInfo, totalDocs, totalRawDocs,
                totalAggDocs, schema.getFieldSpecFor(column), dictionaryElementSize, hasInvertedIndex,
                hllOriginColumn);
    }

    properties.save();
}

From source file:net.sf.zekr.common.config.KeyboardShortcut.java

public KeyboardShortcut(PropertiesConfiguration props, Document shortcut) {
    this.props = props;
    doc = shortcut;//from  www  . j a v  a2 s  .  com

    try {
        commandAndControlAreSame = props.getBoolean("key.commandAndControlAreSame", true);
    } catch (Exception e) {
        // workaround for a bug in Zekr 0.7.5 beta 4
        commandAndControlAreSame = true;
        props.setProperty("key.commandAndControlAreSame", "true");
    }
}

From source file:com.example.titan.dynamodb.hystrix.issue.TitanConfigurationProvider.java

public GraphDatabaseConfiguration load() throws ConfigurationException, FileNotFoundException {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();

    // load property file if provided
    if (propertyFile != null) {
        final URL resource = getClass().getClassLoader().getResource(propertyFile);

        if (null == resource) {
            LOG.error("File 'titan.properties' cannot be found.");
            throw new FileNotFoundException("File 'titan.properties' cannot be found.");
        }//from  w w  w. j a v  a2s . com

        configuration.load(resource);
    }

    configuration.setProperty(STORAGE_HOSTNAME_KEY, storageHostname);

    if (StringUtils.isEmpty(properties.getProperty("storage.dynamodb.client.credentials.class-name"))) {
        properties.remove("storage.dynamodb.client.credentials.class-name");
        properties.remove("storage.dynamodb.client.credentials.constructor-args");
    }

    if (properties != null) {

        properties.stringPropertyNames().stream()
                .forEach(prop -> configuration.setProperty(prop, properties.getProperty(prop)));
    }

    LOG.info("Titan configuration: \n" + secureToString(configuration));

    // Warning: calling GraphDatabaseConfiguration constructor results in opening connections to backend storage
    return new GraphDatabaseConfiguration(new CommonsConfiguration(configuration));
}

From source file:cross.datastructures.pipeline.ResultAwareCommandPipeline.java

/**
 *
 * @param inputFiles/*from   w w w  .  j  a  v  a 2 s.c  o  m*/
 * @param cmd
 */
protected void updateHashes(TupleND<IFileFragment> inputFiles, IFragmentCommand cmd) {
    PropertiesConfiguration pc = getHashes(cmd.getWorkflow());
    Collection<File> files = getInputFiles(inputFiles);
    files.add(cmd.getWorkflow().getOutputDirectory(cmd));
    String fileHash = getRecursiveFileHash(files);
    String parametersHash = getParameterHash(cmd);
    pc.setProperty(getFileHashKey(cmd), fileHash);
    pc.setProperty(getParametersHashKey(cmd), parametersHash);
}

From source file:com.kylinolap.rest.service.AdminService.java

/**
 * Get Java Env info as string/*  ww  w.  ja  v  a  2 s . com*/
 * 
 * @return
 */
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
public String getEnv() {
    logger.debug("Get Kylin Runtime environment");
    PropertiesConfiguration tempConfig = new PropertiesConfiguration();

    // Add Java Env

    try {
        String content = "";
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // env
        Map<String, String> env = System.getenv();
        for (String envName : env.keySet()) {
            tempConfig.addProperty(envName, env.get(envName));
        }
        // properties
        Properties properteis = System.getProperties();
        for (Object propName : properteis.keySet()) {
            tempConfig.setProperty((String) propName, properteis.get(propName));
        }

        // do save
        tempConfig.save(baos);
        content = baos.toString();
        return content;
    } catch (ConfigurationException e) {
        logger.debug("Failed to get Kylin Runtime env", e);
        throw new InternalErrorException("Failed to get Kylin env Config", e);
    }
}

From source file:com.liferay.ide.project.core.tests.ProjectCoreBase.java

private void persistAppServerProperties() throws FileNotFoundException, IOException, ConfigurationException {
    Properties initProps = new Properties();
    initProps.put("app.server.type", "tomcat");
    initProps.put("app.server.tomcat.dir", getLiferayRuntimeDir().toPortableString());
    initProps.put("app.server.tomcat.deploy.dir", getLiferayRuntimeDir().append("webapps").toPortableString());
    initProps.put("app.server.tomcat.lib.global.dir",
            getLiferayRuntimeDir().append("lib/ext").toPortableString());
    initProps.put("app.server.parent.dir", getLiferayRuntimeDir().removeLastSegments(1).toPortableString());
    initProps.put("app.server.tomcat.portal.dir",
            getLiferayRuntimeDir().append("webapps/ROOT").toPortableString());

    IPath loc = getLiferayPluginsSdkDir();
    String userName = System.getProperty("user.name"); //$NON-NLS-1$
    File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$

    try (FileOutputStream fileOutput = new FileOutputStream(userBuildFile)) {
        if (userBuildFile.exists()) {
            PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile);
            for (Object key : initProps.keySet()) {
                propsConfig.setProperty((String) key, initProps.get(key));
            }/*from w  ww  .j  ava 2 s.  co m*/
            propsConfig.setHeader("");
            propsConfig.save(fileOutput);

        } else {
            Properties props = new Properties();
            props.putAll(initProps);
            props.store(fileOutput, StringPool.EMPTY);
        }
    }
}

From source file:net.sf.mpaxs.spi.server.HostRegister.java

/**
 * Prepares the launch of a new host./*from w w w .java2 s.c om*/
 */
private void launchNewHost() {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            reporter.report("Starting new compute host");
            reporter.report("Maximum allowed number of compute hosts: " + settings.getMaxNumberOfChosts());
            reporter.report("Current number of compute hosts: " + getNumberOfHosts());
            if (settings.getMaxNumberOfChosts() > getNumberOfHosts()) {
                ExecutionType et = settings.getExecutionMode();
                reporter.report("Execution mode: " + et);
                IComputeHostLauncher ichl = ExecutionFactory.getComputeHostLaunchers(et).get(0);
                reporter.report("Preparing to launch host " + (getNumberOfHosts() + 1) + "/"
                        + settings.getMaxNumberOfChosts());
                String nativeSpec = "";
                if (settings.getOption(ConfigurationKeys.KEY_NATIVE_SPEC) != null) {
                    nativeSpec = settings.getString(ConfigurationKeys.KEY_NATIVE_SPEC);
                }
                reporter.report("Setting up host configuration");
                PropertiesConfiguration hostConfiguration = new PropertiesConfiguration();
                UUID authToken = UUID.fromString(settings.getString(ConfigurationKeys.KEY_AUTH_TOKEN));
                hostConfiguration.setProperty(ConfigurationKeys.KEY_AUTH_TOKEN, authToken.toString());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_NATIVE_SPEC, nativeSpec);
                hostConfiguration.setProperty(ConfigurationKeys.KEY_MASTERSERVER_IP, settings.getLocalIP());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_MASTERSERVER_PORT, settings.getLocalPort());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_MASTERSERVER_NAME, settings.getName());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_PATH_TO_COMPUTEHOST_JAR,
                        settings.getPathToComputeHostJar());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_COMPUTE_HOST_MAIN_CLASS,
                        settings.getComputeHostMainClass());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR,
                        new File(settings.getComputeHostWorkingDir(), "" + hostsLaunched).getAbsolutePath());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_ERROR_FILE,
                        hostConfiguration.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR)
                                + "/error.txt");
                hostConfiguration.setProperty(ConfigurationKeys.KEY_OUTPUT_FILE,
                        hostConfiguration.getString(ConfigurationKeys.KEY_COMPUTE_HOST_WORKING_DIR)
                                + "/output.txt");
                hostConfiguration.setProperty(ConfigurationKeys.KEY_PATH_TO_JAVA, settings.getPathToJava());
                hostConfiguration.setProperty(ConfigurationKeys.KEY_CODEBASE, settings.getCodebase());
                reporter.report("Starting compute host: " + ichl.getClass());
                ichl.startComputeHost(hostConfiguration);
                hostsLaunched.incrementAndGet();
            } else {
                reporter.report("Not launching new compute host: maximum number of active hosts reached (max: "
                        + settings.getMaxNumberOfChosts() + " current: " + getNumberOfHosts() + ")");
            }
        }
    };
    Future<?> future = executorService.submit(r);
    try {
        future.get(10, TimeUnit.SECONDS);
    } catch (InterruptedException ex) {
        Logger.getLogger(HostRegister.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ExecutionException ex) {
        Logger.getLogger(HostRegister.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(
                "Error occurred while waiting to create compute host. Setting fallback mode to local execution!");
        settings.setOption(ConfigurationKeys.KEY_EXECUTION_MODE, ExecutionType.LOCAL.toString());

        if (hostLaunchRetries.get() < maxHostLaunchRetries.get()) {
            hostLaunchRetries.incrementAndGet();
            return;
        } else {
            throw new RuntimeException("Failed to launch compute host after " + hostLaunchRetries + " tries!",
                    ex);
        }
    } catch (TimeoutException ex) {
        Logger.getLogger(HostRegister.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(
                "Timed out while waiting to create compute host. Setting fallback mode to local execution!");
        settings.setOption(ConfigurationKeys.KEY_EXECUTION_MODE, ExecutionType.LOCAL.toString());

        if (hostLaunchRetries.get() < maxHostLaunchRetries.get()) {
            hostLaunchRetries.incrementAndGet();
            return;
        } else {
            throw new RuntimeException("Failed to launch compute host after " + hostLaunchRetries + " tries!",
                    ex);
        }
    } catch (RuntimeException ex) {
        Logger.getLogger(HostRegister.class.getName()).log(Level.SEVERE, null, ex);
        System.err.println(
                "Caught runtime exception while waiting to create compute host. Setting fallback mode to local execution!");
        settings.setOption(ConfigurationKeys.KEY_EXECUTION_MODE, ExecutionType.LOCAL.toString());

        if (hostLaunchRetries.get() < maxHostLaunchRetries.get()) {
            hostLaunchRetries.incrementAndGet();
            return;
        } else {
            throw new RuntimeException("Failed to launch compute host after " + hostLaunchRetries + " tries!",
                    ex);
        }
    }
}

From source file:evaluation.simulator.conf.service.SimulationConfigService.java

public void writeConfig(File outputFile) {

    PropertiesConfiguration props;
    try {/*from   w w  w.  ja v a2  s . co m*/

        props = new PropertiesConfiguration("inputOutput/simulator/config/experiment_template.cfg");

        props.setProperty("EDF_VERSION", 1);

        // static part
        Map<String, String> plugins = this.simPropRegistry.getActivePlugins(true);
        logger.log(Level.DEBUG, "Active plugins are:");
        for (String key : plugins.keySet()) {
            logger.log(Level.DEBUG, key + " with " + plugins.get(key));
            props.setProperty(key, plugins.get(key));
        }

        // Properties to vary
        for (Entry<String, String> s : this.simPropRegistry.getPropertiesToVary().entrySet()) {
            logger.log(Level.DEBUG, s.getKey() + "=" + s.getValue().toString());
            props.setProperty(s.getKey(), s.getValue());
        }

        // dynamic part
        for (Entry<String, SimProp> s : this.simPropRegistry.getAllSimProps()) {
            try {
                if (s.getValue().getValueType() == Integer.class && ((IntProp) (s.getValue())).getAuto()) {
                    logger.log(Level.DEBUG, s.getKey() + "=AUTO");
                    props.setProperty(s.getKey(), "AUTO");
                } else if (s.getValue().getValueType() == Integer.class
                        && ((IntProp) (s.getValue())).getUnlimited()) {
                    logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED");
                    props.setProperty(s.getKey(), "UNLIMITED");
                } else if (s.getValue().getValueType() == Float.class
                        && ((FloatProp) (s.getValue())).getAuto()) {
                    logger.log(Level.DEBUG, s.getKey() + "=AUTO");
                    props.setProperty(s.getKey(), "AUTO");
                } else if (s.getValue().getValueType() == Float.class
                        && ((FloatProp) (s.getValue())).getUnlimited()) {
                    logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED");
                    props.setProperty(s.getKey(), "UNLIMITED");
                } else if (s.getValue().getValueType() == Double.class
                        && ((DoubleProp) (s.getValue())).getAuto()) {
                    logger.log(Level.DEBUG, s.getKey() + "=AUTO");
                    props.setProperty(s.getKey(), "AUTO");
                } else if (s.getValue().getValueType() == Double.class
                        && ((DoubleProp) (s.getValue())).getUnlimited()) {
                    logger.log(Level.DEBUG, s.getKey() + "=UNLIMITED");
                    props.setProperty(s.getKey(), "UNLIMITED");
                } else {
                    logger.log(Level.DEBUG, s.getKey() + "=" + s.getValue().getValue().toString());
                    props.setProperty(s.getKey(), s.getValue().getValue().toString().trim());
                }
            } catch (Exception e) {
                logger.log(Level.DEBUG, s.getKey() + " has no associated property -> SKIP");
            }
        }

        props.save(outputFile);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }

}

From source file:com.mirth.connect.server.migration.Migrate3_0_0.java

@Override
public void updateConfiguration(PropertiesConfiguration configuration) {
    if (configuration.getProperty("database").equals("derby")) {
        String url = (String) configuration.getProperty("database.url");

        if (!StringUtils.contains(url, ";upgrade=")) {
            url += ";upgrade=true";
        }/*from   www  .  ja  v a2s  .  c  o m*/

        configuration.setProperty("database.url", url);
    }
}

From source file:fr.inria.corese.rdftograph.driver.TitanDriver.java

@Override
public Graph createDatabase(String dbPathTemp) throws IOException {
    File f = new File(dbPathTemp);
    dbPath = f.getAbsolutePath();//from  w  ww . jav  a 2 s  .  c om
    super.createDatabase(dbPath);
    PropertiesConfiguration configuration = null;
    File confFile = new File(dbPath + "/conf.properties");
    try {
        configuration = new PropertiesConfiguration(confFile);

    } catch (ConfigurationException ex) {
        Logger.getLogger(TitanDriver.class.getName()).log(Level.SEVERE, null, ex);
    }
    configuration.setProperty("schema.default", "none");
    configuration.setProperty("storage.batch-loading", true);
    //      configuration.setProperty("storage.batch-loading", false);
    configuration.setProperty("storage.backend", "berkeleyje");
    configuration.setProperty("storage.directory", dbPath + "/db");
    configuration.setProperty("storage.buffer-size", 50_000);
    //      configuration.setProperty("storage.berkeleyje.cache-percentage", 50);
    //      configuration.setProperty("storage.read-only", true);
    configuration.setProperty("index.search.backend", "elasticsearch");
    configuration.setProperty("index.search.directory", dbPath + "/es");
    configuration.setProperty("index.search.elasticsearch.client-only", false);
    configuration.setProperty("index.search.elasticsearch.local-mode", true);
    configuration.setProperty("index.search.refresh_interval", 600);
    configuration.setProperty("ids.block-size", 50_000);

    configuration.setProperty("cache.db-cache", true);
    configuration.setProperty("cache.db-cache-size", 250_000_000);
    configuration.setProperty("cache.db-cache-time", 0);
    //      configuration.setProperty("cache.tx-dirty-size", 100_000);
    // to make queries faster
    configuration.setProperty("query.batch", true);
    configuration.setProperty("query.fast-property", true);
    configuration.setProperty("query.force-index", false);
    configuration.setProperty("query.ignore-unknown-index-key", true);
    try {
        configuration.save();

    } catch (ConfigurationException ex) {
        Logger.getLogger(TitanDriver.class.getName()).log(Level.SEVERE, null, ex);
    }
    g = TitanFactory.open(configuration);

    TitanManagement mgmt = getTitanGraph().openManagement();
    if (!mgmt.containsVertexLabel(RDF_VERTEX_LABEL)) {
        mgmt.makeVertexLabel(RDF_VERTEX_LABEL).make();
    }
    if (!mgmt.containsEdgeLabel(RDF_EDGE_LABEL)) {
        mgmt.makeEdgeLabel(RDF_EDGE_LABEL).multiplicity(Multiplicity.MULTI).make();
    }
    mgmt.commit();

    makeIfNotExistProperty(EDGE_P);
    makeIfNotExistProperty(VERTEX_VALUE);
    makeIfNotExistProperty(VERTEX_LARGE_VALUE);
    makeIfNotExistProperty(EDGE_G);
    makeIfNotExistProperty(EDGE_S);
    makeIfNotExistProperty(EDGE_O);
    makeIfNotExistProperty(KIND);
    makeIfNotExistProperty(TYPE);
    makeIfNotExistProperty(LANG);

    createIndexes();
    return g;
}