Search in sources :

Example 11 with SingularityRequestHistory

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);
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityRequestHistoryQuery(com.hubspot.singularity.SingularityRequestHistoryQuery) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 12 with SingularityRequestHistory

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();
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory)

Example 13 with SingularityRequestHistory

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);
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) RequestHistoryHelper(com.hubspot.singularity.data.history.RequestHistoryHelper) HistoryManager(com.hubspot.singularity.data.history.HistoryManager) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) SingularityRequestHistoryQuery(com.hubspot.singularity.SingularityRequestHistoryQuery) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityRequestHistory (com.hubspot.singularity.SingularityRequestHistory)13 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)3 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)3 Test (org.junit.jupiter.api.Test)3 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityRequest (com.hubspot.singularity.SingularityRequest)2 RequestHistoryType (com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType)2 SingularityRequestHistoryQuery (com.hubspot.singularity.SingularityRequestHistoryQuery)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 ArrayList (java.util.ArrayList)2 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 JavaUtils (com.hubspot.mesos.JavaUtils)1 CrashLoopInfo (com.hubspot.singularity.CrashLoopInfo)1 RequestCleanupType (com.hubspot.singularity.RequestCleanupType)1 RequestState (com.hubspot.singularity.RequestState)1 RequestType (com.hubspot.singularity.RequestType)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)1