Search in sources :

Example 1 with BakeryDefaults

use of com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults in project halyard by spinnaker.

the class AbstractEditBakeryDefaultsCommand method executeThis.

@Override
protected void executeThis() {
    String providerName = getProviderName();
    String currentDeployment = getCurrentDeployment();
    // Disable validation here, since we don't want an illegal config to prevent us from fixing it.
    BakeryDefaults defaults = new OperationHandler<BakeryDefaults>().setFailureMesssage("Failed to get bakery defaults for " + providerName + "'s bakery.").setOperation(Daemon.getBakeryDefaults(currentDeployment, providerName, false)).get();
    int originalHash = defaults.hashCode();
    defaults = editBakeryDefaults((T) defaults);
    if (originalHash == defaults.hashCode()) {
        AnsiUi.failure("No changes supplied.");
        return;
    }
    new OperationHandler<Void>().setSuccessMessage("Successfully edited bakery defaults for " + providerName + "'s bakery.").setFailureMesssage("Failed to edit bakery defaults for " + providerName + "'s bakery.").setOperation(Daemon.setBakeryDefaults(currentDeployment, providerName, !noValidate, defaults)).get();
}
Also used : BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with BakeryDefaults

use of com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults 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 BakeryDefaults

use of com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults in project halyard by spinnaker.

the class BakeryService method getBakeryDefaults.

public BakeryDefaults getBakeryDefaults(String deploymentName, String providerName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setProvider(providerName).setBakeryDefaults();
    List<BakeryDefaults> matching = lookupService.getMatchingNodesOfType(filter, BakeryDefaults.class);
    switch(matching.size()) {
        case 0:
            HasImageProvider provider = providerService.getHasImageProvider(deploymentName, providerName);
            BakeryDefaults bakeryDefaults = provider.emptyBakeryDefaults();
            setBakeryDefaults(deploymentName, providerName, bakeryDefaults);
            return bakeryDefaults;
        case 1:
            return matching.get(0);
        default:
            throw new RuntimeException("It shouldn't be possible to have multiple bakeryDefaults nodes. This is a bug.");
    }
}
Also used : BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter) HasImageProvider(com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider)

Example 4 with BakeryDefaults

use of com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults in project halyard by spinnaker.

the class BakeryService method setBakeryDefaults.

public void setBakeryDefaults(String deploymentName, String providerName, BakeryDefaults newBakeryDefaults) {
    HasImageProvider provider = providerService.getHasImageProvider(deploymentName, providerName);
    provider.setBakeryDefaults(newBakeryDefaults);
}
Also used : HasImageProvider(com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider)

Example 5 with BakeryDefaults

use of com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults in project halyard by spinnaker.

the class BakeryService method deleteBaseImage.

public void deleteBaseImage(String deploymentName, String bakeryDefaultsName, String baseImageId) {
    BakeryDefaults bakeryDefaults = getBakeryDefaults(deploymentName, bakeryDefaultsName);
    boolean removed = bakeryDefaults.getBaseImages().removeIf(baseImage -> ((BaseImage) baseImage).getBaseImage().getId().equals(baseImageId));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "BaseImage \"" + baseImageId + "\" wasn't found").build());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) BakeryDefaults(com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)

Aggregations

BakeryDefaults (com.netflix.spinnaker.halyard.config.model.v1.node.BakeryDefaults)6 HasImageProvider (com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider)2 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 BaseImage (com.netflix.spinnaker.halyard.config.model.v1.node.BaseImage)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)1 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)1 Path (java.nio.file.Path)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1