Search in sources :

Example 66 with NotFoundException

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);
}
Also used : DefaultEndpointPluginContext(co.cask.cdap.internal.app.runtime.DefaultEndpointPluginContext) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ArtifactId(co.cask.cdap.api.artifact.ArtifactId) Id(co.cask.cdap.proto.Id) PluginClass(co.cask.cdap.api.plugin.PluginClass)

Example 67 with NotFoundException

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
    }
}
Also used : ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ArtifactNotFoundException(co.cask.cdap.common.ArtifactNotFoundException) Test(org.junit.Test)

Example 68 with NotFoundException

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");
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) NotFoundException(co.cask.cdap.common.NotFoundException) File(java.io.File) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 69 with NotFoundException

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
    }
}
Also used : NotFoundException(co.cask.cdap.common.NotFoundException) ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) ScheduledRuntime(co.cask.cdap.proto.ScheduledRuntime) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification) Test(org.junit.Test)

Example 70 with NotFoundException

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) WorkflowId(co.cask.cdap.proto.id.WorkflowId)

Aggregations

NotFoundException (co.cask.cdap.common.NotFoundException)122 URL (java.net.URL)42 HttpResponse (co.cask.common.http.HttpResponse)41 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)28 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)25 Path (javax.ws.rs.Path)25 BadRequestException (co.cask.cdap.common.BadRequestException)22 ProgramId (co.cask.cdap.proto.id.ProgramId)19 ApplicationId (co.cask.cdap.proto.id.ApplicationId)17 NamespaceId (co.cask.cdap.proto.id.NamespaceId)14 Test (org.junit.Test)14 POST (javax.ws.rs.POST)12 HttpRequest (co.cask.common.http.HttpRequest)10 IOException (java.io.IOException)10 GET (javax.ws.rs.GET)10 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)9 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)8 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 TypeToken (com.google.common.reflect.TypeToken)8