@Override protected Optional<String> customProfileOutputPath(String profileName) { if (profileName.equals(getCanonicalName() + ".yml") || profileName.startsWith(getCanonicalName() + "-") || profileName.equals(getType().getBaseType().getCanonicalName() + "-local.yml") || profileName.startsWith("spinnaker")) { return Optional.of(Paths.get(getConfigOutputPath(), profileName).toString()); } else { return Optional.empty(); } }
public static Type fromCanonicalName(String canonicalName) { String finalName = reduceName(canonicalName); return Arrays.stream(values()) .filter(t -> reduceName(t.getCanonicalName()).equalsIgnoreCase(finalName)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No service with canonical name " + canonicalName + " exists.")); } }
.anyMatch(s -> s.getService().getType().equals(SpinnakerService.Type.CONSUL_CLIENT));
.anyMatch(s -> s.getService().getType().equals(SpinnakerService.Type.CONSUL_CLIENT));
boolean isDesiredService = services .stream() .filter(s -> s.equals(service.getType())) .count() > 0;
boolean isDesiredService = services .stream() .filter(s -> s.equals(service.getType())) .count() > 0;
if (((SpinnakerService) service).getType().equals(Type.REDIS) && executor.exists(resourceDefinition)) {
serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList());
serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList());
.collect(Collectors.toList()); List<String> serviceInstalls = serviceTypes.stream() .map(t -> installCommands.get(t.getCanonicalName())) .collect(Collectors.toList());
public RemoteAction prep(String deploymentName, List<String> serviceNames, List<String> excludeServiceNames) { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration); Deployer deployer = getDeployer(deploymentConfiguration); SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration); SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration); List<SpinnakerService.Type> serviceTypes = serviceNames.stream() .map(SpinnakerService.Type::fromCanonicalName) .collect(Collectors.toList()); if (serviceTypes.isEmpty()) { serviceTypes = serviceProvider .getServices() .stream() .map(SpinnakerService::getType) .collect(Collectors.toList()); } if (!excludeServiceNames.isEmpty()) { serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList()); } RemoteAction action = deployer.prep(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes); if (!action.getScript().isEmpty()) { action.commitScript(halconfigDirectoryStructure.getPrepScriptPath(deploymentName)); } return action; }
.collect(Collectors.toList()); List<String> serviceInstalls = serviceTypes.stream() .map(t -> installCommands.get(t.getCanonicalName())) .collect(Collectors.toList());
@Override public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands, String startupCommand) { Map<String, Object> bindings = new HashMap<>(); List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList()); List<String> upstartNames = getPrioritizedBakeableServices(serviceTypes) .stream() .filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()) .map(i -> ((BakeDebianService) i).getUpstartServiceName()) .filter(Objects::nonNull) .collect(Collectors.toList()); List<String> systemdServiceConfigs = upstartNames.stream() .map(n -> n + ".service") .collect(Collectors.toList()); List<String> serviceInstalls = serviceTypes.stream() .map(t -> installCommands.get(t.getCanonicalName())) .collect(Collectors.toList()); TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh"); bindings.put("services", Strings.join(upstartNames, " ")); bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " ")); String upstartInit = resource.setBindings(bindings).toString(); BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName()); resource = new StringReplaceJarResource("/debian/pre-bake.sh"); bindings = new HashMap<>(); bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository()); bindings.put("install-commands", String.join("\n", serviceInstalls)); bindings.put("upstart-init", upstartInit); bindings.put("startup-file", Paths.get(startupScriptPath, "startup.sh").toString()); bindings.put("startup-command", startupCommand); return resource.setBindings(bindings).toString(); }
public RemoteAction prep(String deploymentName, List<String> serviceNames, List<String> excludeServiceNames) { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration); Deployer deployer = getDeployer(deploymentConfiguration); SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration); SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration); List<SpinnakerService.Type> serviceTypes = serviceNames.stream() .map(SpinnakerService.Type::fromCanonicalName) .collect(Collectors.toList()); if (serviceTypes.isEmpty()) { serviceTypes = serviceProvider .getServices() .stream() .map(SpinnakerService::getType) .collect(Collectors.toList()); } if (!excludeServiceNames.isEmpty()) { serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList()); } RemoteAction action = deployer.prep(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes); if (!action.getScript().isEmpty()) { action.commitScript(halconfigDirectoryStructure.getPrepScriptPath(deploymentName)); } return action; }
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { ConsulCheck check = new ConsulCheck() .setId("default-hal-check") .setInterval("30s"); if (settings.getHealthEndpoint() != null) { check.setHttp(new URIBuilder() .setScheme(settings.getScheme()) .setHost("localhost") .setPort(settings.getPort()) .setPath(settings.getHealthEndpoint()) .toString() ); } else { check.setTcp("localhost:" + settings.getPort()); } ConsulService consulService = new ConsulService() .setName(type.getCanonicalName()) .setPort(settings.getPort()) .setChecks(Collections.singletonList(check)); ServiceWrapper serviceWrapper = new ServiceWrapper().setService(consulService); try { profile.appendContents(objectMapper.writeValueAsString(serviceWrapper)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) { ConsulCheck check = new ConsulCheck() .setId("default-hal-check") .setInterval("30s"); if (settings.getHealthEndpoint() != null) { check.setHttp(new URIBuilder() .setScheme(settings.getScheme()) .setHost("localhost") .setPort(settings.getPort()) .setPath(settings.getHealthEndpoint()) .toString() ); } else { check.setTcp("localhost:" + settings.getPort()); } ConsulService consulService = new ConsulService() .setName(type.getCanonicalName()) .setPort(settings.getPort()) .setChecks(Collections.singletonList(check)); ServiceWrapper serviceWrapper = new ServiceWrapper().setService(consulService); try { profile.appendContents(objectMapper.writeValueAsString(serviceWrapper)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
@Override public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands, String startupCommand) { Map<String, Object> bindings = new HashMap<>(); List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList()); List<String> upstartNames = getPrioritizedBakeableServices(serviceTypes) .stream() .filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()) .map(i -> ((BakeDebianService) i).getUpstartServiceName()) .filter(Objects::nonNull) .collect(Collectors.toList()); List<String> systemdServiceConfigs = upstartNames.stream() .map(n -> n + ".service") .collect(Collectors.toList()); List<String> serviceInstalls = serviceTypes.stream() .map(t -> installCommands.get(t.getCanonicalName())) .collect(Collectors.toList()); TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh"); bindings.put("services", Strings.join(upstartNames, " ")); bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " ")); String upstartInit = resource.setBindings(bindings).toString(); BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName()); resource = new StringReplaceJarResource("/debian/pre-bake.sh"); bindings = new HashMap<>(); bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository()); bindings.put("install-commands", String.join("\n", serviceInstalls)); bindings.put("upstart-init", upstartInit); bindings.put("startup-file", Paths.get(startupScriptPath, "startup.sh").toString()); bindings.put("startup-command", startupCommand); return resource.setBindings(bindings).toString(); }
public void rollback(String deploymentName, List<String> serviceNames, List<String> excludeServiceNames) { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration); List<SpinnakerService.Type> serviceTypes = serviceNames.stream() .map(SpinnakerService.Type::fromCanonicalName) .collect(Collectors.toList()); if (serviceTypes.isEmpty()) { serviceTypes = serviceProvider .getServices() .stream() .map(SpinnakerService::getType) .collect(Collectors.toList()); } if (!excludeServiceNames.isEmpty()) { serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList()); } SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration); Deployer deployer = getDeployer(deploymentConfiguration); DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration); deployer.rollback(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes); }
public void rollback(String deploymentName, List<String> serviceNames, List<String> excludeServiceNames) { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration); List<SpinnakerService.Type> serviceTypes = serviceNames.stream() .map(SpinnakerService.Type::fromCanonicalName) .collect(Collectors.toList()); if (serviceTypes.isEmpty()) { serviceTypes = serviceProvider .getServices() .stream() .map(SpinnakerService::getType) .collect(Collectors.toList()); } if (!excludeServiceNames.isEmpty()) { serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList()); } SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration); Deployer deployer = getDeployer(deploymentConfiguration); DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration); deployer.rollback(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes); }
public void collectLogs(String deploymentName, List<String> serviceNames, List<String> excludeServiceNames) { DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName); SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration); SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration); Deployer deployer = getDeployer(deploymentConfiguration); DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration); List<SpinnakerService.Type> serviceTypes = serviceNames.stream() .map(SpinnakerService.Type::fromCanonicalName) .collect(Collectors.toList()); if (serviceTypes.isEmpty()) { serviceTypes = serviceProvider .getServices() .stream() .map(SpinnakerService::getType) .collect(Collectors.toList()); } if (!excludeServiceNames.isEmpty()) { serviceTypes = serviceTypes .stream() .filter(serviceType -> !excludeServiceNames.contains(serviceType.getCanonicalName())) .collect(Collectors.toList()); } deployer.collectLogs(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes); }