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");
}
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");
}
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);
}
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();
}
}
Aggregations