use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig 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.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class BakeryController method setBakeryDefaults.
@RequestMapping(value = "/defaults/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setBakeryDefaults(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBakeryDefaults) {
BakeryDefaults bakeryDefaults = objectMapper.convertValue(rawBakeryDefaults, Providers.translateBakeryDefaultsType(providerName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> bakeryDefaults.stageLocalFiles(configPath));
builder.setUpdate(() -> bakeryService.setBakeryDefaults(deploymentName, providerName, bakeryDefaults));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> bakeryService.validateBakeryDefaults(deploymentName, providerName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit " + providerName + " bakery defaults");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class BakeryController method setBaseImage.
@RequestMapping(value = "/defaults/baseImage/{baseImageId:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @PathVariable String baseImageId, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBaseImage) {
BaseImage baseImage = objectMapper.convertValue(rawBaseImage, Providers.translateBaseImageType(providerName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> baseImage.stageLocalFiles(configPath));
builder.setUpdate(() -> bakeryService.setBaseImage(deploymentName, providerName, baseImageId, baseImage));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> bakeryService.validateBaseImage(deploymentName, providerName, baseImage.getBaseImage().getId());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit " + baseImageId + " base image");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class DeploymentController method deploymentConfiguration.
@RequestMapping(value = "/{deploymentName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> deploymentConfiguration(@PathVariable String deploymentName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawDeployment) {
DeploymentConfiguration deploymentConfiguration = objectMapper.convertValue(rawDeployment, DeploymentConfiguration.class);
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> deploymentConfiguration.stageLocalFiles(configPath));
builder.setSeverity(severity);
builder.setUpdate(() -> deploymentService.setDeploymentConfiguration(deploymentName, deploymentConfiguration));
if (validate) {
builder.setValidate(() -> deploymentService.validateDeployment(deploymentName));
} else {
builder.setValidate(ProblemSet::new);
}
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit deployment configuration");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class FeaturesController method setFeatures.
@RequestMapping(value = "/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setFeatures(@PathVariable String deploymentName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawFeatures) {
Features features = objectMapper.convertValue(rawFeatures, Features.class);
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> features.stageLocalFiles(configPath));
builder.setUpdate(() -> featuresService.setFeatures(deploymentName, features));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> featuresService.validateFeatures(deploymentName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit features");
}
Aggregations