Java Code Examples for org.apache.commons.configuration.PropertiesConfiguration#getString()

The following examples show how to use org.apache.commons.configuration.PropertiesConfiguration#getString() . 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: Properties2HoconConverterTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnWikipediaSample() throws IOException {
    File props = new File(root, "/wiki.properties");
    File hocon = Properties2HoconConverter.convert(props, true);

    PropertiesConfiguration properties = loadPropertiesWithApacheConfiguration(props);
    assertThat(properties).isNotNull();
    Config config = load(hocon);
    assertThat(properties.isEmpty()).isFalse();
    assertThat(config.isEmpty()).isFalse();

    Iterator<String> iterator = properties.getKeys();
    String[] names = Iterators.toArray(iterator, String.class);
    for (String name : names) {
        if (!name.isEmpty()) {
            // 'cheeses' is not supported by commons-config.
            String o = properties.getString(name);
            String v = config.getString(name);
            assertThat(o).isEqualTo(v);
        }
    }

    assertThat(config.getString("cheeses")).isEmpty();

}
 
Example 2
Source File: LogConfigUtils.java    From singer with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the given configuration. Unlike configs located in conf.d/, this config
 * contains the configuration for multiple kafka topics and so a list of
 * MercedTransporterConfigs are returned.
 */
public static SingerLogConfig[] parseLogStreamConfig(AbstractConfiguration config) throws ConfigurationException {
  validateNewConfig(config);
  PropertiesConfiguration[] topicConfigs = getTopicConfigs(config);
  SingerLogConfig[] logConfigs = new SingerLogConfig[topicConfigs.length];

  for (int i = 0; i < topicConfigs.length; i++) {
    PropertiesConfiguration topicConfig = topicConfigs[i];
    String topicName = topicConfig.getString("name");
    logConfigs[i] = parseLogConfig(topicName, topicConfig);
  }
  return logConfigs;
}
 
Example 3
Source File: TestGraphProvider.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getBaseConfiguration(
                           String graphName,
                           Class<?> testClass, String testMethod,
                           LoadGraphWith.GraphData graphData) {
    // Check if test in blackList
    String testFullName = testClass.getCanonicalName() + "." + testMethod;
    int index = testFullName.indexOf('@') == -1 ?
                testFullName.length() : testFullName.indexOf('@');

    testFullName = testFullName.substring(0, index);
    Assume.assumeFalse(
           String.format("Test %s will be ignored with reason: %s",
                         testFullName, this.blackMethods.get(testFullName)),
           this.blackMethods.containsKey(testFullName));

    LOG.debug("Full name of test is: {}", testFullName);
    LOG.debug("Prefix of test is: {}", testFullName.substring(0, index));
    HashMap<String, Object> confMap = new HashMap<>();
    PropertiesConfiguration config = Utils.getConf();
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        confMap.put(key, config.getProperty(key));
    }
    String storePrefix = config.getString(CoreOptions.STORE.name());
    confMap.put(CoreOptions.STORE.name(),
                storePrefix + "_" + this.suite + "_" + graphName);
    confMap.put(GREMLIN_GRAPH_KEY, GREMLIN_GRAPH_VALUE);
    confMap.put(TEST_CLASS, testClass);
    confMap.put(TEST_METHOD, testMethod);
    confMap.put(LOAD_GRAPH, graphData);
    confMap.put(EXPECT_CUSTOMIZED_ID, customizedId(testClass, testMethod));

    return confMap;
}
 
Example 4
Source File: Config.java    From jmxmon with Apache License 2.0 5 votes vote down vote up
public void init(String configPath) throws ConfigurationException, IOException{
	logger.info("init config");
	
	PropertiesConfiguration config = new PropertiesConfiguration(configPath);
	config.setThrowExceptionOnMissing(true);
	
	this.workDir = config.getString("workDir");
	if (new File(workDir).isDirectory() == false) {
		throw new IllegalArgumentException("workDir is not a directory");
	}
	
	this.hostname = config.getString("hostname", Utils.getHostNameForLinux());
	
	this.jvmContextFile = new File(workDir, "jmxmon.jvm.context.json");
	
	if (jvmContextFile.exists() && jvmContextFile.isFile() && 
			jvmContextFile.length() > 0) {
		logger.info(jvmContextFile.getAbsolutePath() + " is exist, start loading...");
		this.jvmContext = JacksonUtil.readBeanFromFile(jvmContextFile, JVMContext.class);
	} else {
		logger.info(jvmContextFile.getAbsolutePath() + " is not exist");
	}
	
	this.agentPostUrl = config.getString("agent.posturl");
	this.step = config.getInt("step", Constants.defaultStep);
	
	// 默认的jmxHost为localhost,除非通过-D参数设置(线上不建议以远程方式采集,最好每台机器上部署agent,这样agent才能水平伸缩)
	this.jmxHost = System.getProperty("debug.jmx.host");
	if (this.jmxHost == null) {
		this.jmxHost = "localhost";
	}
	
	String[] jmxPortArray = config.getStringArray("jmx.ports");
	jmxPorts = new int[jmxPortArray.length];
	for (int i = 0; i < jmxPortArray.length; i++) {
		jmxPorts[i] = Integer.parseInt(jmxPortArray[i]);
	}
	
	logger.info("init config ok");
}
 
Example 5
Source File: TerrapinClient.java    From terrapin with Apache License 2.0 5 votes vote down vote up
public TerrapinClient(PropertiesConfiguration configuration,
                      int targetPort,
                      int connectTimeoutMs,
                      int timeoutMs) throws Exception {
  String zkQuorum = configuration.getString(Constants.ZOOKEEPER_QUORUM);
  String clusterName = configuration.getString(Constants.HELIX_CLUSTER);
  FileSetViewManager fileSetViewManager = new FileSetViewManager(
      TerrapinUtil.getZooKeeperClient(zkQuorum, 30), clusterName);
  init(fileSetViewManager, clusterName, targetPort, connectTimeoutMs, timeoutMs);
}
 
Example 6
Source File: TerrapinAdmin.java    From terrapin with Apache License 2.0 5 votes vote down vote up
public TerrapinAdmin(PropertiesConfiguration configuration) throws Exception {
  this.configuration = configuration;

  String zkQuorum = TerrapinUtil.getZKQuorumFromConf(configuration);
  ZooKeeperClient zkClient = TerrapinUtil.getZooKeeperClient(zkQuorum, 30);
  ZooKeeperManager zkManager = new ZooKeeperManager(zkClient,
      configuration.getString(Constants.HELIX_CLUSTER));
  zkManager.registerWatchAllFileSets();
  this.zkQuorum = zkQuorum;
  this.zkManager = zkManager;
}
 
Example 7
Source File: RunConfig.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public RunConfig(String domain) throws Exception {

        config = new PropertiesConfiguration("setting.properties");

        // We have to check if this domain is a valid uri before initializing
        // the config
        this.domain = domain.endsWith("/")
                ? domain.substring(0, domain.length() - 1)
                : domain;

        resourceUriBase = this.domain + config.getString("rdf.uribase", "/resource");

        String typeUriBase = config.getString("rdf.type.uribase",
                "/resource/class");
        String propertyUriBase = config.getString("rdf.property.uribase",
                "/resource/property");

        if (typeUriBase.endsWith("/") || propertyUriBase.endsWith("/")) {
            throw new Exception("Do not add \"/\" at the end of URI base.");
        }

        typeResourceUriBase = this.domain + typeUriBase;

        typeResourcePrefix = config.getString("rdf.type.prefix",
                "class");

        propertyResourceUriBase = this.domain + propertyUriBase;

        propertyResourcePrefix = config.getString("rdf.property.prefix",
                "property");
    }
 
Example 8
Source File: DBConnConf.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public DBConnConf(String prefix, PropertiesConfiguration pc) {
    driver = pc.getString(prefix + KEY_DRIVER);
    url = pc.getString(prefix + KEY_URL);
    user = pc.getString(prefix + KEY_USER);
    pass = pc.getString(prefix + KEY_PASS);
}
 
Example 9
Source File: Atlas.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static String getProjectVersion(PropertiesConfiguration buildConfiguration) {
    return buildConfiguration.getString("project.version");
}
 
Example 10
Source File: Atlas.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static String getProjectVersion(PropertiesConfiguration buildConfiguration) {
    return buildConfiguration.getString("project.version");
}
 
Example 11
Source File: PinLaterQueueConfig.java    From pinlater with Apache License 2.0 4 votes vote down vote up
public PinLaterQueueConfig(PropertiesConfiguration configuration) {
  this(configuration.getString("QUEUE_CONFIG_FILE_PATH"),
      configuration.getString("SERVER_SET_PATH"),
      configuration.getBoolean("SERVER_SET_ENABLED"));
}
 
Example 12
Source File: DBConnConf.java    From kylin with Apache License 2.0 4 votes vote down vote up
public DBConnConf(String prefix, PropertiesConfiguration pc) {
    driver = pc.getString(prefix + KEY_DRIVER);
    url = pc.getString(prefix + KEY_URL);
    user = pc.getString(prefix + KEY_USER);
    pass = pc.getString(prefix + KEY_PASS);
}
 
Example 13
Source File: ColumnMetadata.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public static ColumnMetadata fromPropertiesConfiguration(String column, PropertiesConfiguration config) {
  Builder builder = new Builder();

  builder.setColumnName(column);
  builder.setCardinality(config.getInt(getKeyFor(column, CARDINALITY)));
  int totalDocs = config.getInt(getKeyFor(column, TOTAL_DOCS));
  builder.setTotalDocs(totalDocs);
  DataType dataType = DataType.valueOf(config.getString(getKeyFor(column, DATA_TYPE)).toUpperCase());
  builder.setDataType(dataType);
  builder.setBitsPerElement(config.getInt(getKeyFor(column, BITS_PER_ELEMENT)));
  builder.setColumnMaxLength(config.getInt(getKeyFor(column, DICTIONARY_ELEMENT_SIZE)));
  builder.setFieldType(FieldType.valueOf(config.getString(getKeyFor(column, COLUMN_TYPE)).toUpperCase()));
  builder.setIsSorted(config.getBoolean(getKeyFor(column, IS_SORTED)));
  builder.setContainsNulls(config.getBoolean(getKeyFor(column, HAS_NULL_VALUE)));
  builder.setHasDictionary(config.getBoolean(getKeyFor(column, HAS_DICTIONARY), true));
  builder.setHasInvertedIndex(config.getBoolean(getKeyFor(column, HAS_INVERTED_INDEX)));
  builder.setSingleValue(config.getBoolean(getKeyFor(column, IS_SINGLE_VALUED)));
  builder.setMaxNumberOfMultiValues(config.getInt(getKeyFor(column, MAX_MULTI_VALUE_ELEMTS)));
  builder.setTotalNumberOfEntries(config.getInt(getKeyFor(column, TOTAL_NUMBER_OF_ENTRIES)));
  builder.setAutoGenerated(config.getBoolean(getKeyFor(column, IS_AUTO_GENERATED), false));
  builder.setDefaultNullValueString(config.getString(getKeyFor(column, DEFAULT_NULL_VALUE), null));
  builder.setTimeUnit(TimeUnit.valueOf(config.getString(TIME_UNIT, "DAYS").toUpperCase()));
  builder.setTextIndexType(config.getString(getKeyFor(column, TEXT_INDEX_TYPE), TextIndexType.NONE.name()));

  char paddingCharacter = V1Constants.Str.LEGACY_STRING_PAD_CHAR;
  if (config.containsKey(SEGMENT_PADDING_CHARACTER)) {
    String padding = config.getString(SEGMENT_PADDING_CHARACTER);
    paddingCharacter = StringEscapeUtils.unescapeJava(padding).charAt(0);
  }
  builder.setPaddingCharacter(paddingCharacter);

  String dateTimeFormat = config.getString(getKeyFor(column, DATETIME_FORMAT), null);
  if (dateTimeFormat != null) {
    builder.setDateTimeFormat(dateTimeFormat);
  }

  String dateTimeGranularity = config.getString(getKeyFor(column, DATETIME_GRANULARITY), null);
  if (dateTimeGranularity != null) {
    builder.setDateTimeGranularity(dateTimeGranularity);
  }

  // Set min/max value if available.
  String minString = config.getString(getKeyFor(column, MIN_VALUE), null);
  String maxString = config.getString(getKeyFor(column, MAX_VALUE), null);
  if ((minString != null) && (maxString != null)) {
    switch (dataType) {
      case INT:
        builder.setMinValue(Integer.valueOf(minString));
        builder.setMaxValue(Integer.valueOf(maxString));
        break;
      case LONG:
        builder.setMinValue(Long.valueOf(minString));
        builder.setMaxValue(Long.valueOf(maxString));
        break;
      case FLOAT:
        builder.setMinValue(Float.valueOf(minString));
        builder.setMaxValue(Float.valueOf(maxString));
        break;
      case DOUBLE:
        builder.setMinValue(Double.valueOf(minString));
        builder.setMaxValue(Double.valueOf(maxString));
        break;
      case STRING:
        builder.setMinValue(minString);
        builder.setMaxValue(maxString);
        break;
      default:
        throw new IllegalStateException("Unsupported data type: " + dataType + " for column: " + column);
    }
  }

  String partitionFunctionName =
      config.getString(getKeyFor(column, V1Constants.MetadataKeys.Column.PARTITION_FUNCTION));
  if (partitionFunctionName != null) {
    int numPartitions = config.getInt(getKeyFor(column, V1Constants.MetadataKeys.Column.NUM_PARTITIONS));
    PartitionFunction partitionFunction =
        PartitionFunctionFactory.getPartitionFunction(partitionFunctionName, numPartitions);
    builder.setPartitionFunction(partitionFunction);
    builder.setNumPartitions(numPartitions);
    builder.setPartitions(ColumnPartitionMetadata
        .extractPartitions(config.getList(getKeyFor(column, V1Constants.MetadataKeys.Column.PARTITION_VALUES))));
  }

  return builder.build();
}
 
Example 14
Source File: SegmentMetadataImpl.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
private void init(PropertiesConfiguration segmentMetadataPropertiesConfiguration) {
  if (segmentMetadataPropertiesConfiguration.containsKey(SEGMENT_CREATOR_VERSION)) {
    _creatorName = segmentMetadataPropertiesConfiguration.getString(SEGMENT_CREATOR_VERSION);
  }

  if (segmentMetadataPropertiesConfiguration.containsKey(SEGMENT_PADDING_CHARACTER)) {
    String padding = segmentMetadataPropertiesConfiguration.getString(SEGMENT_PADDING_CHARACTER);
    _paddingCharacter = StringEscapeUtils.unescapeJava(padding).charAt(0);
  }

  String versionString =
      segmentMetadataPropertiesConfiguration.getString(SEGMENT_VERSION, SegmentVersion.v1.toString());
  _segmentVersion = SegmentVersion.valueOf(versionString);

  // NOTE: here we only add physical columns as virtual columns should not be loaded from metadata file
  // NOTE: getList() will always return an non-null List with trimmed strings:
  // - If key does not exist, it will return an empty list
  // - If key exists but value is missing, it will return a singleton list with an empty string
  addPhysicalColumns(segmentMetadataPropertiesConfiguration.getList(DIMENSIONS), _allColumns);
  addPhysicalColumns(segmentMetadataPropertiesConfiguration.getList(METRICS), _allColumns);
  addPhysicalColumns(segmentMetadataPropertiesConfiguration.getList(TIME_COLUMN_NAME), _allColumns);
  addPhysicalColumns(segmentMetadataPropertiesConfiguration.getList(DATETIME_COLUMNS), _allColumns);

  //set the table name
  _tableName = segmentMetadataPropertiesConfiguration.getString(TABLE_NAME);

  // Set segment name.
  _segmentName = segmentMetadataPropertiesConfiguration.getString(SEGMENT_NAME);

  // Build column metadata map, schema and hll derived column map.
  for (String column : _allColumns) {
    ColumnMetadata columnMetadata =
        ColumnMetadata.fromPropertiesConfiguration(column, segmentMetadataPropertiesConfiguration);
    _columnMetadataMap.put(column, columnMetadata);
    _schema.addField(columnMetadata.getFieldSpec());
  }

  // Build star-tree v2 metadata
  int starTreeV2Count =
      segmentMetadataPropertiesConfiguration.getInt(StarTreeV2Constants.MetadataKey.STAR_TREE_COUNT, 0);
  if (starTreeV2Count > 0) {
    _starTreeV2MetadataList = new ArrayList<>(starTreeV2Count);
    for (int i = 0; i < starTreeV2Count; i++) {
      _starTreeV2MetadataList.add(new StarTreeV2Metadata(
          segmentMetadataPropertiesConfiguration.subset(StarTreeV2Constants.MetadataKey.getStarTreePrefix(i))));
    }
  }
}