use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails in project halyard by spinnaker.
the class DistributedDeployer method deployServiceWithOrca.
private <T extends Account> void deployServiceWithOrca(AccountDeploymentDetails<T> details, ResolvedConfiguration resolvedConfiguration, Orca orca, DistributedService distributedService) {
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(details, runtimeSettings);
Supplier<String> idSupplier;
if (!runningServiceDetails.getLoadBalancer().isExists()) {
Map<String, Object> task = distributedService.buildUpsertLoadBalancerTask(details, runtimeSettings);
idSupplier = () -> (String) orca.submitTask(task).get("ref");
orcaRunner.monitorTask(idSupplier, orca);
}
List<String> configs = distributedService.stageProfiles(details, resolvedConfiguration);
Integer maxRemaining = MAX_REMAINING_SERVER_GROUPS;
boolean scaleDown = true;
if (distributedService.isStateful()) {
maxRemaining = null;
scaleDown = false;
}
Map<String, Object> pipeline = distributedService.buildDeployServerGroupPipeline(details, runtimeSettings, configs, maxRemaining, scaleDown);
idSupplier = () -> (String) orca.orchestrate(pipeline).get("ref");
orcaRunner.monitorPipeline(idSupplier, orca);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails 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;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails 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);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails 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);
}
Aggregations