Configure xnf simulator api listen port 49/58849/1
authorJakub Dudycz <jakub.dudycz@nokia.com>
Mon, 23 Jul 2018 12:51:00 +0000 (14:51 +0200)
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>
Fri, 3 Aug 2018 06:51:17 +0000 (08:51 +0200)
Closes ONAP-664
Closes ONAP-647

Change-Id: I8d1e57c0c66f1968925660fe47fa96a2a634c039
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601

hv-collector-main/src/main/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfiguration.kt
hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt
hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt
hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ArgConfigurationProvider.kt
hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/SimulatorConfiguration.kt
hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt
hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulator.kt
hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt
hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt

index a11fe3d..d8ee244 100644 (file)
@@ -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
+    }
 }
index 6da605f..fb0067e 100644 (file)
@@ -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
index a654868..1d94dc3 100644 (file)
@@ -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()
index 96e6577..8954fd2 100644 (file)
@@ -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
     }
 }
index 1052cfc..708ffd1 100644 (file)
@@ -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)
index 0ab248b..24ef578 100644 (file)
@@ -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"
index 2f9e0b5..e8a474d 100644 (file)
@@ -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)
     }
 }
index facf611..a47cef5 100644 (file)
@@ -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")
+                }
+        )
+
index fccd8b5..04d81c7 100644 (file)
@@ -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)
                 }