Search in sources :

Example 16 with WorkflowId

use of co.cask.cdap.proto.id.WorkflowId 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.run(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)

Example 17 with WorkflowId

use of co.cask.cdap.proto.id.WorkflowId in project cdap by caskdata.

the class WorkflowStatsSLAHttpHandler method workflowRunDetail.

/**
 * The endpoint returns a list of workflow metrics based on the workflow run and a surrounding number of runs
 * of the workflow that are spaced apart by a time interval from each other.
 *
 * @param request The request
 * @param responder The responder
 * @param namespaceId The namespace the application is in
 * @param appId The application the workflow is in
 * @param workflowId The workflow that needs to have it stats shown
 * @param runId The run id of the Workflow that the user wants to see
 * @param limit The number of the records that the user wants to compare against on either side of the run
 * @param interval The timeInterval with which the user wants to space out the runs
 */
@GET
@Path("apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/statistics")
public void workflowRunDetail(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId, @QueryParam("limit") @DefaultValue("10") int limit, @QueryParam("interval") @DefaultValue("10s") String interval) throws Exception {
    if (limit <= 0) {
        throw new BadRequestException("Limit has to be greater than 0. Entered value was : " + limit);
    }
    long timeInterval;
    try {
        timeInterval = TimeMathParser.resolutionInSeconds(interval);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Interval is specified with invalid time unit. It should be specified with one" + " of the 'ms', 's', 'm', 'h', 'd' units. Entered value was : " + interval);
    }
    if (timeInterval <= 0) {
        throw new BadRequestException("Interval should be greater than 0 and should be specified with one of the 'ms'," + " 's', 'm', 'h', 'd' units. Entered value was : " + interval);
    }
    WorkflowId workflow = new WorkflowId(namespaceId, appId, workflowId);
    Collection<WorkflowDataset.WorkflowRunRecord> workflowRunRecords = store.retrieveSpacedRecords(workflow, runId, limit, timeInterval);
    List<WorkflowRunMetrics> workflowRunMetricsList = new ArrayList<>();
    Map<String, Long> startTimes = new HashMap<>();
    for (WorkflowDataset.WorkflowRunRecord workflowRunRecord : workflowRunRecords) {
        workflowRunMetricsList.add(getDetailedRecord(workflow, workflowRunRecord.getWorkflowRunId()));
        startTimes.put(workflowRunRecord.getWorkflowRunId(), RunIds.getTime(RunIds.fromString(workflowRunRecord.getWorkflowRunId()), TimeUnit.SECONDS));
    }
    Collection<WorkflowStatsComparison.ProgramNodes> formattedStatisticsMap = format(workflowRunMetricsList);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(new WorkflowStatsComparison(startTimes, formattedStatisticsMap)));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowId(co.cask.cdap.proto.id.WorkflowId) WorkflowStatsComparison(co.cask.cdap.proto.WorkflowStatsComparison) BadRequestException(co.cask.cdap.common.BadRequestException) WorkflowDataset(co.cask.cdap.internal.app.store.WorkflowDataset) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 18 with WorkflowId

use of co.cask.cdap.proto.id.WorkflowId in project cdap by caskdata.

the class DefaultStore method setStop.

@Override
public void setStop(ProgramRunId id, long endTime, ProgramRunStatus runStatus, BasicThrowable failureCause, byte[] sourceId) {
    Preconditions.checkArgument(runStatus != null, "Run state of program run should be defined");
    Transactionals.execute(transactional, context -> {
        AppMetadataStore metaStore = getAppMetadataStore(context);
        metaStore.recordProgramStop(id, endTime, runStatus, failureCause, sourceId);
        // This block has been added so that completed workflow runs can be logged to the workflow dataset
        WorkflowId workflowId = new WorkflowId(id.getParent().getParent(), id.getProgram());
        if (id.getType() == ProgramType.WORKFLOW && runStatus == ProgramRunStatus.COMPLETED) {
            recordCompletedWorkflow(metaStore, getWorkflowDataset(context), workflowId, id.getRun());
        }
    // todo: delete old history data
    });
}
Also used : WorkflowId(co.cask.cdap.proto.id.WorkflowId)

Aggregations

WorkflowId (co.cask.cdap.proto.id.WorkflowId)18 ApplicationId (co.cask.cdap.proto.id.ApplicationId)8 ProgramId (co.cask.cdap.proto.id.ProgramId)7 Test (org.junit.Test)7 NotFoundException (co.cask.cdap.common.NotFoundException)5 RunRecord (co.cask.cdap.proto.RunRecord)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 Id (co.cask.cdap.common.id.Id)4 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 BadRequestException (co.cask.cdap.common.BadRequestException)3 WorkflowTokenDetail (co.cask.cdap.proto.WorkflowTokenDetail)3 TypeToken (com.google.gson.reflect.TypeToken)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HttpResponse (org.apache.http.HttpResponse)3 WorkflowApp (co.cask.cdap.WorkflowApp)2 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)2