@VisibleForTesting int getPartition(ScheduleId scheduleId) { // Similar to ScheduleId#hashCode, but that is not consistent across runtimes due to how Enum#hashCode works. // Ensure that the hash won't change across runtimes: int hash = Hashing.murmur3_32().newHasher() .putString(scheduleId.getNamespace()) .putString(scheduleId.getApplication()) .putString(scheduleId.getVersion()) .putString(scheduleId.getSchedule()) .hash().asInt(); return Math.abs(hash) % numPartitions; }
@VisibleForTesting int getPartition(ScheduleId scheduleId) { // Similar to ScheduleId#hashCode, but that is not consistent across runtimes due to how Enum#hashCode works. // Ensure that the hash won't change across runtimes: int hash = Hashing.murmur3_32().newHasher() .putString(scheduleId.getNamespace()) .putString(scheduleId.getApplication()) .putString(scheduleId.getVersion()) .putString(scheduleId.getSchedule()) .hash().asInt(); return Math.abs(hash) % numPartitions; }
public void resume(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/resume", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
public void suspend(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/suspend", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
public String getStatus(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/status", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject(); return responseObject.get("status"); }
/** * Delete an existing schedule. * * @param scheduleId the ID of the schedule to be deleted */ public void delete(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
private void doUpdate(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException { String path = String.format("apps/%s/versions/%s/schedules/%s/update", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpRequest request = HttpRequest.post(url).withBody(json).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(programId.getType().getSchedulableType(), programId.getProgram()); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), description, programInfo, properties, trigger, constraints, timeoutMillis, null); } }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(programId.getType().getSchedulableType(), programId.getProgram()); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), description, programInfo, properties, trigger, constraints, timeoutMillis, null); } }
/** * Enable a schedule in an application. * * @param scheduleId the id of the schedule to be enabled */ public void enableSchedule(ScheduleId scheduleId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException, BadRequestException { String path = String.format("apps/%s/versions/%s/program-type/schedules/program-id/%s/action/enable", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); HttpResponse response = restClient.execute(HttpMethod.PUT, config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST); int responseCode = response.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(scheduleId.getParent()); } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString())); } } }
ScheduleId scheduleId = (ScheduleId) namespacedEntityId; String namespaceId = scheduleId.getNamespace(); String appId = scheduleId.getApplication(); String version = scheduleId.getVersion(); String scheduleName = scheduleId.getSchedule();
private void doAdd(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException { String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path); HttpRequest request = HttpRequest.put(url).withBody(json).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } else if (HttpURLConnection.HTTP_CONFLICT == response.getResponseCode()) { throw new AlreadyExistsException(scheduleId); } }
ScheduleId scheduleId = (ScheduleId) namespacedEntityId; String namespaceId = scheduleId.getNamespace(); String appId = scheduleId.getApplication(); String version = scheduleId.getVersion(); String scheduleName = scheduleId.getSchedule();
public void enableSchedule(ScheduleId scheduleId) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/program-type/schedules/program-id/%s/action/enable", getNamespacePath(scheduleId.getNamespace()), scheduleId.getVersion(), scheduleId.getApplication(), scheduleId.getSchedule()); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, 0); programLifecycleHttpHandler.performAction(request, responder, scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), "schedules", scheduleId.getSchedule(), "enable"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Enable schedule failed"); }
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()); } }
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()); } }