protected List<ScheduleDetail> getSchedules(String namespace, String appName, String appVersion, String workflowName, ProgramScheduleStatus status) throws Exception { String schedulesUrl = String.format("apps/%s/versions/%s/workflows/%s/schedules?schedule-status=%s", appName, appVersion, workflowName, status.name()); return doGetSchedules(namespace, schedulesUrl); }
ProgramScheduleStatus programScheduleStatus; try { programScheduleStatus = scheduleStatus == null ? null : ProgramScheduleStatus.valueOf(scheduleStatus); } catch (IllegalArgumentException e) { throw new BadRequestException(String.format("Invalid schedule status '%s'. Must be one of %s.", scheduleStatus, Joiner.on(',').join(ProgramScheduleStatus.values())), e); .filter(record -> programScheduleStatus == null || record.getMeta().getStatus().equals(programScheduleStatus)) .map(ProgramScheduleRecord::toScheduleDetail) .collect(Collectors.toList());
/** * 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)); }
/** * Reads the meta data from a row in the schedule store. * * @throws IllegalStateException if one of the expected fields is missing or ill-formed. */ private ProgramScheduleMeta extractMetaFromRow(ScheduleId scheduleId, Row row) { Long updatedTime = row.getLong(UPDATED_COLUMN_BYTES); String statusString = row.getString(STATUS_COLUMN_BYTES); try { Preconditions.checkArgument(updatedTime != null, "Last-updated timestamp is null"); Preconditions.checkArgument(statusString != null, "schedule status is null"); ProgramScheduleStatus status = ProgramScheduleStatus.valueOf(statusString); return new ProgramScheduleMeta(status, updatedTime); } catch (IllegalArgumentException e) { throw new IllegalStateException( String.format("Unexpected stored meta data for schedule %s: %s", scheduleId, e.getMessage())); } }
/** * Reads the meta data from a row in the schedule store. * * @throws IllegalStateException if one of the expected fields is missing or ill-formed. */ private ProgramScheduleMeta extractMetaFromRow(ScheduleId scheduleId, Row row) { Long updatedTime = row.getLong(UPDATED_COLUMN_BYTES); String statusString = row.getString(STATUS_COLUMN_BYTES); try { Preconditions.checkArgument(updatedTime != null, "Last-updated timestamp is null"); Preconditions.checkArgument(statusString != null, "schedule status is null"); ProgramScheduleStatus status = ProgramScheduleStatus.valueOf(statusString); return new ProgramScheduleMeta(status, updatedTime); } catch (IllegalArgumentException e) { throw new IllegalStateException( String.format("Unexpected stored meta data for schedule %s: %s", scheduleId, e.getMessage())); } }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram()); ScheduleId scheduleId = schedule.getScheduleId(); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name()); } }
ProgramScheduleStatus programScheduleStatus; try { programScheduleStatus = scheduleStatus == null ? null : ProgramScheduleStatus.valueOf(scheduleStatus); } catch (IllegalArgumentException e) { throw new BadRequestException(String.format("Invalid schedule status '%s'. Must be one of %s.", scheduleStatus, Joiner.on(',').join(ProgramScheduleStatus.values())), e); .filter(record -> programScheduleStatus == null || record.getMeta().getStatus().equals(programScheduleStatus)) .map(ProgramScheduleRecord::toScheduleDetail) .collect(Collectors.toList());
/** * 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)); }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram()); ScheduleId scheduleId = schedule.getScheduleId(); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name()); } }
status = statusStr == null ? null : ProgramScheduleStatus.valueOf(statusStr); } catch (IllegalArgumentException e) { throw new BadRequestException(String.format("Invalid schedule status '%s'. Must be one of %s.", statusStr, Joiner.on(',').join(ProgramScheduleStatus.values())), e); predicate = predicate.and(record -> record.getMeta().getStatus().equals(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; }
Assert.assertEquals(ProgramScheduleStatus.SUSPENDED.name(), scheduleManager.status(HttpURLConnection.HTTP_OK)); Assert.assertEquals(ProgramScheduleStatus.SCHEDULED.name(), scheduleManager.status(HttpURLConnection.HTTP_OK)); Assert.assertEquals(ProgramScheduleStatus.SUSPENDED.name(), scheduleManager.status(HttpURLConnection.HTTP_OK)); Assert.assertEquals(ProgramScheduleStatus.SUSPENDED.name(), workflowManager.getSchedule(scheduleId.getSchedule()).status(HttpURLConnection.HTTP_OK)); Assert.assertEquals(ProgramScheduleStatus.SUSPENDED.name(), workflowManager.getSchedule(scheduleId.getSchedule()).status(HttpURLConnection.HTTP_OK));
status = statusStr == null ? null : ProgramScheduleStatus.valueOf(statusStr); } catch (IllegalArgumentException e) { throw new BadRequestException(String.format("Invalid schedule status '%s'. Must be one of %s.", statusStr, Joiner.on(',').join(ProgramScheduleStatus.values())), e); predicate = predicate.and(record -> record.getMeta().getStatus().equals(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; }
/** * 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)); } }