diff options
Diffstat (limited to 'hv-collector-xnf-simulator/src/main')
5 files changed, 36 insertions, 33 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") + } + ) + |