use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method liveInfo.
@GET
@Path("/apps/{app-id}/{program-category}/{program-id}/live-info")
@SuppressWarnings("unused")
public void liveInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-category") String programCategory, @PathParam("program-id") String programId) throws BadRequestException {
ProgramType type = getProgramType(programCategory);
ProgramId program = new ProgramId(namespaceId, appId, type, programId);
getLiveInfo(responder, program, runtimeService);
}
use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getServiceAvailability.
/**
* Return the availability (i.e. discoverable registration) status of a service.
*/
@GET
@Path("/apps/{app-name}/versions/{app-version}/{service-type}/{program-name}/available")
public void getServiceAvailability(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("service-type") String serviceType, @PathParam("program-name") String programName) throws Exception {
// Currently we only support services and sparks as the service-type
ProgramType programType = getProgramType(serviceType);
if (!ServiceDiscoverable.getUserServiceTypes().contains(programType)) {
throw new BadRequestException("Only service or spark is support for service availability check");
}
ProgramId programId = new ProgramId(new ApplicationId(namespaceId, appName, appVersion), programType, programName);
ProgramStatus status = lifecycleService.getProgramStatus(programId);
if (status == ProgramStatus.STOPPED) {
throw new ServiceUnavailableException(programId.toString(), "Service is stopped. Please start it.");
}
// Construct discoverable name and return 200 OK if discoverable is present. If not return 503.
String discoverableName = ServiceDiscoverable.getName(programId);
// TODO: CDAP-12959 - Should use the UserServiceEndpointStrategy and discover based on the version
// and have appVersion nullable for the non versioned endpoint
EndpointStrategy strategy = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(discoverableName));
if (strategy.pick(300L, TimeUnit.MILLISECONDS) == null) {
LOG.trace("Discoverable endpoint {} not found", discoverableName);
throw new ServiceUnavailableException(programId.toString(), "Service is running but not accepting requests at this time.");
}
responder.sendString(HttpResponseStatus.OK, "Service is available to accept requests.");
}
use of io.cdap.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerInternal method getProgramRunRecordMeta.
/**
* Return {@link RunRecordDetail} for the given program run id
*
* @param request {@link HttpRequest}
* @param responder {@link HttpResponse}
* @param namespaceId namespace of the program
* @param appName name of the application
* @param appVersion version of the application
* @param type type of the program
* @param programName name of the program
* @param runid for which {@link RunRecordDetail} will be returned
* @throws Exception if failed to to get {@link RunRecordDetail}
*/
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs/{run-id}")
public void getProgramRunRecordMeta(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("app-version") String appVersion, @PathParam("program-type") String type, @PathParam("program-name") String programName, @PathParam("run-id") String runid) throws Exception {
ProgramType programType = ProgramType.valueOfCategoryName(type, BadRequestException::new);
ProgramId programId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName);
RunRecordDetail runRecordMeta = programLifecycleService.getRunRecordMeta(programId.run(runid));
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runRecordMeta));
}
use of io.cdap.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 io.cdap.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 {
WorkflowTable.WorkflowRunRecord workflowRunRecord = store.getWorkflowRun(workflowId, runId);
if (workflowRunRecord == null) {
return null;
}
List<WorkflowTable.ProgramRun> programRuns = workflowRunRecord.getProgramRuns();
List<ProgramMetrics> programMetricsList = new ArrayList<>();
for (WorkflowTable.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);
}
Aggregations