Search in sources :

Example 1 with ProgramTerminator

use of io.cdap.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()));
    Locations.linkOrCopyOverwrite(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(io.cdap.cdap.proto.id.ArtifactId) ProgramTerminator(io.cdap.cdap.internal.app.deploy.ProgramTerminator) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) File(java.io.File) CapabilityNotAvailableException(io.cdap.cdap.internal.capability.CapabilityNotAvailableException) IOException(java.io.IOException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)1 ProgramTerminator (io.cdap.cdap.internal.app.deploy.ProgramTerminator)1 CapabilityNotAvailableException (io.cdap.cdap.internal.capability.CapabilityNotAvailableException)1 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)1 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)1 ProgramId (io.cdap.cdap.proto.id.ProgramId)1 File (java.io.File)1 IOException (java.io.IOException)1 Location (org.apache.twill.filesystem.Location)1 Test (org.junit.Test)1