Skip to content

Commit

Permalink
[Backport 2.x] onboarding system and hidden index (#748)
Browse files Browse the repository at this point in the history
* onboard system and hidden index (#742)

Signed-off-by: Hailong Cui <[email protected]>
(cherry picked from commit be1df94)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* ignore system index warning

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hailong Cui <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent 6d94dd5 commit 2c90d49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.opensearch.core.common.io.stream.NamedWriteableRegistry
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.env.Environment
import org.opensearch.env.NodeEnvironment
import org.opensearch.indices.SystemIndexDescriptor
import org.opensearch.notifications.action.CreateNotificationConfigAction
import org.opensearch.notifications.action.DeleteNotificationConfigAction
import org.opensearch.notifications.action.GetChannelListAction
Expand All @@ -44,6 +45,7 @@ import org.opensearch.notifications.spi.NotificationCore
import org.opensearch.notifications.spi.NotificationCoreExtension
import org.opensearch.plugins.ActionPlugin
import org.opensearch.plugins.Plugin
import org.opensearch.plugins.SystemIndexPlugin
import org.opensearch.repositories.RepositoriesService
import org.opensearch.rest.RestController
import org.opensearch.rest.RestHandler
Expand All @@ -56,7 +58,7 @@ import java.util.function.Supplier
* Entry point of the OpenSearch Notifications plugin
* This class initializes the rest handlers.
*/
class NotificationPlugin : ActionPlugin, Plugin(), NotificationCoreExtension {
class NotificationPlugin : ActionPlugin, Plugin(), NotificationCoreExtension, SystemIndexPlugin {

lateinit var clusterService: ClusterService // initialized in createComponents()

Expand All @@ -80,6 +82,15 @@ class NotificationPlugin : ActionPlugin, Plugin(), NotificationCoreExtension {
return PluginSettings.getAllSettings()
}

override fun getSystemIndexDescriptors(settings: Settings?): Collection<SystemIndexDescriptor> {
return listOf(
SystemIndexDescriptor(
NotificationConfigIndex.INDEX_NAME,
"System index for storing notification channels related configurations."
)
)
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal object NotificationConfigIndex : ConfigOperations {
const val SCHEMA_VERSION = "schema_version"

private val log by logger(NotificationConfigIndex::class.java)
private const val INDEX_NAME = ".opensearch-notifications-config"
const val INDEX_NAME = ".opensearch-notifications-config"
private const val MAPPING_FILE_NAME = "notifications-config-mapping.yml"
private const val SETTINGS_FILE_NAME = "notifications-config-settings.yml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
index:
number_of_shards: "1" # The data size is not expected to be big so keeping it 1 shard
auto_expand_replicas: "0-2"
hidden: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.opensearch.client.RequestOptions
import org.opensearch.client.ResponseException
import org.opensearch.client.RestClient
import org.opensearch.client.WarningsHandler
import org.opensearch.client.WarningsHandler.PERMISSIVE
import org.opensearch.common.io.PathUtils
import org.opensearch.common.settings.Settings
import org.opensearch.commons.ConfigConstants
Expand Down Expand Up @@ -368,6 +369,9 @@ abstract class PluginRestTestCase : OpenSearchRestTestCase() {
protected fun getCurrentMappingsSchemaVersion(): Int {
val indexName = ".opensearch-notifications-config"
val getMappingRequest = Request(RestRequest.Method.GET.name, "$indexName/_mappings")
val options = RequestOptions.DEFAULT.toBuilder()
options.setWarningsHandler(PERMISSIVE)
getMappingRequest.options = options.build()
val response = executeRequest(getMappingRequest, RestStatus.OK.status, client())
val mappingsObject = response.get(indexName).asJsonObject.get("mappings").asJsonObject
return mappingsObject.get(NotificationConfigIndex._META)?.asJsonObject?.get(NotificationConfigIndex.SCHEMA_VERSION)?.asInt
Expand Down

0 comments on commit 2c90d49

Please sign in to comment.