Search in sources :

Example 1 with Halconfig

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);
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) Path(java.nio.file.Path) Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) ServiceProviderFactory(com.netflix.spinnaker.halyard.deploy.deployment.v1.ServiceProviderFactory) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) ArrayList(java.util.ArrayList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Severity(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Path(java.nio.file.Path) DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigParser(com.netflix.spinnaker.halyard.deploy.config.v1.ConfigParser) Collectors(java.util.stream.Collectors) HalconfigDirectoryStructure(com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure) File(java.io.File) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) DeploymentService(com.netflix.spinnaker.halyard.config.services.v1.DeploymentService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) Data(lombok.Data) Optional(java.util.Optional) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerServiceProvider) Collections(java.util.Collections) Optional(java.util.Optional) HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) IOException(java.io.IOException) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 2 with Halconfig

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");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Halconfig

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");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) BaseImage(com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Halconfig

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");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Halconfig

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");
}
Also used : Path(java.nio.file.Path) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) Features(com.netflix.spinnaker.halyard.config.model.v1.node.Features) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)36 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)35 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)33 Path (java.nio.file.Path)33 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)11 Halconfig (com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig)10 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)9 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)7 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)6 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)5 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)5 IOException (java.io.IOException)5 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)4 AbstractCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)3 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)3 List (java.util.List)3 ParseConfigException (com.netflix.spinnaker.halyard.config.error.v1.ParseConfigException)2 ArtifactAccount (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactAccount)2 ArtifactProvider (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactProvider)2 BaseImage (com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage)2