use of com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails in project halyard by spinnaker.
the class LocalDebianServiceProvider method getInstallCommand.
@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands) {
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 = getLocalServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((LocalDebianService) 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/install.sh");
bindings = new HashMap<>();
bindings.put("prepare-environment", "true");
bindings.put("install-redis", "true");
bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
bindings.put("install-commands", String.join("\n", serviceInstalls));
bindings.put("service-action", "restart");
bindings.put("upstart-init", upstartInit);
return resource.setBindings(bindings).toString();
}
use of com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails in project halyard by spinnaker.
the class GenerateService method generateConfig.
/**
* Generate config for a given deployment.
*
* This involves a few steps:
*
* 1. Clear out old config generated in a prior run.
* 2. Generate configuration using the halconfig as the source of truth, while collecting files needed by
* the deployment.
*
* @param deploymentName is the deployment whose config to generate
* @param services is the list of services to generate configs for
* @return a mapping from components to the profile's required local files.
*/
public ResolvedConfiguration generateConfig(String deploymentName, List<SpinnakerService.Type> services) {
DaemonTaskHandler.newStage("Generating all Spinnaker profile files and endpoints");
log.info("Generating config from \"" + halconfigPath + "\" with deploymentName \"" + deploymentName + "\"");
File spinnakerStaging = halconfigDirectoryStructure.getStagingPath(deploymentName).toFile();
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
DaemonTaskHandler.message("Building service endpoints");
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration);
// Step 1.
try {
FileUtils.deleteDirectory(spinnakerStaging);
} catch (IOException e) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Unable to clear old spinnaker config: " + e.getMessage() + ".").build());
}
Path userProfilePath = halconfigDirectoryStructure.getUserProfilePath(deploymentName);
List<String> userProfileNames = aggregateProfilesInPath(userProfilePath.toString(), "");
// Step 2.
Map<SpinnakerService.Type, Map<String, Profile>> serviceProfiles = new HashMap<>();
for (SpinnakerService service : serviceProvider.getServices()) {
boolean isDesiredService = services.stream().filter(s -> s.equals(service.getType())).count() > 0;
if (!isDesiredService) {
continue;
}
ServiceSettings settings = runtimeSettings.getServiceSettings(service);
if (settings == null || !settings.getEnabled()) {
continue;
}
List<Profile> profiles = service.getProfiles(deploymentConfiguration, runtimeSettings);
String pluralModifier = profiles.size() == 1 ? "" : "s";
String profileMessage = "Generated " + profiles.size() + " profile" + pluralModifier;
Map<String, Profile> outputProfiles = processProfiles(spinnakerStaging, profiles);
List<Profile> customProfiles = userProfileNames.stream().map(s -> (Optional<Profile>) service.customProfile(deploymentConfiguration, runtimeSettings, Paths.get(userProfilePath.toString(), s), s)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
pluralModifier = customProfiles.size() == 1 ? "" : "s";
profileMessage += " and discovered " + customProfiles.size() + " custom profile" + pluralModifier + " for " + service.getCanonicalName();
DaemonTaskHandler.message(profileMessage);
mergeProfilesAndPreserveProperties(outputProfiles, processProfiles(spinnakerStaging, customProfiles));
serviceProfiles.put(service.getType(), outputProfiles);
}
return new ResolvedConfiguration().setServiceProfiles(serviceProfiles).setRuntimeSettings(runtimeSettings);
}
use of com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails in project halyard by spinnaker.
the class DeployService method deploy.
public RemoteAction deploy(String deploymentName, List<DeployOption> deployOptions, List<String> serviceNames) {
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());
}
ResolvedConfiguration resolvedConfiguration;
if (deployOptions.contains(DeployOption.OMIT_CONFIG)) {
resolvedConfiguration = generateService.generateConfig(deploymentName, Collections.emptyList());
} else {
resolvedConfiguration = generateService.generateConfig(deploymentName, serviceTypes);
}
Path serviceSettingsPath = halconfigDirectoryStructure.getServiceSettingsPath(deploymentName);
configParser.atomicWrite(serviceSettingsPath, resolvedConfiguration.getRuntimeSettings());
Path serviceProfilesPath = halconfigDirectoryStructure.getServiceProfilesPath(deploymentName);
configParser.atomicWrite(serviceProfilesPath, resolvedConfiguration.getServiceProfiles());
Deployer deployer = getDeployer(deploymentConfiguration);
DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration);
RemoteAction action = deployer.deploy(serviceProvider, deploymentDetails, resolvedConfiguration, serviceTypes);
halconfigParser.backupConfig();
if (deployOptions.contains(DeployOption.FLUSH_INFRASTRUCTURE_CACHES)) {
deployer.flushInfrastructureCaches(serviceProvider, deploymentDetails, resolvedConfiguration.getRuntimeSettings());
}
if (!action.getScript().isEmpty()) {
action.commitScript(halconfigDirectoryStructure.getInstallScriptPath(deploymentName));
}
return action;
}
use of com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails in project halyard by spinnaker.
the class DeployService method connectCommand.
public RemoteAction connectCommand(String deploymentName, List<String> serviceNames) {
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.add(SpinnakerService.Type.DECK);
serviceTypes.add(SpinnakerService.Type.GATE);
}
RemoteAction result = deployer.connectCommand(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes);
result.setAutoRun(true);
result.commitScript(halconfigDirectoryStructure.getConnectScriptPath(deploymentName));
return result;
}
use of com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails in project halyard by spinnaker.
the class DeployService method prep.
public RemoteAction prep(String deploymentName, List<String> serviceNames) {
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());
}
RemoteAction action = deployer.prep(serviceProvider, deploymentDetails, runtimeSettings, serviceTypes);
if (!action.getScript().isEmpty()) {
action.commitScript(halconfigDirectoryStructure.getPrepScriptPath(deploymentName));
}
return action;
}
Aggregations