Search in sources :

Example 6 with WorkflowId

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

the class DefaultStore method setStop.

@Override
public void setStop(final ProgramId id, final String pid, final long endTime, final ProgramRunStatus runStatus, final BasicThrowable failureCause) {
    Preconditions.checkArgument(runStatus != null, "Run state of program run should be defined");
    Transactions.executeUnchecked(transactional, new TxRunnable() {

        @Override
        public void run(DatasetContext context) throws Exception {
            AppMetadataStore metaStore = getAppMetadataStore(context);
            metaStore.recordProgramStop(id, pid, endTime, runStatus, failureCause);
            // This block has been added so that completed workflow runs can be logged to the workflow dataset
            WorkflowId workflowId = new WorkflowId(id.getParent(), id.getProgram());
            if (id.getType() == ProgramType.WORKFLOW && runStatus == ProgramRunStatus.COMPLETED) {
                recordCompletedWorkflow(metaStore, getWorkflowDataset(context), workflowId, pid);
            }
        // todo: delete old history data
        }
    });
}
Also used : TxRunnable(co.cask.cdap.api.TxRunnable) DatasetContext(co.cask.cdap.api.data.DatasetContext) WorkflowId(co.cask.cdap.proto.id.WorkflowId) TransactionFailureException(org.apache.tephra.TransactionFailureException) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) TransactionNotInProgressException(org.apache.tephra.TransactionNotInProgressException) TransactionConflictException(org.apache.tephra.TransactionConflictException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Example 7 with WorkflowId

use of co.cask.cdap.proto.id.WorkflowId 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 = scheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
        } else {
            runtimes = scheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
        }
        responder.sendJson(HttpResponseStatus.OK, 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)

Example 8 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, 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 9 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, 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 10 with WorkflowId

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

the class WorkflowStatsSLAHttpHandlerTest method testDetails.

@Test
public void testDetails() throws Exception {
    deploy(WorkflowApp.class);
    String workflowName = "FunWorkflow";
    String mapreduceName = "ClassicWordCount";
    String sparkName = "SparkWorkflowTest";
    WorkflowId workflowProgram = WORKFLOW_APP.workflow(workflowName);
    ProgramId mapreduceProgram = WORKFLOW_APP.mr(mapreduceName);
    ProgramId sparkProgram = WORKFLOW_APP.spark(sparkName);
    List<RunId> runIdList = setupRuns(workflowProgram, mapreduceProgram, sparkProgram, store, 13);
    String request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/statistics?limit=%s&interval=%s", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), runIdList.get(6).getId(), "3", "10m");
    HttpResponse response = doGet(request);
    WorkflowStatsComparison workflowStatistics = readResponse(response, new TypeToken<WorkflowStatsComparison>() {
    }.getType());
    Assert.assertEquals(7, workflowStatistics.getProgramNodesList().iterator().next().getWorkflowProgramDetailsList().size());
    request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/statistics?limit=0", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), runIdList.get(6).getId());
    response = doGet(request);
    Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.getCode(), response.getStatusLine().getStatusCode());
    request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/statistics?limit=10&interval=10", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), runIdList.get(6).getId());
    response = doGet(request);
    Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.getCode(), response.getStatusLine().getStatusCode());
    request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/statistics?limit=10&interval=10P", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), runIdList.get(6).getId());
    response = doGet(request);
    Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.getCode(), response.getStatusLine().getStatusCode());
    request = String.format("%s/namespaces/%s/apps/%s/workflows/%s/runs/%s/statistics?limit=20&interval=0d", Constants.Gateway.API_VERSION_3, Id.Namespace.DEFAULT.getId(), WorkflowApp.class.getSimpleName(), workflowProgram.getProgram(), runIdList.get(6).getId());
    response = doGet(request);
    Assert.assertEquals(HttpResponseStatus.BAD_REQUEST.getCode(), response.getStatusLine().getStatusCode());
}
Also used : WorkflowApp(co.cask.cdap.WorkflowApp) WorkflowStatsComparison(co.cask.cdap.proto.WorkflowStatsComparison) TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(org.apache.http.HttpResponse) WorkflowId(co.cask.cdap.proto.id.WorkflowId) ProgramId(co.cask.cdap.proto.id.ProgramId) RunId(org.apache.twill.api.RunId) Test(org.junit.Test)

Aggregations

WorkflowId (co.cask.cdap.proto.id.WorkflowId)11 NotFoundException (co.cask.cdap.common.NotFoundException)4 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)3 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)3 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)3 WorkflowStatsComparison (co.cask.cdap.proto.WorkflowStatsComparison)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Test (org.junit.Test)3 WorkflowApp (co.cask.cdap.WorkflowApp)2 BadRequestException (co.cask.cdap.common.BadRequestException)2 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)2 TypeToken (com.google.gson.reflect.TypeToken)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HttpResponse (org.apache.http.HttpResponse)2 RunId (org.apache.twill.api.RunId)2 TxRunnable (co.cask.cdap.api.TxRunnable)1