use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testDeleteApplication.
@Test
public void testDeleteApplication() throws Exception {
namespaceClient.create(new NamespaceMeta.Builder().setName(TEST_NAMESPACE1.toId()).build());
appClient.deploy(TEST_NAMESPACE1, createAppJarFile(WordCountApp.class));
ProgramId programId = TEST_NAMESPACE1.app("WordCountApp").flow("WordCountFlow");
// Set some properties metadata
Map<String, String> flowProperties = ImmutableMap.of("sKey", "sValue", "sK", "sV");
addProperties(programId, flowProperties);
// Get properties
Map<String, String> properties = getProperties(programId, MetadataScope.USER);
Assert.assertEquals(2, properties.size());
// Delete the App after stopping the flow
appClient.delete(TEST_NAMESPACE1.app(programId.getApplication()));
// Delete again should throw not found exception
try {
appClient.delete(TEST_NAMESPACE1.app(programId.getApplication()));
Assert.fail("Expected NotFoundException");
} catch (NotFoundException e) {
// expected
}
// Now try to get from invalid entity should throw 404.
getPropertiesFromInvalidEntity(programId);
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ApplicationClientTestRun method testAppUpdate.
@Test
public void testAppUpdate() throws Exception {
String artifactName = "cfg-programs";
ArtifactId artifactIdV1 = NamespaceId.DEFAULT.artifact(artifactName, "1.0.0");
ArtifactId artifactIdV2 = NamespaceId.DEFAULT.artifact(artifactName, "2.0.0");
ApplicationId appId = NamespaceId.DEFAULT.app("ProgramsApp");
artifactClient.add(NamespaceId.DEFAULT, artifactName, Files.newInputStreamSupplier(createAppJarFile(ConfigurableProgramsApp.class)), "1.0.0");
artifactClient.add(NamespaceId.DEFAULT, artifactName, Files.newInputStreamSupplier(createAppJarFile(ConfigurableProgramsApp2.class)), "2.0.0");
try {
// deploy the app with just the worker
ConfigurableProgramsApp.Programs conf = new ConfigurableProgramsApp.Programs(null, "worker1", "stream1", "dataset1");
AppRequest<ConfigurableProgramsApp.Programs> request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), artifactIdV1.getVersion()), conf);
appClient.deploy(appId, request);
// should only have the worker
Assert.assertTrue(appClient.listPrograms(appId, ProgramType.FLOW).isEmpty());
Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.WORKER).size());
// update to use just the flow
conf = new ConfigurableProgramsApp.Programs("flow1", null, "stream1", "dataset1");
request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), artifactIdV1.getVersion()), conf);
appClient.update(appId, request);
// should only have the flow
Assert.assertTrue(appClient.listPrograms(appId, ProgramType.WORKER).isEmpty());
Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.FLOW).size());
// check nonexistent app is not found
try {
appClient.update(NamespaceId.DEFAULT.app("ghost"), request);
Assert.fail();
} catch (NotFoundException e) {
// expected
}
// check different artifact name is invalid
request = new AppRequest<>(new ArtifactSummary("ghost", artifactIdV1.getVersion()), conf);
try {
appClient.update(appId, request);
Assert.fail();
} catch (BadRequestException e) {
// expected
}
// check nonexistent artifact is not found
request = new AppRequest<>(new ArtifactSummary(artifactIdV1.getArtifact(), "0.0.1"), conf);
try {
appClient.update(appId, request);
Assert.fail();
} catch (NotFoundException e) {
// expected
}
// update artifact version. This version uses a different app class with that can add a service
ConfigurableProgramsApp2.Programs conf2 = new ConfigurableProgramsApp2.Programs(null, null, "stream1", "dataset1", "service2");
AppRequest<ConfigurableProgramsApp2.Programs> request2 = new AppRequest<>(new ArtifactSummary(artifactIdV2.getArtifact(), artifactIdV2.getVersion()), conf2);
appClient.update(appId, request2);
// should only have a single service
Assert.assertTrue(appClient.listPrograms(appId, ProgramType.WORKER).isEmpty());
Assert.assertTrue(appClient.listPrograms(appId, ProgramType.FLOW).isEmpty());
Assert.assertEquals(1, appClient.listPrograms(appId, ProgramType.SERVICE).size());
} finally {
appClient.delete(appId);
appClient.waitForDeleted(appId, 30, TimeUnit.SECONDS);
artifactClient.delete(artifactIdV1);
artifactClient.delete(artifactIdV2);
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ArtifactClientTestRun method testNotFound.
@Test
public void testNotFound() throws Exception {
ArtifactId ghostId = NamespaceId.DEFAULT.artifact("ghost", "1.0.0");
try {
artifactClient.list(new NamespaceId("ghost"));
Assert.fail();
} catch (NotFoundException e) {
// expected
}
try {
artifactClient.getArtifactInfo(ghostId);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
try {
artifactClient.listVersions(ghostId.getParent(), ghostId.getArtifact());
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
// test adding an artifact that extends a non-existent artifact
Set<ArtifactRange> parents = Sets.newHashSet(new ArtifactRange(ghostId.getParent().getNamespace(), ghostId.getArtifact(), new ArtifactVersion("1"), new ArtifactVersion("2")));
try {
artifactClient.add(NamespaceId.DEFAULT, "abc", DUMMY_SUPPLIER, "1.0.0", parents);
Assert.fail();
} catch (NotFoundException e) {
// expected
}
try {
artifactClient.getPluginTypes(ghostId);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
try {
artifactClient.getPluginSummaries(ghostId, "type");
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
try {
artifactClient.getPluginInfo(ghostId, "type", "name");
Assert.fail();
} catch (NotFoundException e) {
// expected
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramClientTestRun method testWorkflowCommand.
private void testWorkflowCommand(final WorkflowId workflow) throws Exception {
// File is used to synchronized between the test case and the FakeWorkflow
File doneFile = TMP_FOLDER.newFile();
Assert.assertTrue(doneFile.delete());
LOG.info("Starting workflow");
programClient.start(workflow, false, ImmutableMap.of("done.file", doneFile.getAbsolutePath()));
assertProgramRunning(programClient, workflow);
Tasks.waitFor(1, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return programClient.getProgramRuns(workflow, "running", Long.MIN_VALUE, Long.MAX_VALUE, 100).size();
}
}, 5, TimeUnit.SECONDS);
List<RunRecord> runRecords = programClient.getProgramRuns(workflow, "running", Long.MIN_VALUE, Long.MAX_VALUE, 100);
Assert.assertEquals(1, runRecords.size());
final String pid = runRecords.get(0).getPid();
Tasks.waitFor(1, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
try {
return programClient.getWorkflowCurrent(workflow, pid).size();
} catch (NotFoundException e) {
// try again if the 'current' endpoint is not discoverable yet
return 0;
}
}
}, 20, TimeUnit.SECONDS);
// Signal the FakeWorkflow that execution can be continued by creating temp file
Assert.assertTrue(doneFile.createNewFile());
assertProgramStopped(programClient, workflow);
LOG.info("Workflow stopped");
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ScheduleClientTestRun method testAll.
@Test
public void testAll() throws Exception {
List<ScheduleDetail> list = scheduleClient.listSchedules(workflow);
List<ScheduleSpecification> specs = scheduleClient.list(workflow);
Assert.assertEquals(2, list.size());
Assert.assertEquals(specs, ScheduleDetail.toScheduleSpecs(list));
ScheduleDetail timeSchedule;
ScheduleDetail streamSchedule;
if (list.get(0).getTrigger() instanceof ProtoTrigger.TimeTrigger) {
timeSchedule = list.get(0);
streamSchedule = list.get(1);
} else {
streamSchedule = list.get(0);
timeSchedule = list.get(1);
}
ProtoTrigger.TimeTrigger timeTrigger = (ProtoTrigger.TimeTrigger) timeSchedule.getTrigger();
ProtoTrigger.StreamSizeTrigger streamSizeTrigger = (ProtoTrigger.StreamSizeTrigger) streamSchedule.getTrigger();
Assert.assertEquals(FakeApp.TIME_SCHEDULE_NAME, timeSchedule.getName());
Assert.assertEquals(FakeApp.SCHEDULE_CRON, timeTrigger.getCronExpression());
Assert.assertEquals(FakeApp.STREAM_SCHEDULE_NAME, streamSchedule.getName());
Assert.assertEquals(FakeApp.STREAM_NAME, streamSizeTrigger.getStreamId().getStream());
Assert.assertEquals(FakeApp.STREAM_TRIGGER_MB, streamSizeTrigger.getTriggerMB());
String status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SUSPENDED", status);
status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SUSPENDED", status);
scheduleClient.resume(schedule);
status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SCHEDULED", status);
scheduleClient.suspend(schedule);
status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SUSPENDED", status);
scheduleClient.resume(schedule);
status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SCHEDULED", status);
scheduleClient.suspend(schedule);
status = scheduleClient.getStatus(schedule);
Assert.assertEquals("SUSPENDED", status);
scheduleClient.resume(schedule);
List<ScheduledRuntime> scheduledRuntimes = scheduleClient.nextRuntimes(workflow);
scheduleClient.suspend(schedule);
Assert.assertEquals(1, scheduledRuntimes.size());
// simply assert that its scheduled for some time in the future (or scheduled for now, but hasn't quite
// executed yet
Assert.assertTrue(scheduledRuntimes.get(0).getTime() >= System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1));
try {
scheduleClient.nextRuntimes(app.workflow("nonexistentWorkflow"));
Assert.fail("Expected not to be able to retrieve next run times for a nonexistent workflow.");
} catch (NotFoundException expected) {
// expected
}
}
Aggregations