use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class HistoryResource method getRequestHistoryForRequestWithMetadata.
@GET
@Path("/request/{requestId}/requests/withmetadata")
@Operation(summary = "Get request history for a single request")
public SingularityPaginatedResponse<SingularityRequestHistory> getRequestHistoryForRequestWithMetadata(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Request ID to look up") @PathParam("requestId") String requestId, @Parameter(description = "Maximum number of items to return") @QueryParam("count") Integer count, @Parameter(description = "Which page of items to view") @QueryParam("page") Integer page, @Parameter(description = "Skip checking zookeeper, items that have not been persisted yet may not appear") @QueryParam("skipZk") @DefaultValue("true") boolean skipZk) {
authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
SingularityRequestHistoryQuery requestHistoryQuery = new SingularityRequestHistoryQuery(requestId, Optional.empty(), Optional.empty(), Optional.empty());
final Optional<Integer> dataCount = requestHistoryHelper.getBlendedHistoryCount(requestHistoryQuery, skipZk);
final Integer limitCount = getLimitCount(count);
final Integer limitStart = getLimitStart(limitCount, page);
final List<SingularityRequestHistory> data = requestHistoryHelper.getBlendedHistory(requestHistoryQuery, limitStart, limitCount, skipZk);
final Optional<Integer> pageCount = getPageCount(dataCount, limitCount);
return new SingularityPaginatedResponse<>(dataCount, pageCount, Optional.ofNullable(page), data);
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class SingularityWebhookSender method checkRequestUpdates.
private int checkRequestUpdates(SingularityWebhook webhook, List<CompletableFuture<Response>> webhookFutures) {
final List<SingularityRequestHistory> requestUpdates = webhookManager.getQueuedRequestHistoryForHook(webhook.getId());
int numRequestUpdates = 0;
for (SingularityRequestHistory requestUpdate : requestUpdates) {
String concreteUri = applyPlaceholders(webhook.getUri(), requestUpdate);
webhookFutures.add(webhookSemaphore.call(() -> executeWebhookAsync(concreteUri, requestUpdate, new SingularityRequestWebhookAsyncHandler(webhookManager, webhook, requestUpdate, shouldDeleteUpdateOnFailure(numRequestUpdates, requestUpdate.getCreatedAt())))));
}
return requestUpdates.size();
}
use of com.hubspot.singularity.SingularityRequestHistory in project Singularity by HubSpot.
the class BlendedHistoryTest method testBlendedRequestHistory.
// DESCENDING
@Test
public void testBlendedRequestHistory() {
HistoryManager hm = mock(HistoryManager.class);
String rid = "rid";
SingularityRequestHistoryQuery requestHistoryQuery = new SingularityRequestHistoryQuery(rid, Optional.empty(), Optional.empty(), Optional.empty());
request = new SingularityRequestBuilder(rid, RequestType.WORKER).build();
RequestHistoryHelper rhh = new RequestHistoryHelper(requestManager, hm, new SingularityConfiguration());
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
Assertions.assertTrue(rhh.getBlendedHistory(requestHistoryQuery, 0, 100).isEmpty());
Assertions.assertTrue(!rhh.getFirstHistory(rid).isPresent());
Assertions.assertTrue(!rhh.getLastHistory(rid).isPresent());
mockRequestHistory(hm, Arrays.asList(makeHistory(52, RequestHistoryType.EXITED_COOLDOWN), makeHistory(51, RequestHistoryType.ENTERED_COOLDOWN), makeHistory(50, RequestHistoryType.CREATED)));
List<SingularityRequestHistory> history = rhh.getBlendedHistory(requestHistoryQuery, 0, 5);
Assertions.assertTrue(history.size() == 3);
saveHistory(100, RequestHistoryType.DELETED);
saveHistory(120, RequestHistoryType.CREATED);
history = rhh.getBlendedHistory(requestHistoryQuery, 0, 5);
Assertions.assertTrue(history.size() == 5);
Assertions.assertTrue(history.get(0).getCreatedAt() == 120);
Assertions.assertTrue(history.get(4).getCreatedAt() == 50);
history = rhh.getBlendedHistory(requestHistoryQuery, 1, 5);
Assertions.assertTrue(history.size() == 4);
Assertions.assertTrue(history.get(0).getCreatedAt() == 100);
Assertions.assertTrue(history.get(3).getCreatedAt() == 50);
history = rhh.getBlendedHistory(requestHistoryQuery, 2, 5);
Assertions.assertTrue(history.size() == 3);
Assertions.assertTrue(history.get(0).getCreatedAt() == 52);
Assertions.assertTrue(history.get(2).getCreatedAt() == 50);
mockRequestHistory(hm, Collections.<SingularityRequestHistory>emptyList());
history = rhh.getBlendedHistory(requestHistoryQuery, 3, 5);
Assertions.assertTrue(history.isEmpty());
history = rhh.getBlendedHistory(requestHistoryQuery, 1, 5);
Assertions.assertTrue(history.size() == 1);
Assertions.assertTrue(history.get(0).getCreatedAt() == 100);
Assertions.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 100);
Assertions.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
mockRequestHistory(hm, Arrays.asList(makeHistory(1, RequestHistoryType.EXITED_COOLDOWN)));
Assertions.assertTrue(rhh.getFirstHistory(rid).get().getCreatedAt() == 1);
Assertions.assertTrue(rhh.getLastHistory(rid).get().getCreatedAt() == 120);
}
Aggregations