use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class MonitorHandler method updateServiceLogLevels.
/**
* Update log levels for this service.
*/
@Path("system/services/{service-name}/loglevels")
@PUT
public void updateServiceLogLevels(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception {
if (!serviceManagementMap.containsKey(serviceName)) {
throw new NotFoundException(String.format("Invalid service name %s", serviceName));
}
MasterServiceManager masterServiceManager = serviceManagementMap.get(serviceName);
if (!masterServiceManager.isServiceEnabled()) {
throw new ForbiddenException(String.format("Failed to update log levels for service %s " + "because the service is not enabled", serviceName));
}
try {
// we are decoding the body to Map<String, String> instead of Map<String, LogEntry.Level> here since Gson will
// serialize invalid enum values to null, which is allowed for log level, instead of throw an Exception.
masterServiceManager.updateServiceLogLevels(transformLogLevelsMap(decodeArguments(request)));
responder.sendStatus(HttpResponseStatus.OK);
} catch (IllegalStateException ise) {
throw new ServiceUnavailableException(String.format("Failed to update log levels for service %s " + "because the service may not be ready yet", serviceName));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid Json in the body");
}
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramIdRuntimeArgs.
private void getProgramIdRuntimeArgs(ProgramId programId, HttpResponder responder) throws BadRequestException, NotImplementedException, NotFoundException, UnauthorizedException {
ProgramType programType = programId.getType();
if (programType == null || programType == ProgramType.WEBAPP) {
throw new NotFoundException(String.format("Getting program runtime arguments is not supported for program " + "type '%s'.", programType));
}
responder.sendJson(HttpResponseStatus.OK, lifecycleService.getRuntimeArgs(programId));
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method saveProgramIdRuntimeArgs.
private void saveProgramIdRuntimeArgs(ProgramId programId, HttpRequest request, HttpResponder responder) throws Exception {
ProgramType programType = programId.getType();
if (programType == null || programType == ProgramType.WEBAPP) {
throw new NotFoundException(String.format("Saving program runtime arguments is not supported for program " + "type '%s'.", programType));
}
lifecycleService.saveRuntimeArgs(programId, decodeArguments(request));
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method doAddSchedule.
private void doAddSchedule(HttpRequest 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, false, new Function<JsonElement, ScheduleDetail>() {
@Override
public ScheduleDetail apply(@Nullable JsonElement input) {
ScheduleSpecification scheduleSpec = GSON.fromJson(input, ScheduleSpecification.class);
return toScheduleDetail(applicationId, scheduleSpec);
}
});
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.getProgramSpecification(programId) == null) {
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);
programScheduler.addSchedule(schedule);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.common.NotFoundException 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);
ProgramSpecification specification = lifecycleService.getProgramSpecification(program);
if (specification == null) {
throw new NotFoundException(program);
}
getRuns(responder, program, status, start, end, resultLimit);
}
Aggregations