Search in sources :

Example 1 with SingularityRequestHistoryQuery

use of com.hubspot.singularity.SingularityRequestHistoryQuery in project Singularity by HubSpot.

the class HistoryResource method getRequestHistoryForRequest.

@GET
@Path("/request/{requestId}/requests")
@Operation(summary = "Get request history for a single request")
public List<SingularityRequestHistory> getRequestHistoryForRequest(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Request ID to look up") @PathParam("requestId") String requestId, @Parameter(description = "Optionally match request histories created before") @QueryParam("createdBefore") Optional<Long> createdBefore, @Parameter(description = "Optionally match request histories created after") @QueryParam("createdAfter") Optional<Long> createdAfter, @Parameter(description = "Sort direction") @QueryParam("orderDirection") Optional<OrderDirection> orderDirection, @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("false") boolean skipZk) {
    authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
    final Integer limitCount = getLimitCount(count);
    final Integer limitStart = getLimitStart(limitCount, page);
    SingularityRequestHistoryQuery requestHistoryQuery = new SingularityRequestHistoryQuery(requestId, createdBefore, createdAfter, orderDirection);
    return requestHistoryHelper.getBlendedHistory(requestHistoryQuery, limitStart, limitCount, skipZk);
}
Also used : SingularityRequestHistoryQuery(com.hubspot.singularity.SingularityRequestHistoryQuery) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with SingularityRequestHistoryQuery

use of com.hubspot.singularity.SingularityRequestHistoryQuery 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)

Example 3 with SingularityRequestHistoryQuery

use of com.hubspot.singularity.SingularityRequestHistoryQuery 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)

Aggregations

SingularityRequestHistoryQuery (com.hubspot.singularity.SingularityRequestHistoryQuery)3 SingularityRequestHistory (com.hubspot.singularity.SingularityRequestHistory)2 Operation (io.swagger.v3.oas.annotations.Operation)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SingularityPaginatedResponse (com.hubspot.singularity.SingularityPaginatedResponse)1 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)1 SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)1 HistoryManager (com.hubspot.singularity.data.history.HistoryManager)1 RequestHistoryHelper (com.hubspot.singularity.data.history.RequestHistoryHelper)1 Test (org.junit.jupiter.api.Test)1