use of com.netflix.spinnaker.halyard.config.model.v1.node.Notification in project halyard by spinnaker.
the class AbstractEditNotificationCommand method executeThis.
@Override
protected void executeThis() {
String notificationName = getNotificationName();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
Notification notification = new OperationHandler<Notification>().setOperation(Daemon.getNotification(currentDeployment, notificationName, !noValidate)).setFailureMesssage("Failed to get " + notificationName + ".").get();
int originalHash = notification.hashCode();
notification = editNotification((N) notification);
if (originalHash == notification.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setOperation(Daemon.setNotification(currentDeployment, notificationName, !noValidate, notification)).setSuccessMessage("Edited " + notificationName + ".").setFailureMesssage("Failed to edit " + notificationName + ".").get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Notification in project halyard by spinnaker.
the class NotificationService method getNotification.
public Notification getNotification(String deploymentName, String notificationName) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setNotification(notificationName);
List<Notification> matching = lookupService.getMatchingNodesOfType(filter, Notification.class);
switch(matching.size()) {
case 0:
throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No notification type with name \"" + notificationName + "\" could be found").build());
case 1:
return matching.get(0);
default:
throw new IllegalConfigException(new ConfigProblemBuilder(Severity.FATAL, "More than one notification type with name \"" + notificationName + "\" found").build());
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Notification in project halyard by spinnaker.
the class NotificationController method setNotification.
@RequestMapping(value = "/{notificationName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setNotification(@PathVariable String deploymentName, @PathVariable String notificationName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawNotification) {
Notification notification = objectMapper.convertValue(rawNotification, Notifications.translateNotificationType(notificationName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> notification.stageLocalFiles(configPath));
builder.setUpdate(() -> notificationService.setNotification(deploymentName, notification));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> notificationService.validateNotification(deploymentName, notificationName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + notificationName + " notification");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Notification in project halyard by spinnaker.
the class NotificationService method setEnabled.
public void setEnabled(String deploymentName, String notificationName, boolean enabled) {
Notification notification = getNotification(deploymentName, notificationName);
notification.setEnabled(enabled);
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Notification in project halyard by spinnaker.
the class NotificationService method setNotification.
public void setNotification(String deploymentName, Notification notification) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
Notifications notifications = deploymentConfiguration.getNotifications();
switch(notification.getNotificationType()) {
case SLACK:
notifications.setSlack((SlackNotification) notification);
break;
default:
throw new IllegalArgumentException("Unknown notification type " + notification.getNotificationType());
}
}
Aggregations