use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class PluginService method getPluginEndpoint.
private PluginEndpoint getPluginEndpoint(NamespaceId namespace, ArtifactDetail artifactDetail, String pluginType, String pluginName, ArtifactDescriptor parentArtifactDescriptor, Set<ArtifactRange> parentArtifactRanges, String methodName) throws NotFoundException, IOException, ClassNotFoundException {
Id.Artifact artifactId = Id.Artifact.from(namespace.toId(), artifactDetail.getDescriptor().getArtifactId());
Set<PluginClass> pluginClasses = artifactDetail.getMeta().getClasses().getPlugins();
PluginClass pluginClass = null;
for (PluginClass plugin : pluginClasses) {
if (plugin.getName().equals(pluginName) && plugin.getType().equals(pluginType)) {
// plugin type and name matched, next check for endpoint method presence
if (plugin.getEndpoints() == null || !plugin.getEndpoints().contains(methodName)) {
throw new NotFoundException(String.format("Plugin with type: %s name: %s found, " + "but Endpoint %s was not found", pluginType, pluginName, methodName));
}
pluginClass = plugin;
}
}
if (pluginClass == null) {
throw new NotFoundException(String.format("No Plugin with type : %s, name: %s was found", pluginType, pluginName));
}
// initialize parent classloader and plugin instantiator
Instantiators instantiators = this.instantiators.getUnchecked(parentArtifactDescriptor);
PluginInstantiator pluginInstantiator = instantiators.getPluginInstantiator(artifactDetail, artifactId.toArtifactId());
// we pass the parent artifact to endpoint plugin context,
// as plugin method will use this context to load other plugins.
DefaultEndpointPluginContext defaultEndpointPluginContext = new DefaultEndpointPluginContext(namespace, artifactRepository, pluginInstantiator, parentArtifactRanges);
return getPluginEndpoint(pluginInstantiator, artifactId, pluginClass, methodName, defaultEndpointPluginContext);
}
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
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowToken.
private WorkflowToken getWorkflowToken(String namespaceId, String appName, String workflow, String runId) throws NotFoundException {
ApplicationId appId = new ApplicationId(namespaceId, appName);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new NotFoundException(appId);
}
WorkflowId workflowId = appId.workflow(workflow);
if (!appSpec.getWorkflows().containsKey(workflow)) {
throw new NotFoundException(workflowId);
}
if (store.getRun(workflowId, runId) == null) {
throw new NotFoundException(workflowId.run(runId));
}
return store.getWorkflowToken(workflowId, runId);
}
Aggregations