diff options
9 files changed, 53 insertions, 71 deletions
diff --git a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt index a11fe3d4..d8ee244b 100644 --- a/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt +++ b/hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt @@ -28,17 +28,6 @@ import org.onap.dcae.collectors.veshv.utils.commandline.ArgBasedConfiguration import org.onap.dcae.collectors.veshv.utils.commandline.CommandLineOption.* import java.time.Duration -internal object DefaultValues { - const val PORT = 6061 - const val CONSUL_FIRST_REQUEST_DELAY = 10L - const val CONSUL_REQUEST_INTERVAL = 5L - const val CONFIG_URL = "" - const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key" - const val CERT_FILE = "/etc/ves-hv/server.crt" - const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt" - const val IDLE_TIMEOUT_SEC = 60L -} - internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfiguration>(DefaultParser()) { override val cmdLineOptionsList = listOf( LISTEN_PORT, @@ -92,4 +81,15 @@ internal class ArgBasedServerConfiguration : ArgBasedConfiguration<ServerConfigu trustedCert = stringPathToPath(trustCertFile) ) } + + internal object DefaultValues { + const val PORT = 6061 + const val CONSUL_FIRST_REQUEST_DELAY = 10L + const val CONSUL_REQUEST_INTERVAL = 5L + const val CONFIG_URL = "" + const val PRIVATE_KEY_FILE = "/etc/ves-hv/server.key" + const val CERT_FILE = "/etc/ves-hv/server.crt" + const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt" + const val IDLE_TIMEOUT_SEC = 60L + } } diff --git a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt index 6da605f4..fb0067ec 100644 --- a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt +++ b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt @@ -27,6 +27,7 @@ import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration +import org.onap.dcae.collectors.veshv.main.ArgBasedServerConfiguration.* import org.onap.dcae.collectors.veshv.model.ServerConfiguration import java.nio.file.Paths import java.time.Duration diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt index a654868e..1d94dc30 100644 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt @@ -47,7 +47,7 @@ enum class CommandLineOption(val option: Option) { .desc("Interval of consul configuration requests in seconds") .build() ), - VES_HV_PORT(Option.builder("p") + VES_HV_PORT(Option.builder("v") .longOpt("ves-port") .required() .hasArg() @@ -61,12 +61,6 @@ enum class CommandLineOption(val option: Option) { .desc("VesHvCollector host") .build() ), - MESSAGES_TO_SEND_AMOUNT(Option.builder("m") - .longOpt("messages") - .hasArg() - .desc("Amount of messages to send") - .build() - ), KAFKA_SERVERS(Option.builder("s") .longOpt("kafka-bootstrap-servers") .required() diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt index 96e65778..8954fd22 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt @@ -34,7 +34,7 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu override val cmdLineOptionsList = listOf( VES_HV_PORT, VES_HV_HOST, - MESSAGES_TO_SEND_AMOUNT, + LISTEN_PORT, SSL_DISABLE, PRIVATE_KEY_FILE, CERT_FILE, @@ -42,14 +42,15 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu ) override fun getConfiguration(cmdLine: CommandLine): SimulatorConfiguration { - val host = cmdLine.stringValue(VES_HV_HOST, DefaultValues.VES_HV_HOST) - val port = cmdLine.intValue(VES_HV_PORT, DefaultValues.VES_HV_PORT) - val messagesAmount = cmdLine.longValue(MESSAGES_TO_SEND_AMOUNT, DefaultValues.MESSAGES_AMOUNT) + val vesHost = cmdLine.stringValue(VES_HV_HOST, DefaultValues.VES_HV_HOST) + val vesPort = cmdLine.intValue(VES_HV_PORT, DefaultValues.VES_HV_PORT) + val listenPort = cmdLine.intValue(LISTEN_PORT, DefaultValues.LISTEN_PORT) + return SimulatorConfiguration( - host, - port, - parseSecurityConfig(cmdLine), - messagesAmount) + listenPort, + vesHost, + vesPort, + parseSecurityConfig(cmdLine)) } private fun parseSecurityConfig(cmdLine: CommandLine): SecurityConfiguration { @@ -57,6 +58,7 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu val pkFile = cmdLine.stringValue(PRIVATE_KEY_FILE, DefaultValues.PRIVATE_KEY_FILE) val certFile = cmdLine.stringValue(CERT_FILE, DefaultValues.CERT_FILE) val trustCertFile = cmdLine.stringValue(TRUST_CERT_FILE, DefaultValues.TRUST_CERT_FILE) + return SecurityConfiguration( sslDisable = sslDisable, privateKey = stringPathToPath(pkFile), @@ -65,11 +67,11 @@ internal class ArgConfigurationProvider : ArgBasedConfiguration<SimulatorConfigu } internal object DefaultValues { - const val MESSAGES_AMOUNT = -1L const val PRIVATE_KEY_FILE = "/etc/ves-hv/client.key" const val CERT_FILE = "/etc/ves-hv/client.crt" const val TRUST_CERT_FILE = "/etc/ves-hv/trust.crt" const val VES_HV_PORT = 6061 const val VES_HV_HOST = "veshvcollector" + const val LISTEN_PORT = 6062 } } diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/SimulatorConfiguration.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/SimulatorConfiguration.kt index 1052cfcc..708ffd13 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/SimulatorConfiguration.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/SimulatorConfiguration.kt @@ -26,7 +26,7 @@ import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration * @since June 2018 */ internal data class SimulatorConfiguration( + val listenPort: Int, val vesHost: String, val vesPort: Int, - val security: SecurityConfiguration, - val messagesAmount: Long) + val security: SecurityConfiguration) diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt index 0ab248b9..24ef578d 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt @@ -33,7 +33,6 @@ import ratpack.server.RatpackServer import ratpack.server.ServerConfig import reactor.core.publisher.Flux import reactor.core.scheduler.Schedulers -import java.nio.charset.Charset import javax.json.Json import javax.json.JsonArray @@ -43,7 +42,7 @@ import javax.json.JsonArray */ internal class HttpServer(private val vesClient: XnfSimulator) { - fun start(port: Int = DEFAULT_PORT): IO<RatpackServer> = IO { + fun start(port: Int): IO<RatpackServer> = IO { RatpackServer.start { server -> server.serverConfig(ServerConfig.embedded().port(port)) .handlers(this::configureHandlers) @@ -113,7 +112,6 @@ internal class HttpServer(private val vesClient: XnfSimulator) { companion object { private val logger = Logger(HttpServer::class) - const val DEFAULT_PORT = 5000 const val STATUS_OK = 200 const val STATUS_BAD_REQUEST = 400 const val CONTENT_TYPE_APPLICATION_JSON = "application/json" diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulator.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulator.kt index 2f9e0b59..e8a474d0 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulator.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulator.kt @@ -25,8 +25,8 @@ import io.netty.handler.ssl.SslContext import io.netty.handler.ssl.SslContextBuilder import io.netty.handler.ssl.SslProvider import org.onap.dcae.collectors.veshv.domain.EndOfTransmissionMessage -import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage +import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.domain.WireFrameEncoder import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration import org.onap.dcae.collectors.veshv.utils.logging.Logger @@ -73,8 +73,8 @@ internal class XnfSimulator(private val configuration: SimulatorConfiguration) { private fun handler(complete: ReplayProcessor<Void>, messages: Flux<PayloadWireFrameMessage>, - nettyOutbound: NettyOutbound): - Publisher<Void> { + nettyOutbound: NettyOutbound): Publisher<Void> { + val allocator = nettyOutbound.alloc() val encoder = WireFrameEncoder(allocator) val frames = messages @@ -109,8 +109,8 @@ internal class XnfSimulator(private val configuration: SimulatorConfiguration) { } companion object { + private val logger = Logger(XnfSimulator::class) private const val MAX_BATCH_SIZE = 128 private const val eotMessageByte = EndOfTransmissionMessage.MARKER_BYTE - private val logger = Logger(XnfSimulator::class) } } diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt index facf611a..a47cef58 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt @@ -36,18 +36,21 @@ const val PROGRAM_NAME = "java $PACKAGE_NAME.MainKt" * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -fun main(args: Array<String>) = - ArgConfigurationProvider().parse(args) - .mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME)) - .map(::XnfSimulator) - .map(::HttpServer) - .map { it.start().void() } - .unsafeRunEitherSync( - { ex -> - logger.error("Failed to start a server", ex) - ExitFailure(1) - }, - { - logger.info("Started xNF Simulator API server") - } - ) +fun main(args: Array<String>) = ArgConfigurationProvider().parse(args) + .mapLeft(handleWrongArgumentErrorCurried(PROGRAM_NAME)) + .map { + XnfSimulator(it) + .run(::HttpServer) + .start(it.listenPort) + .void() + } + .unsafeRunEitherSync( + { ex -> + logger.error("Failed to start a server", ex) + ExitFailure(1) + }, + { + logger.info("Started xNF Simulator API server") + } + ) + diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt index fccd8b5a..04d81c74 100644 --- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt +++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt @@ -28,7 +28,7 @@ import org.jetbrains.spek.api.dsl.it import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider -import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider.* +import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider.DefaultValues import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration import java.nio.file.Paths import kotlin.test.assertTrue @@ -36,7 +36,6 @@ import kotlin.test.assertTrue object ArgConfigurationProviderTest : Spek({ lateinit var cut: ArgConfigurationProvider - val messagesAmount = 3L val vesHost = "localhosting" val pk = Paths.get("/", "etc", "ves", "pk.pem") val cert = Paths.get("/", "etc", "ssl", "certs", "ca-bundle.crt") @@ -61,7 +60,6 @@ object ArgConfigurationProviderTest : Spek({ result = parse("--ssl-disable", "--ves-port", "6969", "--ves-host", vesHost, - "--messages", messagesAmount.toString(), "--private-key-file", pk.toFile().absolutePath, "--cert-file", cert.toFile().absolutePath, "--trust-cert-file", trustCert.toFile().absolutePath) @@ -71,11 +69,6 @@ object ArgConfigurationProviderTest : Spek({ assertThat(result.vesPort).isEqualTo(6969) } - - it("should set proper config url") { - assertThat(result.messagesAmount).isEqualTo(messagesAmount) - } - it("should set proper security configuration") { assertThat(result.security).isEqualTo( SecurityConfiguration(sslDisable = true, privateKey = pk, cert = cert, trustedCert = trustCert) @@ -86,26 +79,18 @@ object ArgConfigurationProviderTest : Spek({ given("some parameters are present in the short form") { beforeEachTest { - result = parse("-h", "ves-hv", "--ves-port", "666", "-m", messagesAmount.toString()) + result = parse("-h", "ves-hv", "--ves-port", "666") } it("should set proper port") { assertThat(result.vesPort).isEqualTo(666) } - - it("should set proper messages amount") { - assertThat(result.messagesAmount).isEqualTo(messagesAmount) - } } given("all optional parameters are absent") { beforeEachTest { - result = parse("-h", "ves-hv", "-p", "666") - } - - it("should set default messages amount") { - assertThat(result.messagesAmount).isEqualTo(DefaultValues.MESSAGES_AMOUNT) + result = parse("-h", "ves-hv", "-v", "666") } on("security config") { @@ -130,7 +115,6 @@ object ArgConfigurationProviderTest : Spek({ result = parse("--ssl-disable", "--ves-port", "888", "--ves-host", vesHost, - "--messages", messagesAmount.toString(), "--private-key-file", pk.toFile().absolutePath, "--cert-file", cert.toFile().absolutePath, "--trust-cert-file", trustCert.toFile().absolutePath) @@ -139,7 +123,7 @@ object ArgConfigurationProviderTest : Spek({ on("security config") { val securityConfiguration = result.security - it("should set ssl disable to true"){ + it("should set ssl disable to true") { assertTrue(securityConfiguration.sslDisable) } |