Search in sources :

Example 51 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class FlowQueuePendingCorrector method run.

/**
 * Corrects queue.pending metric for all flowlets in a namespace.
 */
public void run(NamespaceId namespaceId) throws Exception {
    System.out.println("Running queue.pending correction on namespace " + namespaceId);
    Collection<ApplicationSpecification> apps = store.getAllApplications(namespaceId);
    for (ApplicationSpecification app : apps) {
        ApplicationId appId = namespaceId.app(app.getName(), app.getAppVersion());
        run(appId, app);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationId(co.cask.cdap.proto.id.ApplicationId)

Example 52 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class FlowQueuePendingCorrector method run.

/**
 * Corrects queue.pending metric for a flow.
 */
public void run(final FlowId flowId) throws Exception {
    ApplicationSpecification app = store.getApplication(flowId.getParent());
    Preconditions.checkArgument(app != null);
    Preconditions.checkArgument(app.getFlows().containsKey(flowId.getProgram()));
    FlowSpecification flow = app.getFlows().get(flowId.getProgram());
    run(flowId, flow);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification)

Example 53 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.

the class WorkflowHttpHandler method getWorkflowSpecForValidRun.

/**
 * Get the {@link WorkflowSpecification} if valid application id, workflow id, and runid are provided.
 * @param namespaceId the namespace id
 * @param applicationId the application id
 * @param workflowId the workflow id
 * @param runId the runid of the workflow
 * @return the specifications for the Workflow
 * @throws NotFoundException is thrown when the application, workflow, or runid is not found
 */
private WorkflowSpecification getWorkflowSpecForValidRun(String namespaceId, String applicationId, String workflowId, String runId) throws NotFoundException {
    ApplicationId appId = new ApplicationId(namespaceId, applicationId);
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowId);
    ProgramId programId = new ProgramId(namespaceId, applicationId, ProgramType.WORKFLOW, workflowId);
    if (workflowSpec == null) {
        throw new ProgramNotFoundException(programId);
    }
    if (store.getRun(programId.run(runId)) == null) {
        throw new NotFoundException(new ProgramRunId(programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram(), runId));
    }
    return workflowSpec;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) 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) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException)

Example 54 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification 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 55 with ApplicationSpecification

use of co.cask.cdap.api.app.ApplicationSpecification 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

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)104 ApplicationId (co.cask.cdap.proto.id.ApplicationId)47 ProgramId (co.cask.cdap.proto.id.ProgramId)28 Test (org.junit.Test)27 ProgramType (co.cask.cdap.proto.ProgramType)22 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)16 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)15 NotFoundException (co.cask.cdap.common.NotFoundException)14 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)12 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)12 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)11 NamespaceId (co.cask.cdap.proto.id.NamespaceId)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)9 WordCountApp (co.cask.cdap.WordCountApp)8 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)8 IOException (java.io.IOException)8 RunId (org.apache.twill.api.RunId)8 Map (java.util.Map)7