Search in sources :

Example 1 with DeployAcceptanceHook

use of com.hubspot.singularity.hooks.DeployAcceptanceHook in project Singularity by HubSpot.

the class SingularityDeployAcceptanceManager method getAcceptanceResults.

public Map<String, DeployAcceptanceResult> getAcceptanceResults(SingularityRequest request, SingularityDeploy deploy, SingularityPendingDeploy pendingDeploy, Collection<SingularityTaskId> activeTasksForPendingDeploy, Collection<SingularityTaskId> inactiveTasksForPendingDeploy, Collection<SingularityTaskId> otherActiveTasksForRequest) {
    Map<String, DeployAcceptanceResult> results = new HashMap<>();
    Map<String, DeployAcceptanceState> existing = pendingDeploy.getDeployProgress().getStepAcceptanceResults();
    for (DeployAcceptanceHook hook : acceptanceHooks) {
        if (!existing.containsKey(hook.getName()) || existing.get(hook.getName()) == DeployAcceptanceState.PENDING) {
            try {
                results.put(hook.getName(), hook.getAcceptanceResult(request, deploy, pendingDeploy, activeTasksForPendingDeploy, inactiveTasksForPendingDeploy, otherActiveTasksForRequest));
            } catch (Exception e) {
                LOG.error("Uncaught exception running hook {}", hook.getName(), e);
                if (hook.isFailOnUncaughtException()) {
                    results.put(hook.getName(), new DeployAcceptanceResult(DeployAcceptanceState.FAILED, e.getMessage()));
                } else {
                    results.put(hook.getName(), new DeployAcceptanceResult(DeployAcceptanceState.SUCCEEDED, String.format("Ignored err: %s", e.getMessage())));
                }
            }
        }
    }
    return results;
}
Also used : HashMap(java.util.HashMap) DeployAcceptanceHook(com.hubspot.singularity.hooks.DeployAcceptanceHook) DeployAcceptanceState(com.hubspot.singularity.DeployAcceptanceState) DeployAcceptanceResult(com.hubspot.singularity.DeployAcceptanceResult)

Aggregations

DeployAcceptanceResult (com.hubspot.singularity.DeployAcceptanceResult)1 DeployAcceptanceState (com.hubspot.singularity.DeployAcceptanceState)1 DeployAcceptanceHook (com.hubspot.singularity.hooks.DeployAcceptanceHook)1 HashMap (java.util.HashMap)1