From 061805652a0459f04cc5144ec33d887a0f958ecc Mon Sep 17 00:00:00 2001 From: Petar Dzepina Date: Fri, 30 Dec 2022 01:33:18 +0100 Subject: [PATCH] removed unused code Signed-off-by: Petar Dzepina --- .../org/opensearch/alerting/AlertingPlugin.kt | 6 -- .../alerting/MonitorMetadataFactory.kt | 75 ------------------- 2 files changed, 81 deletions(-) delete mode 100644 alerting/src/main/kotlin/org/opensearch/alerting/MonitorMetadataFactory.kt diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt index ca12f5433..6cce97a21 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertingPlugin.kt @@ -235,12 +235,6 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R this.threadPool = threadPool this.clusterService = clusterService - MonitorMetadataFactory.initialize( - client, - clusterService, - xContentRegistry, - settings - ) MonitorMetadataService.initialize( client, clusterService, diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorMetadataFactory.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorMetadataFactory.kt deleted file mode 100644 index 634a11761..000000000 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorMetadataFactory.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.alerting - -import org.opensearch.action.admin.indices.get.GetIndexRequest -import org.opensearch.action.admin.indices.get.GetIndexResponse -import org.opensearch.alerting.model.MonitorMetadata -import org.opensearch.alerting.opensearchapi.suspendUntil -import org.opensearch.client.Client -import org.opensearch.cluster.service.ClusterService -import org.opensearch.common.settings.Settings -import org.opensearch.common.xcontent.NamedXContentRegistry -import org.opensearch.commons.alerting.model.DocLevelMonitorInput -import org.opensearch.commons.alerting.model.Monitor -import org.opensearch.index.seqno.SequenceNumbers - -object MonitorMetadataFactory { - - private lateinit var client: Client - private lateinit var xContentRegistry: NamedXContentRegistry - private lateinit var clusterService: ClusterService - private lateinit var settings: Settings - - fun initialize( - client: Client, - clusterService: ClusterService, - xContentRegistry: NamedXContentRegistry, - settings: Settings - ) { - this.clusterService = clusterService - this.client = client - this.xContentRegistry = xContentRegistry - this.settings = settings - } - - suspend fun newInstance(monitor: Monitor, createWithRunContext: Boolean): MonitorMetadata { - val monitorIndex = if (monitor.monitorType == Monitor.MonitorType.DOC_LEVEL_MONITOR) - (monitor.inputs[0] as DocLevelMonitorInput).indices[0] - else null - val runContext = - if (monitor.monitorType == Monitor.MonitorType.DOC_LEVEL_MONITOR && createWithRunContext) - createFullRunContext(monitorIndex) - else emptyMap() - return MonitorMetadata( - id = "${monitor.id}-metadata", - seqNo = SequenceNumbers.UNASSIGNED_SEQ_NO, - primaryTerm = SequenceNumbers.UNASSIGNED_PRIMARY_TERM, - monitorId = monitor.id, - lastActionExecutionTimes = emptyList(), - lastRunContext = runContext, - sourceToQueryIndexMapping = mutableMapOf() - ) - } - - private suspend fun createFullRunContext( - index: String?, - existingRunContext: MutableMap>? = null - ): MutableMap> { - if (index == null) return mutableMapOf() - val getIndexRequest = GetIndexRequest().indices(index) - val getIndexResponse: GetIndexResponse = client.suspendUntil { - client.admin().indices().getIndex(getIndexRequest, it) - } - val indices = getIndexResponse.indices() - val lastRunContext = existingRunContext?.toMutableMap() ?: mutableMapOf() - indices.forEach { indexName -> - if (!lastRunContext.containsKey(indexName)) - lastRunContext[indexName] = DocumentLevelMonitorRunner.createRunContext(clusterService, client, indexName) - } - return lastRunContext - } -}