/** * 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 = getProgramType(type); 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)); }
/** * 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 = getProgramType(type); 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)); }
/** * Update the status of a schedule. This also updates the last-updated timestamp. * @return the updated schedule's last modified timestamp */ public long updateScheduleStatus(ScheduleId scheduleId, ProgramScheduleStatus newStatus) throws NotFoundException { long currentTime = System.currentTimeMillis(); String scheduleKey = rowKeyForSchedule(scheduleId); Row row = store.get(new Get(scheduleKey)); if (row.isEmpty()) { throw new NotFoundException(scheduleId); } Put updatePut = new Put(scheduleKey); updatePut.add(UPDATED_COLUMN_BYTES, currentTime); // record current time updatePut.add(STATUS_COLUMN_BYTES, newStatus.toString()); store.put(updatePut); return currentTime; }
/** * Update the status of a schedule. This also updates the last-updated timestamp. * @return the updated schedule's last modified timestamp */ public long updateScheduleStatus(ScheduleId scheduleId, ProgramScheduleStatus newStatus) throws NotFoundException { long currentTime = System.currentTimeMillis(); String scheduleKey = rowKeyForSchedule(scheduleId); Row row = store.get(new Get(scheduleKey)); if (row.isEmpty()) { throw new NotFoundException(scheduleId); } Put updatePut = new Put(scheduleKey); updatePut.add(UPDATED_COLUMN_BYTES, currentTime); // record current time updatePut.add(STATUS_COLUMN_BYTES, newStatus.toString()); store.put(updatePut); return currentTime; }
/** * Add a schedule to the store. * * @param schedule the schedule to add * @param status the status of the schedule to add * @param currentTime the current time in milliseconds when adding the schedule * @return the new schedule's last modified timestamp * @throws AlreadyExistsException if the schedule already exists */ private void addScheduleWithStatus(ProgramSchedule schedule, ProgramScheduleStatus status, long currentTime) throws AlreadyExistsException { byte[] scheduleKey = rowKeyBytesForSchedule(schedule.getProgramId().getParent().schedule(schedule.getName())); if (!store.get(new Get(scheduleKey)).isEmpty()) { throw new AlreadyExistsException(schedule.getProgramId().getParent().schedule(schedule.getName())); } Put schedulePut = new Put(scheduleKey); schedulePut.add(SCHEDULE_COLUMN_BYTES, GSON.toJson(schedule)); schedulePut.add(UPDATED_COLUMN_BYTES, currentTime); schedulePut.add(STATUS_COLUMN_BYTES, status.toString()); store.put(schedulePut); int count = 0; for (String triggerKey : extractTriggerKeys(schedule)) { byte[] triggerRowKey = rowKeyBytesForTrigger(scheduleKey, count++); store.put(new Put(triggerRowKey, TRIGGER_KEY_COLUMN_BYTES, triggerKey)); } }
/** * Add a schedule to the store. * * @param schedule the schedule to add * @param status the status of the schedule to add * @param currentTime the current time in milliseconds when adding the schedule * @return the new schedule's last modified timestamp * @throws AlreadyExistsException if the schedule already exists */ private void addScheduleWithStatus(ProgramSchedule schedule, ProgramScheduleStatus status, long currentTime) throws AlreadyExistsException { byte[] scheduleKey = rowKeyBytesForSchedule(schedule.getProgramId().getParent().schedule(schedule.getName())); if (!store.get(new Get(scheduleKey)).isEmpty()) { throw new AlreadyExistsException(schedule.getProgramId().getParent().schedule(schedule.getName())); } Put schedulePut = new Put(scheduleKey); schedulePut.add(SCHEDULE_COLUMN_BYTES, GSON.toJson(schedule)); schedulePut.add(UPDATED_COLUMN_BYTES, currentTime); schedulePut.add(STATUS_COLUMN_BYTES, status.toString()); store.put(schedulePut); int count = 0; for (String triggerKey : extractTriggerKeys(schedule)) { byte[] triggerRowKey = rowKeyBytesForTrigger(scheduleKey, count++); store.put(new Put(triggerRowKey, TRIGGER_KEY_COLUMN_BYTES, triggerKey)); } }