Search in sources :

Example 21 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by cdapio.

the class ProgramLifecycleHttpHandler method getMapReduceInfo.

/**
 * Relays job-level and task-level information about a particular MapReduce program run.
 */
@GET
@Path("/apps/{app-id}/mapreduce/{mapreduce-id}/runs/{run-id}/info")
public void getMapReduceInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("mapreduce-id") String mapreduceId, @PathParam("run-id") String runId) throws IOException, NotFoundException {
    ProgramId programId = new ProgramId(namespaceId, appId, ProgramType.MAPREDUCE, mapreduceId);
    ProgramRunId run = programId.run(runId);
    ApplicationSpecification appSpec = store.getApplication(programId.getParent());
    if (appSpec == null) {
        throw new NotFoundException(programId.getApplication());
    }
    if (!appSpec.getMapReduce().containsKey(mapreduceId)) {
        throw new NotFoundException(programId);
    }
    RunRecordDetail runRecordMeta = store.getRun(run);
    if (runRecordMeta == null || isTetheredRunRecord(runRecordMeta)) {
        throw new NotFoundException(run);
    }
    MRJobInfo mrJobInfo = mrJobInfoFetcher.getMRJobInfo(Id.Run.fromEntityId(run));
    mrJobInfo.setState(runRecordMeta.getStatus().name());
    // Multiple startTs / endTs by 1000, to be consistent with Task-level start/stop times returned by JobClient
    // in milliseconds. RunRecord returns seconds value.
    // The start time of the MRJob is when the run record has been marked as STARTED
    mrJobInfo.setStartTime(TimeUnit.SECONDS.toMillis(runRecordMeta.getStartTs()));
    Long stopTs = runRecordMeta.getStopTs();
    if (stopTs != null) {
        mrJobInfo.setStopTime(TimeUnit.SECONDS.toMillis(stopTs));
    }
    // JobClient (in DistributedMRJobInfoFetcher) can return NaN as some of the values, and GSON otherwise fails
    Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
    responder.sendJson(HttpResponseStatus.OK, gson.toJson(mrJobInfo, mrJobInfo.getClass()));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) MRJobInfo(io.cdap.cdap.proto.MRJobInfo) GsonBuilder(com.google.gson.GsonBuilder) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) Gson(com.google.gson.Gson) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 22 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by cdapio.

the class ProgramLifecycleHttpHandler method getStatus.

/**
 * Returns status of a type specified by the type{flows,workflows,mapreduce,spark,services,schedules}.
 */
@GET
@Path("/apps/{app-id}/versions/{version-id}/{program-type}/{program-id}/status")
public void getStatus(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("version-id") String versionId, @PathParam("program-type") String type, @PathParam("program-id") String programId) throws Exception {
    ApplicationId applicationId = new ApplicationId(namespaceId, appId, versionId);
    if (SCHEDULES.equals(type)) {
        JsonObject json = new JsonObject();
        ScheduleId scheduleId = applicationId.schedule(programId);
        ApplicationSpecification appSpec = store.getApplication(applicationId);
        if (appSpec == null) {
            throw new NotFoundException(applicationId);
        }
        json.addProperty("status", programScheduleService.getStatus(scheduleId).toString());
        responder.sendJson(HttpResponseStatus.OK, json.toString());
        return;
    }
    ProgramType programType = getProgramType(type);
    ProgramId program = applicationId.program(programType, programId);
    ProgramStatus programStatus = lifecycleService.getProgramStatus(program);
    Map<String, String> status = ImmutableMap.of("status", programStatus.name());
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(status));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) JsonObject(com.google.gson.JsonObject) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramStatus(io.cdap.cdap.proto.ProgramStatus) BatchProgramStatus(io.cdap.cdap.proto.BatchProgramStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by cdapio.

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.run(runId)) == null) {
        throw new NotFoundException(workflowId.run(runId));
    }
    return store.getWorkflowToken(workflowId, runId);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) WorkflowId(io.cdap.cdap.proto.id.WorkflowId)

Example 24 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by cdapio.

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(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException)

Example 25 with ApplicationSpecification

use of io.cdap.cdap.api.app.ApplicationSpecification in project cdap by cdapio.

the class DefaultStore method recordCompletedWorkflow.

private void recordCompletedWorkflow(AppMetadataStore metaStore, WorkflowTable workflowTable, WorkflowId workflowId, String runId) throws IOException, TableNotFoundException {
    RunRecordDetail runRecord = metaStore.getRun(workflowId.run(runId));
    if (runRecord == null) {
        return;
    }
    ApplicationId app = workflowId.getParent();
    ApplicationSpecification appSpec = getApplicationSpec(metaStore, app);
    if (appSpec == null || appSpec.getWorkflows() == null || appSpec.getWorkflows().get(workflowId.getProgram()) == null) {
        LOG.warn("Missing ApplicationSpecification for {}, " + "potentially caused by application removal right after stopping workflow {}", app, workflowId);
        return;
    }
    boolean workFlowNodeFailed = false;
    WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowId.getProgram());
    Map<String, WorkflowNode> nodeIdMap = workflowSpec.getNodeIdMap();
    List<WorkflowTable.ProgramRun> programRunsList = new ArrayList<>();
    for (Map.Entry<String, String> entry : runRecord.getProperties().entrySet()) {
        if (!("workflowToken".equals(entry.getKey()) || "runtimeArgs".equals(entry.getKey()) || "workflowNodeState".equals(entry.getKey()))) {
            WorkflowActionNode workflowNode = (WorkflowActionNode) nodeIdMap.get(entry.getKey());
            ProgramType programType = ProgramType.valueOfSchedulableType(workflowNode.getProgram().getProgramType());
            ProgramId innerProgram = app.program(programType, entry.getKey());
            RunRecordDetail innerProgramRun = metaStore.getRun(innerProgram.run(entry.getValue()));
            if (innerProgramRun != null && innerProgramRun.getStatus().equals(ProgramRunStatus.COMPLETED)) {
                Long stopTs = innerProgramRun.getStopTs();
                // since the program is completed, the stop ts cannot be null
                if (stopTs == null) {
                    LOG.warn("Since the program has completed, expected its stop time to not be null. " + "Not writing workflow completed record for Program = {}, Workflow = {}, Run = {}", innerProgram, workflowId, runRecord);
                    workFlowNodeFailed = true;
                    break;
                }
                programRunsList.add(new WorkflowTable.ProgramRun(entry.getKey(), entry.getValue(), programType, stopTs - innerProgramRun.getStartTs()));
            } else {
                workFlowNodeFailed = true;
                break;
            }
        }
    }
    if (workFlowNodeFailed) {
        return;
    }
    workflowTable.write(workflowId, runRecord, programRunsList);
}
Also used : ForwardingApplicationSpecification(io.cdap.cdap.internal.app.ForwardingApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) WorkflowActionNode(io.cdap.cdap.api.workflow.WorkflowActionNode) ArrayList(java.util.ArrayList) ProgramId(io.cdap.cdap.proto.id.ProgramId) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)231 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)114 ProgramId (io.cdap.cdap.proto.id.ProgramId)93 Test (org.junit.Test)90 AllProgramsApp (io.cdap.cdap.AllProgramsApp)54 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)53 ProgramType (io.cdap.cdap.proto.ProgramType)50 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)42 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)39 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)33 NotFoundException (io.cdap.cdap.common.NotFoundException)32 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)30 Map (java.util.Map)29 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)25 IOException (java.io.IOException)25 HashSet (java.util.HashSet)23 RunId (org.apache.twill.api.RunId)23 DefaultApplicationSpecification (io.cdap.cdap.internal.app.DefaultApplicationSpecification)21 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)20