private <T> Collection<T> getCollection(Function<String, String> hostToUrl, String type, TypeReference<Collection<T>> typeReference) { return getCollectionWithParams(hostToUrl, type, Optional.absent(), typeReference); }
public Collection<SingularityRequestHistory> getQueuedRequestUpdates(String webhookId) { final Function<String, String> requestUri = (host) -> String.format(WEBHOOKS_GET_QUEUED_REQUEST_UPDATES_FORMAT, getApiBase(host)); Builder<String, Object> queryParamBuider = ImmutableMap.<String, Object>builder().put("webhookId", webhookId); return getCollectionWithParams(requestUri, "request updates", Optional.of(queryParamBuider.build()), REQUEST_UPDATES_COLLECTION); }
public Collection<SingularityDeployUpdate> getQueuedDeployUpdates(String webhookId) { final Function<String, String> requestUri = (host) -> String.format(WEBHOOKS_GET_QUEUED_DEPLOY_UPDATES_FORMAT, getApiBase(host)); Builder<String, Object> queryParamBuider = ImmutableMap.<String, Object>builder().put("webhookId", webhookId); return getCollectionWithParams(requestUri, "deploy updates", Optional.of(queryParamBuider.build()), DEPLOY_UPDATES_COLLECTION); }
public Collection<SingularityTaskHistoryUpdate> getQueuedTaskUpdates(String webhookId) { final Function<String, String> requestUri = (host) -> String.format(WEBHOOKS_GET_QUEUED_TASK_UPDATES_FORMAT, getApiBase(host)); Builder<String, Object> queryParamBuider = ImmutableMap.<String, Object>builder().put("webhookId", webhookId); return getCollectionWithParams(requestUri, "request updates", Optional.of(queryParamBuider.build()), TASK_UPDATES_COLLECTION); }
public Collection<SingularityTaskIdHistory> getInactiveTaskHistoryForRequest(String requestId, int count, int page, Optional<String> host, Optional<String> runId, Optional<ExtendedTaskState> lastTaskStatus, Optional<Long> startedBefore, Optional<Long> startedAfter, Optional<Long> updatedBefore, Optional<Long> updatedAfter, Optional<OrderDirection> orderDirection) { final Function<String, String> requestUri = (singularityHost) -> String.format(REQUEST_INACTIVE_TASKS_HISTORY_FORMAT, getApiBase(singularityHost), requestId); final String type = String.format("inactive (failed, killed, lost) task history for request %s", requestId); Map<String, Object> params = taskSearchParams(Optional.of(requestId), Optional.absent(), runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection, count, page); return getCollectionWithParams(requestUri, type, Optional.of(params), TASKID_HISTORY_COLLECTION); }
private Collection<SingularityRack> getRacks(Optional<MachineState> rackState) { final Function<String, String> requestUri = (host) -> String.format(RACKS_FORMAT, getApiBase(host)); Optional<Map<String, Object>> maybeQueryParams = Optional.absent(); String type = "racks"; if (rackState.isPresent()) { maybeQueryParams = Optional.of(ImmutableMap.of("state", rackState.get().toString())); type = String.format("%s racks", rackState.get().toString()); } return getCollectionWithParams(requestUri, type, maybeQueryParams, RACKS_COLLECTION); }
public Collection<SingularityTaskIdHistory> getInactiveTaskHistoryForRequest(String requestId, int count, int page, Optional<String> host, Optional<String> deployId, Optional<String> runId, Optional<ExtendedTaskState> lastTaskStatus, Optional<Long> startedBefore, Optional<Long> startedAfter, Optional<Long> updatedBefore, Optional<Long> updatedAfter, Optional<OrderDirection> orderDirection) { final Function<String, String> requestUri = (singularityHost) -> String.format(REQUEST_INACTIVE_TASKS_HISTORY_FORMAT, getApiBase(singularityHost), requestId); final String type = String.format("inactive (failed, killed, lost) task history for request %s", requestId); Map<String, Object> params = taskSearchParams(Optional.of(requestId), deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection, count, page); return getCollectionWithParams(requestUri, type, Optional.of(params), TASKID_HISTORY_COLLECTION); }
public Collection<SingularityTaskIdHistory> getTaskHistory(Optional<String> requestId, Optional<String> deployId, Optional<String> runId, Optional<String> host, Optional<ExtendedTaskState> lastTaskStatus, Optional<Long> startedBefore, Optional<Long> startedAfter, Optional<Long> updatedBefore, Optional<Long> updatedAfter, Optional<OrderDirection> orderDirection, Integer count, Integer page) { final Function<String, String> requestUri = (singularityHost) -> String.format(TASKS_HISTORY_FORMAT, getApiBase(singularityHost)); Map<String, Object> params = taskSearchParams(requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection, count, page); return getCollectionWithParams(requestUri, "task id history", Optional.of(params), TASKID_HISTORY_COLLECTION); }
/** * Retrieve a paged list of updates for a particular {@link SingularityRequest} * * @param requestId * Request ID to look up * @param count * Number of items to return per page * @param page * Which page of items to return * @return * A list of {@link SingularityRequestHistory} */ public Collection<SingularityRequestHistory> getHistoryForRequest(String requestId, Optional<Integer> count, Optional<Integer> page) { final Function<String, String> requestUri = (host) -> String.format(REQUEST_HISTORY_FORMAT, getApiBase(host), requestId); Optional<Map<String, Object>> maybeQueryParams = Optional.absent(); ImmutableMap.Builder<String, Object> queryParamsBuilder = ImmutableMap.builder(); if (count.isPresent() ) { queryParamsBuilder.put("count", count.get()); } if (page.isPresent()) { queryParamsBuilder.put("page", page.get()); } Map<String, Object> queryParams = queryParamsBuilder.build(); if (!queryParams.isEmpty()) { maybeQueryParams = Optional.of(queryParams); } return getCollectionWithParams(requestUri, "request history", maybeQueryParams, REQUEST_HISTORY_COLLECTION); }
/** * Retrieve the list of all known slaves, optionally filtering by a particular slave state * * @param slaveState * Optionally specify a particular state to filter slaves by * @return * A collection of {@link SingularitySlave} */ public Collection<SingularitySlave> getSlaves(Optional<MachineState> slaveState) { final Function<String, String> requestUri = (host) -> String.format(SLAVES_FORMAT, getApiBase(host)); Optional<Map<String, Object>> maybeQueryParams = Optional.absent(); String type = "slaves"; if (slaveState.isPresent()) { maybeQueryParams = Optional.of(ImmutableMap.of("state", slaveState.get().toString())); type = String.format("%s slaves", slaveState.get().toString()); } return getCollectionWithParams(requestUri, type, maybeQueryParams, SLAVES_COLLECTION); }