com.typesafe.config.ConfigSyntax Java Examples

The following examples show how to use com.typesafe.config.ConfigSyntax. 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: ApplicationModule.java    From winthing with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
Config config() {
    Config cfg = ConfigFactory.load();
    String path = System.getProperty("user.dir") + File.separator + ConfigFile;

    File fp = new File(path);
    if (fp.exists()) {
        ConfigParseOptions options = ConfigParseOptions.defaults();
        options.setSyntax(ConfigSyntax.CONF);

        cfg = ConfigFactory.parseFile(fp, options).withFallback(cfg);
    }

    return cfg;
}
 
Example #2
Source File: SystemCommander.java    From winthing with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
public void parseConfig() {
    String path = System.getProperty("user.dir") + File.separator + ConfigFile;
    File fp = new File(path);
    if (!fp.exists()) {
        logger.warn("No whitelist found. Every command is allowed to execute on this device!");
        return;
    }

    try {
        StringJoiner joiner = new StringJoiner(", ");

        ConfigParseOptions options = ConfigParseOptions.defaults();
        options.setSyntax(ConfigSyntax.CONF);

        Config cfg = ConfigFactory.parseFile(fp, options);
        Set<String> map = cfg.root().keySet();
        for (String key : map) {
            whitelist.put(key, cfg.getString(key));
            joiner.add(key);
        }

        logger.info("Found whitelist of allowed commands to execute, using it...");
        logger.info("Allowed commands: [" + joiner.toString() + "]");

        isEnabled = true;
    } catch (Exception e) {
        logger.error("Unable to process whitelist file", e);
    }
}
 
Example #3
Source File: TestOozieMetadataAccessConfig.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetOozieConfig() throws Exception {
    String oozieConfigStr = "classification.accessType=oozie_api\nclassification.oozieUrl=http://localhost:11000/oozie\nclassification.filter=status=RUNNING\nclassification.authType=SIMPLE";
    ConfigParseOptions options = ConfigParseOptions.defaults()
            .setSyntax(ConfigSyntax.PROPERTIES)
            .setAllowMissing(false);
    Config config = ConfigFactory.parseString(oozieConfigStr, options);
    config = config.getConfig(EagleConfigConstants.CLASSIFICATION_CONFIG);
    OozieMetadataAccessConfig oozieMetadataAccessConfig = OozieMetadataAccessConfig.config2Entity(config);
    System.out.print(oozieMetadataAccessConfig);
    Assert.assertEquals("oozie_api", oozieMetadataAccessConfig.getAccessType());
    Assert.assertEquals("http://localhost:11000/oozie", oozieMetadataAccessConfig.getOozieUrl());
    Assert.assertEquals("status=RUNNING", oozieMetadataAccessConfig.getFilter());
    Assert.assertEquals("SIMPLE", oozieMetadataAccessConfig.getAuthType());
}
 
Example #4
Source File: SwiftConfig.java    From swift-k with Apache License 2.0 5 votes vote down vote up
public static SwiftConfig load(String cmdLineConfig, List<String> configSearchPath, Map<String, Object> cmdLineOptions) {
    List<String> loadedFiles = new ArrayList<String>();
    List<String> loadedFileIndices = new ArrayList<String>();
    
    ConfigParseOptions opt = ConfigParseOptions.defaults();
    opt = opt.setIncluder(new IncluderWrapper(opt.getIncluder(), loadedFiles, loadedFileIndices)).
        setSyntax(ConfigSyntax.CONF).setAllowMissing(false);
    
    Config conf;
    
    if (configSearchPath == null) {
        String envSearchPath = System.getenv("SWIFT_CONF_PATH");
        if (envSearchPath != null) {
            configSearchPath = splitConfigSearchPath(envSearchPath);
        }
    }
    if (configSearchPath == null) {
        conf = loadNormal(cmdLineConfig, opt, loadedFiles, loadedFileIndices);
    }
    else {
        conf = loadFromSearchPath(configSearchPath, cmdLineConfig, opt, 
            loadedFiles, loadedFileIndices);
    }
    
    if (cmdLineOptions != null) {
        Config oconf = ConfigFactory.parseMap(cmdLineOptions, "<Command Line>");
        conf = oconf.withFallback(conf);
        loadedFiles.add("<Command Line>");
        loadedFileIndices.add("C");
    }
    
    conf = conf.resolveWith(getSubstitutions());
    ConfigTree<ValueLocationPair> out = SCHEMA.validate(conf);
    SwiftConfig sc = new SwiftConfig(loadedFiles, loadedFileIndices);
    sc.build(out);
    return sc;
}
 
Example #5
Source File: PullFileLoader.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private Config loadHoconConfigAtPath(Path path) throws IOException {
  try (InputStream is = fs.open(path);
      Reader reader = new InputStreamReader(is, Charsets.UTF_8)) {
      return ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY,
          PathUtils.getPathWithoutSchemeAndAuthority(path).toString()))
          .withFallback(ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF)));
  }
}
 
Example #6
Source File: PullFileLoader.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private Config loadHoconConfigWithFallback(Path path, Config fallback) throws IOException {
  try (InputStream is = fs.open(path);
       Reader reader = new InputStreamReader(is, Charsets.UTF_8)) {
    return ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY,
        PathUtils.getPathWithoutSchemeAndAuthority(path).toString()))
        .withFallback(ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF)))
        .withFallback(fallback);
  }
}
 
Example #7
Source File: IntegrationBasicSuite.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private void copyJobConfFromResource() throws IOException {
  Map<String, Config> jobConfigs;
  try (InputStream resourceStream = this.jobConfResourceUrl.openStream()) {
    Reader reader = new InputStreamReader(resourceStream);
    Config rawJobConfig = ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF));
    jobConfigs = overrideJobConfigs(rawJobConfig);
    jobConfigs.forEach((jobName, jobConfig)-> {
      try {
        writeJobConf(jobName, jobConfig);
      } catch (IOException e) {
        log.error("Job " + jobName + " config cannot be written.");
      }
    });
  }
}
 
Example #8
Source File: IntegrationJobRestartViaSpecSuite.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private Config getJobConfig() throws IOException {
  try (InputStream resourceStream = Resources.getResource(JOB_CONF_NAME).openStream()) {
    Reader reader = new InputStreamReader(resourceStream);
    Config rawJobConfig =
        ConfigFactory.parseReader(reader, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF));
    rawJobConfig = rawJobConfig.withFallback(getClusterConfig());

    Config newConfig = ClusterIntegrationTestUtils.buildSleepingJob(JOB_ID, TASK_STATE_FILE, 100L);

    newConfig = newConfig.withValue(SleepingTask.TASK_STATE_FILE_KEY, ConfigValueFactory.fromAnyRef(TASK_STATE_FILE));
    newConfig = newConfig.withFallback(rawJobConfig);
    return newConfig;
  }
}
 
Example #9
Source File: HoconConfigSourceProvider.java    From smallrye-config with Apache License 2.0 4 votes vote down vote up
static ConfigSource getConfigSource(ClassLoader classLoader, String resource, int ordinal) {
    final Config config = ConfigFactory.parseResourcesAnySyntax(classLoader, resource,
            ConfigParseOptions.defaults().setClassLoader(classLoader).setSyntax(ConfigSyntax.CONF));
    return new HoconConfigSource(config, resource, ordinal);
}
 
Example #10
Source File: InjectorBuilder.java    From Guice-configuration with Apache License 2.0 4 votes vote down vote up
private ConfigParseOptions getOptions(Class beanClass) {
    return defaults().setSyntax(ConfigSyntax.valueOf(getAnnotationConfiguration(beanClass).syntax().name()));
}
 
Example #11
Source File: AvroToRestJsonEntryConverter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
/**
 * Use resource key(Optional) and rest json entry as a template and fill in template using Avro as a reference.
 * e.g:
 *  Rest JSON entry HOCON template:
 *    AccountId=${sf_account_id},Member_Id__c=${member_id}
 *  Avro:
 *    {"sf_account_id":{"string":"0016000000UiCYHAA3"},"member_id":{"long":296458833}}
 *
 *  Converted Json:
 *    {"AccountId":"0016000000UiCYHAA3","Member_Id__c":296458833}
 *
 *  As it's template based approach, it can produce nested JSON structure even Avro is flat (or vice versa).
 *
 * e.g:
 *  Rest resource template:
 *    /sobject/account/memberId/${member_id}
 *  Avro:
 *    {"sf_account_id":{"string":"0016000000UiCYHAA3"},"member_id":{"long":296458833}}
 *  Converted resource:
 *    /sobject/account/memberId/296458833
 *
 *  Converted resource will be used to form end point.
 *    http://www.server.com:9090/sobject/account/memberId/296458833
 *
 * {@inheritDoc}
 * @see org.apache.gobblin.converter.Converter#convertRecord(java.lang.Object, java.lang.Object, org.apache.gobblin.configuration.WorkUnitState)
 */
@Override
public Iterable<RestEntry<JsonObject>> convertRecord(Void outputSchema, GenericRecord inputRecord, WorkUnitState workUnit)
    throws DataConversionException {

  Config srcConfig = ConfigFactory.parseString(inputRecord.toString(),
                                               ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON));

  String resourceKey = workUnit.getProp(CONVERTER_AVRO_REST_ENTRY_RESOURCE_KEY, "");
  if(!StringUtils.isEmpty(resourceKey)) {
    final String dummyKey = "DUMMY";
    Config tmpConfig = ConfigFactory.parseString(dummyKey + "=" + resourceKey).resolveWith(srcConfig);
    resourceKey = tmpConfig.getString(dummyKey);
  }

  String hoconInput = workUnit.getProp(CONVERTER_AVRO_REST_JSON_ENTRY_TEMPLATE);
  if(StringUtils.isEmpty(hoconInput)) {
    return new SingleRecordIterable<>(new RestEntry<>(resourceKey, parser.parse(inputRecord.toString()).getAsJsonObject()));
  }

  Config destConfig = ConfigFactory.parseString(hoconInput).resolveWith(srcConfig);
  JsonObject json = parser.parse(destConfig.root().render(ConfigRenderOptions.concise())).getAsJsonObject();
  return new SingleRecordIterable<>(new RestEntry<>(resourceKey, json));
}