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 references for Get Channels API for Notifications #140

Merged
merged 1 commit 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 @@ -52,7 +52,7 @@ object NotificationConstants {
const val CREATED_TIME_TAG = "created_time_ms"
const val CONFIG_LIST_TAG = "config_list"
const val EVENT_LIST_TAG = "event_list"
const val FEATURE_CONFIG_LIST_TAG = "feature_channel_list"
const val CHANNEL_LIST_TAG = "channel_list"
const val DELETE_RESPONSE_LIST_TAG = "delete_response_list"
const val FROM_INDEX_TAG = "from_index"
const val MAX_ITEMS_TAG = "max_items"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,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 @@ -26,7 +26,7 @@ import org.opensearch.commons.notifications.action.LegacyPublishNotificationRequ
import org.opensearch.commons.notifications.action.LegacyPublishNotificationResponse
import org.opensearch.commons.notifications.action.NotificationsActions.CREATE_NOTIFICATION_CONFIG_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.DELETE_NOTIFICATION_CONFIG_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.GET_FEATURE_CHANNEL_LIST_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.GET_CHANNEL_LIST_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.GET_NOTIFICATION_CONFIG_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.GET_NOTIFICATION_EVENT_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.GET_PLUGIN_FEATURES_ACTION_TYPE
Expand Down Expand Up @@ -156,20 +156,20 @@ object NotificationsPluginInterface {
}

/**
* Get notification channel configuration enabled for a feature.
* Get notification channel configuration.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun getFeatureChannelList(
fun getChannelList(
client: NodeClient,
request: GetFeatureChannelListRequest,
listener: ActionListener<GetFeatureChannelListResponse>
request: GetChannelListRequest,
listener: ActionListener<GetChannelListResponse>
) {
client.execute(
GET_FEATURE_CHANNEL_LIST_ACTION_TYPE,
GET_CHANNEL_LIST_ACTION_TYPE,
request,
wrapActionListener(listener) { response -> recreateObject(response) { GetFeatureChannelListResponse(it) } }
wrapActionListener(listener) { response -> recreateObject(response) { GetChannelListResponse(it) } }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ import java.io.IOException
/**
* This request is plugin-only call. i.e. REST interface is not exposed.
*/
class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
class GetChannelListRequest : ActionRequest, ToXContentObject {
val compact: Boolean // Dummy request parameter for transport request

companion object {
private val log by logger(GetFeatureChannelListRequest::class.java)
private val log by logger(GetChannelListRequest::class.java)

/**
* reader to create instance of class from writable.
*/
val reader = Writeable.Reader { GetFeatureChannelListRequest(it) }
val reader = Writeable.Reader { GetChannelListRequest(it) }

/**
* Creator used in REST communication.
* @param parser XContentParser to deserialize data from.
*/
@JvmStatic
@Throws(IOException::class)
fun parse(parser: XContentParser): GetFeatureChannelListRequest {
fun parse(parser: XContentParser): GetChannelListRequest {
var compact = false

XContentParserUtils.ensureExpectedToken(
Expand All @@ -53,11 +53,11 @@ class GetFeatureChannelListRequest : ActionRequest, ToXContentObject {
COMPACT_TAG -> compact = parser.booleanValue()
else -> {
parser.skipChildren()
log.info("Unexpected field: $fieldName, while parsing GetFeatureChannelListRequest")
log.info("Unexpected field: $fieldName, while parsing GetChannelListRequest")
}
}
}
return GetFeatureChannelListRequest()
return GetChannelListRequest()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@ import org.opensearch.common.io.stream.Writeable
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.commons.notifications.model.FeatureChannelList
import org.opensearch.commons.notifications.model.ChannelList
import java.io.IOException

/**
* Action Response for creating new configuration.
*/
class GetFeatureChannelListResponse : BaseResponse {
val searchResult: FeatureChannelList
class GetChannelListResponse : BaseResponse {
val searchResult: ChannelList

companion object {

/**
* reader to create instance of class from writable.
*/
val reader = Writeable.Reader { GetFeatureChannelListResponse(it) }
val reader = Writeable.Reader { GetChannelListResponse(it) }

/**
* Creator used in REST communication.
* @param parser XContentParser to deserialize data from.
*/
@JvmStatic
@Throws(IOException::class)
fun parse(parser: XContentParser): GetFeatureChannelListResponse {
return GetFeatureChannelListResponse(FeatureChannelList(parser))
fun parse(parser: XContentParser): GetChannelListResponse {
return GetChannelListResponse(ChannelList(parser))
}
}

/**
* constructor for creating the class
* @param searchResult the notification configuration list
*/
constructor(searchResult: FeatureChannelList) {
constructor(searchResult: ChannelList) {
this.searchResult = searchResult
}

Expand All @@ -50,7 +50,7 @@ class GetFeatureChannelListResponse : BaseResponse {
*/
@Throws(IOException::class)
constructor(input: StreamInput) : super(input) {
searchResult = FeatureChannelList(input)
searchResult = ChannelList(input)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object NotificationsActions {
/**
* Get Config List for feature. Internal only - Inter plugin communication.
*/
const val GET_FEATURE_CHANNEL_LIST_NAME = "cluster:admin/opensearch/notifications/feature/channels/get"
const val GET_CHANNEL_LIST_NAME = "cluster:admin/opensearch/notifications/channels/get"

/**
* Send notification message. Internal only - Inter plugin communication.
Expand Down Expand Up @@ -93,10 +93,10 @@ object NotificationsActions {
ActionType(GET_PLUGIN_FEATURES_NAME, ::GetPluginFeaturesResponse)

/**
* Get Config List for feature transport action type.
* Get notification channel List transport action type.
*/
val GET_FEATURE_CHANNEL_LIST_ACTION_TYPE =
ActionType(GET_FEATURE_CHANNEL_LIST_NAME, ::GetFeatureChannelListResponse)
val GET_CHANNEL_LIST_ACTION_TYPE =
ActionType(GET_CHANNEL_LIST_NAME, ::GetChannelListResponse)

/**
* Send notification transport action type. Internal only - Inter plugin communication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import org.opensearch.commons.utils.logger
import java.io.IOException

/**
* Data class representing Notification config for exposed for other plugins.
* Data class representing Notification config exposed for other plugins.
*/
data class FeatureChannel(
data class Channel(
val configId: String,
val name: String,
val description: String,
Expand All @@ -37,12 +37,12 @@ data class FeatureChannel(
}

companion object {
private val log by logger(FeatureChannel::class.java)
private val log by logger(Channel::class.java)

/**
* reader to create instance of class from writable.
*/
val reader = Writeable.Reader { FeatureChannel(it) }
val reader = Writeable.Reader { Channel(it) }

/**
* Creator used in REST communication.
Expand All @@ -51,7 +51,7 @@ data class FeatureChannel(
@Suppress("ComplexMethod")
@JvmStatic
@Throws(IOException::class)
fun parse(parser: XContentParser): FeatureChannel {
fun parse(parser: XContentParser): Channel {
var configId: String? = null
var name: String? = null
var description = ""
Expand All @@ -74,14 +74,14 @@ data class FeatureChannel(
IS_ENABLED_TAG -> isEnabled = parser.booleanValue()
else -> {
parser.skipChildren()
log.info("Unexpected field: $fieldName, while parsing FeatureChannel")
log.info("Unexpected field: $fieldName, while parsing Channel")
}
}
}
configId ?: throw IllegalArgumentException("$CONFIG_ID_TAG field absent")
name ?: throw IllegalArgumentException("$NAME_TAG field absent")
configType ?: throw IllegalArgumentException("$CONFIG_TYPE_TAG field absent")
return FeatureChannel(
return Channel(
configId,
name,
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import org.apache.lucene.search.TotalHits
import org.opensearch.action.search.SearchResponse
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.commons.notifications.NotificationConstants.FEATURE_CONFIG_LIST_TAG
import org.opensearch.commons.notifications.NotificationConstants.CHANNEL_LIST_TAG

/**
* FeatureChannel search results
* Channel search results
*/
class FeatureChannelList : SearchResults<FeatureChannel> {
class ChannelList : SearchResults<Channel> {

/**
* single item result constructor
*/
constructor(objectItem: FeatureChannel) : super(FEATURE_CONFIG_LIST_TAG, objectItem)
constructor(objectItem: Channel) : super(CHANNEL_LIST_TAG, objectItem)

/**
* multiple items result constructor
*/
constructor(objectList: List<FeatureChannel>) : this(
constructor(objectList: List<Channel>) : this(
0,
objectList.size.toLong(),
TotalHits.Relation.EQUAL_TO,
Expand All @@ -38,34 +38,34 @@ class FeatureChannelList : SearchResults<FeatureChannel> {
startIndex: Long,
totalHits: Long,
totalHitRelation: TotalHits.Relation,
objectList: List<FeatureChannel>
) : super(startIndex, totalHits, totalHitRelation, FEATURE_CONFIG_LIST_TAG, objectList)
objectList: List<Channel>
) : super(startIndex, totalHits, totalHitRelation, CHANNEL_LIST_TAG, objectList)

/**
* Constructor used in transport action communication.
* @param input StreamInput stream to deserialize data from.
*/
constructor(input: StreamInput) : super(input, FeatureChannel.reader)
constructor(input: StreamInput) : super(input, Channel.reader)

/**
* Construct object from XContentParser
*/
constructor(parser: XContentParser) : super(parser, FEATURE_CONFIG_LIST_TAG)
constructor(parser: XContentParser) : super(parser, CHANNEL_LIST_TAG)

/**
* Construct object from SearchResponse
*/
constructor(from: Long, response: SearchResponse, searchHitParser: SearchHitParser<FeatureChannel>) : super(
constructor(from: Long, response: SearchResponse, searchHitParser: SearchHitParser<Channel>) : super(
from,
response,
searchHitParser,
FEATURE_CONFIG_LIST_TAG
CHANNEL_LIST_TAG
)

/**
* {@inheritDoc}
*/
override fun parseItem(parser: XContentParser): FeatureChannel {
return FeatureChannel.parse(parser)
override fun parseItem(parser: XContentParser): Channel {
return Channel.parse(parser)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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 @@ -38,13 +38,13 @@ import org.opensearch.commons.notifications.action.LegacyPublishNotificationResp
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.Channel
import org.opensearch.commons.notifications.model.ChannelList
import org.opensearch.commons.notifications.model.ChannelMessage
import org.opensearch.commons.notifications.model.ConfigType
import org.opensearch.commons.notifications.model.DeliveryStatus
import org.opensearch.commons.notifications.model.EventSource
import org.opensearch.commons.notifications.model.EventStatus
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 @@ -168,25 +168,25 @@ internal class NotificationsPluginInterfaceTests {
}

@Test
fun getFeatureChannelList() {
val sampleConfig = FeatureChannel(
fun getChannelList() {
val sampleConfig = Channel(
"config_id",
"name",
"description",
ConfigType.SLACK
)

val request = mock(GetFeatureChannelListRequest::class.java)
val response = GetFeatureChannelListResponse(FeatureChannelList(sampleConfig))
val listener: ActionListener<GetFeatureChannelListResponse> =
mock(ActionListener::class.java) as ActionListener<GetFeatureChannelListResponse>
val request = mock(GetChannelListRequest::class.java)
val response = GetChannelListResponse(ChannelList(sampleConfig))
val listener: ActionListener<GetChannelListResponse> =
mock(ActionListener::class.java) as ActionListener<GetChannelListResponse>

doAnswer {
(it.getArgument(2) as ActionListener<GetFeatureChannelListResponse>)
(it.getArgument(2) as ActionListener<GetChannelListResponse>)
.onResponse(response)
}.whenever(client).execute(any(ActionType::class.java), any(), any())

NotificationsPluginInterface.getFeatureChannelList(client, request, listener)
NotificationsPluginInterface.getChannelList(client, request, listener)
verify(listener, times(1)).onResponse(eq(response))
}

Expand Down
Loading