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

Handle NPE in isRollupIndex #855

Merged
merged 4 commits into from
Jul 22, 2023
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 @@ -68,9 +68,12 @@ const val DATE_FIELD_EPOCH_MILLIS_FORMAT = "epoch_millis"

@Suppress("ReturnCount")
fun isRollupIndex(index: String, clusterState: ClusterState): Boolean {
if (RollupSettings.ROLLUP_INDEX.get(clusterState.metadata.index(index).settings)) {
val idx = clusterState.metadata.index(index)
if (idx == null) {
return false
} else if (RollupSettings.ROLLUP_INDEX.get(idx.settings)) {
return true
} else if (LegacyOpenDistroRollupSettings.ROLLUP_INDEX.get(clusterState.metadata.index(index).settings)) {
} else if (LegacyOpenDistroRollupSettings.ROLLUP_INDEX.get(idx.settings)) {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

package org.opensearch.indexmanagement.rollup.util

import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import org.opensearch.cluster.ClusterState
import org.opensearch.cluster.metadata.Metadata
import org.opensearch.index.query.BoolQueryBuilder
import org.opensearch.index.query.ConstantScoreQueryBuilder
import org.opensearch.index.query.DisMaxQueryBuilder
Expand Down Expand Up @@ -230,4 +235,16 @@ class RollupUtilsTests : OpenSearchTestCase() {
assertEquals("Rewritten aggregation builder is not the correct type", aggBuilder.type, rewrittenAgg.type)
}
}

fun `test isRollupIndex`() {
val indexName = "missing index"
val clusterState: ClusterState = mock()
val metadata: Metadata = mock()

whenever(clusterState.metadata).doReturn(metadata)
whenever(metadata.index(indexName)).doReturn(null)

val actual = isRollupIndex(indexName, clusterState)
assertFalse(actual)
}
}