Search in sources :

Example 21 with ApplicationClass

use of io.cdap.cdap.api.artifact.ApplicationClass in project cdap by caskdata.

the class ApplicationClassCodecTest method testCodec.

@Test
public void testCodec() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).registerTypeAdapter(ApplicationClass.class, new ApplicationClassCodec()).create();
    String testApp1 = getData("ApplicationClass_6_2.json");
    ApplicationClass applicationClass62 = gson.fromJson(testApp1, ApplicationClass.class);
    Assert.assertEquals(Requirements.EMPTY, applicationClass62.getRequirements());
    Assert.assertEquals("io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp", applicationClass62.getClassName());
    Assert.assertEquals("", applicationClass62.getDescription());
    Assert.assertNotNull(applicationClass62.getConfigSchema());
    Assert.assertEquals(applicationClass62, gson.fromJson(gson.toJson(applicationClass62), ApplicationClass.class));
    String testApp2 = getData("ApplicationClass_6_3.json");
    ApplicationClass applicationClass63 = gson.fromJson(testApp2, ApplicationClass.class);
    Requirements requirements = applicationClass63.getRequirements();
    Assert.assertEquals(Collections.singleton("cdc"), requirements.getCapabilities());
    Assert.assertEquals(applicationClass63, gson.fromJson(gson.toJson(applicationClass63), ApplicationClass.class));
}
Also used : SchemaTypeAdapter(io.cdap.cdap.internal.io.SchemaTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Example 22 with ApplicationClass

use of io.cdap.cdap.api.artifact.ApplicationClass in project cdap by cdapio.

the class ApplicationClassCodecTest method testCodec.

@Test
public void testCodec() throws IOException {
    Gson gson = new GsonBuilder().registerTypeAdapter(Schema.class, new SchemaTypeAdapter()).registerTypeAdapter(ApplicationClass.class, new ApplicationClassCodec()).create();
    String testApp1 = getData("ApplicationClass_6_2.json");
    ApplicationClass applicationClass62 = gson.fromJson(testApp1, ApplicationClass.class);
    Assert.assertEquals(Requirements.EMPTY, applicationClass62.getRequirements());
    Assert.assertEquals("io.cdap.cdap.internal.app.runtime.artifact.app.inspection.InspectionApp", applicationClass62.getClassName());
    Assert.assertEquals("", applicationClass62.getDescription());
    Assert.assertNotNull(applicationClass62.getConfigSchema());
    Assert.assertEquals(applicationClass62, gson.fromJson(gson.toJson(applicationClass62), ApplicationClass.class));
    String testApp2 = getData("ApplicationClass_6_3.json");
    ApplicationClass applicationClass63 = gson.fromJson(testApp2, ApplicationClass.class);
    Requirements requirements = applicationClass63.getRequirements();
    Assert.assertEquals(Collections.singleton("cdc"), requirements.getCapabilities());
    Assert.assertEquals(applicationClass63, gson.fromJson(gson.toJson(applicationClass63), ApplicationClass.class));
}
Also used : SchemaTypeAdapter(io.cdap.cdap.internal.io.SchemaTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) Requirements(io.cdap.cdap.api.plugin.Requirements) Test(org.junit.Test)

Example 23 with ApplicationClass

use of io.cdap.cdap.api.artifact.ApplicationClass in project cdap by cdapio.

the class ConfiguratorTest method testInMemoryConfigurator.

@Test
public void testInMemoryConfigurator() throws Exception {
    LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, AllProgramsApp.class.getSimpleName(), "1.0.0");
    CConfiguration cConf = CConfiguration.create();
    ArtifactRepository baseArtifactRepo = new DefaultArtifactRepository(conf, null, null, null, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null));
    ArtifactRepository artifactRepo = new AuthorizationArtifactRepository(baseArtifactRepo, authEnforcer, authenticationContext);
    PluginFinder pluginFinder = new LocalPluginFinder(artifactRepo);
    AppDeploymentInfo appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(AllProgramsApp.class.getName(), "", null), null, null, null);
    // Create a configurator that is testable. Provide it a application.
    Configurator configurator = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
    // Extract response from the configurator.
    ListenableFuture<ConfigResponse> result = configurator.config();
    ConfigResponse response = result.get(10, TimeUnit.SECONDS);
    Assert.assertNotNull(response);
    AppSpecInfo appSpecInfo = response.getAppSpecInfo();
    if (appSpecInfo == null) {
        throw new IllegalStateException("Failed to deploy application");
    }
    ApplicationSpecification specification = appSpecInfo.getAppSpec();
    Assert.assertNotNull(specification);
    // Simple checks.
    Assert.assertEquals(AllProgramsApp.NAME, specification.getName());
    ApplicationSpecification expectedSpec = Specifications.from(new AllProgramsApp());
    for (ProgramType programType : ProgramType.values()) {
        Assert.assertEquals(expectedSpec.getProgramsByType(programType), specification.getProgramsByType(programType));
    }
    Assert.assertEquals(expectedSpec.getDatasets(), specification.getDatasets());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AuthorizationArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository) DummyProgramRunnerFactory(io.cdap.cdap.app.runtime.DummyProgramRunnerFactory) LocalPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.LocalPluginFinder) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) Configurator(io.cdap.cdap.app.deploy.Configurator) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AllProgramsApp(io.cdap.cdap.AllProgramsApp) AuthorizationArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) DefaultImpersonator(io.cdap.cdap.security.impersonation.DefaultImpersonator) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) PluginFinder(io.cdap.cdap.internal.app.runtime.artifact.PluginFinder) LocalPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.LocalPluginFinder) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ProgramType(io.cdap.cdap.api.app.ProgramType) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 24 with ApplicationClass

use of io.cdap.cdap.api.artifact.ApplicationClass in project cdap by cdapio.

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 baseArtifactRepo = new DefaultArtifactRepository(conf, null, null, null, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null));
    ArtifactRepository artifactRepo = new AuthorizationArtifactRepository(baseArtifactRepo, authEnforcer, authenticationContext);
    PluginFinder pluginFinder = new LocalPluginFinder(artifactRepo);
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myTable");
    AppDeploymentInfo appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), null, null, new Gson().toJson(config));
    // Create a configurator that is testable. Provide it an application.
    Configurator configurator = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
    ListenableFuture<ConfigResponse> result = configurator.config();
    ConfigResponse response = result.get(10, TimeUnit.SECONDS);
    Assert.assertNotNull(response);
    AppSpecInfo appSpecInfo = response.getAppSpecInfo();
    if (appSpecInfo == null) {
        throw new IllegalStateException("Failed to deploy application");
    }
    ApplicationSpecification specification = appSpecInfo.getAppSpec();
    Assert.assertNotNull(specification);
    Assert.assertEquals(1, specification.getDatasets().size());
    Assert.assertTrue(specification.getDatasets().containsKey("myTable"));
    // Create a deployment info without the app configuration
    appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), null, null, null);
    Configurator configuratorWithoutConfig = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
    result = configuratorWithoutConfig.config();
    response = result.get(10, TimeUnit.SECONDS);
    Assert.assertNotNull(response);
    appSpecInfo = response.getAppSpecInfo();
    if (appSpecInfo == null) {
        throw new IllegalStateException("Failed to deploy application");
    }
    specification = appSpecInfo.getAppSpec();
    Assert.assertNotNull(specification);
    Assert.assertEquals(1, specification.getDatasets().size());
    Assert.assertTrue(specification.getDatasets().containsKey(ConfigTestApp.DEFAULT_TABLE));
    Assert.assertNotNull(specification.getProgramSchedules().get(ConfigTestApp.SCHEDULE_NAME));
    ProgramStatusTrigger trigger = (ProgramStatusTrigger) specification.getProgramSchedules().get(ConfigTestApp.SCHEDULE_NAME).getTrigger();
    Assert.assertEquals(trigger.getProgramId().getProgram(), ConfigTestApp.WORKFLOW_NAME);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) LocalPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.LocalPluginFinder) Configurator(io.cdap.cdap.app.deploy.Configurator) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) Gson(com.google.gson.Gson) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) PluginFinder(io.cdap.cdap.internal.app.runtime.artifact.PluginFinder) LocalPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.LocalPluginFinder) ProgramStatusTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.ProgramStatusTrigger) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ConfigTestApp(io.cdap.cdap.ConfigTestApp) AuthorizationArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository) DummyProgramRunnerFactory(io.cdap.cdap.app.runtime.DummyProgramRunnerFactory) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AuthorizationArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) DefaultImpersonator(io.cdap.cdap.security.impersonation.DefaultImpersonator) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 25 with ApplicationClass

use of io.cdap.cdap.api.artifact.ApplicationClass in project cdap by cdapio.

the class LocalApplicationManagerTest method testDeployCustomDatasetModule.

@Test
public void testDeployCustomDatasetModule() throws Exception {
    Location deployedJar = AppJarHelper.createDeploymentJar(lf, AppWithCustomDatasetModule.class);
    ArtifactId artifactId = new ArtifactId("customDSModule", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
    ApplicationClass applicationClass = new ApplicationClass(AppWithCustomDatasetModule.class.getName(), "", null);
    AppDeploymentInfo info = new AppDeploymentInfo(Artifacts.toProtoArtifactId(NamespaceId.DEFAULT, artifactId), deployedJar, NamespaceId.DEFAULT, applicationClass, "CustomDSApp", null, null);
    try {
        AppFabricTestHelper.getLocalManager().deploy(info).get();
        if (!allowCustomDatasetModule) {
            Assert.fail("Expected to throw IllegalArgumentException when custom dataset module is not supported");
        }
    } catch (ExecutionException e) {
        // There shouldn't be any exception if custom dataset module is allowed
        if (allowCustomDatasetModule) {
            throw e;
        }
        if (!(e.getCause() instanceof IllegalStateException)) {
            throw e;
        }
    }
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) AppWithCustomDatasetModule(io.cdap.cdap.AppWithCustomDatasetModule) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ExecutionException(java.util.concurrent.ExecutionException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)64 Test (org.junit.Test)40 Location (org.apache.twill.filesystem.Location)30 AppDeploymentInfo (io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo)28 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)20 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)16 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)16 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)16 PluginClass (io.cdap.cdap.api.plugin.PluginClass)14 Id (io.cdap.cdap.common.id.Id)14 LocationFactory (org.apache.twill.filesystem.LocationFactory)14 AllProgramsApp (io.cdap.cdap.AllProgramsApp)12 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)12 Configurator (io.cdap.cdap.app.deploy.Configurator)12 ConfigTestApp (io.cdap.cdap.ConfigTestApp)10 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)10 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)10 ReflectionSchemaGenerator (io.cdap.cdap.internal.io.ReflectionSchemaGenerator)10 Map (java.util.Map)10