Skip to content

Commit 63a6681

Browse files
committed
Integration with ES Settings with default values configuration file
Other changes: Changed "notification" to "notifications" to match with repo
1 parent 6fa0d77 commit 63a6681

File tree

25 files changed

+246
-89
lines changed

25 files changed

+246
-89
lines changed

build-tools/pkgbuild.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ afterEvaluate {
4343
maintainer 'OpenDistro for Elasticsearch Team <[email protected]>'
4444
url 'https://opendistro.github.io/elasticsearch/downloads'
4545
summary '''
46-
Open Distro for Elasticsearch Notification.
46+
Open Distro for Elasticsearch Notifications.
4747
Reference documentation can be found at https://opendistro.github.io/elasticsearch/docs.
4848
'''.stripIndent().replace('\n', ' ').trim()
4949
}

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ if (!usingRemoteCluster && !usingMultiNode) {
6060
check.dependsOn jacocoTestReport
6161

6262
esplugin {
63-
name 'opendistro_notification'
64-
description 'Open Distro Notification Plugin'
65-
classname 'com.amazon.opendistroforelasticsearch.notification.NotificationPlugin'
63+
name 'opendistro-notifications'
64+
description 'Open Distro Notifications Plugin'
65+
classname 'com.amazon.opendistroforelasticsearch.notifications.NotificationPlugin'
6666
extendedPlugins = []
6767
}
6868

6969
allOpen {
70-
annotation("com.amazon.opendistroforelasticsearch.notification.util.OpenForTesting")
70+
annotation("com.amazon.opendistroforelasticsearch.notifications.util.OpenForTesting")
7171
}
7272

7373
configurations {
@@ -121,7 +121,7 @@ dependencies {
121121
}
122122

123123
repositories {
124-
// TODO: remove mavenLocal once notification is published to maven
124+
// TODO: remove mavenLocal once notifications is published to maven
125125
mavenLocal()
126126
}
127127

release-notes/create_release_notes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import fileinput
77
import re
88

9-
link_prefix = "https://github.com/opendistro-for-elasticsearch/notification/pull/"
9+
link_prefix = "https://github.com/opendistro-for-elasticsearch/notifications/"
1010
searchExp = re.compile("([\(\[]).*?([\)\]])")
1111

1212
current_date = raw_input("what day is today (e.g. 2020-06-29): ")
1313
file_path = raw_input("Path to raw note file (e.g., note.md): ")
14-
plugin_name = "notification"
14+
plugin_name = "notifications"
1515
plugin_version = raw_input('Plugin version (x.x.x.x): ')
1616

1717
app_num = int(

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
*
1515
*/
1616

17-
rootProject.name = 'opendistro-notification'
17+
rootProject.name = 'opendistro-notifications'

src/main/config/notifications.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# configuration file for the notifications plugin
2+
opendistro.notifications:
3+
email:
4+
channel: "ses" # smtp
5+
fromAddress: "[email protected]"
6+
monthlyLimit: 200

src/main/kotlin/com/amazon/opendistroforelasticsearch/notification/NotificationPlugin.kt renamed to src/main/kotlin/com/amazon/opendistroforelasticsearch/notifications/NotificationPlugin.kt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
*
1515
*/
1616

17-
package com.amazon.opendistroforelasticsearch.notification
17+
package com.amazon.opendistroforelasticsearch.notifications
1818

19-
import com.amazon.opendistroforelasticsearch.notification.resthandler.SendRestHandler
19+
import com.amazon.opendistroforelasticsearch.notifications.resthandler.SendRestHandler
20+
import com.amazon.opendistroforelasticsearch.notifications.settings.PluginSettings
2021
import org.apache.logging.log4j.LogManager
2122
import org.elasticsearch.action.ActionRequest
2223
import org.elasticsearch.action.ActionResponse
@@ -49,23 +50,13 @@ internal class NotificationPlugin : ActionPlugin, Plugin() {
4950
lateinit var clusterService: ClusterService
5051

5152
companion object {
52-
const val PLUGIN_NAME = "opendistro-notification"
53-
const val PLUGIN_BASE_URI = "/_opendistro/_notification"
53+
const val PLUGIN_NAME = "opendistro-notifications"
54+
const val PLUGIN_BASE_URI = "/_opendistro/_notifications"
5455
}
5556

56-
override fun getRestHandlers(
57-
settings: Settings,
58-
restController: RestController,
59-
clusterSettings: ClusterSettings,
60-
indexScopedSettings: IndexScopedSettings,
61-
settingsFilter: SettingsFilter,
62-
indexNameExpressionResolver: IndexNameExpressionResolver,
63-
nodesInCluster: Supplier<DiscoveryNodes>
64-
): List<RestHandler> {
65-
log.debug("$PLUGIN_NAME:getRestHandlers")
66-
return listOf(
67-
SendRestHandler()
68-
)
57+
override fun getSettings(): List<Setting<*>> {
58+
log.debug("$PLUGIN_NAME:getSettings")
59+
return PluginSettings.getAllSettings()
6960
}
7061

7162
override fun createComponents(
@@ -86,13 +77,23 @@ internal class NotificationPlugin : ActionPlugin, Plugin() {
8677
return listOf()
8778
}
8879

89-
override fun getSettings(): List<Setting<*>> {
90-
log.debug("$PLUGIN_NAME:getSettings")
91-
return listOf()
92-
}
93-
9480
override fun getActions(): List<ActionPlugin.ActionHandler<out ActionRequest, out ActionResponse>> {
9581
log.debug("$PLUGIN_NAME:getActions")
9682
return listOf()
9783
}
84+
85+
override fun getRestHandlers(
86+
settings: Settings,
87+
restController: RestController,
88+
clusterSettings: ClusterSettings,
89+
indexScopedSettings: IndexScopedSettings,
90+
settingsFilter: SettingsFilter,
91+
indexNameExpressionResolver: IndexNameExpressionResolver,
92+
nodesInCluster: Supplier<DiscoveryNodes>
93+
): List<RestHandler> {
94+
log.debug("$PLUGIN_NAME:getRestHandlers")
95+
return listOf(
96+
SendRestHandler(settings)
97+
)
98+
}
9899
}

src/main/kotlin/com/amazon/opendistroforelasticsearch/notification/action/SendAction.kt renamed to src/main/kotlin/com/amazon/opendistroforelasticsearch/notifications/action/SendAction.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,39 @@
1414
*
1515
*/
1616

17-
package com.amazon.opendistroforelasticsearch.notification.action
17+
package com.amazon.opendistroforelasticsearch.notifications.action
1818

19-
import com.amazon.opendistroforelasticsearch.notification.NotificationPlugin.Companion.PLUGIN_NAME
20-
import com.amazon.opendistroforelasticsearch.notification.channel.ChannelFactory
21-
import com.amazon.opendistroforelasticsearch.notification.core.RestRequestParser
19+
import com.amazon.opendistroforelasticsearch.notifications.NotificationPlugin.Companion.PLUGIN_NAME
20+
import com.amazon.opendistroforelasticsearch.notifications.channel.ChannelFactory
21+
import com.amazon.opendistroforelasticsearch.notifications.core.RestRequestParser
2222
import org.apache.logging.log4j.LogManager
2323
import org.elasticsearch.client.node.NodeClient
24+
import org.elasticsearch.common.settings.Settings
2425
import org.elasticsearch.common.xcontent.XContentType
2526
import org.elasticsearch.rest.BytesRestResponse
2627
import org.elasticsearch.rest.RestChannel
2728
import org.elasticsearch.rest.RestRequest
2829
import org.elasticsearch.rest.RestStatus
2930

30-
class SendAction(private val request: RestRequest, private val client: NodeClient, private val restChannel: RestChannel) {
31+
class SendAction(
32+
private val settings: Settings,
33+
private val request: RestRequest,
34+
private val client: NodeClient,
35+
private val restChannel: RestChannel
36+
) {
3137
private val log = LogManager.getLogger(javaClass)
3238
fun send() {
3339
log.info("$PLUGIN_NAME:send")
3440
val message = RestRequestParser.parse(request)
3541
val response = restChannel.newBuilder(XContentType.JSON, false).startObject()
36-
.field("type", "notification_response")
42+
.field("type", "notifications_response")
3743
.startObject("params")
3844
.field("refTag", message.refTag)
3945
.startArray("recipients")
4046
var restStatus = RestStatus.OK // Default to success
4147
message.recipients.forEach {
42-
val channel = ChannelFactory.getNotificationChannel(it)
43-
val status = channel.sendMessage(message.refTag, it, message.channelMessage)
48+
val channel = ChannelFactory.getNotificationChannel(settings, it)
49+
val status = channel.sendMessage(settings, message.refTag, it, message.channelMessage)
4450
if (status.statusCode != RestStatus.OK) {
4551
restStatus = RestStatus.MULTI_STATUS // if any of the value != success then return 207
4652
}

src/main/kotlin/com/amazon/opendistroforelasticsearch/notification/channel/ChannelFactory.kt renamed to src/main/kotlin/com/amazon/opendistroforelasticsearch/notifications/channel/ChannelFactory.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
*
1515
*/
1616

17-
package com.amazon.opendistroforelasticsearch.notification.channel
17+
package com.amazon.opendistroforelasticsearch.notifications.channel
1818

19-
import com.amazon.opendistroforelasticsearch.notification.channel.EmailFactory.EMAIL_PREFIX
19+
import com.amazon.opendistroforelasticsearch.notifications.channel.EmailFactory.EMAIL_PREFIX
20+
import org.elasticsearch.common.settings.Settings
2021

21-
object ChannelFactory {
22-
private val channelMap = mapOf(EMAIL_PREFIX to EmailFactory.getNotificationChannel())
22+
object ChannelFactory : ChannelProvider {
23+
private val channelMap = mapOf(EMAIL_PREFIX to EmailFactory)
2324

24-
fun getNotificationChannel(recipient: String): NotificationChannel {
25+
override fun getNotificationChannel(settings: Settings, recipient: String): NotificationChannel {
2526
var mappedChannel: NotificationChannel = EmptyChannel
2627
if (!recipient.contains(':')) { // if channel info not present
27-
mappedChannel = EmailFactory.getNotificationChannel() // Default channel is email
28+
mappedChannel = EmailFactory.getNotificationChannel(settings, recipient) // Default channel is email
2829
} else {
2930
for (it in channelMap) {
3031
if (recipient.startsWith(it.key, true)) {
31-
mappedChannel = it.value
32+
mappedChannel = it.value.getNotificationChannel(settings, recipient)
3233
break
3334
}
3435
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
*
1515
*/
1616

17-
package com.amazon.opendistroforelasticsearch.notification.channel
17+
package com.amazon.opendistroforelasticsearch.notifications.channel
1818

19-
import com.amazon.opendistroforelasticsearch.notification.core.ChannelMessage
20-
import com.amazon.opendistroforelasticsearch.notification.core.ChannelMessageResponse
19+
import org.elasticsearch.common.settings.Settings
2120

22-
interface NotificationChannel {
23-
fun sendMessage(refTag: String, recipient: String, channelMessage: ChannelMessage): ChannelMessageResponse
21+
interface ChannelProvider {
22+
fun getNotificationChannel(settings: Settings, recipient: String): NotificationChannel
2423
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*
15+
*/
16+
17+
package com.amazon.opendistroforelasticsearch.notifications.channel
18+
19+
import com.amazon.opendistroforelasticsearch.notifications.settings.EmailChannelType
20+
import com.amazon.opendistroforelasticsearch.notifications.settings.PluginSettings
21+
import org.elasticsearch.common.settings.Settings
22+
23+
object EmailFactory : ChannelProvider {
24+
const val EMAIL_PREFIX = "mailto:"
25+
private val channelMap = mapOf(
26+
EmailChannelType.SMTP.stringValue to EmptyChannel,
27+
EmailChannelType.SES.stringValue to SesChannel
28+
)
29+
30+
override fun getNotificationChannel(settings: Settings, recipient: String): NotificationChannel {
31+
return channelMap.getOrDefault(PluginSettings.EMAIL_CHANNEL.get(settings), EmptyChannel)
32+
}
33+
}

0 commit comments

Comments
 (0)