Search in sources :

Example 6 with Orca

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca in project halyard by spinnaker.

the class DistributedDeployer method disableOrcaServerGroups.

private <T extends Account> Set<Integer> disableOrcaServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Orca, T> orcaService, RunningServiceDetails runningOrcaDetails) {
    Map<Integer, List<RunningServiceDetails.Instance>> instances = runningOrcaDetails.getInstances();
    List<Integer> existingVersions = new ArrayList<>(instances.keySet());
    existingVersions.sort(Integer::compareTo);
    Map<String, String> disableRequest = new HashMap<>();
    Set<Integer> result = new HashSet<>();
    disableRequest.put("enabled", "false");
    List<Integer> disabledVersions = existingVersions.subList(0, existingVersions.size() - 1);
    for (Integer version : disabledVersions) {
        try {
            for (RunningServiceDetails.Instance instance : instances.get(version)) {
                log.info("Disabling instance " + instance.getId());
                Orca orca = orcaService.connectToInstance(details, runtimeSettings, orcaService.getService(), instance.getId());
                orca.setInstanceStatusEnabled(disableRequest);
            }
            result.add(version);
        } catch (RetrofitError e) {
            Response response = e.getResponse();
            if (response == null) {
                log.warn("Unexpected error disabling orca", e);
            } else if (response.getStatus() == 400 && ((Map) e.getBodyAs(Map.class)).containsKey("discovery")) {
                log.info("Orca instance is managed by eureka");
                result.add(version);
            } else {
                log.warn("Orca version doesn't support explicit disabling of instances", e);
            }
        }
    }
    Set<Integer> unknownVersions = disabledVersions.stream().filter(i -> !result.contains(i)).collect(Collectors.toSet());
    if (unknownVersions.size() > 0) {
        log.warn("There are existing orca server groups that cannot be explicitly disabled, we will have to wait for these to drain work");
    }
    return unknownVersions;
}
Also used : RedisService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RedisService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) LogCollector(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.LogCollector) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) HashSet(java.util.HashSet) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) Rosco(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.RoscoService.Rosco) Map(java.util.Map) ResolvedConfiguration(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.ResolvedConfiguration) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Response(retrofit.client.Response) DistributedServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedServiceProvider) Set(java.util.Set) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) Collectors(java.util.stream.Collectors) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) RetrofitError(retrofit.RetrofitError) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) Jedis(redis.clients.jedis.Jedis) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) Collections(java.util.Collections) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Response(retrofit.client.Response) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) RetrofitError(retrofit.RetrofitError)

Example 7 with Orca

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca in project halyard by spinnaker.

the class DistributedDeployer method rollback.

@Override
public void rollback(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings, List<SpinnakerService.Type> serviceTypes) {
    DaemonTaskHandler.newStage("Checking if it is safe to roll back all services");
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = runtimeSettings.getServiceSettings(service);
        boolean safeToUpdate = settings.getSafeToUpdate();
        if (!settings.getEnabled() || distributedService.isRequiredToBootstrap() || !safeToUpdate || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
        if (runningServiceDetails.getInstances().keySet().size() == 1) {
            throw new HalException(Problem.Severity.FATAL, "Service " + service.getCanonicalName() + " has only one server group - there is nothing to rollback to.");
        }
    }
    DaemonTaskHandler.newStage("Rolling back all updatable services");
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = runtimeSettings.getServiceSettings(service);
        if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        boolean safeToUpdate = settings.getSafeToUpdate();
        if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
        // Do nothing, the bootstrapping services should already be running, and the services that can't be updated
        // having nothing to rollback to
        } else {
            DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
                Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
                DaemonTaskHandler.message("Rolling back " + distributedService.getServiceName() + " via Spinnaker red/black");
                rollbackService(deploymentDetails, orca, distributedService, runtimeSettings);
                return null;
            });
            DaemonTaskHandler.submitTask(builder::build, "Rollback " + distributedService.getServiceName());
        }
    }
    DaemonTaskHandler.message("Waiting on rollbacks to complete");
    DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
}
Also used : DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)

Aggregations

RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)5 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)4 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)3 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)3 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)3 Orca (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca)3 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)3 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)3 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)2 ProblemBuilder (com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)1 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)1 DaemonTaskHandler (com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler)1 ResolvedConfiguration (com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.ResolvedConfiguration)1 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)1 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)1 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)1