Search in sources :

Example 26 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory 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 artifactRepo = new ArtifactRepository(conf, null, null, authorizer, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null), 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);
    }
}
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) 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) WordCountApp(co.cask.cdap.WordCountApp) Id(co.cask.cdap.proto.Id) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 27 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory 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 28 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class ArtifactInspectorTest method createJar.

private static File createJar(Class<?> cls, File destFile, Manifest manifest) throws IOException {
    Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), cls, manifest);
    DirUtils.mkdirs(destFile.getParentFile());
    Files.copy(Locations.newInputSupplier(deploymentJar), destFile);
    return destFile;
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location)

Example 29 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class SystemMetadataWriterStageTest method createAppWithWorkflow.

@SuppressWarnings("unchecked")
private ApplicationWithPrograms createAppWithWorkflow(ArtifactId artifactId, ApplicationId appId, String workflowName) throws IOException {
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    AbstractApplication app = new WorkflowAppWithFork();
    ApplicationSpecification appSpec = Specifications.from(app);
    Location workflowJar = AppJarHelper.createDeploymentJar(locationFactory, WorkflowAppWithFork.class);
    ApplicationDeployable appDeployable = new ApplicationDeployable(artifactId, workflowJar, appId, appSpec, null, ApplicationDeployScope.USER);
    return new ApplicationWithPrograms(appDeployable, ImmutableList.of(new ProgramDescriptor(appId.workflow(workflowName), appSpec)));
}
Also used : WorkflowAppWithFork(co.cask.cdap.WorkflowAppWithFork) ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) AbstractApplication(co.cask.cdap.api.app.AbstractApplication) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location)

Example 30 with LocalLocationFactory

use of org.apache.twill.filesystem.LocalLocationFactory in project cdap by caskdata.

the class JarResourcesTest method testGetResource.

@Test
public void testGetResource() throws IOException {
    File jarFile = createJar(tmpFolder.newFile());
    Location jarLocation = new LocalLocationFactory(jarFile.getParentFile()).create(jarFile.toURI());
    String classPath = JarResourcesTest.class.getName().replace('.', '/') + ".class";
    JarResources jarResources = new JarResources(jarLocation);
    Assert.assertFalse(jarResources.contains("test"));
    Assert.assertTrue(jarResources.contains("logback-test.xml"));
    Assert.assertTrue(jarResources.contains(classPath));
    Assert.assertArrayEquals(ByteStreams.toByteArray(getClass().getClassLoader().getResourceAsStream("logback-test.xml")), jarResources.getResource("logback-test.xml"));
    Assert.assertArrayEquals(ByteStreams.toByteArray(getClass().getClassLoader().getResourceAsStream(classPath)), jarResources.getResource(classPath));
    Assert.assertArrayEquals(ByteStreams.toByteArray(getClass().getClassLoader().getResourceAsStream("logback-test.xml")), ByteStreams.toByteArray(jarResources.getResourceAsStream("logback-test.xml")));
    Assert.assertArrayEquals(ByteStreams.toByteArray(getClass().getClassLoader().getResourceAsStream(classPath)), ByteStreams.toByteArray(jarResources.getResourceAsStream(classPath)));
}
Also used : File(java.io.File) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)41 Location (org.apache.twill.filesystem.Location)29 LocationFactory (org.apache.twill.filesystem.LocationFactory)21 File (java.io.File)15 CConfiguration (co.cask.cdap.common.conf.CConfiguration)11 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)11 NamespacedLocationFactory (co.cask.cdap.common.namespace.NamespacedLocationFactory)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)4 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)4 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)4 Injector (com.google.inject.Injector)4 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 URL (java.net.URL)3 CloseableClassLoader (co.cask.cdap.api.artifact.CloseableClassLoader)2 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)2 Configurator (co.cask.cdap.app.deploy.Configurator)2 DummyProgramRunnerFactory (co.cask.cdap.app.runtime.DummyProgramRunnerFactory)2 StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)2