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);
}
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);
}
Aggregations