Search in sources :

Example 1 with RequestHistoryType

use of com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType in project Singularity by HubSpot.

the class SingularitySchedulerTest method itCorrectlyUpdatesRequestDeletingStateHistory.

@Test
public void itCorrectlyUpdatesRequestDeletingStateHistory() {
    initRequest();
    Assert.assertEquals(RequestState.ACTIVE, requestManager.getRequest(requestId).get().getState());
    Assert.assertEquals(1, requestManager.getRequestHistory(requestId).size());
    requestManager.startDeletingRequest(request, Optional.absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.of("the cake is a lie"));
    Assert.assertEquals(RequestState.DELETING, requestManager.getRequest(requestId).get().getState());
    Assert.assertEquals(2, requestManager.getRequestHistory(requestId).size());
    cleaner.drainCleanupQueue();
    Assert.assertEquals(3, requestManager.getRequestHistory(requestId).size());
    List<RequestHistoryType> historyTypes = new ArrayList<>();
    for (SingularityRequestHistory request : requestManager.getRequestHistory(requestId)) {
        historyTypes.add(request.getEventType());
    }
    Assert.assertTrue(historyTypes.contains(RequestHistoryType.CREATED));
    Assert.assertTrue(historyTypes.contains(RequestHistoryType.DELETING));
    Assert.assertTrue(historyTypes.contains(RequestHistoryType.DELETED));
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) RequestHistoryType(com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with RequestHistoryType

use of com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType in project Singularity by HubSpot.

the class RequestHelper method updateRequest.

public void updateRequest(SingularityRequest request, Optional<SingularityRequest> maybeOldRequest, RequestState requestState, Optional<RequestHistoryType> historyType, Optional<String> user, Optional<Boolean> skipHealthchecks, Optional<String> message, Optional<SingularityBounceRequest> maybeBounceRequest) {
    SingularityRequestDeployHolder deployHolder = getDeployHolder(request.getId());
    SingularityRequest newRequest = validator.checkSingularityRequest(request, maybeOldRequest, deployHolder.getActiveDeploy(), deployHolder.getPendingDeploy());
    final long now = System.currentTimeMillis();
    if (requestState == RequestState.FINISHED && maybeOldRequest.isPresent() && shouldReschedule(newRequest, maybeOldRequest.get())) {
        requestState = RequestState.ACTIVE;
    }
    RequestHistoryType historyTypeToSet = null;
    if (historyType.isPresent()) {
        historyTypeToSet = historyType.get();
    } else if (maybeOldRequest.isPresent()) {
        historyTypeToSet = RequestHistoryType.UPDATED;
    } else {
        historyTypeToSet = RequestHistoryType.CREATED;
    }
    requestManager.save(newRequest, requestState, historyTypeToSet, now, user, message);
    checkReschedule(newRequest, maybeOldRequest, user, now, skipHealthchecks, message, maybeBounceRequest);
}
Also used : RequestHistoryType(com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Aggregations

RequestHistoryType (com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType)2 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityRequestHistory (com.hubspot.singularity.SingularityRequestHistory)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1