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,
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
+ }
}
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
.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()
.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()
override val cmdLineOptionsList = listOf(
VES_HV_PORT,
VES_HV_HOST,
- MESSAGES_TO_SEND_AMOUNT,
+ LISTEN_PORT,
SSL_DISABLE,
PRIVATE_KEY_FILE,
CERT_FILE,
)
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 {
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),
}
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
}
}
* @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)
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
*/
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)
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"
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
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
}
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)
}
}
* @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")
+ }
+ )
+
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
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")
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)
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)
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") {
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)
on("security config") {
val securityConfiguration = result.security
- it("should set ssl disable to true"){
+ it("should set ssl disable to true") {
assertTrue(securityConfiguration.sslDisable)
}