Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Get Channels API REST endpoint #384

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.opensearch.env.Environment
import org.opensearch.env.NodeEnvironment
import org.opensearch.notifications.action.CreateNotificationConfigAction
import org.opensearch.notifications.action.DeleteNotificationConfigAction
import org.opensearch.notifications.action.GetFeatureChannelListAction
import org.opensearch.notifications.action.GetChannelListAction
import org.opensearch.notifications.action.GetNotificationConfigAction
import org.opensearch.notifications.action.GetNotificationEventAction
import org.opensearch.notifications.action.GetPluginFeaturesAction
Expand All @@ -36,9 +36,9 @@ import org.opensearch.notifications.index.ConfigIndexingActions
import org.opensearch.notifications.index.EventIndexingActions
import org.opensearch.notifications.index.NotificationConfigIndex
import org.opensearch.notifications.index.NotificationEventIndex
import org.opensearch.notifications.resthandler.NotificationChannelListRestHandler
import org.opensearch.notifications.resthandler.NotificationConfigRestHandler
import org.opensearch.notifications.resthandler.NotificationEventRestHandler
import org.opensearch.notifications.resthandler.NotificationFeatureChannelListRestHandler
import org.opensearch.notifications.resthandler.NotificationFeaturesRestHandler
import org.opensearch.notifications.resthandler.NotificationStatsRestHandler
import org.opensearch.notifications.resthandler.SendTestMessageRestHandler
Expand Down Expand Up @@ -140,8 +140,8 @@ class NotificationPlugin : ActionPlugin, Plugin(), NotificationCoreExtension {
GetNotificationEventAction::class.java
),
ActionPlugin.ActionHandler(
NotificationsActions.GET_FEATURE_CHANNEL_LIST_ACTION_TYPE,
GetFeatureChannelListAction::class.java
NotificationsActions.GET_CHANNEL_LIST_ACTION_TYPE,
GetChannelListAction::class.java
),
ActionPlugin.ActionHandler(
NotificationsActions.GET_PLUGIN_FEATURES_ACTION_TYPE,
Expand Down Expand Up @@ -175,7 +175,7 @@ class NotificationPlugin : ActionPlugin, Plugin(), NotificationCoreExtension {
NotificationConfigRestHandler(),
NotificationEventRestHandler(),
NotificationFeaturesRestHandler(),
NotificationFeatureChannelListRestHandler(),
NotificationChannelListRestHandler(),
SendTestMessageRestHandler(),
NotificationStatsRestHandler()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import org.opensearch.client.Client
import org.opensearch.common.inject.Inject
import org.opensearch.common.xcontent.NamedXContentRegistry
import org.opensearch.commons.authuser.User
import org.opensearch.commons.notifications.action.GetFeatureChannelListRequest
import org.opensearch.commons.notifications.action.GetFeatureChannelListResponse
import org.opensearch.commons.notifications.action.GetChannelListRequest
import org.opensearch.commons.notifications.action.GetChannelListResponse
import org.opensearch.commons.notifications.action.NotificationsActions
import org.opensearch.commons.utils.recreateObject
import org.opensearch.notifications.index.ConfigIndexingActions
import org.opensearch.tasks.Task
import org.opensearch.transport.TransportService

/**
* Get feature channel list transport action
* Get channel list transport action
*/
internal class GetFeatureChannelListAction @Inject constructor(
internal class GetChannelListAction @Inject constructor(
transportService: TransportService,
client: Client,
actionFilters: ActionFilters,
val xContentRegistry: NamedXContentRegistry
) : PluginBaseAction<GetFeatureChannelListRequest, GetFeatureChannelListResponse>(
NotificationsActions.GET_FEATURE_CHANNEL_LIST_NAME,
) : PluginBaseAction<GetChannelListRequest, GetChannelListResponse>(
NotificationsActions.GET_CHANNEL_LIST_NAME,
transportService,
client,
actionFilters,
::GetFeatureChannelListRequest
::GetChannelListRequest
) {

/**
Expand All @@ -43,20 +43,20 @@ internal class GetFeatureChannelListAction @Inject constructor(
override fun doExecute(
task: Task?,
request: ActionRequest,
listener: ActionListener<GetFeatureChannelListResponse>
listener: ActionListener<GetChannelListResponse>
) {
val transformedRequest = request as? GetFeatureChannelListRequest
?: recreateObject(request) { GetFeatureChannelListRequest(it) }
val transformedRequest = request as? GetChannelListRequest
?: recreateObject(request) { GetChannelListRequest(it) }
super.doExecute(task, transformedRequest, listener)
}

/**
* {@inheritDoc}
*/
override fun executeRequest(
request: GetFeatureChannelListRequest,
request: GetChannelListRequest,
user: User?
): GetFeatureChannelListResponse {
return ConfigIndexingActions.getFeatureChannelList(request, user)
): GetChannelListResponse {
return ConfigIndexingActions.getChannelList(request, user)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import org.opensearch.commons.notifications.action.CreateNotificationConfigReque
import org.opensearch.commons.notifications.action.CreateNotificationConfigResponse
import org.opensearch.commons.notifications.action.DeleteNotificationConfigRequest
import org.opensearch.commons.notifications.action.DeleteNotificationConfigResponse
import org.opensearch.commons.notifications.action.GetFeatureChannelListRequest
import org.opensearch.commons.notifications.action.GetFeatureChannelListResponse
import org.opensearch.commons.notifications.action.GetChannelListRequest
import org.opensearch.commons.notifications.action.GetChannelListResponse
import org.opensearch.commons.notifications.action.GetNotificationConfigRequest
import org.opensearch.commons.notifications.action.GetNotificationConfigResponse
import org.opensearch.commons.notifications.action.UpdateNotificationConfigRequest
import org.opensearch.commons.notifications.action.UpdateNotificationConfigResponse
import org.opensearch.commons.notifications.model.Channel
import org.opensearch.commons.notifications.model.ChannelList
import org.opensearch.commons.notifications.model.Chime
import org.opensearch.commons.notifications.model.ConfigType
import org.opensearch.commons.notifications.model.Email
import org.opensearch.commons.notifications.model.EmailGroup
import org.opensearch.commons.notifications.model.FeatureChannel
import org.opensearch.commons.notifications.model.FeatureChannelList
import org.opensearch.commons.notifications.model.NotificationConfig
import org.opensearch.commons.notifications.model.NotificationConfigInfo
import org.opensearch.commons.notifications.model.NotificationConfigSearchResult
Expand Down Expand Up @@ -340,12 +340,12 @@ object ConfigIndexingActions {

/**
* Get NotificationConfig info
* @param request [GetFeatureChannelListRequest] object
* @param request [GetChannelListRequest] object
* @param user the user info object
* @return [GetFeatureChannelListResponse]
* @return [GetChannelListResponse]
*/
fun getFeatureChannelList(request: GetFeatureChannelListRequest, user: User?): GetFeatureChannelListResponse {
log.info("$LOG_PREFIX:getFeatureChannelList $request")
fun getChannelList(request: GetChannelListRequest, user: User?): GetChannelListResponse {
log.info("$LOG_PREFIX:getChannelList $request")
userAccess.validateUser(user)
val supportedChannelListString = getSupportedChannelList().joinToString(",")
val filterParams = mapOf(
Expand All @@ -359,10 +359,10 @@ object ConfigIndexingActions {
val searchResult = getAllResult.objectList.map {
val configId = it.configId
val config = it.notificationConfig
FeatureChannel(configId, config.name, config.description, config.configType, config.isEnabled)
Channel(configId, config.name, config.description, config.configType, config.isEnabled)
}
val featureChannelList = FeatureChannelList(searchResult)
return GetFeatureChannelListResponse(featureChannelList)
val ChannelList = ChannelList(searchResult)
return GetChannelListResponse(ChannelList)
}

private fun getSupportedChannelList(): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,16 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
"notifications_events.info.system_error", RollingCounter()
),
// Feature Channels Endpoints
// GET _plugins/_notifications/feature/channels/{featureTag}
NOTIFICATIONS_FEATURE_CHANNELS_INFO_TOTAL(
"notifications_feature_channels.info.total",
// GET _plugins/_notifications/channels
NOTIFICATIONS_CHANNELS_INFO_TOTAL(
"notifications_channels.info.total",
BasicCounter()
),
NOTIFICATIONS_FEATURE_CHANNELS_INFO_INTERVAL_COUNT(
"notifications_feature_channels.info.count", RollingCounter()
NOTIFICATIONS_CHANNELS_INFO_INTERVAL_COUNT(
"notifications_channels.info.count", RollingCounter()
),
NOTIFICATIONS_FEATURE_CHANNELS_INFO_USER_ERROR_INVALID_FEATURE_TAG(
"notifications_feature_channels.info.user_error.invalid_feature_tag", RollingCounter()
),
NOTIFICATIONS_FEATURE_CHANNELS_INFO_SYSTEM_ERROR(
"notifications_feature_channels.info.system_error", RollingCounter()
NOTIFICATIONS_CHANNELS_INFO_SYSTEM_ERROR(
"notifications_channels.info.system_error", RollingCounter()
),
// Features Endpoints
// GET _plugins/_notifications/features
Expand Down Expand Up @@ -193,9 +190,6 @@ enum class Metrics(val metricName: String, val counter: Counter<*>) {
NOTIFICATIONS_SEND_MESSAGE_USER_ERROR_NOT_FOUND(
"notifications.send_message.user_error.not_found", RollingCounter()
),
NOTIFICATIONS_SEND_MESSAGE_USER_ERROR_FEATURE_NOT_FOUND(
"notifications.send_message.user_error.feature_not_found", RollingCounter()
),
NOTIFICATIONS_SEND_MESSAGE_SYSTEM_ERROR(
"notifications.send_message.system_error",
RollingCounter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package org.opensearch.notifications.resthandler

import org.opensearch.client.node.NodeClient
import org.opensearch.commons.notifications.NotificationsPluginInterface
import org.opensearch.commons.notifications.action.GetFeatureChannelListRequest
import org.opensearch.commons.notifications.action.GetChannelListRequest
import org.opensearch.notifications.NotificationPlugin.Companion.PLUGIN_BASE_URI
import org.opensearch.notifications.metrics.Metrics
import org.opensearch.rest.BaseRestHandler.RestChannelConsumer
Expand All @@ -21,19 +21,19 @@ import org.opensearch.rest.action.RestToXContentListener
/**
* Rest handler for getting notification channels.
*/
internal class NotificationFeatureChannelListRestHandler : PluginBaseHandler() {
internal class NotificationChannelListRestHandler : PluginBaseHandler() {
companion object {
/**
* Base URL for this handler
*/
private const val REQUEST_URL = "$PLUGIN_BASE_URI/feature/channels"
private const val REQUEST_URL = "$PLUGIN_BASE_URI/channels"
}

/**
* {@inheritDoc}
*/
override fun getName(): String {
return "notifications_feature_channel_list"
return "notifications_channel_list"
}

/**
Expand All @@ -42,10 +42,10 @@ internal class NotificationFeatureChannelListRestHandler : PluginBaseHandler() {
override fun routes(): List<Route> {
return listOf(
/**
* Get a notification event
* Get notification channels
* Request URL: GET [REQUEST_URL]
* Request body: Ref [org.opensearch.commons.notifications.action.GetFeatureChannelListRequest]
* Response body: [org.opensearch.commons.notifications.action.GetFeatureChannelListResponse]
* Request body: Ref [org.opensearch.commons.notifications.action.GetChannelListRequest]
* Response body: [org.opensearch.commons.notifications.action.GetChannelListResponse]
*/
Route(GET, REQUEST_URL)
)
Expand All @@ -64,12 +64,12 @@ internal class NotificationFeatureChannelListRestHandler : PluginBaseHandler() {
override fun executeRequest(request: RestRequest, client: NodeClient): RestChannelConsumer {
return when (request.method()) {
GET -> {
Metrics.NOTIFICATIONS_FEATURE_CHANNELS_INFO_TOTAL.counter.increment()
Metrics.NOTIFICATIONS_FEATURE_CHANNELS_INFO_INTERVAL_COUNT.counter.increment()
Metrics.NOTIFICATIONS_CHANNELS_INFO_TOTAL.counter.increment()
Metrics.NOTIFICATIONS_CHANNELS_INFO_INTERVAL_COUNT.counter.increment()
RestChannelConsumer {
NotificationsPluginInterface.getFeatureChannelList(
NotificationsPluginInterface.getChannelList(
client,
GetFeatureChannelListRequest(),
GetChannelListRequest(),
RestToXContentListener(it)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ object SendMessageActionHelper {
*/
private fun sendMessageToLegacyDestination(baseMessage: LegacyBaseMessage): LegacyDestinationResponse {
val message =
MessageContent(title = "Index Management Notification", textDescription = baseMessage.messageContent)
// These legacy destination calls do not have reference Ids, just passing index management feature constant
MessageContent(title = "Legacy Notification", textDescription = baseMessage.messageContent)
// These legacy destination calls do not have reference Ids, just passing 'legacy' constant
return when (baseMessage.channelType) {
LegacyDestinationType.LEGACY_SLACK -> {
val destination = SlackDestination(baseMessage.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.opensearch.rest.RestRequest
import org.opensearch.rest.RestStatus
import kotlin.random.Random

class GetNotificationFeatureChannelListIT : PluginRestTestCase() {
class GetNotificationChannelListIT : PluginRestTestCase() {
private val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9')

private fun getCreateRequestJsonString(
Expand Down Expand Up @@ -107,7 +107,7 @@ class GetNotificationFeatureChannelListIT : PluginRestTestCase() {
if (totalHits >= 0) {
Assert.assertEquals(totalHits, jsonObject.get("total_hits").asInt)
}
val items = jsonObject.get("feature_channel_list").asJsonArray
val items = jsonObject.get("channel_list").asJsonArray
Assert.assertEquals(idSet.size, items.size())
items.forEach {
val item = it.asJsonObject
Expand All @@ -117,25 +117,25 @@ class GetNotificationFeatureChannelListIT : PluginRestTestCase() {
}
}

fun `test POST feature channel list should result in error`() {
fun `test POST channel list should result in error`() {
executeRequest(
RestRequest.Method.POST.name,
"$PLUGIN_BASE_URI/feature/channels",
"$PLUGIN_BASE_URI/channels",
"{\"feature\":\"reports\"}",
RestStatus.METHOD_NOT_ALLOWED.status
)
}

fun `test PUT feature channel list should result in error`() {
fun `test PUT channel list should result in error`() {
executeRequest(
RestRequest.Method.PUT.name,
"$PLUGIN_BASE_URI/feature/channels",
"$PLUGIN_BASE_URI/channels",
"{\"feature\":\"reports\"}",
RestStatus.METHOD_NOT_ALLOWED.status
)
}

fun `test getFeatureChannelList should return only channels`() {
fun `test getChannelList should return only channels`() {
val slackId = createConfig(configType = ConfigType.SLACK)
val chimeId = createConfig(configType = ConfigType.CHIME)
val webhookId = createConfig(configType = ConfigType.WEBHOOK)
Expand All @@ -151,7 +151,7 @@ class GetNotificationFeatureChannelListIT : PluginRestTestCase() {
val channelIds = setOf(slackId, chimeId, webhookId, emailId)
val response = executeRequest(
RestRequest.Method.GET.name,
"$PLUGIN_BASE_URI/feature/channels",
"$PLUGIN_BASE_URI/channels",
"",
RestStatus.OK.status
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import org.opensearch.commons.notifications.action.CreateNotificationConfigReque
import org.opensearch.commons.notifications.action.CreateNotificationConfigResponse
import org.opensearch.commons.notifications.action.DeleteNotificationConfigRequest
import org.opensearch.commons.notifications.action.DeleteNotificationConfigResponse
import org.opensearch.commons.notifications.action.GetFeatureChannelListRequest
import org.opensearch.commons.notifications.action.GetFeatureChannelListResponse
import org.opensearch.commons.notifications.action.GetChannelListRequest
import org.opensearch.commons.notifications.action.GetChannelListResponse
import org.opensearch.commons.notifications.action.GetNotificationConfigRequest
import org.opensearch.commons.notifications.action.GetNotificationConfigResponse
import org.opensearch.commons.notifications.action.GetNotificationEventRequest
Expand All @@ -37,7 +37,7 @@ import org.opensearch.commons.notifications.action.SendNotificationRequest
import org.opensearch.commons.notifications.action.SendNotificationResponse
import org.opensearch.commons.notifications.action.UpdateNotificationConfigRequest
import org.opensearch.commons.notifications.action.UpdateNotificationConfigResponse
import org.opensearch.commons.notifications.model.FeatureChannelList
import org.opensearch.commons.notifications.model.ChannelList
import org.opensearch.commons.notifications.model.NotificationConfigSearchResult
import org.opensearch.commons.notifications.model.NotificationEventSearchResult
import org.opensearch.notifications.index.ConfigIndexingActions
Expand Down Expand Up @@ -163,18 +163,18 @@ internal class PluginActionTests {
}

@Test
fun `Get feature channel list action should call back action listener`() {
val request = mock(GetFeatureChannelListRequest::class.java)
val response = GetFeatureChannelListResponse(mock(FeatureChannelList::class.java))
fun `Get channel list action should call back action listener`() {
val request = mock(GetChannelListRequest::class.java)
val response = GetChannelListResponse(mock(ChannelList::class.java))

// Mock singleton's method by mockk framework
mockkObject(ConfigIndexingActions)
every { ConfigIndexingActions.getFeatureChannelList(request, any()) } returns response
every { ConfigIndexingActions.getChannelList(request, any()) } returns response

val getFeatureChannelListAction = GetFeatureChannelListAction(
val getChannelListAction = GetChannelListAction(
transportService, client, actionFilters, xContentRegistry
)
getFeatureChannelListAction.execute(task, request, AssertionListener(response))
getChannelListAction.execute(task, request, AssertionListener(response))
}

@Test
Expand Down