Search in sources :

Example 1 with ProgramTerminator

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

the class ApplicationLifecycleServiceTest method testDeployArtifactAndApplicationCleansUpArtifactOnFailure.

// test that the call to deploy an artifact and application in a single step will delete the artifact
// if the application could not be created
@Test(expected = ArtifactNotFoundException.class)
public void testDeployArtifactAndApplicationCleansUpArtifactOnFailure() throws Exception {
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "missing-mr", "1.0.0-SNAPSHOT");
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, MissingMapReduceWorkflowApp.class);
    File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getName(), artifactId.getVersion().getVersion()));
    Files.copy(Locations.newInputSupplier(appJar), appJarFile);
    appJar.delete();
    try {
        applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, "appName", artifactId, appJarFile, null, null, new ProgramTerminator() {

            @Override
            public void stop(ProgramId programId) throws Exception {
            // no-op
            }
        }, true);
        Assert.fail("expected application deployment to fail.");
    } catch (Exception e) {
    // expected
    }
    // the artifact should have been cleaned up, and this should throw a not found exception
    artifactRepository.getArtifact(artifactId);
}
Also used : NamespaceId(co.cask.cdap.proto.id.NamespaceId) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Id(co.cask.cdap.common.id.Id) ProgramTerminator(co.cask.cdap.internal.app.deploy.ProgramTerminator) ProgramId(co.cask.cdap.proto.id.ProgramId) File(java.io.File) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) IOException(java.io.IOException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 2 with ProgramTerminator

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

the class ApplicationLifecycleServiceTest method testMissingDependency.

@Test
public void testMissingDependency() throws Exception {
    // tests the fix for CDAP-2543, by having programs which fail to start up due to missing dependency jars
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("missing-guava-dependency", "1.0.0-SNAPSHOT");
    Location appJar = createDeploymentJar(locationFactory, AppWithProgramsUsingGuava.class);
    File appJarFile = new File(tmpFolder.newFolder(), String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion()));
    Files.copy(Locations.newInputSupplier(appJar), appJarFile);
    appJar.delete();
    applicationLifecycleService.deployAppAndArtifact(NamespaceId.DEFAULT, "appName", Id.Artifact.fromEntityId(artifactId), appJarFile, null, null, new ProgramTerminator() {

        @Override
        public void stop(ProgramId programId) throws Exception {
        // no-op
        }
    }, true);
    ApplicationId appId = NamespaceId.DEFAULT.app("appName");
    // run records for programs that have missing dependencies should be FAILED, instead of hanging in RUNNING
    // fail the Worker#initialize
    ProgramId worker = appId.worker(AppWithProgramsUsingGuava.NoOpWorker.NAME);
    startProgram(Id.Program.fromEntityId(worker));
    waitForRuns(1, worker, ProgramRunStatus.FAILED);
    // fail the MapReduce#initialize
    ProgramId mapreduce = appId.mr(AppWithProgramsUsingGuava.NoOpMR.NAME);
    startProgram(Id.Program.fromEntityId(mapreduce));
    waitForRuns(1, mapreduce, ProgramRunStatus.FAILED);
    // fail the CustomAction#initialize
    ProgramId workflow = appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
    startProgram(Id.Program.fromEntityId(workflow));
    waitForRuns(1, workflow, ProgramRunStatus.FAILED);
    // fail the Workflow#initialize
    appId.workflow(AppWithProgramsUsingGuava.NoOpWorkflow.NAME);
    startProgram(Id.Program.fromEntityId(workflow), ImmutableMap.of("fail.in.workflow.initialize", "true"));
    waitForRuns(1, workflow, ProgramRunStatus.FAILED);
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) ProgramTerminator(co.cask.cdap.internal.app.deploy.ProgramTerminator) ProgramId(co.cask.cdap.proto.id.ProgramId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) File(java.io.File) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) IOException(java.io.IOException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)2 ProgramTerminator (co.cask.cdap.internal.app.deploy.ProgramTerminator)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 ArtifactId (co.cask.cdap.proto.id.ArtifactId)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 File (java.io.File)2 IOException (java.io.IOException)2 Location (org.apache.twill.filesystem.Location)2 Test (org.junit.Test)2 Id (co.cask.cdap.common.id.Id)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1