Search in sources :

Example 1 with DistributedServiceProvider

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedServiceProvider in project halyard by spinnaker.

the class DistributedDeployer method deploy.

@Override
public RemoteAction deploy(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    DaemonTaskHandler.newStage("Deploying Spinnaker");
    // First deploy all services not owned by Spinnaker
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = resolvedConfiguration.getServiceSettings(service);
        if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        DaemonTaskHandler.newStage("Determining status of " + distributedService.getServiceName());
        boolean safeToUpdate = settings.getSafeToUpdate();
        RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
        if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
            deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
        } else {
            DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
                if (runningServiceDetails.getLatestEnabledVersion() == null) {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via provider API");
                    deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
                } else {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via red/black");
                    Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
                    deployServiceWithOrca(deploymentDetails, resolvedConfiguration, orca, distributedService);
                }
                return null;
            });
            DaemonTaskHandler.submitTask(builder::build, "Deploy " + distributedService.getServiceName());
        }
    }
    DaemonTaskHandler.message("Waiting on deployments to complete");
    DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
    DistributedService<Orca, T> orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA);
    Set<Integer> unknownVersions = reapOrcaServerGroups(deploymentDetails, runtimeSettings, orca);
    reapRoscoServerGroups(deploymentDetails, runtimeSettings, serviceProvider.getDeployableService(SpinnakerService.Type.ROSCO));
    if (!unknownVersions.isEmpty()) {
        String versions = String.join(", ", unknownVersions.stream().map(orca::getVersionedName).collect(Collectors.toList()));
        throw new HalException(new ProblemBuilder(Problem.Severity.ERROR, "The following orca versions (" + versions + ") could not safely be drained of work.").setRemediation("Please make sure that no pipelines are running, and manually destroy the server groups at those versions.").build());
    }
    return new RemoteAction();
}
Also used : Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction)

Example 2 with DistributedServiceProvider

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedServiceProvider 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

DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)2 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)2 Orca (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca)2 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)2 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)2 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)2 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)1 ProblemBuilder (com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)1 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)1