use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getMapReduceInfo.
/**
* Relays job-level and task-level information about a particular MapReduce program run.
*/
@GET
@Path("/apps/{app-id}/mapreduce/{mapreduce-id}/runs/{run-id}/info")
public void getMapReduceInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("mapreduce-id") String mapreduceId, @PathParam("run-id") String runId) throws IOException, NotFoundException {
ProgramId programId = new ProgramId(namespaceId, appId, ProgramType.MAPREDUCE, mapreduceId);
ProgramRunId run = programId.run(runId);
ApplicationSpecification appSpec = store.getApplication(programId.getParent());
if (appSpec == null) {
throw new NotFoundException(programId.getApplication());
}
if (!appSpec.getMapReduce().containsKey(mapreduceId)) {
throw new NotFoundException(programId);
}
RunRecordMeta runRecordMeta = store.getRun(programId, runId);
if (runRecordMeta == null) {
throw new NotFoundException(run);
}
MRJobInfo mrJobInfo = mrJobInfoFetcher.getMRJobInfo(run.toId());
mrJobInfo.setState(runRecordMeta.getStatus().name());
// Multiple startTs / endTs by 1000, to be consistent with Task-level start/stop times returned by JobClient
// in milliseconds. RunRecord returns seconds value.
mrJobInfo.setStartTime(TimeUnit.SECONDS.toMillis(runRecordMeta.getStartTs()));
Long stopTs = runRecordMeta.getStopTs();
if (stopTs != null) {
mrJobInfo.setStopTime(TimeUnit.SECONDS.toMillis(stopTs));
}
// JobClient (in DistributedMRJobInfoFetcher) can return NaN as some of the values, and GSON otherwise fails
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
responder.sendJson(HttpResponseStatus.OK, mrJobInfo, mrJobInfo.getClass(), gson);
}
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);
}
Aggregations