Search in sources :

Example 1 with RunningServiceDetails

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

the class KubernetesV1DistributedService method connectCommand.

default String connectCommand(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, int localPort) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Map<Integer, List<Instance>> instances = runningServiceDetails.getInstances();
    Integer latest = runningServiceDetails.getLatestEnabledVersion();
    String namespace = getNamespace(settings);
    List<Instance> latestInstances = instances.get(latest);
    if (latestInstances.isEmpty()) {
        throw new HalException(Problem.Severity.FATAL, "No instances running in latest server group for service " + getServiceName() + " in namespace " + namespace);
    }
    return Strings.join(KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, latestInstances.get(0).getId(), settings.getPort(), localPort), " ");
}
Also used : Instance(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.Instance) 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) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with RunningServiceDetails

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

the class DistributedDeployer method reapOrcaServerGroups.

private <T extends Account> Set<Integer> reapOrcaServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Orca, T> orcaService) {
    if (runtimeSettings.getServiceSettings(orcaService.getService()).getSkipLifeCycleManagement()) {
        return Collections.emptySet();
    }
    RunningServiceDetails runningOrcaDetails = orcaService.getRunningServiceDetails(details, runtimeSettings);
    Map<Integer, List<RunningServiceDetails.Instance>> instances = runningOrcaDetails.getInstances();
    List<Integer> versions = new ArrayList<>(instances.keySet());
    versions.sort(Integer::compareTo);
    Set<Integer> unknownVersions = disableOrcaServerGroups(details, runtimeSettings, orcaService, runningOrcaDetails);
    Map<Integer, Integer> executionsByServerGroupVersion = new HashMap<>();
    for (Integer version : versions) {
        if (unknownVersions.contains(version)) {
            executionsByServerGroupVersion.put(version, // we make the assumption that there is non-0 work for the unknown versions
            1);
        } else {
            executionsByServerGroupVersion.put(version, 0);
        }
    }
    ServiceSettings orcaSettings = runtimeSettings.getServiceSettings(orcaService.getService());
    cleanupServerGroups(details, orcaService, orcaSettings, executionsByServerGroupVersion, versions);
    return unknownVersions;
}
Also used : HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with RunningServiceDetails

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

the class DistributedService method buildDeployServerGroupPipeline.

default Map<String, Object> buildDeployServerGroupPipeline(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer maxRemaining, boolean scaleDown) {
    String accountName = details.getAccount().getName();
    String region = runtimeSettings.getServiceSettings(getService()).getLocation();
    Map<String, Object> deployDescription = getServerGroupDescription(details, runtimeSettings, configSources);
    deployDescription.put("name", "deploy");
    Map<String, String> source = new HashMap<>();
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    if (runningServiceDetails.getLatestEnabledVersion() == null) {
        throw new HalException(Problem.Severity.FATAL, "No prior server group to clone for " + getServiceName());
    }
    source.put("account", accountName);
    source.put("credentials", accountName);
    source.put("serverGroupName", getVersionedName(runningServiceDetails.getLatestEnabledVersion()));
    source.put("region", region);
    source.put("namespace", region);
    deployDescription.put("source", source);
    deployDescription.put("interestingHealthProviders", getHealthProviders());
    deployDescription.put("type", AtomicOperations.CLONE_SERVER_GROUP);
    deployDescription.put("cloudProvider", getProviderType().getId());
    deployDescription.put("refId", "deployredblack");
    deployDescription.put("region", getRegion(runtimeSettings.getServiceSettings(getService())));
    deployDescription.put("strategy", "redblack");
    if (maxRemaining != null) {
        deployDescription.put("maxRemainingAsgs", maxRemaining + "");
    }
    deployDescription.put("scaleDown", scaleDown + "");
    if (scaleDown) {
        deployDescription.put("allowShrinkDownActive", "true");
    }
    List<Map<String, Object>> stages = new ArrayList<>();
    stages.add(deployDescription);
    Map<String, Object> pipeline = new HashMap<>();
    pipeline.put("stages", stages);
    pipeline.put("application", "spin");
    pipeline.put("name", "Deploy/Upgrade " + getServiceName());
    pipeline.put("description", "Auto-generated by Halyard");
    return pipeline;
}
Also used : HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with RunningServiceDetails

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

the class DistributedService method buildRollbackPipeline.

default Map<String, Object> buildRollbackPipeline(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) {
    RunningServiceDetails serviceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = serviceDetails.getLatestEnabledVersion();
    if (version == null) {
        throw new HalException(Problem.Severity.FATAL, "There are no enabled server groups for service " + getServiceName() + " nothing to rollback to.");
    }
    int targetSize = serviceDetails.getInstances().get(version).size();
    targetSize = targetSize == 0 ? 1 : targetSize;
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    Map<String, Object> baseDescription = new HashMap<>();
    baseDescription.put("cloudProvider", getProviderType().getId());
    baseDescription.put("cloudProviderType", getProviderType().getId());
    baseDescription.put("region", getRegion(settings));
    baseDescription.put("credentials", details.getAccount().getName());
    baseDescription.put("cluster", getServiceName());
    baseDescription.put("name", "rollback");
    Map<String, Object> capacity = new HashMap<>();
    capacity.put("desired", targetSize);
    Map<String, Object> resizeDescription = new HashMap<>();
    resizeDescription.putAll(baseDescription);
    String resizeId = "resize";
    resizeDescription.put("name", "Resize old " + getServiceName() + " to prior size");
    resizeDescription.put("capacity", capacity);
    resizeDescription.put("type", "resizeServerGroup");
    resizeDescription.put("refId", resizeId);
    resizeDescription.put("target", "ancestor_asg_dynamic");
    resizeDescription.put("action", "scale_exact");
    resizeDescription.put("requisiteStageRefIds", Collections.emptyList());
    Map<String, Object> enableDescription = new HashMap<>();
    enableDescription.putAll(baseDescription);
    String enableId = "enable";
    enableDescription.put("name", "Enable old " + getServiceName());
    enableDescription.put("type", "enableServerGroup");
    enableDescription.put("refId", enableId);
    enableDescription.put("target", "ancestor_asg_dynamic");
    enableDescription.put("requisiteStageRefIds", Collections.singletonList(resizeId));
    // This is a destroy, rather than a disable because the typical flow will look like this:
    // 
    // 1. You deploy a new version/config
    // 2. Something is wrong, so you rollback.
    // 3. Fixing the bad server group requires redeploying.
    // 
    // Since you can't fix the newest destroyed server group in place, and you won't (at least I can't imagine why)
    // want to reenable that server group, there is no point it keeping it around. There's an argument
    // to be made for keeping it around to debug, but that's far from what the average halyard user will want
    // to do.
    Map<String, Object> destroyDescription = new HashMap<>();
    String destroyId = "destroy";
    destroyDescription.putAll(baseDescription);
    destroyDescription.put("name", "Destroy current " + getServiceName());
    destroyDescription.put("type", "destroyServerGroup");
    destroyDescription.put("refId", destroyId);
    destroyDescription.put("requisiteStageRefIds", Collections.singletonList(enableId));
    destroyDescription.put("target", "current_asg_dynamic");
    List<Map<String, Object>> stages = new ArrayList<>();
    stages.add(resizeDescription);
    stages.add(enableDescription);
    stages.add(destroyDescription);
    Map<String, Object> pipeline = new HashMap<>();
    pipeline.put("stages", stages);
    pipeline.put("application", "spin");
    pipeline.put("name", "Rollback " + getServiceName());
    pipeline.put("description", "Auto-generated by Halyard");
    return pipeline;
}
Also used : HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with RunningServiceDetails

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

the class GoogleDistributedService method buildConnectionDetails.

default VaultConnectionDetails buildConnectionDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, String secretName) {
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    ServiceSettings vaultSettings = runtimeSettings.getServiceSettings(vaultService);
    RunningServiceDetails vaultDetails = vaultService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestVaultVersion = vaultDetails.getLatestEnabledVersion();
    if (latestVaultVersion == null) {
        throw new IllegalStateException("No vault services have been started yet. This is a bug.");
    }
    List<RunningServiceDetails.Instance> instances = vaultDetails.getInstances().get(latestVaultVersion);
    if (instances.isEmpty()) {
        throw new IllegalStateException("Current vault service has no running instances. This is a bug.");
    }
    String instanceId = instances.get(0).getId();
    String address = new URIBuilder().setScheme("http").setHost(instanceId).setPort(vaultSettings.getPort()).toString();
    String token = vaultService.getToken(details.getDeploymentName(), vault);
    return new VaultConnectionDetails().setAddress(address).setSecret(secretName).setToken(token);
}
Also used : VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)19 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)14 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)8 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)6 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)6 List (java.util.List)6 Map (java.util.Map)6 HashSet (java.util.HashSet)5 ManagedInstance (com.google.api.services.compute.model.ManagedInstance)4 Names (com.netflix.frigga.Names)4 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)4 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)4 DaemonTaskHandler (com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler)4 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)4 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)4 Collections (java.util.Collections)4 Set (java.util.Set)4