use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method programRunRecord.
/**
* Returns run record for a particular run of a program of an app version.
*/
@GET
@Path("/apps/{app-name}/versions/{app-version}/{program-type}/{program-name}/runs/{run-id}")
public void programRunRecord(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 NotFoundException {
ProgramType programType = getProgramType(type);
if (programType == null || programType == ProgramType.WEBAPP) {
throw new NotFoundException(String.format("Program run record is not supported for program type '%s'.", programType));
}
ProgramId progId = new ApplicationId(namespaceId, appName, appVersion).program(programType, programName);
RunRecordMeta runRecordMeta = store.getRun(progId.run(runid));
if (runRecordMeta != null) {
RunRecord runRecord = RunRecord.builder(runRecordMeta).build();
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runRecord));
return;
}
throw new NotFoundException(progId.run(runid));
}
use of co.cask.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 = ProgramType.valueOfCategoryName(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 endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(discoverableName));
if (endpointStrategy.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 co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class Schedulers method toProgramSchedule.
public static ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleSpecification spec) {
Schedule schedule = spec.getSchedule();
ProgramType programType = ProgramType.valueOfSchedulableType(spec.getProgram().getProgramType());
ProgramId programId = appId.program(programType, spec.getProgram().getProgramName());
Trigger trigger;
if (schedule instanceof TimeSchedule) {
TimeSchedule timeSchedule = (TimeSchedule) schedule;
trigger = new TimeTrigger(timeSchedule.getCronEntry());
} else {
StreamSizeSchedule streamSchedule = (StreamSizeSchedule) schedule;
StreamId streamId = programId.getNamespaceId().stream(streamSchedule.getStreamName());
trigger = new StreamSizeTrigger(streamId, streamSchedule.getDataTriggerMB());
}
Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
return new ProgramSchedule(schedule.getName(), schedule.getDescription(), programId, spec.getProperties(), trigger, constraints);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method saveProgramRuntimeArgs.
/**
* Save program runtime args.
*/
@PUT
@Path("/apps/{app-name}/{program-type}/{program-name}/runtimeargs")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void saveProgramRuntimeArgs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-name") String appName, @PathParam("program-type") String type, @PathParam("program-name") String programName) throws Exception {
ProgramType programType = getProgramType(type);
ProgramId programId = new ProgramId(namespaceId, appName, programType, programName);
saveProgramIdRuntimeArgs(programId, request, responder);
}
use of co.cask.cdap.proto.ProgramType in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method resetLogLevels.
private void resetLogLevels(HttpRequest 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 {
Set<String> loggerNames = parseBody(request, SET_STRING_TYPE);
lifecycleService.resetProgramLogLevels(new ApplicationId(namespace, appName, appVersion).program(programType, programName), loggerNames == null ? Collections.<String>emptySet() : loggerNames, component, runId);
responder.sendStatus(HttpResponseStatus.OK);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid JSON in body");
} catch (SecurityException e) {
throw new UnauthorizedException("Unauthorized to reset the log levels");
}
}
Aggregations