private <T extends Account> void rollbackService(AccountDeploymentDetails<T> details, Orca orca, DistributedService distributedService, SpinnakerRuntimeSettings runtimeSettings) { DaemonTaskHandler.newStage("Rolling back " + distributedService.getServiceName()); Map<String, Object> pipeline = distributedService .buildRollbackPipeline(details, runtimeSettings); Supplier<String> idSupplier = () -> (String) orca.orchestrate(pipeline).get("ref"); orcaRunner.monitorPipeline(idSupplier, orca); }
default T connectToPrimaryService(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) { return connectToService(details, runtimeSettings, getService()); }
private <T extends Account> void deployServiceManually(AccountDeploymentDetails<T> details, ResolvedConfiguration resolvedConfiguration, DistributedService distributedService, boolean safeToUpdate) { DaemonTaskHandler.message("Manually deploying " + distributedService.getServiceName()); List<ConfigSource> configs = distributedService.stageProfiles(details, resolvedConfiguration); distributedService.ensureRunning(details, resolvedConfiguration, configs, safeToUpdate); }
default Map<String, Object> buildUpsertLoadBalancerTask(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) { Map<String, Object> upsertDescription = getLoadBalancerDescription(details, runtimeSettings); upsertDescription.put("name", "upsert"); upsertDescription.put("type", AtomicOperations.UPSERT_LOAD_BALANCER); upsertDescription.put("cloudProvider", getProviderType().getId()); upsertDescription.put("refId", "upsertlb"); upsertDescription.put("application", "spin"); upsertDescription.put("availabilityZones", getAvailabilityZones(runtimeSettings.getServiceSettings(getService()))); List<Map<String, Object>> job = new ArrayList<>(); job.add(upsertDescription); Map<String, Object> task = new HashMap<>(); task.put("job", job); task.put("application", "spin"); task.put("name", "Upsert LB of " + getServiceName()); task.put("description", "Auto-generated by Halyard"); return task; }
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; .getRunningServiceDetails(deploymentDetails, runtimeSettings); if (runningServiceDetails.getInstances().keySet().size() == 1) { throw new HalException(Problem.Severity.FATAL, "Service " + service.getCanonicalName() for (DistributedService distributedService : serviceProvider .getPrioritizedDistributedServices(serviceTypes)) { SpinnakerService service = distributedService.getService(); ServiceSettings settings = runtimeSettings.getServiceSettings(service); if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) { if (distributedService.isRequiredToBootstrap() || !safeToUpdate) { 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);
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); }
DistributedService<Rosco, T> roscoService ) { if (runtimeSettings.getServiceSettings(roscoService.getService()) .getSkipLifeCycleManagement()) { return; ServiceSettings roscoSettings = runtimeSettings.getServiceSettings(roscoService.getService()); Rosco.AllStatus allStatus; Rosco rosco = roscoService.connectToPrimaryService(details, runtimeSettings); allStatus = rosco.getAllStatus(); } catch (RetrofitError e) { .getRunningServiceDetails(details, runtimeSettings);
if (workloadByVersion.get(version) == 0) { DaemonTaskHandler.message("Reaping old server group sequence " + version); service.deleteVersion(details, settings, version); if (workloadByVersion.get(version) == 0) { DaemonTaskHandler.message("Shrinking old server group sequence " + version); service.resizeVersion(details, settings, version, 0);
log.info("Disabling instance " + instance.getId()); Orca orca = orcaService .connectToInstance(details, runtimeSettings, orcaService.getService(), instance.getId()); orca.setInstanceStatusEnabled(disableRequest);
@Override public void flushInfrastructureCaches(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) { try { Jedis jedis = (Jedis) serviceProvider .getDeployableService(SpinnakerService.Type.REDIS) .connectToPrimaryService(deploymentDetails, runtimeSettings); RedisService.flushKeySpace(jedis, "com.netflix.spinnaker.clouddriver*"); } catch (Exception e) { throw new HalException(Problem.Severity.FATAL, "Failed to flush redis cache: " + e.getMessage()); } }
@Override default Map<String, Object> buildRollbackPipeline(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) { ServiceSettings settings = runtimeSettings.getServiceSettings(getService()); Map<String, Object> pipeline = DistributedService.super.buildRollbackPipeline(details, runtimeSettings); List<Map<String, Object>> stages = (List<Map<String, Object>>) pipeline.get("stages"); assert(stages != null && !stages.isEmpty()); for (Map<String, Object> stage : stages) { stage.put("namespaces", Collections.singletonList(getNamespace(settings))); stage.put("interestingHealthProviderNames", Collections.singletonList("KubernetesService")); stage.remove("region"); } return pipeline; }
@Override public RemoteAction connectCommand(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings, List<SpinnakerService.Type> serviceTypes) { RemoteAction result = new RemoteAction(); String connectCommands = String.join(" &\n", serviceTypes.stream() .map(t -> serviceProvider.getDeployableService(t) .connectCommand(deploymentDetails, runtimeSettings)) .collect(Collectors.toList())); result.setScript("#!/bin/bash\n" + connectCommands); result.setScriptDescription( "The generated script will open connections to the API & UI servers using ssh tunnels"); result.setAutoRun(false); return result; }
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; .getRunningServiceDetails(deploymentDetails, runtimeSettings); if (runningServiceDetails.getInstances().keySet().size() == 1) { throw new HalException(Problem.Severity.FATAL, "Service " + service.getCanonicalName() for (DistributedService distributedService : serviceProvider .getPrioritizedDistributedServices(serviceTypes)) { SpinnakerService service = distributedService.getService(); ServiceSettings settings = runtimeSettings.getServiceSettings(service); if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) { if (distributedService.isRequiredToBootstrap() || !safeToUpdate) { 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);
default Map<String, Object> buildUpsertLoadBalancerTask(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) { Map<String, Object> upsertDescription = getLoadBalancerDescription(details, runtimeSettings); upsertDescription.put("name", "upsert"); upsertDescription.put("type", AtomicOperations.UPSERT_LOAD_BALANCER); upsertDescription.put("cloudProvider", getProviderType().getId()); upsertDescription.put("refId", "upsertlb"); upsertDescription.put("application", "spin"); upsertDescription.put("availabilityZones", getAvailabilityZones(runtimeSettings.getServiceSettings(getService()))); List<Map<String, Object>> job = new ArrayList<>(); job.add(upsertDescription); Map<String, Object> task = new HashMap<>(); task.put("job", job); task.put("application", "spin"); task.put("name", "Upsert LB of " + getServiceName()); task.put("description", "Auto-generated by Halyard"); return task; }
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); }
DistributedService<Rosco, T> roscoService ) { if (runtimeSettings.getServiceSettings(roscoService.getService()) .getSkipLifeCycleManagement()) { return; ServiceSettings roscoSettings = runtimeSettings.getServiceSettings(roscoService.getService()); Rosco.AllStatus allStatus; Rosco rosco = roscoService.connectToPrimaryService(details, runtimeSettings); allStatus = rosco.getAllStatus(); } catch (RetrofitError e) { .getRunningServiceDetails(details, runtimeSettings);
if (workloadByVersion.get(version) == 0) { DaemonTaskHandler.message("Reaping old server group sequence " + version); service.deleteVersion(details, settings, version); if (workloadByVersion.get(version) == 0) { DaemonTaskHandler.message("Shrinking old server group sequence " + version); service.resizeVersion(details, settings, version, 0);
log.info("Disabling instance " + instance.getId()); Orca orca = orcaService .connectToInstance(details, runtimeSettings, orcaService.getService(), instance.getId()); orca.setInstanceStatusEnabled(disableRequest);
@Override public void flushInfrastructureCaches(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) { try { Jedis jedis = (Jedis) serviceProvider .getDeployableService(SpinnakerService.Type.REDIS) .connectToPrimaryService(deploymentDetails, runtimeSettings); RedisService.flushKeySpace(jedis, "com.netflix.spinnaker.clouddriver*"); } catch (Exception e) { throw new HalException(Problem.Severity.FATAL, "Failed to flush redis cache: " + e.getMessage()); } }
@Override default Map<String, Object> buildRollbackPipeline(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) { ServiceSettings settings = runtimeSettings.getServiceSettings(getService()); Map<String, Object> pipeline = DistributedService.super.buildRollbackPipeline(details, runtimeSettings); List<Map<String, Object>> stages = (List<Map<String, Object>>) pipeline.get("stages"); assert(stages != null && !stages.isEmpty()); for (Map<String, Object> stage : stages) { stage.put("namespaces", Collections.singletonList(getNamespace(settings))); stage.put("interestingHealthProviderNames", Collections.singletonList("KubernetesService")); stage.remove("region"); } return pipeline; }