use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method saveProgramRuntimeArgs.
/**
* Save runtime args of program with app version.
*/
@PUT
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runtimeargs")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void saveProgramRuntimeArgs(FullHttpRequest 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);
saveProgramIdRuntimeArgs(programId, request, responder);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getProgramIdRuntimeArgs.
private void getProgramIdRuntimeArgs(ProgramId programId, HttpResponder responder) throws Exception {
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, GSON.toJson(lifecycleService.getRuntimeArgs(programId)));
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method doPerformAction.
private void doPerformAction(FullHttpRequest request, HttpResponder responder, String namespaceId, String appId, String appVersion, String type, String programId, String action) throws Exception {
ApplicationId applicationId = new ApplicationId(namespaceId, appId, appVersion);
if (SCHEDULES.equals(type)) {
ScheduleId scheduleId = applicationId.schedule(programId);
if (action.equals("disable") || action.equals("suspend")) {
programScheduleService.suspend(scheduleId);
} else if (action.equals("enable") || action.equals("resume")) {
programScheduleService.resume(scheduleId);
} else {
throw new BadRequestException("Action for schedules may only be 'enable', 'disable', 'suspend', or 'resume' but is'" + action + "'");
}
responder.sendJson(HttpResponseStatus.OK, "OK");
return;
}
ProgramType programType;
try {
programType = ProgramType.valueOfCategoryName(type);
} catch (IllegalArgumentException e) {
throw new BadRequestException(String.format("Unknown program type '%s'", type), e);
}
ProgramId program = applicationId.program(programType, programId);
Map<String, String> args = decodeArguments(request);
// we have already validated that the action is valid
switch(action.toLowerCase()) {
case "start":
lifecycleService.start(program, args, false);
break;
case "debug":
if (!isDebugAllowed(programType)) {
throw new NotImplementedException(String.format("debug action is not implemented for program type %s", programType));
}
lifecycleService.start(program, args, true);
break;
case "stop":
lifecycleService.stop(program);
break;
default:
throw new NotFoundException(String.format("%s action was not found", action));
}
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method getStatus.
/**
* Returns status of a type specified by the type{flows,workflows,mapreduce,spark,services,schedules}.
*/
@GET
@Path("/apps/{app-id}/versions/{version-id}/{program-type}/{program-id}/status")
public void getStatus(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("version-id") String versionId, @PathParam("program-type") String type, @PathParam("program-id") String programId) throws Exception {
ApplicationId applicationId = new ApplicationId(namespaceId, appId, versionId);
if (SCHEDULES.equals(type)) {
JsonObject json = new JsonObject();
ScheduleId scheduleId = applicationId.schedule(programId);
ApplicationSpecification appSpec = store.getApplication(applicationId);
if (appSpec == null) {
throw new NotFoundException(applicationId);
}
json.addProperty("status", programScheduleService.getStatus(scheduleId).toString());
responder.sendJson(HttpResponseStatus.OK, json.toString());
return;
}
ProgramType programType;
try {
programType = ProgramType.valueOfCategoryName(type);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
}
ProgramId program = applicationId.program(programType, programId);
ProgramStatus programStatus = lifecycleService.getProgramStatus(program);
Map<String, String> status = ImmutableMap.of("status", programStatus.name());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(status));
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method updateLogLevels.
private void updateLogLevels(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 {
// 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.
lifecycleService.updateProgramLogLevels(new ApplicationId(namespace, appName, appVersion).program(programType, programName), transformLogLevelsMap(decodeArguments(request)), component, runId);
responder.sendStatus(HttpResponseStatus.OK);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid JSON in body");
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
} catch (SecurityException e) {
throw new UnauthorizedException("Unauthorized to update the log levels");
}
}
Aggregations