From 0ab463f97e471bab20428eb324bee43dfab78c61 Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Mon, 8 Mar 2021 19:56:30 +0100 Subject: [PATCH] apply detekt code suggestions --- .../theodolite/benchmark/BenchmarkExecution.kt | 12 ++++++------ .../theodolite/benchmark/KubernetesBenchmark.kt | 16 ++++++++-------- .../execution/BenchmarkExecutorImpl.kt | 2 +- .../execution/TheodoliteYamlExecutor.kt | 2 +- .../src/main/kotlin/theodolite/k8s/K8sManager.kt | 2 -- .../main/kotlin/theodolite/k8s/TopicManager.kt | 8 +++----- .../k8s/WorkloadGeneratorStateCleaner.kt | 10 +++++----- .../kotlin/theodolite/patcher/AbstractPatcher.kt | 3 +-- .../kotlin/theodolite/patcher/EnvVarPatcher.kt | 4 +--- .../theodolite/patcher/NodeSelectorPatcher.kt | 1 - .../restriction/RestrictionStrategy.kt | 2 +- .../strategies/searchstrategy/BinarySearch.kt | 2 +- .../strategies/searchstrategy/LinearSearch.kt | 3 +-- .../strategies/searchstrategy/SearchStrategy.kt | 3 +-- 14 files changed, 30 insertions(+), 40 deletions(-) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index 4fba0d362..bb816fb1d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -4,7 +4,7 @@ import theodolite.util.ConfigurationOverride import kotlin.properties.Delegates -class BenchmarkExecution() { +class BenchmarkExecution { lateinit var name: String lateinit var benchmark: String lateinit var load: LoadDefinition @@ -13,24 +13,24 @@ class BenchmarkExecution() { lateinit var execution: Execution lateinit var configOverrides: List<ConfigurationOverride> - class Execution() { + class Execution { lateinit var strategy: String var duration by Delegates.notNull<Long>() - var repititions by Delegates.notNull<Int>() + var repetitions by Delegates.notNull<Int>() lateinit var restrictions: List<String> } - class Slo(){ + class Slo{ lateinit var sloType: String var threshold by Delegates.notNull<Int>() } - class LoadDefinition() { + class LoadDefinition { lateinit var loadType: String lateinit var loadValues: List<Int> } - class ResourceDefinition() { + class ResourceDefinition { lateinit var resourceType: String lateinit var resourceValues: List<Int> } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index cef47a556..69e45e46a 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -7,20 +7,20 @@ import theodolite.patcher.PatcherManager import theodolite.util.* import java.util.* -class KubernetesBenchmark(): Benchmark { +class KubernetesBenchmark: Benchmark { lateinit var name: String - lateinit var appResource: List<String> - lateinit var loadGenResource: List<String> - lateinit var resourceTypes: List<TypeName> - lateinit var loadTypes: List<TypeName> - lateinit var kafkaConfig: KafkaConfig - lateinit var zookeeperConfig: HashMap<String,String> + private lateinit var appResource: List<String> + private lateinit var loadGenResource: List<String> + private lateinit var resourceTypes: List<TypeName> + private lateinit var loadTypes: List<TypeName> + private lateinit var kafkaConfig: KafkaConfig + private lateinit var zookeeperConfig: HashMap<String,String> private fun loadKubernetesResources(resources: List<String>): List<Pair<String, KubernetesResource>> { val basePath = "./../../../resources/main/yaml/" - var parser = YamlParser() + val parser = YamlParser() val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("theodolite-she")) return resources .map { resource -> diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index ee7273c02..1c286b7f2 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -13,6 +13,6 @@ class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDur // todo evaluate val result = false // if success else false this.results.setResult(Pair(load, res), result) - return result; + return result } } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt index c297894f8..8ae567f97 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt @@ -7,7 +7,7 @@ import theodolite.benchmark.KubernetesBenchmark class TheodoliteYamlExecutor { fun run() { // load the BenchmarkExecution and the BenchmarkType - var parser = YamlParser() + val parser = YamlParser() val benchmarkExecution = parser.parse("./../../../resources/main/yaml/testBenchmarkExecution.yaml", BenchmarkExecution::class.java) !! val benchmark = parser.parse("./../../../resources/main/yaml/testBenchmarkType.yaml", KubernetesBenchmark::class.java) !! diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt index ef0c52207..8a7a9304b 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt @@ -3,8 +3,6 @@ package theodolite.k8s import io.fabric8.kubernetes.api.model.ConfigMap import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.Service -import io.fabric8.kubernetes.api.model.Volume -import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.StatefulSet import io.fabric8.kubernetes.client.NamespacedKubernetesClient diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt index 08a4d19ff..1336f5751 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt @@ -2,7 +2,6 @@ package theodolite.k8s import mu.KotlinLogging import org.apache.kafka.clients.admin.AdminClient -import org.apache.kafka.clients.admin.AdminClientConfig import org.apache.kafka.clients.admin.ListTopicsResult import org.apache.kafka.clients.admin.NewTopic import java.util.* @@ -11,10 +10,10 @@ private val logger = KotlinLogging.logger {} /** * Manages the topics related tasks - * @param bootstrapServers Ip of the kafka server + * @param kafkaConfig Kafka Configuration as HashMap */ class TopicManager(kafkaConfig: HashMap<String, Any>) { - lateinit var kafkaAdmin: AdminClient + private lateinit var kafkaAdmin: AdminClient init { try { @@ -26,8 +25,7 @@ class TopicManager(kafkaConfig: HashMap<String, Any>) { /** * Creates topics. - * @param topics Map that holds a numPartition for each topic it should create - * @param replicationFactor + * @param newTopics List of all Topic which should be created */ fun createTopics(newTopics: Collection<NewTopic>) { kafkaAdmin.createTopics(newTopics) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt index 9fd386ba9..46194c411 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt @@ -10,14 +10,14 @@ import java.time.Duration private val logger = KotlinLogging.logger {} /** - * Resets the Workloadgenerator states in Zookeeper (and potentially watches for Zookeeper events) + * Resets the WorkloadGenerator states in Zookeeper (and potentially watches for Zookeeper events) * * @param connectionString of zookeeper */ class WorkloadGeneratorStateCleaner(connectionString: String) { private val timeout: Duration = Duration.ofMillis(500) private val retryAfter: Duration = Duration.ofSeconds(5) - lateinit var zookeeperClient: ZooKeeper + private lateinit var zookeeperClient: ZooKeeper private val path = "/workload-generation" init { @@ -44,7 +44,7 @@ class WorkloadGeneratorStateCleaner(connectionString: String) { try { children = zookeeperClient.getChildren(nodePath, true) } catch (e: KeeperException.NoNodeException) { - break; + break } // recursively delete all children nodes for (s: String in children) { @@ -58,11 +58,11 @@ class WorkloadGeneratorStateCleaner(connectionString: String) { // delete main node try { zookeeperClient.delete(nodePath, -1) - break; + break } catch (ex: Exception) { // no instance of node found if (ex is KeeperException.NoNodeException) { - break; + break } else { logger.error { ex.toString() } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt index 9435a8d27..7ee31881e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt @@ -2,5 +2,4 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource -abstract class AbstractPatcher(k8sResource: KubernetesResource, container: String? = null, variableName: String? = null): Patcher { -} +abstract class AbstractPatcher(k8sResource: KubernetesResource, container: String? = null, variableName: String? = null): Patcher diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt index 941890ca3..a9eafb93e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt @@ -41,9 +41,7 @@ class EnvVarPatcher(private val k8sResource: KubernetesResource, private val con */ private fun setEnv(workloadDeployment: Deployment, containerName: String, map: Map<String, String>) { workloadDeployment.spec.template.spec.containers.filter { it.name == containerName } - .forEach { it: Container -> - setContainerEnv(it, map) - } + .forEach { setContainerEnv(it, map) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt index b6d75eb80..d588e7dae 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt @@ -1,7 +1,6 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource -import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.api.model.apps.Deployment class NodeSelectorPatcher(private val k8sResource: KubernetesResource, private val variableName: String): AbstractPatcher(k8sResource, variableName){ diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt index 2479e9429..6cca627e6 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt @@ -16,5 +16,5 @@ abstract class RestrictionStrategy(val results: Results) { * @param resources List of resources to be restricted. * @return Returns a list containing only elements that have not been filtered out by the restriction (possibly empty). */ - public abstract fun next(load: LoadDimension, resources: List<Resource>): List<Resource> + abstract fun next(load: LoadDimension, resources: List<Resource>): List<Resource> } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt index 474389c92..88972ffdb 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt @@ -14,7 +14,7 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { val result = binarySearch(load, resources, 0, resources.size - 1) if( result == -1 ) { - return null; + return null } return resources[result] } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt index 67a254989..c2d6c0933 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -3,7 +3,6 @@ package theodolite.strategies.searchstrategy import theodolite.execution.BenchmarkExecutor import theodolite.util.LoadDimension import theodolite.util.Resource -import theodolite.util.Results class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { @@ -11,6 +10,6 @@ class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm for (res in resources) { if (this.benchmarkExecutor.runExperiment(load, res)) return res } - return null; + return null } } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt index 118d2f162..2c03d1eeb 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -3,7 +3,6 @@ package theodolite.strategies.searchstrategy import theodolite.execution.BenchmarkExecutor import theodolite.util.LoadDimension import theodolite.util.Resource -import theodolite.util.Results abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) { /** @@ -13,5 +12,5 @@ abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) { * @param resources List of all possible resources. * @return suitable resource for the specified load, or null if no suitable resource exists. */ - abstract fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource?; + abstract fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? } \ No newline at end of file -- GitLab