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();
}
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");
}
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.");
}
}
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);
}
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());
}
}
Aggregations