use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.Instance 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;
}
Aggregations