diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-07-23 14:51:00 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 08:51:17 +0200 |
commit | 53dbf8e66ad83c2d5f06279a0d7446e5e8be68e8 (patch) | |
tree | 44bdf2a4845440372fe8d63c40cb3112add2727f /hv-collector-xnf-simulator/src | |
parent | a2d18b375631d010432089ed18db327c9e4f26bf (diff) |
Configure xnf simulator api listen port
Closes ONAP-664
Closes ONAP-647
Change-Id: I8d1e57c0c66f1968925660fe47fa96a2a634c039
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-xnf-simulator/src')
6 files changed, 40 insertions, 53 deletions
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) } |