aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt
diff options
context:
space:
mode:
Diffstat (limited to 'sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt')
-rw-r--r--sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt70
1 files changed, 18 insertions, 52 deletions
diff --git a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt
index 63d590a2..8e6bafc4 100644
--- a/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt
+++ b/sources/hv-collector-configuration/src/main/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMerger.kt
@@ -20,12 +20,12 @@
package org.onap.dcae.collectors.veshv.config.impl
-import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.getOrElse
import arrow.core.toOption
-import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
+import kotlin.reflect.KProperty0
+import kotlin.reflect.KProperty1
/**
* @author Pawel Biniek <pawel.biniek@nokia.com>
@@ -34,62 +34,28 @@ import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
internal class ConfigurationMerger {
fun merge(base: PartialConfiguration, update: PartialConfiguration): PartialConfiguration =
PartialConfiguration(
- mergeServerConfig(base.server, update.server),
- mergeCbsConfig(base.cbs, update.cbs),
- mergeSecurityConfig(base.security, update.security),
- mergeCollectorConfig(base.collector, update.collector),
- mergeLogLevel(base.logLevel, update.logLevel)
- )
-
-
- private fun mergeServerConfig(baseOption: Option<PartialServerConfig>,
- updateOption: Option<PartialServerConfig>) =
- applyUpdate(baseOption, updateOption) { base, update ->
- PartialServerConfig(
- base.listenPort.updateToGivenOrNone(update.listenPort),
- base.idleTimeoutSec.updateToGivenOrNone(update.idleTimeoutSec),
- base.maxPayloadSizeBytes.updateToGivenOrNone(update.maxPayloadSizeBytes)
- )
- }
+ listenPort = base.listenPort.updateToGivenOrNone(update.listenPort),
+ idleTimeoutSec = base.idleTimeoutSec.updateToGivenOrNone(update.idleTimeoutSec),
+ maxPayloadSizeBytes = base.maxPayloadSizeBytes.updateToGivenOrNone(update.maxPayloadSizeBytes),
+ firstRequestDelaySec = base.firstRequestDelaySec.updateToGivenOrNone(update.firstRequestDelaySec),
+ requestIntervalSec = base.requestIntervalSec.updateToGivenOrNone(update.requestIntervalSec),
- private fun mergeCbsConfig(baseOption: Option<PartialCbsConfig>,
- updateOption: Option<PartialCbsConfig>) =
- applyUpdate(baseOption, updateOption) { base, update ->
- PartialCbsConfig(
- base.firstRequestDelaySec.updateToGivenOrNone(update.firstRequestDelaySec),
- base.requestIntervalSec.updateToGivenOrNone(update.requestIntervalSec)
- )
- }
+ sslDisable = base.sslDisable.updateToGivenOrNone(update.sslDisable),
+ keyStoreFile = base.keyStoreFile.updateToGivenOrNone(update.keyStoreFile),
+ keyStorePassword = base.keyStorePassword.updateToGivenOrNone(update.keyStorePassword),
+ trustStoreFile = base.trustStoreFile.updateToGivenOrNone(update.trustStoreFile),
+ trustStorePassword = base.trustStorePassword.updateToGivenOrNone(update.trustStorePassword),
- private fun mergeSecurityConfig(baseOption: Option<PartialSecurityConfig>,
- updateOption: Option<PartialSecurityConfig>) =
- applyUpdate(baseOption, updateOption) { base, update ->
- PartialSecurityConfig(
- base.keys.updateToGivenOrNone(update.keys)
- )
- }
+ routing = base.routing.updateToGivenOrNone(update.routing),
- private fun mergeCollectorConfig(baseOption: Option<PartialCollectorConfig>,
- updateOption: Option<PartialCollectorConfig>) =
- applyUpdate(baseOption, updateOption) { base, update ->
- PartialCollectorConfig(
- base.routing.updateToGivenOrNone(update.routing)
- )
- }
+ logLevel = base.logLevel.updateToGivenOrNone(update.logLevel)
+ )
+ private fun <T> Option<T>.updateToGivenOrNone(update: Option<T>) =
+ update.getOrElse(this::orNull).toOption()
- private fun mergeLogLevel(base: Option<LogLevel>, update: Option<LogLevel>) =
- base.updateToGivenOrNone(update)
}
-private fun <T> applyUpdate(base: Option<T>, update: Option<T>, overrider: (base: T, update: T) -> T) =
- when {
- base is Some && update is Some -> overrider(base.t, update.t).toOption()
- base is Some && update is None -> base
- base is None && update is Some -> update
- else -> None
- }
-private fun <T> Option<T>.updateToGivenOrNone(update: Option<T>) =
- update.getOrElse(this::orNull).toOption()
+