Search in sources :

Example 26 with ApplicationClass

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

the class LocalApplicationManagerTest method testValidConfigPipeline.

@Test
public void testValidConfigPipeline() throws Exception {
    Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class);
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myTable");
    ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER);
    ApplicationClass applicationClass = new ApplicationClass(ConfigTestApp.class.getName(), "", null);
    AppDeploymentInfo info = new AppDeploymentInfo(Artifacts.toProtoArtifactId(NamespaceId.DEFAULT, artifactId), deployedJar, NamespaceId.DEFAULT, applicationClass, "MyApp", null, GSON.toJson(config));
    AppFabricTestHelper.getLocalManager().deploy(info).get();
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) ConfigTestApp(io.cdap.cdap.ConfigTestApp) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 27 with ApplicationClass

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

the class RemoteConfiguratorTest method testBadAppConfig.

@Test(expected = ExecutionException.class)
public void testBadAppConfig() throws Exception {
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, ConfigTestApp.class);
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(ConfigTestApp.class.getSimpleName(), "1.0.0");
    artifacts.put(artifactId, new ArtifactDetail(new ArtifactDescriptor(artifactId.getNamespace(), artifactId.toApiArtifactId(), appJar), new ArtifactMeta(ArtifactClasses.builder().build())));
    AppDeploymentInfo info = new AppDeploymentInfo(artifactId, appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), "BadApp", null, GSON.toJson("invalid"));
    Configurator configurator = new RemoteConfigurator(cConf, metricsCollectionService, info, remoteClientFactory);
    // Expect the future.get would throw an exception
    configurator.config().get(10, TimeUnit.SECONDS);
}
Also used : ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) Configurator(io.cdap.cdap.app.deploy.Configurator) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ConfigTestApp(io.cdap.cdap.ConfigTestApp) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Test(org.junit.Test)

Example 28 with ApplicationClass

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

the class SystemMetadataWriterStageTest method testCapabilityTags.

@Test
public void testCapabilityTags() throws Exception {
    String appName = CapabilityAppWithWorkflow.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    String[] capabilityTestNames = { "cdc", "healthcare" };
    Requirements requirements = new Requirements(Collections.emptySet(), Stream.of(capabilityTestNames).collect(Collectors.toSet()));
    ApplicationClass applicationClass = new ApplicationClass(CapabilityAppWithWorkflow.class.getName(), appName, null, requirements);
    String workflowName = CapabilityAppWithWorkflow.SampleWorkflow.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, new CapabilityAppWithWorkflow(), applicationClass);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
    // Test that all test capabilities are present in the metadata
    Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
    Set<String> capabilityNames = Arrays.stream(metadataProperties.get(AppSystemMetadataWriter.CAPABILITY_TAG).split(AppSystemMetadataWriter.CAPABILITY_DELIMITER)).collect(Collectors.toSet());
    Assert.assertEquals(Arrays.stream(capabilityTestNames).collect(Collectors.toSet()), capabilityNames);
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Requirements(io.cdap.cdap.api.plugin.Requirements) Read(io.cdap.cdap.spi.metadata.Read) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) Test(org.junit.Test)

Example 29 with ApplicationClass

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

the class SystemMetadataWriterStageTest method testWorkflowTags.

@Test
public void testWorkflowTags() throws Exception {
    String appName = WorkflowAppWithFork.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    ApplicationClass applicationClass = new ApplicationClass(WorkflowAppWithFork.class.getName(), appName, null);
    String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName, applicationClass);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    MetadataWriterStage systemMetadataWriterStage = new MetadataWriterStage(metadataServiceClient);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.TAG)).isEmpty());
    Set<String> workflowSystemTags = metadataStorage.read(new Read(appId.workflow(workflowName).toMetadataEntity())).getTags(MetadataScope.SYSTEM);
    Sets.SetView<String> intersection = Sets.intersection(workflowSystemTags, getWorkflowForkNodes(workflowSpec));
    Assert.assertTrue("Workflows should not be tagged with fork node names, but found the following fork nodes " + "in the workflow's system tags: " + intersection, intersection.isEmpty());
    Assert.assertEquals(false, metadataStorage.read(new Read(appId.toMetadataEntity(), MetadataScope.SYSTEM, MetadataKind.PROPERTY)).isEmpty());
    Map<String, String> metadataProperties = metadataStorage.read(new Read(appId.toMetadataEntity())).getProperties(MetadataScope.SYSTEM);
    Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME));
}
Also used : WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) StageContext(io.cdap.cdap.internal.pipeline.StageContext) Read(io.cdap.cdap.spi.metadata.Read) Sets(com.google.common.collect.Sets) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 30 with ApplicationClass

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

the class AppFabricTestHelper method deployApplicationWithManager.

public static ApplicationWithPrograms deployApplicationWithManager(Id.Namespace namespace, Class<?> appClass, Supplier<File> folderSupplier, Config config) throws Exception {
    NamespaceId namespaceId = namespace.toEntityId();
    ensureNamespaceExists(namespaceId);
    Location deployedJar = createAppJar(appClass, folderSupplier);
    ArtifactVersion artifactVersion = new ArtifactVersion(String.format("1.0.%d", System.currentTimeMillis()));
    ArtifactId artifactId = new ArtifactId(appClass.getSimpleName(), artifactVersion, ArtifactScope.USER);
    ArtifactRepository artifactRepository = getInjector().getInstance(ArtifactRepository.class);
    artifactRepository.addArtifact(Id.Artifact.fromEntityId(Artifacts.toProtoArtifactId(namespaceId, artifactId)), new File(deployedJar.toURI()));
    ApplicationClass applicationClass = new ApplicationClass(appClass.getName(), "", null);
    AppDeploymentInfo info = new AppDeploymentInfo(Artifacts.toProtoArtifactId(namespaceId, artifactId), deployedJar, namespaceId, applicationClass, null, null, config == null ? null : new Gson().toJson(config));
    return getLocalManager().deploy(info).get();
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) Gson(com.google.gson.Gson) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) File(java.io.File) Location(org.apache.twill.filesystem.Location)

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