use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService 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.service.distributed.DistributedService in project halyard by spinnaker.
the class DistributedLogCollector method collectLogs.
@Override
public void collectLogs(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) {
DistributedService<T, A> distributedService = (DistributedService<T, A>) getService();
RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(details, runtimeSettings);
runningServiceDetails.getInstances().values().forEach(is -> is.stream().filter(RunningServiceDetails.Instance::isRunning).forEach(i -> {
File outputDir = getDirectoryStructure().getServiceLogsPath(details.getDeploymentName(), i.getId(), getService().getCanonicalName()).toFile();
collectInstanceLogs(details, runtimeSettings, outputDir, i.getId());
}));
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService 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();
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService 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.service.distributed.DistributedService 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