use of org.apache.gobblin.service.modules.dataset.FSDatasetDescriptor in project incubator-gobblin by apache.
the class FSFlowTemplateCatalogTest method testGetFlowTemplate.
@Test
public void testGetFlowTemplate() throws Exception {
URI flowTemplateCatalogUri = this.getClass().getClassLoader().getResource("template_catalog").toURI();
// Create a FSFlowTemplateCatalog instance
Properties properties = new Properties();
properties.put(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY, flowTemplateCatalogUri.toString());
Config config = ConfigFactory.parseProperties(properties);
Config templateCatalogCfg = config.withValue(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, config.getValue(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY));
FSFlowTemplateCatalog catalog = new FSFlowTemplateCatalog(templateCatalogCfg);
FlowTemplate flowTemplate = catalog.getFlowTemplate(new URI(TEST_TEMPLATE_DIR_URI));
// Basic sanity check for the FlowTemplate
List<JobTemplate> jobTemplates = flowTemplate.getJobTemplates();
Assert.assertEquals(jobTemplates.size(), 4);
for (int i = 0; i < 4; i++) {
String uri = new Path(jobTemplates.get(i).getUri()).getName().split("\\.")[0];
String templateId = uri.substring(uri.length() - 1);
for (int j = 0; j < 2; j++) {
Config jobTemplateConfig = jobTemplates.get(i).getRawTemplateConfig();
String suffix = templateId + Integer.toString(j + 1);
Assert.assertEquals(jobTemplateConfig.getString("key" + suffix), "val" + suffix);
}
}
Config flowConfig = ConfigFactory.empty().withValue("team.name", ConfigValueFactory.fromAnyRef("test-team")).withValue("dataset.name", ConfigValueFactory.fromAnyRef("test-dataset"));
List<Pair<DatasetDescriptor, DatasetDescriptor>> inputOutputDescriptors = flowTemplate.getDatasetDescriptors(flowConfig, true);
Assert.assertTrue(inputOutputDescriptors.size() == 2);
List<String> dirs = Lists.newArrayList("inbound", "outbound");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
FSDatasetDescriptor datasetDescriptor;
if (j == 0) {
datasetDescriptor = (FSDatasetDescriptor) inputOutputDescriptors.get(i).getLeft();
} else {
datasetDescriptor = (FSDatasetDescriptor) inputOutputDescriptors.get(i).getRight();
}
Assert.assertEquals(datasetDescriptor.getPlatform(), "hdfs");
Assert.assertEquals(datasetDescriptor.getFormatConfig().getFormat(), "avro");
Assert.assertEquals(datasetDescriptor.getPath(), "/data/" + dirs.get(i) + "/test-team/test-dataset");
}
}
Config flowTemplateConfig = flowTemplate.getRawTemplateConfig();
Assert.assertEquals(flowTemplateConfig.getString(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX + ".0." + DatasetDescriptorConfigKeys.CLASS_KEY), FSDatasetDescriptor.class.getCanonicalName());
Assert.assertEquals(flowTemplateConfig.getString(DatasetDescriptorConfigKeys.FLOW_EDGE_OUTPUT_DATASET_DESCRIPTOR_PREFIX + ".0." + DatasetDescriptorConfigKeys.CLASS_KEY), FSDatasetDescriptor.class.getCanonicalName());
}
Aggregations