Search in sources :

Example 36 with ServiceSettings

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

the class MetricRegistryProfileFactoryBuilder method build.

public ProfileFactory build(ServiceSettings settings) {
    return new ProfileFactory() {

        @Override
        protected ArtifactService getArtifactService() {
            return artifactService;
        }

        @Override
        protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
            URI uri;
            try {
                String baseUrl;
                if (settings.getBasicAuthEnabled() != null && settings.getBasicAuthEnabled()) {
                    baseUrl = settings.getAuthBaseUrl();
                } else {
                    baseUrl = settings.getBaseUrl();
                }
                uri = new URIBuilder(baseUrl).setHost("localhost").setPath("/spectator/metrics").build();
            } catch (URISyntaxException e) {
                throw new HalException(Problem.Severity.FATAL, "Unable to build service URL: " + e.getMessage());
            }
            profile.appendContents("metrics_url: " + uri.toString());
        }

        @Override
        protected Profile getBaseProfile(String name, String version, String outputFile) {
            return new Profile(name, version, outputFile, "");
        }

        @Override
        public SpinnakerArtifact getArtifact() {
            return SpinnakerArtifact.SPINNAKER_MONITORING_DAEMON;
        }

        @Override
        protected String commentPrefix() {
            return "## ";
        }
    };
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 37 with ServiceSettings

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

the class SpinnakerMonitoringDaemonProfileFactory method setProfile.

@Override
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    SpinnakerRuntimeSettings.Services services = endpoints.getServices();
    ServiceSettings monitoringService = services.getMonitoringDaemon();
    MetricStores metricStores = deploymentConfiguration.getMetricStores();
    List<String> enabledMetricStores = new ArrayList<>();
    List<String> files = new ArrayList<>();
    DatadogStore datadogStore = metricStores.getDatadog();
    if (datadogStore.isEnabled()) {
        enabledMetricStores.add("datadog");
    }
    PrometheusStore prometheusStore = metricStores.getPrometheus();
    if (prometheusStore.isEnabled()) {
        enabledMetricStores.add("prometheus");
    }
    StackdriverStore stackdriverStore = metricStores.getStackdriver();
    if (stackdriverStore.isEnabled()) {
        enabledMetricStores.add("stackdriver");
        files.addAll(backupRequiredFiles(stackdriverStore, deploymentConfiguration.getName()));
    }
    profile.appendContents(yamlToString(metricStores));
    Server server = new Server().setHost(monitoringService.getHost()).setPort(monitoringService.getPort());
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setServer(server);
    profile.appendContents(yamlToString(serverConfig));
    Monitor monitor = new Monitor().setPeriod(metricStores.getPeriod()).setMetricStore(enabledMetricStores);
    MonitorConfig monitorConfig = new MonitorConfig();
    monitorConfig.setMonitor(monitor);
    profile.appendContents(yamlToString(monitorConfig));
    profile.appendContents(profile.getBaseContents());
    profile.setRequiredFiles(files);
}
Also used : MetricStores(com.netflix.spinnaker.halyard.config.model.v1.node.MetricStores) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) StackdriverStore(com.netflix.spinnaker.halyard.config.model.v1.metricStores.stackdriver.StackdriverStore) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DatadogStore(com.netflix.spinnaker.halyard.config.model.v1.metricStores.datadog.DatadogStore) PrometheusStore(com.netflix.spinnaker.halyard.config.model.v1.metricStores.prometheus.PrometheusStore)

Example 38 with ServiceSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings 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 39 with ServiceSettings

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

Example 40 with ServiceSettings

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

ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)35 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)18 ArrayList (java.util.ArrayList)18 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)14 HashMap (java.util.HashMap)14 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)12 Map (java.util.Map)12 List (java.util.List)10 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)9 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)9 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)8 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)8 HashSet (java.util.HashSet)7 Names (com.netflix.frigga.Names)6 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)6 Collectors (java.util.stream.Collectors)6 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)5 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)5 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)5 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)5