Search in sources :

Example 1 with StageContext

use of co.cask.cdap.internal.pipeline.StageContext in project cdap by caskdata.

the class ProgramGenerationStageTest method testProgramGenerationForToyApp.

@Test
public void testProgramGenerationForToyApp() throws Exception {
    cConf.set(Constants.AppFabric.OUTPUT_DIR, "programs");
    LocationFactory lf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    // have to do this since we are not going through the route of create namespace -> deploy application
    // in real scenarios, the namespace directory would already be created
    Location namespaceLocation = lf.create(DefaultId.APPLICATION.getNamespace());
    Locations.mkdirsIfNotExists(namespaceLocation);
    LocationFactory jarLf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    Location appArchive = AppJarHelper.createDeploymentJar(jarLf, ToyApp.class);
    ApplicationSpecification appSpec = Specifications.from(new ToyApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    ProgramGenerationStage pgmStage = new ProgramGenerationStage(new NoOpAuthorizer(), new AuthenticationTestContext());
    // Can do better here - fixed right now to run the test.
    pgmStage.process(new StageContext(Object.class));
    pgmStage.process(new ApplicationDeployable(NamespaceId.DEFAULT.artifact("ToyApp", "1.0"), appArchive, DefaultId.APPLICATION, newSpec, null, ApplicationDeployScope.USER));
    Assert.assertTrue(true);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ToyApp(co.cask.cdap.ToyApp) AuthenticationTestContext(co.cask.cdap.security.auth.context.AuthenticationTestContext) NoOpAuthorizer(co.cask.cdap.security.spi.authorization.NoOpAuthorizer) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) StageContext(co.cask.cdap.internal.pipeline.StageContext) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 2 with StageContext

use of co.cask.cdap.internal.pipeline.StageContext in project cdap by caskdata.

the class SystemMetadataWriterStageTest method testWorkflowTags.

@Test
public void testWorkflowTags() throws Exception {
    String appName = WorkflowAppWithFork.class.getSimpleName();
    ApplicationId appId = NamespaceId.DEFAULT.app(appName);
    String workflowName = WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName();
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(appId.getApplication(), "1.0");
    ApplicationWithPrograms appWithPrograms = createAppWithWorkflow(artifactId, appId, workflowName);
    WorkflowSpecification workflowSpec = appWithPrograms.getSpecification().getWorkflows().get(workflowName);
    SystemMetadataWriterStage systemMetadataWriterStage = new SystemMetadataWriterStage(metadataStore);
    StageContext stageContext = new StageContext(Object.class);
    systemMetadataWriterStage.process(stageContext);
    systemMetadataWriterStage.process(appWithPrograms);
    // verify that the workflow is not tagged with the fork node name
    Set<String> workflowSystemTags = metadataStore.getTags(MetadataScope.SYSTEM, appId.workflow(workflowName));
    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());
    // verify that metadata was added for the workflow's schedule
    Map<String, String> metadataProperties = metadataStore.getMetadata(MetadataScope.SYSTEM, appId).getProperties();
    Assert.assertEquals(WorkflowAppWithFork.SCHED_NAME + ":testDescription", metadataProperties.get("schedule:" + WorkflowAppWithFork.SCHED_NAME));
}
Also used : WorkflowAppWithFork(co.cask.cdap.WorkflowAppWithFork) ArtifactId(co.cask.cdap.proto.id.ArtifactId) Sets(com.google.common.collect.Sets) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ApplicationId(co.cask.cdap.proto.id.ApplicationId) StageContext(co.cask.cdap.internal.pipeline.StageContext) Test(org.junit.Test)

Aggregations

StageContext (co.cask.cdap.internal.pipeline.StageContext)2 Test (org.junit.Test)2 ToyApp (co.cask.cdap.ToyApp)1 WorkflowAppWithFork (co.cask.cdap.WorkflowAppWithFork)1 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)1 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 ArtifactId (co.cask.cdap.proto.id.ArtifactId)1 AuthenticationTestContext (co.cask.cdap.security.auth.context.AuthenticationTestContext)1 NoOpAuthorizer (co.cask.cdap.security.spi.authorization.NoOpAuthorizer)1 Sets (com.google.common.collect.Sets)1 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)1 Location (org.apache.twill.filesystem.Location)1 LocationFactory (org.apache.twill.filesystem.LocationFactory)1