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

The following examples show how to use org.apache.commons.configuration.Configuration#getStringArray() . 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: AtlasAdminClient.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private int run(String[] args) throws AtlasException {
    CommandLine commandLine = parseCommandLineOptions(args);
    Configuration configuration = ApplicationProperties.get();
    String[] atlasServerUri = configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);

    if (atlasServerUri == null || atlasServerUri.length == 0) {
        atlasServerUri = new String[] { AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS };
    }

    AtlasClient atlasClient = null;
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
        atlasClient = new AtlasClient(atlasServerUri, basicAuthUsernamePassword);
    } else {
        atlasClient = new AtlasClient(atlasServerUri);
    }
    return handleCommand(commandLine, atlasServerUri, atlasClient);
}
 
Example 2
Source File: JobHandler.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
public void init(AppConfiguration appConfig) throws SchedulerException {
    this.appconfig = appConfig;

    Configuration jobsConfig = appConfig.getJobCofig();

    loadDevices(jobsConfig);

    scheduler.clear();

    //job.list
    for (String jobId : jobsConfig.getStringArray(JOBS_LIST)) {
        Configuration jobConfig = jobsConfig.subset(jobId);

        for (ProArcJob job : getJobs()) {
            //job.name.type
            if (job.getType().equals(jobConfig.getString(JOB_TYPE))) {
                job.initJob(scheduler, jobId, jobConfig);
            }
        }
    }
}
 
Example 3
Source File: ConfigurationHelperTest.java    From googleads-java-lib with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromSystem_containsListValues() throws Exception {
  AbstractConfiguration.setDefaultListDelimiter('|');
  Map<String, String> properties = Maps.newHashMap();
  properties.put("testProperty", "b,bee");

  properties.forEach(System::setProperty);

  Splitter splitter = Splitter.on(',');
  Configuration systemConfiguration = configurationHelper.fromSystem();
  for (Entry<String, String> entry : properties.entrySet()) {
    String[] actualValues = systemConfiguration.getStringArray(entry.getKey());
    String[] expectedValues;
    if ("line.separator".equals(entry.getKey())) {
      expectedValues = new String[] {SystemUtils.LINE_SEPARATOR};
    } else {
      expectedValues = splitter.splitToList(entry.getValue()).toArray(new String[0]);
    }
    assertArrayEquals(String.format("Values for key %s do not match", entry.getKey()),
        expectedValues, actualValues);
  }
}
 
Example 4
Source File: JobHandler.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private void loadDevices(Configuration jobsConfig) {
    devices = new HashMap<>();

    //job.devices
    for (String device : jobsConfig.getStringArray(JOB_DEVICES)) {
        //job.device.name
        Configuration deviceConfig = jobsConfig.subset(JOB_DEVICE_PREFIX + "." + device);
        //job.device.name.dirname
        String dir = deviceConfig.getString(JOB_DEVICE_DIR);

        if (dir == null || dir.isEmpty()) {
            throw new IllegalArgumentException("Job device: " + device + " config directory cannot be empty");
        }
        //job.device.name.uuid
        String uuid = deviceConfig.getString(JOB_DEVICE_UUID);

        if (uuid == null || uuid.isEmpty()) {
            throw new IllegalArgumentException("Job device: " + device + " config uuid cannot be empty");
        }

        devices.put(dir, uuid);
    }
}
 
Example 5
Source File: LensAPI.java    From cognition with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for creating the spark context from the given cognition configuration
 * @return a new configured spark context
 */
public SparkContext createSparkContext() {
  SparkConf conf = new SparkConf();

  Configuration config = cognition.getProperties();

  conf.set("spark.serializer", KryoSerializer.class.getName());
  conf.setAppName(config.getString("app.name"));
  conf.setMaster(config.getString("master"));

  Iterator<String> iterator = config.getKeys("spark");
  while (iterator.hasNext()) {
    String key = iterator.next();
    conf.set(key, config.getString(key));
  }

  SparkContext sc = new SparkContext(conf);
  for (String jar : config.getStringArray("jars")) {
    sc.addJar(jar);
  }

  return sc;
}
 
Example 6
Source File: QuickStart.java    From atlas with Apache License 2.0 5 votes vote down vote up
static String[] getServerUrl(String[] args) throws AtlasException {
    if (args.length > 0) {
        return args[0].split(",");
    }

    Configuration configuration = ApplicationProperties.get();
    String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS);
    if (urls == null || urls.length == 0) {
        System.out.println("Usage: quick_start_v1.py <atlas endpoint of format <http/https>://<atlas-fqdn>:<atlas port> like http://localhost:21000>");
        System.exit(-1);
    }

    return urls;
}
 
Example 7
Source File: MicroserviceFactory.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * {@code service_description.description} is split by {@code ,},
 * need to combine the description array to raw description.
 */
private void setDescription(Configuration configuration, Microservice microservice) {
  String[] descriptionArray = configuration.getStringArray(CONFIG_QUALIFIED_MICROSERVICE_DESCRIPTION_KEY);
  if (null == descriptionArray || descriptionArray.length < 1) {
    return;
  }

  StringBuilder rawDescriptionBuilder = new StringBuilder();
  for (String desc : descriptionArray) {
    rawDescriptionBuilder.append(desc).append(",");
  }

  microservice.setDescription(rawDescriptionBuilder.substring(0, rawDescriptionBuilder.length() - 1));
}
 
Example 8
Source File: StormAtlasHookIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    // start a local storm cluster
    stormCluster = StormTestUtil.createLocalStormCluster();
    LOG.info("Created a storm local cluster");

    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[]{"admin", "admin"});
    } else {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}
 
Example 9
Source File: AddressResolverConfig.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private static List<String> getStringListProperty(Configuration configSource,
    List<String> defaultValue, String... keys) {
  configSource = guardConfigSource(configSource);
  if (configSource == null) {
    return defaultValue;
  }
  for (String key : keys) {
    String[] vals = configSource.getStringArray(key);
    if (vals != null && vals.length > 0) {
      return Arrays.asList(vals);
    }
  }
  return defaultValue;
}
 
Example 10
Source File: FalconHookIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    Configuration atlasProperties = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[]{"admin", "admin"});
    } else {
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }

    AtlasService service = new AtlasService();
    service.init();
    STORE.registerListener(service);
    CurrentUser.authenticate(System.getProperty("user.name"));
}
 
Example 11
Source File: StormAtlasHookIT.java    From atlas with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    // start a local storm cluster
    stormCluster = StormTestUtil.createLocalStormCluster();
    LOG.info("Created a storm local cluster");

    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[]{"admin", "admin"});
    } else {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}
 
Example 12
Source File: ConfigurationHelperTest.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that reading list values from a properties file works properly when the default
 * list delimiter is modified.
 */
@Test
public void testFromFile_listValuesWithDefaultDelimiterChanged() throws Exception {
  AbstractConfiguration.setDefaultListDelimiter('|');
  Configuration configuration = configurationHelper.fromFile(
      ConfigurationHelperTest.class.getResource("props/test3.properties"));
  assertPropertiesEquals(test3Properties, configuration);
  String[] stringArray = configuration.getStringArray("i.j.k");
  assertArrayEquals(new String[] {"foo", "bar"}, stringArray);
}
 
Example 13
Source File: RootConfig.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ExperimentType[] getAvailableExperimentTypes() {
    Configuration config = GerbilConfiguration.getInstance();
    Set<ExperimentType> types = new HashSet<ExperimentType>();
    if (config.containsKey(AVAILABLE_EXPERIMENT_TYPES_KEY)) {
        String typeNames[] = config.getStringArray(AVAILABLE_EXPERIMENT_TYPES_KEY);
        ExperimentType type = null;
        for (int i = 0; i < typeNames.length; ++i) {
            try {
                type = ExperimentType.valueOf(typeNames[i]);
                types.add(type);
            } catch (IllegalArgumentException e) {
                LOGGER.warn(
                        "Couldn't find the experiment type \"{}\" defined in the properties file. It will be ignored.",
                        typeNames[i]);
            }
        }
    }
    if (types.size() == 0) {
        LOGGER.error(
                "Couldn't load the list of available experiment types. This GERBIL instance won't work as expected. Please define a list of experiment types using the {} key in the configuration file.",
                AVAILABLE_EXPERIMENT_TYPES_KEY);
        return new ExperimentType[0];
    } else {
        ExperimentType typesArray[] = types.toArray(new ExperimentType[types.size()]);
        Arrays.sort(typesArray);
        return typesArray;
    }
}
 
Example 14
Source File: BulkFetchAndUpdate.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static String[] getAtlasRESTUrl() {
    Configuration atlasConf = null;
    try {
        atlasConf = ApplicationProperties.get();
        return atlasConf.getStringArray(APPLICATION_PROPERTY_ATLAS_ENDPOINT);
    } catch (AtlasException e) {
        return new String[]{DEFAULT_ATLAS_URL};
    }
}
 
Example 15
Source File: SqoopHookIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    //Set-up sqoop session
    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[]{"admin", "admin"});
    } else {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}
 
Example 16
Source File: FalconHookIT.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
    Configuration atlasProperties = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[]{"admin", "admin"});
    } else {
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }

    AtlasService service = new AtlasService();
    service.init();
    STORE.registerListener(service);
    CurrentUser.authenticate(System.getProperty("user.name"));
}
 
Example 17
Source File: HAConfiguration.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether HA is enabled or not.
 * @param configuration underlying configuration instance
 * @return
 */
public static boolean isHAEnabled(Configuration configuration) {
    boolean ret = false;

    if (configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)) {
        ret = configuration.getBoolean(ATLAS_SERVER_HA_ENABLED_KEY);
    } else {
        String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);

        ret = ids != null && ids.length > 1;
    }

    return ret;
}
 
Example 18
Source File: QuickStartV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
static String[] getServerUrl(String[] args) throws AtlasException {
    if (args.length > 0) {
        return args[0].split(",");
    }

    Configuration configuration = ApplicationProperties.get();
    String[]      urls          = configuration.getStringArray(ATLAS_REST_ADDRESS);

    if (ArrayUtils.isEmpty(urls)) {
        System.out.println("org.apache.atlas.examples.QuickStartV2 <Atlas REST address <http/https>://<atlas-fqdn>:<atlas-port> like http://localhost:21000>");
        System.exit(-1);
    }

    return urls;
}
 
Example 19
Source File: GenericExternalProcess.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Merges result parameters. {@code onExit} and {@code onSkip} are experimental features.
 *
 * @param conf
 * @param inputParameters
 * @param skippedProcess
 * @param exitCode
 * @param log
 * @return
 */
public static ProcessResult getResultParameters(Configuration conf,
        Map<String, String> inputParameters, boolean skippedProcess,
        int exitCode, String log) {

    // gets <processorId>.param.* parameters with interpolated values
    // it allows to share properties among process and read helper values from process declaration (mime, output file, ...)
    String processorId = conf.getString("id");
    Map<String, String> hm = new HashMap<String, String>(inputParameters);
    addResultParamaters(conf, processorId, hm);

    ExitStrategy exit = new ExitStrategy();
    if (skippedProcess) {
        Configuration onSkip = conf.subset("onSkip");
        addResultParamaters(onSkip, processorId, hm);
        exit.setSkip(true);
        exit.setContinueWithProcessIds(Arrays.asList(onSkip.getStringArray("next")));
        return new ProcessResult(processorId, hm, exit);
    }

    exit.setExitCode(exitCode);
    String[] onExitIds = conf.getStringArray("onExits");
    Configuration onExitConf = conf.subset("onExit");
    boolean defaultExit = true;
    for (String onExitId : onExitIds) {
        if (isExitId(onExitId, exitCode)) {
            Configuration onExitIdConf = onExitConf.subset(onExitId);
            addResultParamaters(onExitIdConf, processorId, hm);
            exit.setErrorMessage(onExitIdConf.getString("message"));
            exit.setStop(onExitIdConf.getBoolean("stop", exitCode != 0));
            exit.setContinueWithProcessIds(Arrays.asList(onExitIdConf.getStringArray("next")));
            defaultExit = false;
            break;
        }
    }
    if (defaultExit) {
        exit.setStop(exitCode != 0);
        exit.setErrorMessage(log);
    }
    return new ProcessResult(processorId, hm, exit);
}
 
Example 20
Source File: ClientConfig.java    From juddi with Apache License 2.0 4 votes vote down vote up
private Map<String, UDDIClerk> readClerkConfig(Configuration config, Map<String, UDDINode> uddiNodes)
     throws ConfigurationException {
        clientName = config.getString("client[@name]");
        clientCallbackUrl = config.getString("client[@callbackUrl]");
        Map<String, UDDIClerk> clerks = new HashMap<String, UDDIClerk>();
        if (config.containsKey("client.clerks.clerk[@name]")) {
                String[] names = config.getStringArray("client.clerks.clerk[@name]");

                log.debug("clerk names=" + names.length);
                for (int i = 0; i < names.length; i++) {
                        UDDIClerk uddiClerk = new UDDIClerk();
                        uddiClerk.setManagerName(clientName);
                        uddiClerk.setName(config.getString("client.clerks.clerk(" + i + ")[@name]"));
                        String nodeRef = config.getString("client.clerks.clerk(" + i + ")[@node]");
                        if (!uddiNodes.containsKey(nodeRef)) {
                                throw new ConfigurationException("Could not find Node with name=" + nodeRef);
                        }
                        UDDINode uddiNode = uddiNodes.get(nodeRef);
                        uddiClerk.setUDDINode(uddiNode);
                        uddiClerk.setPublisher(config.getString("client.clerks.clerk(" + i + ")[@publisher]"));
                        uddiClerk.setPassword(config.getString("client.clerks.clerk(" + i + ")[@password]"));
                        uddiClerk.setIsPasswordEncrypted(config.getBoolean("client.clerks.clerk(" + i + ")[@isPasswordEncrypted]", false));
                        uddiClerk.setCryptoProvider(config.getString("client.clerks.clerk(" + i + ")[@cryptoProvider]"));

                        String clerkBusinessKey = config.getString("client.clerks.clerk(" + i + ")[@businessKey]");
                        String clerkBusinessName = config.getString("client.clerks.clerk(" + i + ")[@businessName]");
                        String clerkKeyDomain = config.getString("client.clerks.clerk(" + i + ")[@keyDomain]");

                        String[] classes = config.getStringArray("client.clerks.clerk(" + i + ").class");
                        uddiClerk.setClassWithAnnotations(classes);

                        int numberOfWslds = config.getStringArray("client.clerks.clerk(" + i + ").wsdl").length;
                        if (numberOfWslds > 0) {
                                UDDIClerk.WSDL[] wsdls = new UDDIClerk.WSDL[numberOfWslds];
                                for (int w = 0; w < wsdls.length; w++) {

                                        UDDIClerk.WSDL wsdl = new UDDIClerk.WSDL();
                                        String fileName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")");
                                        wsdl.setFileName(fileName);
                                        if (!new File(fileName).exists()) {
                                                log.warn("The wsdl file referenced in the config at '" + fileName + "' doesn't exist!");
                                        }
                                        String businessKey = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                                        String businessName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessName]");
                                        String keyDomain = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@keyDomain]");
                                        if (businessKey == null) {
                                                businessKey = clerkBusinessKey;
                                        }
                                        if (businessKey == null) {
                                                businessKey = uddiClerk.getUDDINode().getProperties().getProperty("businessKey");
                                        }
                                        if (businessKey == null) {
                                                //use key convention to build the businessKey
                                                if (businessName == null) {
                                                        businessName = clerkBusinessName;
                                                }
                                                if (keyDomain == null) {
                                                        keyDomain = clerkKeyDomain;
                                                }
                                                if (keyDomain == null) {
                                                        keyDomain = uddiClerk.getUDDINode().getProperties().getProperty("keyDomain");
                                                }
                                                if ((businessName == null && !uddiClerk.getUDDINode().getProperties().containsKey("businessName"))
                                                     || keyDomain == null && !uddiClerk.getUDDINode().getProperties().containsKey("keyDomain")) {
                                                        throw new ConfigurationException("Either the wsdl(" + wsdls[w]
                                                             + ") or clerk (" + uddiClerk.name + ") elements require a businessKey, or businessName & keyDomain attributes");
                                                } else {
                                                        Properties properties = new Properties(uddiClerk.getUDDINode().getProperties());
                                                        if (businessName != null) {
                                                                properties.put("businessName", businessName);
                                                        }
                                                        if (keyDomain != null) {
                                                                properties.put("keyDomain", keyDomain);
                                                        }
                                                        businessKey = UDDIKeyConvention.getBusinessKey(properties);
                                                }
                                        }
                                        if (!businessKey.toLowerCase().startsWith("uddi:") || !businessKey.substring(5).contains(":")) {
                                                throw new ConfigurationException("The businessKey '" + businessKey + "' does not implement a valid UDDI v3 key format. See config file at client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                                        }
                                        wsdl.setBusinessKey(businessKey);
                                        if (keyDomain == null) {
                                                keyDomain = businessKey.split(":")[1];
                                        }
                                        wsdl.setKeyDomain(keyDomain);
                                        wsdls[w] = wsdl;
                                }
                                uddiClerk.setWsdls(wsdls);
                        }

                        clerks.put(names[i], uddiClerk);
                }
        }
        return clerks;
}