diff --git a/reports-scheduler/build.gradle b/reports-scheduler/build.gradle index 46670b88..b35c0f2a 100644 --- a/reports-scheduler/build.gradle +++ b/reports-scheduler/build.gradle @@ -40,6 +40,7 @@ buildscript { classpath "${opensearch_group}.gradle:build-tools:${opensearch_version}" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}" classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}" + classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0" classpath "org.jacoco:org.jacoco.agent:0.8.5" } } @@ -56,9 +57,16 @@ apply plugin: 'idea' apply plugin: 'opensearch.opensearchplugin' apply plugin: 'opensearch.pluginzip' apply plugin: 'opensearch.testclusters' +apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.jetbrains.kotlin.plugin.allopen' +configurations.all { + resolutionStrategy { + force 'org.yaml:snakeyaml:1.32' + } +} + def usingRemoteCluster = System.properties.containsKey('tests.rest.cluster') || System.properties.containsKey('tests.cluster') def usingMultiNode = project.properties.containsKey('numNodes') @@ -105,6 +113,11 @@ configurations { testRuntime } +detekt { + config = files("detekt.yml") + buildUponDefaultConfig = true +} + configurations.testCompile { exclude module: "securemock" } diff --git a/reports-scheduler/detekt.yml b/reports-scheduler/detekt.yml index cad046bd..9b1d91fd 100644 --- a/reports-scheduler/detekt.yml +++ b/reports-scheduler/detekt.yml @@ -15,3 +15,8 @@ style: ReturnCount: active: true max: 10 +complexity: + LongMethod: + threshold: 120 + NestedBlockDepth: + threshold: 5 \ No newline at end of file diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportDefinitionsIndex.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportDefinitionsIndex.kt index 60fb34ce..35d76481 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportDefinitionsIndex.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportDefinitionsIndex.kt @@ -41,7 +41,6 @@ internal object ReportDefinitionsIndex { const val REPORT_DEFINITIONS_INDEX_NAME = ".opendistro-reports-definitions" private const val REPORT_DEFINITIONS_MAPPING_FILE_NAME = "report-definitions-mapping.yml" private const val REPORT_DEFINITIONS_SETTINGS_FILE_NAME = "report-definitions-settings.yml" - private const val MAPPING_TYPE = "_doc" private lateinit var client: Client private lateinit var clusterService: ClusterService @@ -75,10 +74,12 @@ internal object ReportDefinitionsIndex { log.info("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation Acknowledged") } else { Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment() - throw IllegalStateException("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged") + error("$LOG_PREFIX:Index $REPORT_DEFINITIONS_INDEX_NAME creation not Acknowledged") } + } catch (exception: ResourceAlreadyExistsException) { + log.warn("message: ${exception.message}") } catch (exception: Exception) { - if (exception !is ResourceAlreadyExistsException && exception.cause !is ResourceAlreadyExistsException) { + if (exception.cause !is ResourceAlreadyExistsException) { Metrics.REPORT_DEFINITION_CREATE_SYSTEM_ERROR.counter.increment() throw exception } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt index 1291e758..42e98935 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/index/ReportInstancesIndex.kt @@ -41,7 +41,6 @@ internal object ReportInstancesIndex { private const val REPORT_INSTANCES_INDEX_NAME = ".opendistro-reports-instances" private const val REPORT_INSTANCES_MAPPING_FILE_NAME = "report-instances-mapping.yml" private const val REPORT_INSTANCES_SETTINGS_FILE_NAME = "report-instances-settings.yml" - private const val MAPPING_TYPE = "_doc" private lateinit var client: Client private lateinit var clusterService: ClusterService @@ -74,10 +73,12 @@ internal object ReportInstancesIndex { if (response.isAcknowledged) { log.info("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation Acknowledged") } else { - throw IllegalStateException("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged") + error("$LOG_PREFIX:Index $REPORT_INSTANCES_INDEX_NAME creation not Acknowledged") } + } catch (exception: ResourceAlreadyExistsException) { + log.warn("message: ${exception.message}") } catch (exception: Exception) { - if (exception !is ResourceAlreadyExistsException && exception.cause !is ResourceAlreadyExistsException) { + if (exception.cause !is ResourceAlreadyExistsException) { throw exception } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt index 6544a284..dfa1b5a7 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/model/ReportDefinition.kt @@ -370,7 +370,6 @@ internal data class ReportDefinition( val configIds: List ) : ToXContentObject { internal companion object { - private const val DELIVERY_FORMAT_TAG = "deliveryFormat" private const val TITLE_TAG = "title" private const val TEXT_DESCRIPTION_TAG = "textDescription" private const val HTML_DESCRIPTION_TAG = "htmlDescription" @@ -382,7 +381,6 @@ internal data class ReportDefinition( * @return created Delivery object */ fun parse(parser: XContentParser): Delivery { - var recipients: List = listOf() var title: String? = null var textDescription: String? = null var htmlDescription: String? = null diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/SecurityAccess.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/SecurityAccess.kt index d18f652d..e08fc735 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/SecurityAccess.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/security/SecurityAccess.kt @@ -24,7 +24,7 @@ internal object SecurityAccess { SpecialPermission.check() return try { AccessController.doPrivileged(operation) - } catch (e: PrivilegedActionException) { + } catch (@Suppress("SwallowedException") e: PrivilegedActionException) { throw (e.cause as Exception?)!! } } diff --git a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt index 1521c0a9..bb54852c 100644 --- a/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt +++ b/reports-scheduler/src/main/kotlin/org/opensearch/reportsscheduler/settings/PluginSettings.kt @@ -99,7 +99,7 @@ internal object PluginSettings { try { settings = Settings.builder().loadFromPath(defaultSettingYmlFile).build() } catch (exception: IOException) { - log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()}") + log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()} message:${exception.message}") } } // Initialize the settings values to default values diff --git a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportSchedularPluginTests.kt b/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportSchedularPluginTests.kt deleted file mode 100644 index d29129cb..00000000 --- a/reports-scheduler/src/test/kotlin/org/opensearch/integTest/ReportSchedularPluginTests.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.integTest - -import org.opensearch.test.OpenSearchTestCase - -class ReportSchedularPluginTests : OpenSearchTestCase() { - fun testSample() { - } -}