Skip to content

Commit efe2d33

Browse files
authored
Fix kotlin warnings (opensearch-project#551)
* Fix low hanging fruit warnings Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com> * Revert change causing IT failure Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com> Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
1 parent 5217af0 commit efe2d33

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexStateManagementHistory.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.opensearch.action.index.IndexRequest
1919
import org.opensearch.action.support.IndicesOptions
2020
import org.opensearch.action.support.master.AcknowledgedResponse
2121
import org.opensearch.client.Client
22-
import org.opensearch.cluster.LocalNodeMasterListener
22+
import org.opensearch.cluster.LocalNodeClusterManagerListener
2323
import org.opensearch.cluster.service.ClusterService
2424
import org.opensearch.common.settings.Settings
2525
import org.opensearch.common.xcontent.ToXContent
@@ -47,7 +47,7 @@ class IndexStateManagementHistory(
4747
private val threadPool: ThreadPool,
4848
private val clusterService: ClusterService,
4949
private val indexManagementIndices: IndexManagementIndices
50-
) : LocalNodeMasterListener {
50+
) : LocalNodeClusterManagerListener {
5151

5252
private val logger = LogManager.getLogger(javaClass)
5353
private var scheduledRollover: Scheduler.Cancellable? = null
@@ -61,7 +61,7 @@ class IndexStateManagementHistory(
6161
@Volatile private var historyNumberOfReplicas = ManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS.get(settings)
6262

6363
init {
64-
clusterService.addLocalNodeMasterListener(this)
64+
clusterService.addLocalNodeClusterManagerListener(this)
6565
clusterService.clusterSettings.addSettingsUpdateConsumer(ManagedIndexSettings.HISTORY_ENABLED) {
6666
historyEnabled = it
6767
}
@@ -82,7 +82,7 @@ class IndexStateManagementHistory(
8282
}
8383
}
8484

85-
override fun onMaster() {
85+
override fun onClusterManager() {
8686
try {
8787
// try to rollover immediately as we might be restarting the cluster
8888
if (historyEnabled) rolloverHistoryIndex()
@@ -97,12 +97,12 @@ class IndexStateManagementHistory(
9797
}
9898
}
9999

100-
override fun offMaster() {
100+
override fun offClusterManager() {
101101
scheduledRollover?.cancel()
102102
}
103103

104104
private fun rescheduleRollover() {
105-
if (clusterService.state().nodes.isLocalNodeElectedMaster) {
105+
if (clusterService.state().nodes.isLocalNodeElectedClusterManager) {
106106
scheduledRollover?.cancel()
107107
scheduledRollover = threadPool.scheduleWithFixedDelay(
108108
{ rolloverAndDeleteHistoryIndex() },

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ class ManagedIndexCoordinator(
202202
// Instead of using a LocalNodeMasterListener to track cluster manager changes, this service will
203203
// track them here to avoid conditions where cluster manager listener events run after other
204204
// listeners that depend on what happened in the cluster manager listener
205-
if (this.isClusterManager != event.localNodeMaster()) {
206-
this.isClusterManager = event.localNodeMaster()
205+
if (this.isClusterManager != event.localNodeClusterManager()) {
206+
this.isClusterManager = event.localNodeClusterManager()
207207
if (this.isClusterManager) {
208208
onClusterManager()
209209
} else {
@@ -215,7 +215,7 @@ class ManagedIndexCoordinator(
215215

216216
if (event.isNewCluster) return
217217

218-
if (!event.localNodeMaster()) return
218+
if (!event.localNodeClusterManager()) return
219219

220220
if (!event.metadataChanged()) return
221221

@@ -474,7 +474,7 @@ class ManagedIndexCoordinator(
474474
if (!isIndexStateManagementEnabled()) return
475475

476476
// Do not setup background sweep if we're not the elected cluster manager node
477-
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
477+
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return
478478

479479
// Cancel existing background sweep
480480
scheduledFullSweep?.cancel()
@@ -505,7 +505,7 @@ class ManagedIndexCoordinator(
505505
fun initMoveMetadata() {
506506
if (!metadataServiceEnabled) return
507507
if (!isIndexStateManagementEnabled()) return
508-
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
508+
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return
509509
scheduledMoveMetadata?.cancel()
510510

511511
if (metadataService.finishFlag) {
@@ -535,7 +535,7 @@ class ManagedIndexCoordinator(
535535
fun initTemplateMigration(enableSetting: Long) {
536536
if (!templateMigrationEnabled) return
537537
if (!isIndexStateManagementEnabled()) return
538-
if (!clusterService.state().nodes().isLocalNodeElectedMaster) return
538+
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager) return
539539
scheduledTemplateMigration?.cancel()
540540

541541
// if service has finished, re-enable it

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ object ManagedIndexRunner :
253253
// the cluster state index uuid differs from the one in the managed index config then the config is referring
254254
// to a different index which does not exist in the cluster. We need to check all of the extensions to confirm an index exists
255255
if (clusterStateIndexMetadata == null || clusterStateIndexUUID != managedIndexConfig.indexUuid) {
256-
clusterStateIndexMetadata = null
257256
// If the cluster state/default index type didn't have an index with a matching name and uuid combination, try all other index types
258257
val nonDefaultIndexTypes = indexMetadataProvider.services.keys.filter { it != DEFAULT_INDEX_TYPE }
259258
val multiTypeIndexNameToMetaData =

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ManagedIndexConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ data class ManagedIndexConfig(
178178
policySeqNo = policySeqNo,
179179
policyPrimaryTerm = policyPrimaryTerm,
180180
policy = policy?.copy(
181-
id = policyID ?: NO_ID,
181+
id = policyID,
182182
seqNo = policySeqNo ?: SequenceNumbers.UNASSIGNED_SEQ_NO,
183183
primaryTerm = policyPrimaryTerm ?: SequenceNumbers.UNASSIGNED_PRIMARY_TERM
184184
),

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AttemptCloseStep : Step(name) {
4444
} catch (e: RemoteTransportException) {
4545
val cause = ExceptionsHelper.unwrapCause(e)
4646
if (cause is SnapshotInProgressException) {
47-
handleSnapshotException(indexName, cause as SnapshotInProgressException)
47+
handleSnapshotException(indexName, cause)
4848
} else {
4949
handleException(indexName, cause as Exception)
5050
}

0 commit comments

Comments
 (0)