Search in sources :

Example 76 with SingularityRequest

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

the class TaskRequestManager method getTaskRequests.

public List<SingularityTaskRequest> getTaskRequests(List<SingularityPendingTask> tasks) {
    final Multimap<String, SingularityPendingTask> requestIdToPendingTaskId = ArrayListMultimap.create(tasks.size(), 1);
    for (SingularityPendingTask task : tasks) {
        requestIdToPendingTaskId.put(task.getPendingTaskId().getRequestId(), task);
    }
    final List<SingularityRequestWithState> matchingRequests = requestManager.getRequests(requestIdToPendingTaskId.keySet());
    final Map<SingularityPendingTask, SingularityDeployKey> deployKeys = SingularityDeployKey.fromPendingTasks(requestIdToPendingTaskId.values());
    final Map<SingularityDeployKey, SingularityDeploy> matchingDeploys = deployManager.getDeploysForKeys(Sets.newHashSet(deployKeys.values()));
    final List<SingularityTaskRequest> taskRequests = Lists.newArrayListWithCapacity(matchingRequests.size());
    for (SingularityRequestWithState request : matchingRequests) {
        Optional<SingularityPendingDeploy> maybePendingDeploy = deployManager.getPendingDeploy(request.getRequest().getId());
        for (SingularityPendingTask task : requestIdToPendingTaskId.get(request.getRequest().getId())) {
            SingularityDeploy foundDeploy = matchingDeploys.get(deployKeys.get(task));
            if (foundDeploy == null) {
                LOG.warn("Couldn't find a matching deploy for pending task {}", task);
                continue;
            }
            if (!request.getState().isRunnable()) {
                LOG.warn("Request was in state {} for pending task {}", request.getState(), task);
                continue;
            }
            Optional<SingularityRequest> updatedRequest = maybePendingDeploy.isPresent() && maybePendingDeploy.get().getDeployMarker().getDeployId().equals(task.getPendingTaskId().getDeployId()) ? maybePendingDeploy.get().getUpdatedRequest() : Optional.<SingularityRequest>absent();
            taskRequests.add(new SingularityTaskRequest(updatedRequest.or(request.getRequest()), foundDeploy, task));
        }
    }
    return taskRequests;
}
Also used : SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest)

Example 77 with SingularityRequest

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

the class RequestResource method scale.

public SingularityRequestParent scale(String requestId, SingularityScaleRequest scaleRequest, SingularityUser user) {
    SingularityRequestWithState oldRequestWithState = fetchRequestWithState(requestId, user);
    SingularityRequest oldRequest = oldRequestWithState.getRequest();
    authorizationHelper.checkForAuthorization(oldRequest, user, SingularityAuthorizationScope.WRITE);
    validator.checkActionEnabled(SingularityAction.SCALE_REQUEST);
    SingularityRequest newRequest = oldRequest.toBuilder().setInstances(scaleRequest.getInstances()).build();
    validator.checkScale(newRequest, Optional.<Integer>absent());
    checkBadRequest(oldRequest.getInstancesSafe() != newRequest.getInstancesSafe(), "Scale request has no affect on the # of instances (%s)", newRequest.getInstancesSafe());
    String scaleMessage = String.format("Scaling from %d -> %d", oldRequest.getInstancesSafe(), newRequest.getInstancesSafe());
    if (scaleRequest.getMessage().isPresent()) {
        scaleMessage = String.format("%s -- %s", scaleRequest.getMessage().get(), scaleMessage);
    } else {
        scaleMessage = String.format("%s", scaleMessage);
    }
    if (scaleRequest.getBounce().or(newRequest.getBounceAfterScale().or(false))) {
        validator.checkActionEnabled(SingularityAction.BOUNCE_REQUEST);
        checkBadRequest(newRequest.isLongRunning(), "Can not bounce a %s request (%s)", newRequest.getRequestType(), newRequest);
        checkConflict(oldRequestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to bounce (it must be manually unpaused first)", newRequest.getId());
        checkConflict(!requestManager.cleanupRequestExists(newRequest.getId(), RequestCleanupType.BOUNCE), "Request %s is already bouncing cannot bounce again", newRequest.getId());
        final boolean isIncrementalBounce = scaleRequest.getIncremental().or(true);
        validator.checkResourcesForBounce(newRequest, isIncrementalBounce);
        validator.checkRequestForPriorityFreeze(newRequest);
        SingularityBounceRequest bounceRequest = new SingularityBounceRequest(Optional.of(isIncrementalBounce), scaleRequest.getSkipHealthchecks(), Optional.<Long>absent(), Optional.of(UUID.randomUUID().toString()), Optional.<String>absent(), Optional.<SingularityShellCommand>absent());
        submitRequest(newRequest, Optional.of(oldRequestWithState), Optional.of(RequestHistoryType.SCALED), scaleRequest.getSkipHealthchecks(), Optional.of(scaleMessage), Optional.of(bounceRequest), user);
    } else {
        submitRequest(newRequest, Optional.of(oldRequestWithState), Optional.of(RequestHistoryType.SCALED), scaleRequest.getSkipHealthchecks(), Optional.of(scaleMessage), Optional.absent(), user);
    }
    if (scaleRequest.getDurationMillis().isPresent()) {
        requestManager.saveExpiringObject(new SingularityExpiringScale(requestId, user.getEmail(), System.currentTimeMillis(), scaleRequest, oldRequest.getInstances(), scaleRequest.getActionId().or(UUID.randomUUID().toString()), scaleRequest.getBounce()));
    } else {
        requestManager.deleteExpiringObject(SingularityExpiringScale.class, requestId);
    }
    if (!scaleRequest.getSkipEmailNotification().isPresent() || !scaleRequest.getSkipEmailNotification().get()) {
        mailer.sendRequestScaledMail(newRequest, Optional.of(scaleRequest), oldRequest.getInstances(), user.getEmail());
    }
    return fillEntireRequest(fetchRequestWithState(requestId, user));
}
Also used : SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) SingularityExpiringScale(com.hubspot.singularity.expiring.SingularityExpiringScale)

Example 78 with SingularityRequest

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

the class RequestResource method updateAuthorizedGroups.

public SingularityRequestParent updateAuthorizedGroups(SingularityUser user, String requestId, SingularityUpdateGroupsRequest updateGroupsRequest) {
    SingularityRequestWithState oldRequestWithState = fetchRequestWithState(requestId, user);
    authorizationHelper.checkForAuthorization(oldRequestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
    SingularityRequest newRequest = oldRequestWithState.getRequest().toBuilder().setGroup(updateGroupsRequest.getGroup()).setReadWriteGroups(Optional.of(updateGroupsRequest.getReadWriteGroups())).setReadOnlyGroups(Optional.of(updateGroupsRequest.getReadOnlyGroups())).build();
    submitRequest(newRequest, Optional.of(oldRequestWithState), Optional.of(RequestHistoryType.UPDATED), Optional.absent(), updateGroupsRequest.getMessage(), Optional.absent(), user);
    return fillEntireRequest(fetchRequestWithState(requestId, user));
}
Also used : SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Example 79 with SingularityRequest

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

the class RequestResource method deleteRequest.

public SingularityRequest deleteRequest(String requestId, Optional<SingularityDeleteRequestRequest> deleteRequest, SingularityUser user) {
    SingularityRequest request = fetchRequestWithState(requestId, user).getRequest();
    authorizationHelper.checkForAuthorization(request, user, SingularityAuthorizationScope.WRITE);
    validator.checkActionEnabled(SingularityAction.REMOVE_REQUEST);
    Optional<String> message = Optional.absent();
    Optional<String> actionId = Optional.absent();
    Optional<Boolean> deleteFromLoadBalancer = Optional.absent();
    if (deleteRequest.isPresent()) {
        actionId = deleteRequest.get().getActionId();
        message = deleteRequest.get().getMessage();
        deleteFromLoadBalancer = deleteRequest.get().getDeleteFromLoadBalancer();
    }
    requestManager.startDeletingRequest(request, deleteFromLoadBalancer, user.getEmail(), actionId, message);
    mailer.sendRequestRemovedMail(request, user.getEmail(), message);
    return request;
}
Also used : SingularityRequest(com.hubspot.singularity.SingularityRequest)

Example 80 with SingularityRequest

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

the class RequestResource method skipHealthchecks.

public SingularityRequestParent skipHealthchecks(String requestId, SingularitySkipHealthchecksRequest skipHealthchecksRequest, SingularityUser user) {
    SingularityRequestWithState oldRequestWithState = fetchRequestWithState(requestId, user);
    SingularityRequest oldRequest = oldRequestWithState.getRequest();
    SingularityRequest newRequest = oldRequest.toBuilder().setSkipHealthchecks(skipHealthchecksRequest.getSkipHealthchecks()).build();
    submitRequest(newRequest, Optional.of(oldRequestWithState), Optional.absent(), Optional.absent(), skipHealthchecksRequest.getMessage(), Optional.absent(), user);
    if (skipHealthchecksRequest.getDurationMillis().isPresent()) {
        requestManager.saveExpiringObject(new SingularityExpiringSkipHealthchecks(requestId, user.getEmail(), System.currentTimeMillis(), skipHealthchecksRequest, oldRequest.getSkipHealthchecks(), skipHealthchecksRequest.getActionId().or(UUID.randomUUID().toString())));
    }
    return fillEntireRequest(fetchRequestWithState(requestId, user));
}
Also used : SingularityExpiringSkipHealthchecks(com.hubspot.singularity.expiring.SingularityExpiringSkipHealthchecks) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest)

Aggregations

SingularityRequest (com.hubspot.singularity.SingularityRequest)83 Test (org.junit.Test)57 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)37 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)29 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)25 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)16 SingularityTask (com.hubspot.singularity.SingularityTask)15 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)14 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)11 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)8 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)7 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)6 ArrayList (java.util.ArrayList)6 Resources (com.hubspot.mesos.Resources)5 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4