public static BenderConfig load(String filename, String data) { /* * Configure Mapper and register polymorphic types */ ObjectMapper mapper = BenderConfig.getObjectMapper(filename); mapper.setPropertyNamingStrategy( PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); /* * Optionally don't validate the config. Assume user has already * done this. */ String v = System.getenv("BENDER_SKIP_VALIDATE"); if (v != null && v.equals("true")) { return BenderConfig.load(filename, data, mapper, false); } else { return BenderConfig.load(filename, data, mapper, true); } }
public static BenderConfig load(String filename, String data) { /* * Configure Mapper and register polymorphic types */ ObjectMapper mapper = BenderConfig.getObjectMapper(filename); mapper.setPropertyNamingStrategy( PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); /* * Optionally don't validate the config. Assume user has already * done this. */ String v = System.getenv("BENDER_SKIP_VALIDATE"); if (v != null && v.equals("true")) { return BenderConfig.load(filename, data, mapper, false); } else { return BenderConfig.load(filename, data, mapper, true); } }
mapper.setPropertyNamingStrategy( PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); BenderConfig.load(configFilename, sb.toString(), mapper, true); System.out.println("Valid"); BenderConfig config = BenderConfig.load(configFilename, sb.toString()); } catch (ConfigurationException e) { System.out.println("Invalid");
BenderConfig config = load(resource, data); config.setConfigFile(resource);
BenderConfig config = load(resource, data); config.setConfigFile(resource);
public static BenderConfig load(AmazonS3ClientFactory s3ClientFactory, AmazonS3URI s3Uri) { AmazonS3Client s3 = s3ClientFactory.newInstance(); S3Object s3object = s3.getObject(s3Uri.getBucket(), s3Uri.getKey()); StringWriter writer = new StringWriter(); try { IOUtils.copy(s3object.getObjectContent(), writer, "UTF-8"); } catch (IOException e) { throw new ConfigurationException("Unable to read file from s3", e); } BenderConfig config = load(s3Uri.getKey().toString(), writer.toString()); config.setConfigFile(s3Uri.getURI().toString()); return config; }
public static BenderConfig load(AmazonS3ClientFactory s3ClientFactory, AmazonS3URI s3Uri) { AmazonS3Client s3 = s3ClientFactory.newInstance(); S3Object s3object = s3.getObject(s3Uri.getBucket(), s3Uri.getKey()); StringWriter writer = new StringWriter(); try { IOUtils.copy(s3object.getObjectContent(), writer, "UTF-8"); } catch (IOException e) { throw new ConfigurationException("Unable to read file from s3", e); } BenderConfig config = load(s3Uri.getKey().toString(), writer.toString()); config.setConfigFile(s3Uri.getURI().toString()); return config; }
@Test(expected = ConfigurationException.class) public void testMissingStringTemplatesInConfig() throws ConfigurationException, ClassNotFoundException { BenderConfig.load("/config/config_with_env.json"); }
@Test public void testYaml() throws ConfigurationException, ClassNotFoundException { envVars.set("CUSTOM_SOURCE_NAME", "TestSourceName"); BenderConfig config = BenderConfig.load("/config/config_with_env.yaml"); List<SourceConfig> sources = config.getSources(); assertEquals(sources.size(), 1); assertEquals(sources.get(0).getName(), "TestSourceName"); } }
@Test public void testStringTemplatesInConfig() throws ConfigurationException, ClassNotFoundException { envVars.set("CUSTOM_SOURCE_NAME", "TestSourceName"); BenderConfig config = BenderConfig.load("/config/config_with_env.json"); List<SourceConfig> sources = config.getSources(); assertEquals(sources.size(), 1); assertEquals(sources.get(0).getName(), "TestSourceName"); }
config = BenderConfig.load(s3ClientFactory, new AmazonS3URI(configFile)); } else if (configFile.startsWith("file://")) { File file = new File(configFile.replaceFirst("file://", "")); String string = FileUtils.readFileToString(file); config = BenderConfig.load(configFile, string); } else { config = BenderConfig.load(configFile);
config = BenderConfig.load(s3ClientFactory, new AmazonS3URI(configFile)); } else if (configFile.startsWith("file://")) { File file = new File(configFile.replaceFirst("file://", "")); String string = FileUtils.readFileToString(file); config = BenderConfig.load(configFile, string); } else { config = BenderConfig.load(configFile);
@Test public void testLoadConfg() { BenderConfig config = BenderConfig.load("/com/nextdoor/bender/partition/partition_config.json"); PartitionOperationConfig op = (PartitionOperationConfig) config.getSources().get(0).getOperationConfigs().get(0); PartitionSpec spec = op.getPartitionSpecs().get(0); assertEquals("type", spec.getName()); assertEquals(Interpreter.STRING, spec.getInterpreter()); List<String> expected = Arrays.asList("one", "two", "three"); assertEquals(expected, spec.getSources()); }
@Test public void testLoadConfgTime() { BenderConfig config = BenderConfig.load("/com/nextdoor/bender/partition/partition_config_time.json"); PartitionOperationConfig op = (PartitionOperationConfig) config.getSources().get(0).getOperationConfigs().get(0); PartitionSpec spec = op.getPartitionSpecs().get(0); assertEquals("dt", spec.getName()); assertEquals(Interpreter.SECONDS, spec.getInterpreter()); List<String> expected = Arrays.asList("epoch"); assertEquals(expected, spec.getSources()); assertEquals("2017-01-19 05:05:59", spec.interpret("1484802359")); }
@Test public void testStringFormatUpper() { BenderConfig config = BenderConfig.load("/com/nextdoor/bender/partition/partition_config_format.json"); PartitionOperationConfig op = (PartitionOperationConfig) config.getSources().get(0).getOperationConfigs().get(0); PartitionSpec spec = op.getPartitionSpecs().get(0); assertEquals("type", spec.getName()); assertEquals(Interpreter.STRING, spec.getInterpreter()); assertEquals(StringFormat.TOUPPER, spec.getStringFormat()); assertEquals("THISISATEST", spec.interpret("ThisIsATest")); }
@Test public void testStringFormatLower() { BenderConfig config = BenderConfig.load("/com/nextdoor/bender/partition/partition_config_format.json"); PartitionOperationConfig op = (PartitionOperationConfig) config.getSources().get(0).getOperationConfigs().get(0); PartitionSpec spec = op.getPartitionSpecs().get(0); spec.setStringFormat(StringFormat.TOLOWER); assertEquals("type", spec.getName()); assertEquals(Interpreter.STRING, spec.getInterpreter()); assertEquals("thisisatest", spec.interpret("ThisIsATest")); } }