Search in sources :

Example 1 with Notification

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();
}
Also used : Notification(com.netflix.spinnaker.halyard.config.model.v1.node.Notification) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with Notification

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());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) Notification(com.netflix.spinnaker.halyard.config.model.v1.node.Notification) SlackNotification(com.netflix.spinnaker.halyard.config.model.v1.notifications.SlackNotification) IllegalConfigException(com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 3 with Notification

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

Example 4 with 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);
}
Also used : Notification(com.netflix.spinnaker.halyard.config.model.v1.node.Notification) SlackNotification(com.netflix.spinnaker.halyard.config.model.v1.notifications.SlackNotification)

Example 5 with Notification

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());
    }
}
Also used : Notifications(com.netflix.spinnaker.halyard.config.model.v1.node.Notifications) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Aggregations

Notification (com.netflix.spinnaker.halyard.config.model.v1.node.Notification)4 SlackNotification (com.netflix.spinnaker.halyard.config.model.v1.notifications.SlackNotification)2 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 Notifications (com.netflix.spinnaker.halyard.config.model.v1.node.Notifications)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)1 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)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