Search in sources :

Example 6 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class ConfiguratorTest method testAppWithConfig.

@Test
public void testAppWithConfig() throws Exception {
    LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, ConfigTestApp.class);
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, ConfigTestApp.class.getSimpleName(), "1.0.0");
    CConfiguration cConf = CConfiguration.create();
    ArtifactRepository artifactRepo = new ArtifactRepository(conf, null, null, authorizer, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null), authEnforcer, authenticationContext);
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myStream", "myTable");
    // Create a configurator that is testable. Provide it an application.
    try (CloseableClassLoader artifactClassLoader = artifactRepo.createArtifactClassLoader(appJar, new EntityImpersonator(artifactId.getNamespace().toEntityId(), new DefaultImpersonator(cConf, null)))) {
        Configurator configuratorWithConfig = new InMemoryConfigurator(conf, Id.Namespace.DEFAULT, artifactId, ConfigTestApp.class.getName(), artifactRepo, artifactClassLoader, null, null, new Gson().toJson(config));
        ListenableFuture<ConfigResponse> result = configuratorWithConfig.config();
        ConfigResponse response = result.get(10, TimeUnit.SECONDS);
        Assert.assertNotNull(response);
        ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
        ApplicationSpecification specification = adapter.fromJson(response.get());
        Assert.assertNotNull(specification);
        Assert.assertTrue(specification.getStreams().size() == 1);
        Assert.assertTrue(specification.getStreams().containsKey("myStream"));
        Assert.assertTrue(specification.getDatasets().size() == 1);
        Assert.assertTrue(specification.getDatasets().containsKey("myTable"));
        Configurator configuratorWithoutConfig = new InMemoryConfigurator(conf, Id.Namespace.DEFAULT, artifactId, ConfigTestApp.class.getName(), artifactRepo, artifactClassLoader, null, null, null);
        result = configuratorWithoutConfig.config();
        response = result.get(10, TimeUnit.SECONDS);
        Assert.assertNotNull(response);
        specification = adapter.fromJson(response.get());
        Assert.assertNotNull(specification);
        Assert.assertTrue(specification.getStreams().size() == 1);
        Assert.assertTrue(specification.getStreams().containsKey(ConfigTestApp.DEFAULT_STREAM));
        Assert.assertTrue(specification.getDatasets().size() == 1);
        Assert.assertTrue(specification.getDatasets().containsKey(ConfigTestApp.DEFAULT_TABLE));
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) DummyProgramRunnerFactory(co.cask.cdap.app.runtime.DummyProgramRunnerFactory) Configurator(co.cask.cdap.app.deploy.Configurator) EntityImpersonator(co.cask.cdap.security.impersonation.EntityImpersonator) Gson(com.google.gson.Gson) ArtifactRepository(co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository) ConfigResponse(co.cask.cdap.app.deploy.ConfigResponse) CloseableClassLoader(co.cask.cdap.api.artifact.CloseableClassLoader) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) CConfiguration(co.cask.cdap.common.conf.CConfiguration) DefaultImpersonator(co.cask.cdap.security.impersonation.DefaultImpersonator) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) Id(co.cask.cdap.proto.Id) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ConfigTestApp(co.cask.cdap.ConfigTestApp) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 7 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter 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());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) QueueSpecificationGenerator(co.cask.cdap.app.queue.QueueSpecificationGenerator) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) WordCountApp(co.cask.cdap.WordCountApp) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) Test(org.junit.Test)

Example 8 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter 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())));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) QueueSpecificationGenerator(co.cask.cdap.app.queue.QueueSpecificationGenerator) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ToyApp(co.cask.cdap.ToyApp) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) Test(org.junit.Test)

Example 9 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class FlowVerificationTest method testValidFlow.

@Test
public void testValidFlow() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowSpec = new FlowVerification();
    for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
        VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) Test(org.junit.Test)

Example 10 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class WorkflowVerificationTest method testGoodWorkflow.

@Test
public void testGoodWorkflow() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new GoodWorkflowApp());
    verifyGoodWorkflowSpecifications(appSpec);
    verifyAnotherGoodWorkflowSpecification(appSpec);
    verifyWorkflowWithLocalDatasetSpecification(appSpec);
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    verifyGoodWorkflowSpecifications(newSpec);
    verifyAnotherGoodWorkflowSpecification(newSpec);
    verifyWorkflowWithLocalDatasetSpecification(newSpec);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) GoodWorkflowApp(co.cask.cdap.GoodWorkflowApp) Test(org.junit.Test)

Aggregations

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)10 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)10 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)10 Test (org.junit.Test)10 VerifyResult (co.cask.cdap.app.verification.VerifyResult)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 WebCrawlApp (co.cask.cdap.WebCrawlApp)3 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)3 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)3 Location (org.apache.twill.filesystem.Location)3 LocationFactory (org.apache.twill.filesystem.LocationFactory)3 ToyApp (co.cask.cdap.ToyApp)2 WordCountApp (co.cask.cdap.WordCountApp)2 CloseableClassLoader (co.cask.cdap.api.artifact.CloseableClassLoader)2 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)2 Configurator (co.cask.cdap.app.deploy.Configurator)2 QueueSpecificationGenerator (co.cask.cdap.app.queue.QueueSpecificationGenerator)2 DummyProgramRunnerFactory (co.cask.cdap.app.runtime.DummyProgramRunnerFactory)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)2