Skip to content

Commit

Permalink
Notification plugin interface and models
Browse files Browse the repository at this point in the history
[Tests]
Contains unit test for all model classes

Signed-off-by: @akbhatta
  • Loading branch information
akbhatta committed Jun 3, 2021
1 parent 200649d commit dfcac8f
Show file tree
Hide file tree
Showing 94 changed files with 13,772 additions and 1 deletion.
10 changes: 9 additions & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ style:
max: 10
ReturnCount:
active: true
max: 10
max: 10

complexity:
LargeClass:
excludes: ['**/test/**']
LongMethod:
excludes: ['**/test/**']
LongParameterList:
excludes: ['**/test/**']
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.opensearch.commons.notifications

/**
* Class containing Internal constants like JSON tags and defaults.
*/
object NotificationConstants {
const val CONFIG_ID_TAG = "config_id"
const val CONFIG_ID_LIST_TAG = "config_id_list"
const val EVENT_ID_TAG = "event_id"
const val EVENT_ID_LIST_TAG = "event_id_list"
const val EMAIL_ACCOUNT_ID_TAG = "email_account_id"
const val REFERENCE_ID_TAG = "reference_id"
const val CHANNEL_ID_LIST_TAG = "channel_id_list"
const val CONFIG_NAME_TAG = "config_name"
const val CONFIG_TYPE_TAG = "config_type"
const val CONFIG_TAG = "config"
const val EVENT_TAG = "event"
const val EVENT_SOURCE_TAG = "event_source"
const val FEATURE_TAG = "feature"
const val THREAD_CONTEXT_TAG = "context"
const val CHANNEL_MESSAGE_TAG = "channel_message"
const val TEXT_DESCRIPTION_TAG = "text_description"
const val HTML_DESCRIPTION_TAG = "html_description"
const val ATTACHMENT_TAG = "attachment"
const val RECIPIENT_TAG = "recipient"
const val RECIPIENT_LIST_TAG = "recipient_list"
const val EMAIL_RECIPIENT_STATUS_TAG = "email_recipient_status"
const val EMAIL_GROUP_ID_LIST_TAG = "email_group_id_list"
const val STATUS_CODE_TAG = "status_code"
const val STATUS_TEXT_TAG = "status_text"
const val DELIVERY_STATUS_TAG = "delivery_status"
const val NAME_TAG = "name"
const val DESCRIPTION_TAG = "description"
const val IS_ENABLED_TAG = "is_enabled"
const val FEATURE_LIST_TAG = "feature_list"
const val TITLE_TAG = "title"
const val SEVERITY_TAG = "severity"
const val TAGS_TAG = "tags"
const val URL_TAG = "url"
const val HEADER_PARAMS_TAG = "header_params"
const val HOST_TAG = "host"
const val PORT_TAG = "port"
const val METHOD_TAG = "method"
const val FROM_ADDRESS_TAG = "from_address"
const val UPDATED_TIME_TAG = "last_updated_time_ms"
const val CREATED_TIME_TAG = "created_time_ms"
const val TENANT_TAG = "tenant"
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 DELETE_RESPONSE_LIST_TAG = "delete_response_list"
const val FROM_INDEX_TAG = "from_index"
const val MAX_ITEMS_TAG = "max_items"
const val SORT_FIELD_TAG = "sort_field"
const val SORT_ORDER_TAG = "sort_order"
const val FILTER_PARAM_LIST_TAG = "filter_param_list"
const val STATUS_LIST_TAG = "status_list"
const val START_INDEX_TAG = "start_index"
const val TOTAL_HITS_TAG = "total_hits"
const val TOTAL_HIT_RELATION_TAG = "total_hit_relation"
const val QUERY_TAG = "query"
const val COMPACT_TAG = "compact"
const val CONFIG_TYPE_LIST_TAG = "config_type_list"
const val PLUGIN_FEATURES_TAG = "plugin_features"

const val DEFAULT_MAX_ITEMS = 1000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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 org.opensearch.commons.notifications

import org.opensearch.action.ActionListener
import org.opensearch.client.node.NodeClient
import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT
import org.opensearch.commons.notifications.action.CreateNotificationConfigRequest
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.GetNotificationConfigRequest
import org.opensearch.commons.notifications.action.GetNotificationConfigResponse
import org.opensearch.commons.notifications.action.GetNotificationEventRequest
import org.opensearch.commons.notifications.action.GetNotificationEventResponse
import org.opensearch.commons.notifications.action.GetPluginFeaturesRequest
import org.opensearch.commons.notifications.action.GetPluginFeaturesResponse
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_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
import org.opensearch.commons.notifications.action.NotificationsActions.SEND_NOTIFICATION_ACTION_TYPE
import org.opensearch.commons.notifications.action.NotificationsActions.UPDATE_NOTIFICATION_CONFIG_ACTION_TYPE
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.ChannelMessage
import org.opensearch.commons.notifications.model.EventSource
import org.opensearch.commons.utils.SecureClientWrapper

/**
* All the transport action plugin interfaces for the Notification plugin
*/
object NotificationsPluginInterface {

/**
* Create notification configuration.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun createNotificationConfig(
client: NodeClient,
request: CreateNotificationConfigRequest,
listener: ActionListener<CreateNotificationConfigResponse>
) {
client.execute(
CREATE_NOTIFICATION_CONFIG_ACTION_TYPE,
request,
listener
)
}

/**
* Update notification configuration.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun updateNotificationConfig(
client: NodeClient,
request: UpdateNotificationConfigRequest,
listener: ActionListener<UpdateNotificationConfigResponse>
) {
client.execute(
UPDATE_NOTIFICATION_CONFIG_ACTION_TYPE,
request,
listener
)
}

/**
* Delete notification configuration.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun deleteNotificationConfig(
client: NodeClient,
request: DeleteNotificationConfigRequest,
listener: ActionListener<DeleteNotificationConfigResponse>
) {
client.execute(
DELETE_NOTIFICATION_CONFIG_ACTION_TYPE,
request,
listener
)
}

/**
* Get notification configuration.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun getNotificationConfig(
client: NodeClient,
request: GetNotificationConfigRequest,
listener: ActionListener<GetNotificationConfigResponse>
) {
client.execute(
GET_NOTIFICATION_CONFIG_ACTION_TYPE,
request,
listener
)
}

/**
* Get notification events.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun getNotificationEvent(
client: NodeClient,
request: GetNotificationEventRequest,
listener: ActionListener<GetNotificationEventResponse>
) {
client.execute(
GET_NOTIFICATION_EVENT_ACTION_TYPE,
request,
listener
)
}

/**
* Get notification plugin features.
* @param client Node client for making transport action
* @param request The request object
* @param listener The listener for getting response
*/
fun getPluginFeatures(
client: NodeClient,
request: GetPluginFeaturesRequest,
listener: ActionListener<GetPluginFeaturesResponse>
) {
client.execute(
GET_PLUGIN_FEATURES_ACTION_TYPE,
request,
listener
)
}

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

/**
* Send notification API enabled for a feature. No REST API. Internal API only for Inter plugin communication.
* @param client Node client for making transport action
* @param eventSource The notification event information
* @param channelMessage The notification message
* @param channelIds The list of channel ids to send message to.
* @param listener The listener for getting response
*/
fun sendNotification(
client: NodeClient,
eventSource: EventSource,
channelMessage: ChannelMessage,
channelIds: List<String>,
listener: ActionListener<SendNotificationResponse>
) {
val threadContext: String? =
client.threadPool().threadContext.getTransient<String>(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)
val wrapper = SecureClientWrapper(client) // Executing request in privileged mode
wrapper.execute(
SEND_NOTIFICATION_ACTION_TYPE,
SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext),
listener
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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 org.opensearch.commons.notifications.action

import org.opensearch.action.ActionResponse
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.xcontent.ToXContentObject
import org.opensearch.rest.RestStatus
import java.io.IOException

/**
* Base response which give REST status.
*/
abstract class BaseResponse : ActionResponse, ToXContentObject {

/**
* constructor for creating the class
*/
constructor()

/**
* {@inheritDoc}
*/
@Throws(IOException::class)
constructor(input: StreamInput) : super(input)

/**
* get rest status for the response. Useful override for multi-status response.
* @return RestStatus for the response
*/
open fun getStatus(): RestStatus {
return RestStatus.OK
}
}
Loading

0 comments on commit dfcac8f

Please sign in to comment.