Search in sources :

Example 16 with ProgramNotFoundException

use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class WorkflowHttpHandler method getWorkflowNodeStates.

@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state")
public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
    ApplicationId appId = Ids.namespace(namespaceId).app(applicationId);
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    ProgramId workflowProgramId = appId.workflow(workflowId);
    WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram());
    if (workflowSpec == null) {
        throw new ProgramNotFoundException(workflowProgramId);
    }
    ProgramRunId workflowRunId = workflowProgramId.run(runId);
    if (store.getRun(workflowRunId) == null) {
        throw new NotFoundException(workflowRunId);
    }
    List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId);
    Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>();
    for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) {
        nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail);
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HashMap(java.util.HashMap) 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) ProgramId(co.cask.cdap.proto.id.ProgramId) WorkflowNodeStateDetail(co.cask.cdap.proto.WorkflowNodeStateDetail) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 17 with ProgramNotFoundException

use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class WorkflowHttpHandler method getScheduledRuntime.

private void getScheduledRuntime(HttpResponder responder, String namespaceId, String appName, String workflowName, boolean previousRuntimeRequested) throws SchedulerException, NotFoundException {
    try {
        ApplicationId appId = new ApplicationId(namespaceId, appName);
        WorkflowId workflowId = new WorkflowId(appId, workflowName);
        ApplicationSpecification appSpec = store.getApplication(appId);
        if (appSpec == null) {
            throw new ApplicationNotFoundException(appId);
        }
        if (appSpec.getWorkflows().get(workflowName) == null) {
            throw new ProgramNotFoundException(workflowId);
        }
        List<ScheduledRuntime> runtimes;
        if (previousRuntimeRequested) {
            runtimes = timeScheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
        } else {
            runtimes = timeScheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
        }
        responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimes));
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) WorkflowId(co.cask.cdap.proto.id.WorkflowId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ScheduledRuntime(co.cask.cdap.proto.ScheduledRuntime)

Aggregations

ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)17 HttpResponse (co.cask.common.http.HttpResponse)10 URL (java.net.URL)10 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)6 ApplicationId (co.cask.cdap.proto.id.ApplicationId)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 NotFoundException (co.cask.cdap.common.NotFoundException)2 HttpRequest (co.cask.common.http.HttpRequest)2 TypeToken (com.google.common.reflect.TypeToken)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)1 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)1 RuntimeInfo (co.cask.cdap.app.runtime.ProgramRuntimeService.RuntimeInfo)1 BadRequestException (co.cask.cdap.common.BadRequestException)1 AbstractListener (co.cask.cdap.internal.app.runtime.AbstractListener)1 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)1 ApplicationRecord (co.cask.cdap.proto.ApplicationRecord)1