-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): add NotificationAgent extension point (#962)
- Loading branch information
1 parent
d3c50cf
commit 50c86c3
Showing
8 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
echo-api/src/main/java/com/netflix/spinnaker/echo/api/events/NotificationAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2020 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.api.events; | ||
|
||
import com.netflix.spinnaker.kork.annotations.Alpha; | ||
import com.netflix.spinnaker.kork.plugins.api.internal.SpinnakerExtensionPoint; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
|
||
/** A NotificationAgent handles user-configured pipeline notifications. */ | ||
@Alpha | ||
public interface NotificationAgent extends SpinnakerExtensionPoint { | ||
/** The notification's type (e.g., Slack, SMS, email). */ | ||
@Nonnull | ||
String getNotificationType(); | ||
|
||
/** | ||
* @param notificationConfig - User-defined configuration. Arbitrary key-value pairs can be passed | ||
* to the agent here (e.g., a Slack channel name). | ||
* @param application - The name of the application where the pipeline was run. | ||
* @param event - a Spinnaker {@link Event}. | ||
* @param status - The state of the referenced resource (e.g., failed, complete, etc.). | ||
*/ | ||
void sendNotifications( | ||
@Nonnull Map<String, Object> notificationConfig, | ||
@Nonnull String application, | ||
@Nonnull Event event, | ||
@Nonnull String status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...s/src/main/groovy/com/netflix/spinnaker/echo/notification/ExtensionNotificationAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.notification; | ||
|
||
import com.netflix.spinnaker.echo.api.events.Event; | ||
import com.netflix.spinnaker.echo.api.events.NotificationAgent; | ||
import java.util.Map; | ||
|
||
public class ExtensionNotificationAgent extends AbstractEventNotificationAgent { | ||
|
||
private final NotificationAgent agent; | ||
|
||
public ExtensionNotificationAgent(NotificationAgent agent) { | ||
this.agent = agent; | ||
} | ||
|
||
@Override | ||
public String getNotificationType() { | ||
return agent.getNotificationType(); | ||
} | ||
|
||
@Override | ||
public void sendNotifications( | ||
Map notification, String application, Event event, Map config, String status) { | ||
agent.sendNotifications(notification, application, event, status); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ins-test/src/main/kotlin/com/netflix/spinnaker/echo/plugins/NotificationAgentExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2020 Armory, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.echo.plugins | ||
|
||
import com.netflix.spinnaker.echo.api.events.Event | ||
import com.netflix.spinnaker.echo.api.events.NotificationAgent | ||
import org.pf4j.Extension | ||
|
||
@Extension | ||
class NotificationAgentExtension : NotificationAgent { | ||
override fun getNotificationType() = "extension_notification" | ||
override fun sendNotifications(notification: MutableMap<String, Any>, application: String, event: Event, status: String) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters