Search in sources :

Example 1 with JobCatalogWithTemplates

use of org.apache.gobblin.runtime.api.JobCatalogWithTemplates in project incubator-gobblin by apache.

the class InheritingJobTemplateTest method testLoopInheritance.

@Test
public void testLoopInheritance() throws Exception {
    JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class);
    Mockito.when(catalog.getTemplate(new URI("template2"))).thenAnswer(new TestTemplateAnswer(Lists.newArrayList(new URI("template3")), ImmutableMap.of("key2", "value2"), Lists.<String>newArrayList(), catalog));
    Mockito.when(catalog.getTemplate(new URI("template3"))).thenAnswer(new TestTemplateAnswer(Lists.newArrayList(new URI("template1")), ImmutableMap.of("key3", "value3"), Lists.newArrayList("required3"), catalog));
    TestTemplate template = new TestTemplate(new URI("template1"), Lists.newArrayList(new URI("template2")), ImmutableMap.of("key1", "value1"), Lists.newArrayList("required"), catalog);
    Collection<String> required = template.getRequiredConfigList();
    Assert.assertEquals(required.size(), 2);
    Assert.assertTrue(required.contains("required"));
    Assert.assertTrue(required.contains("required3"));
    Config rawTemplate = template.getRawTemplateConfig();
    Assert.assertEquals(rawTemplate.getString("key1"), "value1");
    Assert.assertEquals(rawTemplate.getString("key2"), "value2");
    Assert.assertEquals(rawTemplate.getString("key3"), "value3");
    Config resolved = template.getResolvedConfig(ConfigFactory.parseMap(ImmutableMap.of("required", "r1", "required3", "r3")));
    Assert.assertEquals(resolved.getString("key1"), "value1");
    Assert.assertEquals(resolved.getString("key2"), "value2");
    Assert.assertEquals(resolved.getString("key3"), "value3");
    Assert.assertEquals(resolved.getString("required"), "r1");
    Assert.assertEquals(resolved.getString("required3"), "r3");
}
Also used : JobCatalogWithTemplates(org.apache.gobblin.runtime.api.JobCatalogWithTemplates) Config(com.typesafe.config.Config) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with JobCatalogWithTemplates

use of org.apache.gobblin.runtime.api.JobCatalogWithTemplates in project incubator-gobblin by apache.

the class StaticJobTemplateTest method test.

@Test
public void test() throws Exception {
    Map<String, String> confMap = Maps.newHashMap();
    confMap.put("key1", "value1");
    confMap.put(ConfigurationKeys.REQUIRED_ATRRIBUTES_LIST, "required1,required2");
    confMap.put(StaticJobTemplate.SUPER_TEMPLATE_KEY, "template2");
    JobCatalogWithTemplates catalog = Mockito.mock(JobCatalogWithTemplates.class);
    Mockito.when(catalog.getTemplate(new URI("template2"))).thenAnswer(new InheritingJobTemplateTest.TestTemplateAnswer(Lists.<URI>newArrayList(), ImmutableMap.of("key2", "value2"), Lists.<String>newArrayList(), catalog));
    StaticJobTemplate template = new StaticJobTemplate(new URI("template"), "1", "desc", ConfigFactory.parseMap(confMap), catalog);
    Assert.assertEquals(template.getSuperTemplates().size(), 1);
    Assert.assertEquals(template.getSuperTemplates().iterator().next().getUri(), new URI("template2"));
    Collection<String> required = template.getRequiredConfigList();
    Assert.assertEquals(required.size(), 2);
    Assert.assertTrue(required.contains("required1"));
    Assert.assertTrue(required.contains("required2"));
    Config rawTemplate = template.getRawTemplateConfig();
    Assert.assertEquals(rawTemplate.getString("key1"), "value1");
    Assert.assertEquals(rawTemplate.getString("key2"), "value2");
    Config resolved = template.getResolvedConfig(ConfigFactory.parseMap(ImmutableMap.of("required1", "r1", "required2", "r2")));
    Assert.assertEquals(resolved.getString("key1"), "value1");
    Assert.assertEquals(resolved.getString("key2"), "value2");
    Assert.assertEquals(resolved.getString("required1"), "r1");
    Assert.assertEquals(resolved.getString("required2"), "r2");
}
Also used : JobCatalogWithTemplates(org.apache.gobblin.runtime.api.JobCatalogWithTemplates) Config(com.typesafe.config.Config) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 3 with JobCatalogWithTemplates

use of org.apache.gobblin.runtime.api.JobCatalogWithTemplates in project incubator-gobblin by apache.

the class PackagedTemplatesJobCatalogDecoratorTest method test.

@Test
public void test() throws Exception {
    JobCatalogWithTemplates underlying = Mockito.mock(JobCatalogWithTemplates.class);
    JobCatalogWithTemplates catalog = new PackagedTemplatesJobCatalogDecorator(underlying);
    JobTemplate classTemplate = catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.CLASS + "://" + TestTemplate.class.getName()));
    Assert.assertEquals(classTemplate.getClass(), TestTemplate.class);
    try {
        catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.CLASS + "://" + "non.existing.class"));
        Assert.fail();
    } catch (SpecNotFoundException exc) {
    // expect exception
    }
    JobTemplate resourceTemplate = catalog.getTemplate(new URI(PackagedTemplatesJobCatalogDecorator.RESOURCE + ":///templates/test.template"));
    Assert.assertEquals(resourceTemplate.getClass(), ResourceBasedJobTemplate.class);
    Assert.assertEquals(resourceTemplate.getRequiredConfigList().size(), 3);
    URI uri = new URI("scheme:///templates/test.template");
    try {
        catalog.getTemplate(uri);
        Assert.fail();
    } catch (SpecNotFoundException exc) {
    // expect exception
    }
    Mockito.verify(underlying).getTemplate(uri);
}
Also used : JobCatalogWithTemplates(org.apache.gobblin.runtime.api.JobCatalogWithTemplates) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) JobTemplate(org.apache.gobblin.runtime.api.JobTemplate) ResourceBasedJobTemplate(org.apache.gobblin.runtime.template.ResourceBasedJobTemplate) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 4 with JobCatalogWithTemplates

use of org.apache.gobblin.runtime.api.JobCatalogWithTemplates in project incubator-gobblin by apache.

the class ResolvedJobSpec method resolveConfig.

private static Config resolveConfig(JobSpec jobSpec, JobCatalog catalog) throws SpecNotFoundException, JobTemplate.TemplateException {
    Optional<URI> templateURIOpt = jobSpec.getTemplateURI();
    if (templateURIOpt.isPresent()) {
        JobCatalogWithTemplates catalogWithTemplates = new PackagedTemplatesJobCatalogDecorator(catalog);
        JobTemplate template = catalogWithTemplates.getTemplate(templateURIOpt.get());
        return template.getResolvedConfig(jobSpec.getConfig()).resolve();
    } else {
        return jobSpec.getConfig().resolve();
    }
}
Also used : JobCatalogWithTemplates(org.apache.gobblin.runtime.api.JobCatalogWithTemplates) PackagedTemplatesJobCatalogDecorator(org.apache.gobblin.runtime.job_catalog.PackagedTemplatesJobCatalogDecorator) JobTemplate(org.apache.gobblin.runtime.api.JobTemplate) URI(java.net.URI)

Aggregations

URI (java.net.URI)4 JobCatalogWithTemplates (org.apache.gobblin.runtime.api.JobCatalogWithTemplates)4 Test (org.testng.annotations.Test)3 Config (com.typesafe.config.Config)2 JobTemplate (org.apache.gobblin.runtime.api.JobTemplate)2 SpecNotFoundException (org.apache.gobblin.runtime.api.SpecNotFoundException)1 PackagedTemplatesJobCatalogDecorator (org.apache.gobblin.runtime.job_catalog.PackagedTemplatesJobCatalogDecorator)1 ResourceBasedJobTemplate (org.apache.gobblin.runtime.template.ResourceBasedJobTemplate)1