use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ConfiguratorTest method testInMemoryConfigurator.
@Test
public void testInMemoryConfigurator() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, WordCountApp.class);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, WordCountApp.class.getSimpleName(), "1.0.0");
CConfiguration cConf = CConfiguration.create();
ArtifactRepository baseArtifactRepo = new DefaultArtifactRepository(conf, null, null, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null));
ArtifactRepository artifactRepo = new AuthorizationArtifactRepository(baseArtifactRepo, authEnforcer, authenticationContext);
// Create a configurator that is testable. Provide it a application.
try (CloseableClassLoader artifactClassLoader = artifactRepo.createArtifactClassLoader(appJar, new EntityImpersonator(artifactId.getNamespace().toEntityId(), new DefaultImpersonator(cConf, null)))) {
Configurator configurator = new InMemoryConfigurator(conf, Id.Namespace.DEFAULT, artifactId, WordCountApp.class.getName(), artifactRepo, artifactClassLoader, null, null, "");
// Extract response from the configurator.
ListenableFuture<ConfigResponse> result = configurator.config();
ConfigResponse response = result.get(10, TimeUnit.SECONDS);
Assert.assertNotNull(response);
// Deserialize the JSON spec back into Application object.
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification specification = adapter.fromJson(response.get());
Assert.assertNotNull(specification);
// Simple checks.
Assert.assertTrue(specification.getName().equals("WordCountApp"));
// # of flows.
Assert.assertTrue(specification.getFlows().size() == 1);
}
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class SimpleQueueSpecificationGeneratorTest method testQueueSpecificationGenWithToyApp.
@Test
public void testQueueSpecificationGenWithToyApp() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new ToyApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
QueueSpecificationGenerator generator = new SimpleQueueSpecificationGenerator(NamespaceId.DEFAULT.app(newSpec.getName()));
table = generator.create(newSpec.getFlows().values().iterator().next());
dumpConnectionQueue(table);
// Stream X
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.STREAM, "X", "A"), String.format("stream:///%s/X", TEST_NAMESPACE_ID)));
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.STREAM, "Y", "B"), String.format("stream:///%s/Y", TEST_NAMESPACE_ID)));
// Node A
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "A", "E"), String.format("queue:///%s/ToyApp/ToyFlow/A/out1", Id.Namespace.DEFAULT.getId())));
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "A", "C"), String.format("queue:///%s/ToyApp/ToyFlow/A/queue", Id.Namespace.DEFAULT.getId())));
// Node B
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "B", "E"), String.format("queue:///%s/ToyApp/ToyFlow/B/queue", Id.Namespace.DEFAULT.getId())));
// Node C
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "C", "D"), String.format("queue:///%s/ToyApp/ToyFlow/C/c1", Id.Namespace.DEFAULT.getId())));
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "C", "F"), String.format("queue:///%s/ToyApp/ToyFlow/C/c2", Id.Namespace.DEFAULT.getId())));
// Node D
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "D", "G"), String.format("queue:///%s/ToyApp/ToyFlow/D/d1", Id.Namespace.DEFAULT.getId())));
// Node E
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "E", "G"), String.format("queue:///%s/ToyApp/ToyFlow/E/queue", Id.Namespace.DEFAULT.getId())));
// Node F
Assert.assertTrue(containsQueue(get(FlowletConnection.Type.FLOWLET, "F", "G"), String.format("queue:///%s/ToyApp/ToyFlow/F/f1", Id.Namespace.DEFAULT.getId())));
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class SimpleQueueSpecificationGeneratorTest method testQueueSpecificationGenWithWordCount.
@Test
public void testQueueSpecificationGenWithWordCount() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WordCountApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
QueueSpecificationGenerator generator = new SimpleQueueSpecificationGenerator(NamespaceId.DEFAULT.app(newSpec.getName()));
table = generator.create(newSpec.getFlows().values().iterator().next());
Assert.assertEquals(get(FlowletConnection.Type.STREAM, "text", "StreamSource").iterator().next().getQueueName().toString(), String.format("stream:///%s/text", TEST_NAMESPACE_ID));
Assert.assertEquals(get(FlowletConnection.Type.FLOWLET, "StreamSource", "Tokenizer").iterator().next().getQueueName().toString(), String.format("queue:///%s/WordCountApp/WordCountFlow/StreamSource/queue", Id.Namespace.DEFAULT.getId()));
Assert.assertEquals(1, get(FlowletConnection.Type.FLOWLET, "Tokenizer", "CountByField").size());
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ArtifactStoreTest method testGetAppClasses.
@Test
public void testGetAppClasses() throws Exception {
// create 2 versions of the same artifact with the same app class
Id.Artifact app1v1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "appA", "1.0.0");
ApplicationClass inspectionClass1 = new ApplicationClass(InspectionApp.class.getName(), "v1", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(inspectionClass1).build());
writeArtifact(app1v1Id, artifactMeta, "my artifact contents");
ArtifactDetail app1v1Detail = artifactStore.getArtifact(app1v1Id);
Id.Artifact app1v2Id = Id.Artifact.from(Id.Namespace.DEFAULT, "appA", "2.0.0");
ApplicationClass inspectionClass2 = new ApplicationClass(InspectionApp.class.getName(), "v2", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(inspectionClass2).build());
writeArtifact(app1v2Id, artifactMeta, "my artifact contents");
ArtifactDetail app1v2Detail = artifactStore.getArtifact(app1v2Id);
// create a different artifact with the same app class
Id.Artifact app2v1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "appB", "1.0.0");
artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(inspectionClass1).build());
writeArtifact(app2v1Id, artifactMeta, "other contents");
ArtifactDetail app2v1Detail = artifactStore.getArtifact(app2v1Id);
// create another artifact with a different app class
Id.Artifact app3v1Id = Id.Artifact.from(Id.Namespace.DEFAULT, "appC", "1.0.0");
ApplicationClass wordCountClass1 = new ApplicationClass(WordCountApp.class.getName(), "v1", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(wordCountClass1).build());
writeArtifact(app3v1Id, artifactMeta, "wc contents");
ArtifactDetail app3v1Detail = artifactStore.getArtifact(app3v1Id);
// test getting all app classes in the namespace
Map<ArtifactDescriptor, List<ApplicationClass>> appClasses = artifactStore.getApplicationClasses(NamespaceId.DEFAULT);
Map<ArtifactDescriptor, List<ApplicationClass>> expected = ImmutableMap.<ArtifactDescriptor, List<ApplicationClass>>of(app1v1Detail.getDescriptor(), ImmutableList.of(inspectionClass1), app1v2Detail.getDescriptor(), ImmutableList.of(inspectionClass2), app2v1Detail.getDescriptor(), ImmutableList.of(inspectionClass1), app3v1Detail.getDescriptor(), ImmutableList.of(wordCountClass1));
Assert.assertEquals(expected, appClasses);
// test getting all app classes by class name
Map<ArtifactDescriptor, ApplicationClass> appArtifacts = artifactStore.getApplicationClasses(NamespaceId.DEFAULT, InspectionApp.class.getName());
Map<ArtifactDescriptor, ApplicationClass> expectedAppArtifacts = ImmutableMap.of(app1v1Detail.getDescriptor(), inspectionClass1, app1v2Detail.getDescriptor(), inspectionClass2, app2v1Detail.getDescriptor(), inspectionClass1);
Assert.assertEquals(expectedAppArtifacts, appArtifacts);
appArtifacts = artifactStore.getApplicationClasses(NamespaceId.DEFAULT, WordCountApp.class.getName());
expectedAppArtifacts = ImmutableMap.of(app3v1Detail.getDescriptor(), wordCountClass1);
Assert.assertEquals(expectedAppArtifacts, appArtifacts);
Assert.assertTrue(artifactStore.getApplicationClasses(Ids.namespace("ghost")).isEmpty());
}
use of co.cask.cdap.internal.io.ReflectionSchemaGenerator in project cdap by caskdata.
the class ArtifactStoreTest method testAddGetSingleArtifact.
@Test
public void testAddGetSingleArtifact() throws Exception {
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "myplugins", "1.0.0");
PluginClass plugin1 = new PluginClass("atype", "plugin1", "", "c.c.c.plugin1", "cfg", ImmutableMap.<String, PluginPropertyField>of());
PluginClass plugin2 = new PluginClass("atype", "plugin2", "", "c.c.c.plugin2", "cfg", ImmutableMap.<String, PluginPropertyField>of());
PluginClass plugin3 = new PluginClass("btype", "plugin3", "", "c.c.c.plugin3", "cfg", ImmutableMap.<String, PluginPropertyField>of());
Set<PluginClass> plugins = ImmutableSet.of(plugin1, plugin2, plugin3);
ApplicationClass appClass = new ApplicationClass(InspectionApp.class.getName(), "", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(plugins).addApp(appClass).build());
String artifactContents = "my artifact contents";
writeArtifact(artifactId, artifactMeta, artifactContents);
ArtifactDetail artifactDetail = artifactStore.getArtifact(artifactId);
assertEqual(artifactId, artifactMeta, artifactContents, artifactDetail);
// test that plugins in the artifact show up when getting plugins for that artifact
Map<ArtifactDescriptor, Set<PluginClass>> pluginsMap = artifactStore.getPluginClasses(NamespaceId.DEFAULT, artifactId);
Assert.assertEquals(1, pluginsMap.size());
Assert.assertTrue(pluginsMap.containsKey(artifactDetail.getDescriptor()));
Set<PluginClass> expected = ImmutableSet.copyOf(plugins);
Set<PluginClass> actual = ImmutableSet.copyOf(pluginsMap.get(artifactDetail.getDescriptor()));
Assert.assertEquals(expected, actual);
// test plugins for the specific type
pluginsMap = artifactStore.getPluginClasses(NamespaceId.DEFAULT, artifactId, "atype");
Assert.assertEquals(1, pluginsMap.size());
Assert.assertTrue(pluginsMap.containsKey(artifactDetail.getDescriptor()));
expected = ImmutableSet.of(plugin1, plugin2);
actual = ImmutableSet.copyOf(pluginsMap.get(artifactDetail.getDescriptor()));
Assert.assertEquals(expected, actual);
// test plugins for specific type and name
Map<ArtifactDescriptor, PluginClass> pluginClasses = artifactStore.getPluginClasses(NamespaceId.DEFAULT.getNamespaceId(), artifactId, "btype", "plugin3", null, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, pluginClasses.size());
Assert.assertTrue(pluginClasses.containsKey(artifactDetail.getDescriptor()));
Assert.assertEquals(plugin3, pluginClasses.get(artifactDetail.getDescriptor()));
}
Aggregations