Search in sources :

Example 51 with ProgramId

use of co.cask.cdap.proto.id.ProgramId 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);
        json.addProperty("status", lifecycleService.getScheduleStatus(scheduleId).toString());
        responder.sendJson(HttpResponseStatus.OK, json);
        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, status);
}
Also used : JsonObject(com.google.gson.JsonObject) BadRequestException(co.cask.cdap.common.BadRequestException) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ScheduleId(co.cask.cdap.proto.id.ScheduleId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramStatus(co.cask.cdap.proto.ProgramStatus) BatchProgramStatus(co.cask.cdap.proto.BatchProgramStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 52 with ProgramId

use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.

the class ProgramLifecycleHttpHandler method getFlowletInstances.

/* ********************* Flow/Flowlet APIs ***********************************************************/
/**
   * Returns number of instances for a flowlet within a flow.
   */
@GET
@Path("/apps/{app-id}/flows/{flow-id}/flowlets/{flowlet-id}/instances")
public void getFlowletInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("flow-id") String flowId, @PathParam("flowlet-id") String flowletId) {
    try {
        int count = store.getFlowletInstances(new ProgramId(namespaceId, appId, ProgramType.FLOW, flowId), flowletId);
        responder.sendJson(HttpResponseStatus.OK, new Instances(count));
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (Throwable e) {
        if (respondIfElementNotFound(e, responder)) {
            return;
        }
        throw e;
    }
}
Also used : BatchRunnableInstances(co.cask.cdap.proto.BatchRunnableInstances) Instances(co.cask.cdap.proto.Instances) ServiceInstances(co.cask.cdap.proto.ServiceInstances) ProgramId(co.cask.cdap.proto.id.ProgramId) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 53 with ProgramId

use of co.cask.cdap.proto.id.ProgramId 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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) MRJobInfo(co.cask.cdap.proto.MRJobInfo) GsonBuilder(com.google.gson.GsonBuilder) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) Gson(com.google.gson.Gson) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 54 with ProgramId

use of co.cask.cdap.proto.id.ProgramId 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);
}
Also used : NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) JsonElement(com.google.gson.JsonElement) BadRequestException(co.cask.cdap.common.BadRequestException) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ScheduleSpecification(co.cask.cdap.api.schedule.ScheduleSpecification)

Example 55 with ProgramId

use of co.cask.cdap.proto.id.ProgramId 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);
}
Also used : BadRequestException(co.cask.cdap.common.BadRequestException) ProgramType(co.cask.cdap.proto.ProgramType) ProgramId(co.cask.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

ProgramId (co.cask.cdap.proto.id.ProgramId)209 Test (org.junit.Test)89 ApplicationId (co.cask.cdap.proto.id.ApplicationId)69 Path (javax.ws.rs.Path)45 StreamId (co.cask.cdap.proto.id.StreamId)35 DatasetId (co.cask.cdap.proto.id.DatasetId)34 RunId (org.apache.twill.api.RunId)34 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)31 NamespaceId (co.cask.cdap.proto.id.NamespaceId)29 ProgramType (co.cask.cdap.proto.ProgramType)25 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)24 IOException (java.io.IOException)24 NotFoundException (co.cask.cdap.common.NotFoundException)22 HttpResponse (org.apache.http.HttpResponse)19 ArrayList (java.util.ArrayList)18 GET (javax.ws.rs.GET)18 Id (co.cask.cdap.proto.Id)16 File (java.io.File)15 POST (javax.ws.rs.POST)15 ArtifactId (co.cask.cdap.proto.id.ArtifactId)13