use of com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED in project halyard by spinnaker.
the class AnsiFormatUtils method format.
static void format(NodeDiff diff, AnsiStoryBuilder resultBuilder) {
AnsiSnippet snippet = null;
AnsiParagraphBuilder paragraph = null;
boolean printLocation = true;
switch(diff.getChangeType()) {
case EDITED:
if (!diff.getFieldDiffs().isEmpty()) {
snippet = new AnsiSnippet("~ EDITED\n").setForegroundColor(AnsiForegroundColor.MAGENTA);
} else {
printLocation = false;
}
break;
case REMOVED:
snippet = new AnsiSnippet("- REMOVED\n").setForegroundColor(AnsiForegroundColor.RED);
break;
case ADDED:
snippet = new AnsiSnippet("+ ADDED\n").setForegroundColor(AnsiForegroundColor.GREEN);
break;
default:
throw new RuntimeException("Unknown changetype " + diff.getChangeType());
}
if (printLocation) {
paragraph = resultBuilder.addParagraph();
paragraph.addSnippet(snippet.addStyle(AnsiStyle.BOLD).toString());
paragraph.addSnippet(diff.getLocation()).addStyle(AnsiStyle.BOLD);
}
for (NodeDiff.FieldDiff fieldDiff : diff.getFieldDiffs()) {
paragraph = resultBuilder.addParagraph();
paragraph.addSnippet(" - ");
paragraph.addSnippet(fieldDiff.getFieldName()).addStyle(AnsiStyle.UNDERLINE);
paragraph.addSnippet(" " + fieldDiff.getOldValue() + " -> " + fieldDiff.getNewValue());
}
if (printLocation) {
resultBuilder.addNewline();
}
for (NodeDiff nodeDiff : diff.getNodeDiffs()) {
format(nodeDiff, resultBuilder);
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED in project halyard by spinnaker.
the class BakeryController method addBaseImage.
@RequestMapping(value = "/defaults/baseImage/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @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.setSeverity(severity);
// TODO(lwander): Would be good to indicate when an added base image id conflicts with an existing base image id.
builder.setUpdate(() -> bakeryService.addBaseImage(deploymentName, providerName, baseImage));
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, "Add " + baseImage.getNodeName() + " base image");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED in project halyard by spinnaker.
the class AbstractAddAccountCommand method executeThis.
@Override
protected void executeThis() {
String accountName = getAccountName();
Account account = buildAccount(accountName);
account.setRequiredGroupMembership(requiredGroupMembership);
account.setProviderVersion(providerVersion);
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
new OperationHandler<Void>().setFailureMesssage("Failed to add account " + accountName + " for provider " + providerName + ".").setSuccessMessage("Successfully added account " + accountName + " for provider " + providerName + ".").setOperation(Daemon.addAccount(currentDeployment, providerName, !noValidate, account)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED in project halyard by spinnaker.
the class AbstractAddBaseImageCommand method executeThis.
@Override
protected void executeThis() {
String baseImageId = getBaseImageId();
BaseImage baseImage = buildBaseImage(baseImageId);
BaseImage.ImageSettings imageSettings = baseImage.getBaseImage();
if (imageSettings == null) {
throw new RuntimeException("Provider " + getProviderName() + " must provide image settings when building a base image. This is a bug with this provider's implementation of halyard.");
}
imageSettings.setId(getBaseImageId());
imageSettings.setShortDescription(shortDescription);
imageSettings.setDetailedDescription(detailedDescription);
imageSettings.setPackageType(packageType);
imageSettings.setTemplateFile(templateFile);
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
new OperationHandler<Void>().setSuccessMessage("Successfully added base image " + baseImageId + " to " + providerName + "'s bakery.").setFailureMesssage("Failed to add base image " + baseImageId + " to " + providerName + "'s bakery.").setOperation(Daemon.addBaseImage(currentDeployment, providerName, !noValidate, baseImage)).get();
}
Aggregations