Search in sources :

Example 1 with Rosco

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco in project halyard by spinnaker.

the class DistributedDeployer method reapRoscoServerGroups.

private <T extends Account> void reapRoscoServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Rosco, T> roscoService) {
    if (runtimeSettings.getServiceSettings(roscoService.getService()).getSkipLifeCycleManagement()) {
        return;
    }
    ServiceSettings roscoSettings = runtimeSettings.getServiceSettings(roscoService.getService());
    Rosco.AllStatus allStatus;
    try {
        Rosco rosco = roscoService.connectToPrimaryService(details, runtimeSettings);
        allStatus = rosco.getAllStatus();
    } catch (RetrofitError e) {
        boolean enabled = roscoSettings.getEnabled() != null && roscoSettings.getEnabled();
        if (enabled) {
            throw new HalException(Problem.Severity.FATAL, "Rosco is enabled, and no connection to rosco could be established: " + e, e);
        }
        Response response = e.getResponse();
        if (response == null) {
            throw new IllegalStateException("Unknown connection failure: " + e, e);
        }
        // 404 when the service couldn't be found, 503 when k8s couldn't establish a connection
        if (response.getStatus() == 404 || response.getStatus() == 503) {
            log.info("Rosco is not enabled, and there are no server groups to reap");
            return;
        } else {
            throw new HalException(Problem.Severity.FATAL, "Rosco is not enabled, but couldn't be connected to for unknown reason: " + e, e);
        }
    }
    RunningServiceDetails roscoDetails = roscoService.getRunningServiceDetails(details, runtimeSettings);
    Set<String> activeInstances = new HashSet<>();
    allStatus.getInstances().forEach((s, e) -> {
        if (e.getStatus().equals(Rosco.Status.RUNNING)) {
            String[] split = s.split("@");
            if (split.length != 2) {
                log.warn("Unsupported rosco status format");
                return;
            }
            String instanceId = split[1];
            activeInstances.add(instanceId);
        }
    });
    Map<Integer, Integer> executionsByServerGroupVersion = new HashMap<>();
    roscoDetails.getInstances().forEach((s, is) -> {
        int count = is.stream().reduce(0, (c, i) -> c + (activeInstances.contains(i) ? 1 : 0), (a, b) -> a + b);
        executionsByServerGroupVersion.put(s, count);
    });
    // Omit the last deployed roscos from being deleted, since they are kept around for rollbacks.
    List<Integer> allRoscos = new ArrayList<>(executionsByServerGroupVersion.keySet());
    allRoscos.sort(Integer::compareTo);
    cleanupServerGroups(details, roscoService, roscoSettings, executionsByServerGroupVersion, allRoscos);
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Response(retrofit.client.Response) Rosco(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RetrofitError(retrofit.RetrofitError) HashSet(java.util.HashSet)

Aggregations

DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)1 Rosco (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco)1 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 RetrofitError (retrofit.RetrofitError)1 Response (retrofit.client.Response)1