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

The following examples show how to use org.apache.commons.configuration.Configuration#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: S3PinotFS.java    From incubator-pinot with Apache License 2.0 7 votes vote down vote up
@Override
public void init(Configuration config) {
  Preconditions.checkArgument(!isNullOrEmpty(config.getString(REGION)));
  String region = config.getString(REGION);

  AwsCredentialsProvider awsCredentialsProvider;
  try {

    if (!isNullOrEmpty(config.getString(ACCESS_KEY)) && !isNullOrEmpty(config.getString(SECRET_KEY))) {
      String accessKey = config.getString(ACCESS_KEY);
      String secretKey = config.getString(SECRET_KEY);
      AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create(accessKey, secretKey);
      awsCredentialsProvider = StaticCredentialsProvider.create(awsBasicCredentials);
    } else {
      awsCredentialsProvider =
          AwsCredentialsProviderChain.builder().addCredentialsProvider(SystemPropertyCredentialsProvider.create())
              .addCredentialsProvider(EnvironmentVariableCredentialsProvider.create()).build();
    }

    _s3Client = S3Client.builder().region(Region.of(region)).credentialsProvider(awsCredentialsProvider).build();
  } catch (S3Exception e) {
    throw new RuntimeException("Could not initialize S3PinotFS", e);
  }
}
 
Example 2
Source File: NdkExportOptions.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
public static NdkExportOptions getOptions(Configuration config) {
    NdkExportOptions options = new NdkExportOptions();

    String creator = config.getString(PROP_NDK_AGENT_CREATOR);
    if (creator != null && !creator.isEmpty()) {
        options.setCreator(creator);
    }

    String archivist = config.getString(PROP_NDK_AGENT_ARCHIVIST);
    if (archivist != null && !archivist.isEmpty()) {
        options.setArchivist(archivist);
    }

    String version = config.getString(PROP_PROARC_VERSION);
    if (version != null && !version.isEmpty()) {
        options.setVersion(version);
    }

    return options;
}
 
Example 3
Source File: ParametersHelper.java    From vsphere-automation-sdk-java with MIT License 6 votes vote down vote up
private Object getOptionValueFromConfig(
    Option option, Configuration config) {
    Object optionValue = null;
    try {
        if (option.getType().equals(Boolean.class)) {
            optionValue = config.getString(option.getLongOpt());
            if (optionValue != null) {
                optionValue = config.getBoolean(option.getLongOpt());
            }

        } else {
            optionValue = config.getString(option.getLongOpt());
        }
    } catch (ConversionException cex) {
        optionValue = null;
    }
    return optionValue;
}
 
Example 4
Source File: AtlasTopicCreator.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
protected boolean handleSecurity(Configuration atlasProperties) {
    if (AuthenticationUtil.isKerberosAuthenticationEnabled(atlasProperties)) {
        String kafkaPrincipal = atlasProperties.getString("atlas.notification.kafka.service.principal");
        String kafkaKeyTab = atlasProperties.getString("atlas.notification.kafka.keytab.location");
        org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
        SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, hadoopConf);
        try {
            String serverPrincipal = SecurityUtil.getServerPrincipal(kafkaPrincipal, (String) null);
            UserGroupInformation.setConfiguration(hadoopConf);
            UserGroupInformation.loginUserFromKeytab(serverPrincipal, kafkaKeyTab);
        } catch (IOException e) {
            LOG.warn("Could not login as {} from keytab file {}", kafkaPrincipal, kafkaKeyTab, e);
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: AccessControlFactory.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public static AccessControlFactory loadFactory(Configuration configuration) {
  AccessControlFactory accessControlFactory;
  String accessControlFactoryClassName = configuration.getString(ACCESS_CONTROL_CLASS_CONFIG);
  if (accessControlFactoryClassName == null) {
    accessControlFactoryClassName = AllowAllAccessControlFactory.class.getName();
  }
  try {
    LOGGER.info("Instantiating Access control factory class {}", accessControlFactoryClassName);
    accessControlFactory = (AccessControlFactory) Class.forName(accessControlFactoryClassName).newInstance();
    LOGGER.info("Initializing Access control factory class {}", accessControlFactoryClassName);
    accessControlFactory.init(configuration);
    return accessControlFactory;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 6
Source File: Titan0GraphDatabase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
static void validateIndexBackend(Configuration config) {
    String configuredIndexBackend = config.getString(INDEX_BACKEND_CONF);
    TitanManagement managementSystem = null;

    try {
        managementSystem = getGraphInstance().getManagementSystem();
        String currentIndexBackend = managementSystem.get(INDEX_BACKEND_CONF);

        if (!equals(configuredIndexBackend, currentIndexBackend)) {
            throw new RuntimeException("Configured Index Backend " + configuredIndexBackend
                    + " differs from earlier configured Index Backend " + currentIndexBackend + ". Aborting!");
        }

    } finally {
        if (managementSystem != null) {
            managementSystem.commit();
        }
    }


}
 
Example 7
Source File: ConfigurableIngestTopologyTest.java    From cognition with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureStreamFieldsGrouping(
    @Injectable String prevComponent,
    @Injectable String streamId,
    @Injectable Configuration boltConf,
    @Injectable BoltDeclarer declarer,
    @Injectable Fields fields) throws Exception {
  new Expectations(Fields.class) {{
    boltConf.getString(STREAM_GROUPING_CONF_ARGS);
    result = "a,b";
    new Fields(new String[]{"a", "b"});
    result = fields;
    declarer.fieldsGrouping(prevComponent, streamId, fields);
  }};

  topology.configureStreamFieldsGrouping(prevComponent, streamId, boltConf, declarer);
}
 
Example 8
Source File: ConfigurationMapEntryUtils.java    From cognition with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts map entries from configuration.
 *
 * @param conf
 * @param mappingEntry
 * @param fields       first field should be unique and exist in all entries, other fields are optional from map
 * @return
 */
public static Map<String, Map<String, String>> extractMapList(
    final Configuration conf,
    final String mappingEntry,
    final String... fields) {
  String keyField = fields[0];
  List<Object> keys = conf.getList(mappingEntry + "." + keyField);
  Map<String, Map<String, String>> maps = new HashMap<>(keys.size());

  for (int i = 0; i < keys.size(); i++) {
    Map<String, String> map = new HashMap<>();
    Object key = keys.get(i);
    map.put(keyField, key.toString());

    for (int j = 1; j < fields.length; j++) {
      String field = fields[j];
      String fieldPath = String.format("%s(%s).%s", mappingEntry, i, field);
      String value = conf.getString(fieldPath);
      if (value != null)
        map.put(field, value);
    }

    maps.put(key.toString(), map);
  }
  return maps;
}
 
Example 9
Source File: AtlasTopicCreator.java    From atlas with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
protected boolean handleSecurity(Configuration atlasProperties) {
    if (AuthenticationUtil.isKerberosAuthenticationEnabled(atlasProperties)) {
        String kafkaPrincipal = atlasProperties.getString("atlas.notification.kafka.service.principal");
        String kafkaKeyTab = atlasProperties.getString("atlas.notification.kafka.keytab.location");
        org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
        SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, hadoopConf);
        try {
            String serverPrincipal = SecurityUtil.getServerPrincipal(kafkaPrincipal, (String) null);
            UserGroupInformation.setConfiguration(hadoopConf);
            UserGroupInformation.loginUserFromKeytab(serverPrincipal, kafkaKeyTab);
        } catch (IOException e) {
            LOG.warn("Could not login as {} from keytab file {}", kafkaPrincipal, kafkaKeyTab, e);
            return false;
        }
    }
    return true;
}
 
Example 10
Source File: DecomposeObjectArrayBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigure(@Injectable Configuration conf) {
  new Expectations() {{
    conf.getString(DecomposeObjectArrayBolt.ARRAY_FIELD);
    result = "field0";
    conf.getString(DecomposeObjectArrayBolt.OBJECT_FIELD);
    result = "field1";
    conf.getString(DecomposeObjectArrayBolt.DEST_FIELD);
    result = "field2";
  }};
  bolt.configure(conf);
  assertThat(bolt.arrayField, is("field0"));
  assertThat(bolt.objectField, is("field1"));
  assertThat(bolt.destField, is("field2"));
}
 
Example 11
Source File: ConfigurableIngestTopology.java    From cognition with Apache License 2.0 5 votes vote down vote up
void configureStreamFieldsGrouping(String prevComponent, String streamId, Configuration boltConf, BoltDeclarer declarer)
    throws ConfigurationException {

  String streamTypeArgs = boltConf.getString(STREAM_GROUPING_CONF_ARGS);

  if (StringUtils.isBlank(streamTypeArgs)) {
    logger.error("{} stream grouping requires {} configuration",
        STREAM_GROUPING_FIELDS, STREAM_GROUPING_CONF_ARGS);
    throw new ConfigurationException("Missing stream grouping configuration");
  } else {
    String[] fields = streamTypeArgs.split(",");
    declarer.fieldsGrouping(prevComponent, streamId, new Fields(fields));
  }
}
 
Example 12
Source File: FileDataset.java    From KEEL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * <p>
 * Configuration method
 * Configuration parameters for ArrayDataset are:
 * </p> 
 * @param settings Configuration object to read the parameters 
 */
public void configure(Configuration settings)
{
	// Set number-of-parents
	String fileName = settings.getString("file-name");
	setFileName(fileName);
	
}
 
Example 13
Source File: CoreConfiguration.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * <p>getAppContext.</p>
 *
 * @param _c a {@link com.sap.psr.vulas.shared.util.VulasConfiguration} object.
 * @return a {@link com.sap.psr.vulas.shared.json.model.Application} object.
 * @throws org.apache.commons.configuration.ConfigurationException if any.
 */
public static Application getAppContext(VulasConfiguration _c) throws ConfigurationException {
	final Configuration c = _c.getConfiguration();
	Application a = null;
	try {
		a = new Application(c.getString(APP_CTX_GROUP), c.getString(APP_CTX_ARTIF), c.getString(APP_CTX_VERSI));
	} catch (IllegalArgumentException e) {
		throw new ConfigurationException("Application incomplete: " + e.getMessage(), e);
	}
	if(!a.isComplete())
		throw new ConfigurationException("Application incomplete: " + a.toString());
	return a;
}
 
Example 14
Source File: Neo4JTestGraphProvider.java    From neo4j-gremlin-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(Graph graph, Configuration configuration) throws Exception {
    // check graph instance
    if (graph != null) {
        // close graph instance
        graph.close();
    }
    // create driver instance
    Driver driver = Neo4JGraphFactory.createDriverInstance(configuration);
    // session configuration
    SessionConfig.Builder config = SessionConfig.builder();
    // check database is set
    String database = configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JDatabaseConfigurationKey, null);
    if (database != null) {
        // update session config
        config.withDatabase(database);
    }
    // open session
    try (Session session = driver.session(config.build())) {
        // begin transaction
        try (org.neo4j.driver.Transaction transaction = session.beginTransaction()) {
            // delete everything in database
            transaction.run("MATCH (n) DETACH DELETE n");
            // commit
            transaction.commit();
        }
    }
}
 
Example 15
Source File: ConfigurableIngestTopology.java    From cognition with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a topology builder and a storm spout configuration. Initializes the spout and sets it with the topology
 * builder.
 *
 * @param builder
 * @param spout
 * @return
 * @throws ConfigurationException
 */
String configureSpout(TopologyBuilder builder, Configuration spout)
    throws ConfigurationException {
  String spoutType = spout.getString(TYPE);
  Configuration spoutConf = spout.subset(CONF);
  StormParallelismConfig parallelismConfig = getStormParallelismConfig(spoutConf);

  IRichSpout spoutComponent = (IRichSpout) buildComponent(spoutType, spoutConf);

  builder
      .setSpout(spoutType, spoutComponent, parallelismConfig.getParallelismHint())
      .setNumTasks(parallelismConfig.getNumTasks());
  return spoutType;
}
 
Example 16
Source File: DataStorageManager.java    From eagle with Apache License 2.0 5 votes vote down vote up
/**
 * Get data storage by configuration
 *
 * @param configuration
 * @return
 * @throws IllegalDataStorageTypeException
 */
public static DataStorage newDataStorage(Configuration configuration) throws IllegalDataStorageTypeException {
    String storageType = configuration.getString(EAGLE_STORAGE_TYPE);
    if (storageType == null) {
        throw new IllegalDataStorageTypeException(EAGLE_STORAGE_TYPE + " is null");
    }
    return newDataStorage(storageType);
}
 
Example 17
Source File: ClientConfig.java    From juddi with Apache License 2.0 5 votes vote down vote up
private Set<XRegistration> readXRegConfig(Configuration config, Map<String, UDDIClerk> clerks, String entityType)
     throws ConfigurationException {
        String[] entityKeys = config.getStringArray("client.clerks.xregister." + entityType + "[@entityKey]");
        Set<XRegistration> xRegistrations = new HashSet<XRegistration>();
        if (entityKeys.length > 0) {
                log.info("XRegistration " + entityKeys.length + " " + entityType + "Keys");
        }
        for (int i = 0; i < entityKeys.length; i++) {
                XRegistration xRegistration = new XRegistration();
                xRegistration.setEntityKey(config.getString("client.clerks.xregister." + entityType + "(" + i + ")[@entityKey]"));

                String fromClerkRef = config.getString("client.clerks.xregister." + entityType + "(" + i + ")[@fromClerk]");
                if (!clerks.containsKey(fromClerkRef)) {
                        throw new ConfigurationException("Could not find fromClerk with name=" + fromClerkRef);
                }
                UDDIClerk fromClerk = clerks.get(fromClerkRef);
                xRegistration.setFromClerk(fromClerk);

                String toClerkRef = config.getString("client.clerks.xregister." + entityType + "(" + i + ")[@toClerk]");
                if (!clerks.containsKey(toClerkRef)) {
                        throw new ConfigurationException("Could not find toClerk with name=" + toClerkRef);
                }
                UDDIClerk toClerk = clerks.get(toClerkRef);
                xRegistration.setToClerk(toClerk);
                log.debug(xRegistration);

                xRegistrations.add(xRegistration);
        }
        return xRegistrations;
}
 
Example 18
Source File: SqoopHook.java    From atlas with Apache License 2.0 4 votes vote down vote up
private String getClusterName(Configuration config) {
    return config.getString(CLUSTER_NAME_KEY, DEFAULT_CLUSTER_NAME);
}
 
Example 19
Source File: GeneratorUtils.java    From springboot-admin with Apache License 2.0 4 votes vote down vote up
/**
 * 生成代码
 */
public static void generatorCode(Map<String, String> table,
		List<Map<String, String>> columns, ZipOutputStream zip){
	//配置信息
	Configuration config = getConfig();
	
	//表信息
	SysTable sysTable = new SysTable();
	sysTable.setTableName(table.get("tableName"));
	sysTable.setComments(table.get("tableComment"));
	//表名转换成Java类名
	String className = tableToJava(sysTable.getTableName(), config.getString("tablePrefix"));
	sysTable.setClassName(className);
	sysTable.setClassname(StringUtils.uncapitalize(className));
	
	//列信息
	List<SysColumn> columsList = new ArrayList<>();
	for(Map<String, String> column : columns){
		SysColumn sysColumn = new SysColumn();
		sysColumn.setColumnName(column.get("columnName"));
		sysColumn.setDataType(column.get("dataType"));
		sysColumn.setComments(column.get("columnComment"));
		sysColumn.setExtra(column.get("extra"));
		
		//列名转换成Java属性名
		String attrName = columnToJava(sysColumn.getColumnName());
		sysColumn.setAttrName(attrName);
		sysColumn.setAttrname(StringUtils.uncapitalize(attrName));
		
		//列的数据类型,转换成Java类型
		String attrType = config.getString(sysColumn.getDataType(), "unknowType");
		sysColumn.setAttrType(attrType);
		
		//是否主键
		if("PRI".equalsIgnoreCase(column.get("columnKey")) && sysTable.getPk() == null){
			sysTable.setPk(sysColumn);
		}
		
		columsList.add(sysColumn);
	}
	sysTable.setColumns(columsList);
	
	//没主键,则第一个字段为主键
	if(sysTable.getPk() == null){
		sysTable.setPk(sysTable.getColumns().get(0));
	}
	
	//设置velocity资源加载器
	Properties prop = new Properties();  
	prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");  
	Velocity.init(prop);

	String entityPrefix=config.getString("entityPrefix");
	String classNameTemp=entityPrefix+sysTable.getClassName();
	String classnameTmep=sysTable.getClassname();
	String pathPrefix=config.getString("pathPrefix");

	//封装模板数据
	Map<String, Object> map = new HashMap<>();
	map.put("tableName", sysTable.getTableName());
	map.put("comments", sysTable.getComments());
	map.put("pk", sysTable.getPk());
	map.put("className", classNameTemp);
	map.put("classname", classnameTmep);
	map.put("pathPrefix", pathPrefix);
	map.put("pathName", "/"+ sysTable.getClassname().toLowerCase());
	map.put("columns", sysTable.getColumns());
	map.put("package", config.getString("package"));
	map.put("author", config.getString("author"));
	map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
       VelocityContext context = new VelocityContext(map);
       
       //获取模板列表
	List<String> templates = getTemplates();
	for(String template : templates){
		//渲染模板
		StringWriter sw = new StringWriter();
		Template tpl = Velocity.getTemplate(template, "UTF-8");
		tpl.merge(context, sw);
		
		try {
			//添加到zip
			zip.putNextEntry(new ZipEntry(getFileName(template, classNameTemp, classnameTmep, config.getString("package"))));
			IOUtils.write(sw.toString(), zip, "UTF-8");
			IOUtils.closeQuietly(sw);
			zip.closeEntry();
		} catch (IOException e) {
			throw new AppException("渲染模板失败,表名:" + sysTable.getTableName(), e);
		}
	}
}
 
Example 20
Source File: HAConfiguration.java    From atlas with Apache License 2.0 3 votes vote down vote up
/**
 * Get the web server address that a server instance with the passed ID is bound to.
 *
 * This method uses the property {@link SecurityProperties#TLS_ENABLED} to determine whether
 * the URL is http or https.
 *
 * @param configuration underlying configuration
 * @param serverId serverId whose host:port property is picked to build the web server address.
 * @return
 */
public static String getBoundAddressForId(Configuration configuration, String serverId) {
    String hostPort = configuration.getString(ATLAS_SERVER_ADDRESS_PREFIX +serverId);
    boolean isSecure = configuration.getBoolean(SecurityProperties.TLS_ENABLED);
    String protocol = (isSecure) ? "https://" : "http://";
    return protocol + hostPort;
}