public BakeService getBakeService(SpinnakerService.Type type) { return getBakeService(type, Object.class); }
public List<BakeService> getPrioritizedBakeableServices(List<SpinnakerService.Type> serviceTypes) { List<BakeService> result = getFieldsOfType(BakeService.class) .stream() .filter(s -> serviceTypes.contains(s.getService().getType())) .collect(Collectors.toList()); result.sort((a, b) -> b.getPriority().compareTo(a.getPriority())); return result; } }
public <S> BakeService<S> getBakeService(SpinnakerService.Type type, Class<S> clazz) { Field serviceField = getField(type.getCanonicalName() + "service"); if (serviceField == null) { return null; } serviceField.setAccessible(true); try { return (BakeService<S>) serviceField.get(this); } catch (IllegalAccessException e) { throw new HalException(Problem.Severity.FATAL, "Can't access service field for " + type + ": " + e.getMessage()); } finally { serviceField.setAccessible(false); } }
List<SpinnakerService.Type> serviceTypes, boolean waitForCompletion) { List<BakeService> enabledServices = serviceProvider.getPrioritizedBakeableServices(serviceTypes) .stream() .filter(i -> { ServiceSettings serviceSettings = resolvedConfiguration.getServiceSettings(i.getService()); return serviceSettings != null && serviceSettings.getEnabled(); }) installable.installArtifactCommand(deploymentDetails), installable.stageStartupScripts(deploymentDetails, resolvedConfiguration)); commands.put(installable.getService().getCanonicalName(), command); return commands; }, (m1, m2) -> { .collect(Collectors.toList())); String installCommand = serviceProvider.getInstallCommand(deploymentDetails, resolvedConfiguration, installCommands, startupCommand); RemoteAction result = new RemoteAction(); result.setAutoRun(true);
@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(); }
default String stageStartupScripts(DeploymentDetails details, GenerateService.ResolvedConfiguration resolvedConfiguration) { Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getService().getType()); List<String> allCommands = new ArrayList<>(); for (Map.Entry<String, Profile> entry : profiles.entrySet()) { Profile profile = entry.getValue(); String source = profile.getStagedFile(getSpinnakerStagingPath(details.getDeploymentName())); String dest = profile.getOutputFile(); allCommands.add(String.format("mkdir -p $(dirname %s)", dest)); allCommands.add(String.format("cp -p %s %s", source, dest)); if (profile.isExecutable()) { allCommands.add(String.format("chmod +x %s", dest)); } } return Strings.join(allCommands, "\n"); }
GenerateService.ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) { List<BakeService> enabledServices = serviceProvider.getPrioritizedBakeableServices(serviceTypes) .stream() .filter(i -> { ServiceSettings serviceSettings = resolvedConfiguration.getServiceSettings(i.getService()); return serviceSettings != null && serviceSettings.getEnabled(); }) installable.installArtifactCommand(deploymentDetails), installable.stageStartupScripts(deploymentDetails, resolvedConfiguration)); commands.put(installable.getService().getCanonicalName(), command); return commands; }, (m1, m2) -> { .collect(Collectors.toList())); String installCommand = serviceProvider.getInstallCommand(deploymentDetails, resolvedConfiguration, installCommands, startupCommand); RemoteAction result = new RemoteAction(); result.setAutoRun(true);
public List<BakeService> getPrioritizedBakeableServices(List<SpinnakerService.Type> serviceTypes) { List<BakeService> result = getFieldsOfType(BakeService.class) .stream() .filter(s -> serviceTypes.contains(s.getService().getType())) .collect(Collectors.toList()); result.sort((a, b) -> b.getPriority().compareTo(a.getPriority())); return result; } }
@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(); }
default String stageStartupScripts(DeploymentDetails details, GenerateService.ResolvedConfiguration resolvedConfiguration) { Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getService().getType()); List<String> allCommands = new ArrayList<>(); for (Map.Entry<String, Profile> entry : profiles.entrySet()) { Profile profile = entry.getValue(); String source = profile.getStagedFile(getSpinnakerStagingPath(details.getDeploymentName())); String dest = profile.getOutputFile(); allCommands.add(String.format("mkdir -p $(dirname %s)", dest)); allCommands.add(String.format("cp -p %s %s", source, dest)); if (profile.isExecutable()) { allCommands.add(String.format("chmod +x %s", dest)); } } return Strings.join(allCommands, "\n"); }
public BakeService getBakeService(SpinnakerService.Type type) { return getBakeService(type, Object.class); }
public <S> BakeService<S> getBakeService(SpinnakerService.Type type, Class<S> clazz) { Field serviceField = getField(type.getCanonicalName() + "service"); if (serviceField == null) { return null; } serviceField.setAccessible(true); try { return (BakeService<S>) serviceField.get(this); } catch (IllegalAccessException e) { throw new HalException(Problem.Severity.FATAL, "Can't access service field for " + type + ": " + e.getMessage()); } finally { serviceField.setAccessible(false); } }