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), " ");
}
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;
}
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;
}
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;
}
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);
}
Aggregations