use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class UsageHandler method getProgramDatasetUsage.
@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/datasets")
public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) {
ProgramType type = ProgramType.valueOfCategoryName(programType);
final ProgramId id = new ProgramId(namespaceId, appId, type, programId);
Set<DatasetId> ids = registry.getDatasets(id);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class UsageHandler method getProgramStreamUsage.
@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/streams")
public void getProgramStreamUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) {
ProgramType type = ProgramType.valueOfCategoryName(programType);
final ProgramId id = new ProgramId(namespaceId, appId, type, programId);
Set<StreamId> ids = registry.getStreams(id);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class WorkflowStatsSLAHttpHandler method getDetailedRecord.
/**
* Returns the detailed Record for the Workflow
*
* @param workflowId Workflow that needs to get its detailed record
* @param runId Run Id of the workflow
* @return Return the Workflow Run Metrics
*/
@Nullable
private WorkflowRunMetrics getDetailedRecord(WorkflowId workflowId, String runId) throws Exception {
WorkflowDataset.WorkflowRunRecord workflowRunRecord = store.getWorkflowRun(workflowId, runId);
if (workflowRunRecord == null) {
return null;
}
List<WorkflowDataset.ProgramRun> programRuns = workflowRunRecord.getProgramRuns();
List<ProgramMetrics> programMetricsList = new ArrayList<>();
for (WorkflowDataset.ProgramRun programRun : programRuns) {
Map<String, Long> programMap = new HashMap<>();
String programName = programRun.getName();
ProgramType programType = programRun.getProgramType();
ProgramId program = new ProgramId(workflowId.getNamespace(), workflowId.getApplication(), programType, programName);
String programRunId = programRun.getRunId();
if (programType == ProgramType.MAPREDUCE) {
programMap = getMapreduceDetails(program, programRunId);
} else if (programType == ProgramType.SPARK) {
programMap = getSparkDetails(program, programRunId);
}
programMap.put("timeTaken", programRun.getTimeTaken());
long programStartTime = RunIds.getTime(RunIds.fromString(programRunId), TimeUnit.SECONDS);
programMetricsList.add(new ProgramMetrics(programName, programType, programRunId, programStartTime, programMap));
}
return new WorkflowRunMetrics(runId, programMetricsList);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramInstances.
/**
* Get requested and provisioned instances for a program type.
* The program type passed here should be one that can have instances (flows, services, ...)
* Requires caller to do this validation.
*/
private BatchRunnableInstances getProgramInstances(BatchRunnable runnable, ApplicationSpecification spec, ProgramId programId) {
int requested;
String programName = programId.getProgram();
String runnableId = programName;
ProgramType programType = programId.getType();
if (programType == ProgramType.WORKER) {
if (!spec.getWorkers().containsKey(programName)) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Worker: " + programName + " not found");
}
requested = spec.getWorkers().get(programName).getInstances();
} else if (programType == ProgramType.SERVICE) {
if (!spec.getServices().containsKey(programName)) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Service: " + programName + " not found");
}
requested = spec.getServices().get(programName).getInstances();
} else if (programType == ProgramType.FLOW) {
// flows must have runnable id
runnableId = runnable.getRunnableId();
if (runnableId == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Must provide the flowlet id as the runnableId for flows");
}
FlowSpecification flowSpec = spec.getFlows().get(programName);
if (flowSpec == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flow: " + programName + " not found");
}
FlowletDefinition flowletDefinition = flowSpec.getFlowlets().get(runnableId);
if (flowletDefinition == null) {
return new BatchRunnableInstances(runnable, HttpResponseStatus.NOT_FOUND.code(), "Flowlet: " + runnableId + " not found");
}
requested = flowletDefinition.getInstances();
} else {
return new BatchRunnableInstances(runnable, HttpResponseStatus.BAD_REQUEST.code(), "Instances not supported for program type + " + programType);
}
int provisioned = getInstanceCount(programId, runnableId);
// use the pretty name of program types to be consistent
return new BatchRunnableInstances(runnable, HttpResponseStatus.OK.code(), provisioned, requested);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method resetLogLevels.
private void resetLogLevels(FullHttpRequest request, HttpResponder responder, String namespace, String appName, String appVersion, String type, String programName, @Nullable String component, String runId) throws Exception {
ProgramType programType = getProgramType(type);
if (programType == null) {
throw new BadRequestException("Invalid program type provided");
}
try {
Set<String> loggerNames = parseBody(request, SET_STRING_TYPE);
lifecycleService.resetProgramLogLevels(new ApplicationId(namespace, appName, appVersion).program(programType, programName), loggerNames == null ? Collections.emptySet() : loggerNames, component, runId);
responder.sendStatus(HttpResponseStatus.OK);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid JSON in body");
} catch (SecurityException e) {
throw new UnauthorizedException("Unauthorized to reset the log levels");
}
}
Aggregations