Search in sources :

Example 1 with FSDatasetDescriptor

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());
}
Also used : Path(org.apache.hadoop.fs.Path) FlowTemplate(org.apache.gobblin.service.modules.template.FlowTemplate) Config(com.typesafe.config.Config) Properties(java.util.Properties) JobTemplate(org.apache.gobblin.runtime.api.JobTemplate) URI(java.net.URI) FSDatasetDescriptor(org.apache.gobblin.service.modules.dataset.FSDatasetDescriptor) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.testng.annotations.Test)

Aggregations

Config (com.typesafe.config.Config)1 URI (java.net.URI)1 Properties (java.util.Properties)1 Pair (org.apache.commons.lang3.tuple.Pair)1 JobTemplate (org.apache.gobblin.runtime.api.JobTemplate)1 FSDatasetDescriptor (org.apache.gobblin.service.modules.dataset.FSDatasetDescriptor)1 FlowTemplate (org.apache.gobblin.service.modules.template.FlowTemplate)1 Path (org.apache.hadoop.fs.Path)1 Test (org.testng.annotations.Test)1