use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method performRunLevelStop.
/**
* Stops the particular run of the Workflow or MapReduce program.
*/
@POST
@Path("/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/stop")
public void performRunLevelStop(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String type, @PathParam("program-id") String programId, @PathParam("run-id") String runId) throws Exception {
ProgramType programType;
try {
programType = ProgramType.valueOfCategoryName(type);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
ProgramId program = new ProgramId(namespaceId, appId, programType, programId);
lifecycleService.stop(program, runId);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramStatusSchedules.
/**
* Get schedules containing {@link ProgramStatusTrigger} filtered by triggering program, and optionally by
* triggering program statuses or schedule status
* @param triggerNamespaceId namespace of the triggering program in {@link ProgramStatusTrigger}
* @param triggerAppName application name of the triggering program in {@link ProgramStatusTrigger}
* @param triggerAppVersion application version of the triggering program in {@link ProgramStatusTrigger}
* @param triggerProgramType program type of the triggering program in {@link ProgramStatusTrigger}
* @param triggerProgramName program name of the triggering program in {@link ProgramStatusTrigger}
* @param triggerProgramStatuses comma separated {@link ProgramStatus} in {@link ProgramStatusTrigger}.
* Schedules with {@link ProgramStatusTrigger} triggered by none of the
* {@link ProgramStatus} in triggerProgramStatuses will be filtered out.
* If not specified, schedules will be returned regardless of triggering program status.
* @param scheduleStatus status of the schedule. Can only be one of "SCHEDULED" or "SUSPENDED".
* If specified, only schedules with matching status will be returned.
*/
@GET
@Path("schedules/trigger-type/program-status")
public void getProgramStatusSchedules(HttpRequest request, HttpResponder responder, @QueryParam("trigger-namespace-id") String triggerNamespaceId, @QueryParam("trigger-app-name") String triggerAppName, @QueryParam("trigger-app-version") @DefaultValue(ApplicationId.DEFAULT_VERSION) String triggerAppVersion, @QueryParam("trigger-program-type") String triggerProgramType, @QueryParam("trigger-program-name") String triggerProgramName, @QueryParam("trigger-program-statuses") String triggerProgramStatuses, @QueryParam("schedule-status") String scheduleStatus) throws Exception {
if (triggerNamespaceId == null) {
throw new BadRequestException("Must specify trigger-namespace-id as a query param");
}
if (triggerAppName == null) {
throw new BadRequestException("Must specify trigger-app-name as a query param");
}
if (triggerProgramType == null) {
throw new BadRequestException("Must specify trigger-program-type as a query param");
}
if (triggerProgramName == null) {
throw new BadRequestException("Must specify trigger-program-name as a query param");
}
ProgramType programType;
try {
programType = ProgramType.valueOfCategoryName(triggerProgramType);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage(), e);
}
ProgramScheduleStatus programScheduleStatus;
try {
programScheduleStatus = scheduleStatus == null ? null : ProgramScheduleStatus.valueOf(scheduleStatus);
} catch (IllegalArgumentException e) {
throw new BadRequestException(String.format("Invalid schedule status '%s'. Must be one of %s.", scheduleStatus, Joiner.on(',').join(ProgramScheduleStatus.values())), e);
}
ProgramId triggerProgramId = new NamespaceId(triggerNamespaceId).app(triggerAppName, triggerAppVersion).program(programType, triggerProgramName);
Set<co.cask.cdap.api.ProgramStatus> queryProgramStatuses = new HashSet<>();
if (triggerProgramStatuses != null) {
try {
for (String status : triggerProgramStatuses.split(",")) {
queryProgramStatuses.add(co.cask.cdap.api.ProgramStatus.valueOf(status));
}
} catch (Exception e) {
throw new BadRequestException(String.format("Unable to parse program statuses '%s'. Must be comma separated " + "valid ProgramStatus names such as COMPLETED, FAILED, KILLED.", triggerProgramStatuses), e);
}
} else {
// Query for schedules with all the statuses if no query status is specified
Collections.addAll(queryProgramStatuses, co.cask.cdap.api.ProgramStatus.values());
}
List<ScheduleDetail> details = programScheduleService.findTriggeredBy(triggerProgramId, queryProgramStatuses).stream().filter(record -> programScheduleStatus == null || record.getMeta().getStatus().equals(programScheduleStatus)).map(ProgramScheduleRecord::toScheduleDetail).collect(Collectors.toList());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(details, Schedulers.SCHEDULE_DETAILS_TYPE));
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method doAddSchedule.
private void doAddSchedule(FullHttpRequest request, HttpResponder responder, String namespace, String appName, String appVersion, String scheduleName) throws Exception {
final ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
ScheduleDetail scheduleFromRequest = readScheduleDetailBody(request, scheduleName);
if (scheduleFromRequest.getProgram() == null) {
throw new BadRequestException("No program was specified for the schedule");
}
if (scheduleFromRequest.getProgram().getProgramType() == null) {
throw new BadRequestException("No program type was specified for the schedule");
}
if (scheduleFromRequest.getProgram().getProgramName() == null) {
throw new BadRequestException("No program name was specified for the schedule");
}
if (scheduleFromRequest.getTrigger() == null) {
throw new BadRequestException("No trigger was specified for the schedule");
}
ProgramType programType = ProgramType.valueOfSchedulableType(scheduleFromRequest.getProgram().getProgramType());
String programName = scheduleFromRequest.getProgram().getProgramName();
ProgramId programId = applicationId.program(programType, programName);
if (!lifecycleService.programExists(programId)) {
throw new NotFoundException(programId);
}
String description = Objects.firstNonNull(scheduleFromRequest.getDescription(), "");
Map<String, String> properties = Objects.firstNonNull(scheduleFromRequest.getProperties(), EMPTY_PROPERTIES);
List<? extends Constraint> constraints = Objects.firstNonNull(scheduleFromRequest.getConstraints(), NO_CONSTRAINTS);
long timeoutMillis = Objects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS);
ProgramSchedule schedule = new ProgramSchedule(scheduleName, description, programId, properties, scheduleFromRequest.getTrigger(), constraints, timeoutMillis);
programScheduleService.add(schedule);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramRuntimeArgs.
/**
* Get runtime args of a program with app version.
*/
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runtimeargs")
public void getProgramRuntimeArgs(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) throws Exception {
ProgramType programType = getProgramType(type);
ProgramId programId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName);
getProgramIdRuntimeArgs(programId, responder);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method programHistory.
/**
* Returns program runs of an app version based on options it returns either currently running or completed or failed.
* Default it returns all.
*/
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs")
public void programHistory(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, @QueryParam("status") String status, @QueryParam("start") String startTs, @QueryParam("end") String endTs, @QueryParam("limit") @DefaultValue("100") final int resultLimit) throws Exception {
ProgramType programType = getProgramType(type);
if (programType == null || programType == ProgramType.WEBAPP) {
throw new NotFoundException(String.format("Program history is not supported for program type '%s'.", type));
}
long start = (startTs == null || startTs.isEmpty()) ? 0 : Long.parseLong(startTs);
long end = (endTs == null || endTs.isEmpty()) ? Long.MAX_VALUE : Long.parseLong(endTs);
ProgramId program = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName);
if (!lifecycleService.programExists(program)) {
throw new NotFoundException(program);
}
getRuns(responder, program, status, start, end, resultLimit);
}
Aggregations