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);
}
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)));
}
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
});
}
Aggregations