diff options
Diffstat (limited to 'hv-collector-utils/src/main/kotlin/org/onap')
11 files changed, 0 insertions, 820 deletions
diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt deleted file mode 100644 index 7381592d..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.arrow - -import arrow.core.Either -import arrow.core.Option -import arrow.core.identity -import arrow.syntax.collections.firstOption -import java.util.concurrent.atomic.AtomicReference - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since July 2018 - */ - -fun <A> Either<A, A>.flatten() = fold(::identity, ::identity) - -fun <B> Either<Throwable, B>.rightOrThrow() = fold({ throw it }, ::identity) - -fun <A, B> Either<A, B>.rightOrThrow(mapper: (A) -> Throwable) = fold({ throw mapper(it) }, ::identity) - -fun <A> AtomicReference<A>.getOption() = Option.fromNullable(get()) - -fun <A> Option.Companion.fromNullablesChain(firstValue: A?, vararg nextValues: () -> A?): Option<A> = - if (firstValue != null) - Option.just(firstValue) - else nextValues.asSequence() - .map { it() } - .filter { it != null } - .firstOption() diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt deleted file mode 100644 index 05d13094..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.arrow - -import arrow.core.Either -import arrow.core.Left -import arrow.core.Right -import arrow.effects.IO -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import kotlin.system.exitProcess - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since June 2018 - */ - -sealed class ExitCode { - abstract val code: Int - - fun io() = IO { - exitProcess(code) - } -} - -object ExitSuccess : ExitCode() { - override val code = 0 -} - -data class ExitFailure(override val code: Int) : ExitCode() - -fun Either<IO<Unit>, IO<Unit>>.unsafeRunEitherSync(onError: (Throwable) -> ExitCode, onSuccess: () -> Unit) = - flatten().attempt().unsafeRunSync().fold({ onError(it).io().unsafeRunSync() }, { onSuccess() }) - - -fun IO<Any>.unit() = map { Unit } - -fun <T> Mono<T>.asIo() = IO.async<T> { callback -> - subscribe({ - callback(Right(it)) - }, { - callback(Left(it)) - }) -} - -fun <T> Flux<IO<T>>.evaluateIo(): Flux<T> = - flatMap { io -> - io.attempt().unsafeRunSync().fold( - { Flux.error<T>(it) }, - { Flux.just<T>(it) } - ) - } diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt deleted file mode 100644 index b14f1be5..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/ArgBasedConfiguration.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.commandline - -import arrow.core.Either -import arrow.core.Option -import arrow.core.Try -import arrow.core.flatMap -import org.apache.commons.cli.CommandLine -import org.apache.commons.cli.CommandLineParser -import org.apache.commons.cli.Options -import java.io.File -import java.nio.file.Path -import java.nio.file.Paths - -abstract class ArgBasedConfiguration<T>(private val parser: CommandLineParser) { - abstract val cmdLineOptionsList: List<CommandLineOption> - - fun parse(args: Array<out String>): Either<WrongArgumentError, T> { - val parseResult = Try { - val commandLineOptions = cmdLineOptionsList.map { it.option }.fold(Options(), Options::addOption) - parser.parse(commandLineOptions, args) - } - return parseResult - .toEither() - .mapLeft { ex -> WrongArgumentError(ex, cmdLineOptionsList) } - .map(this::getConfiguration) - .flatMap { - it.toEither { - WrongArgumentError( - message = "Unexpected error when parsing command line arguments", - cmdLineOptionsList = cmdLineOptionsList) - } - } - } - - protected abstract fun getConfiguration(cmdLine: CommandLine): Option<T> - - protected fun stringPathToPath(path: String): Path = Paths.get(File(path).toURI()) -} 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 deleted file mode 100644 index 9439bff5..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/CommandLineOption.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.commandline - -import org.apache.commons.cli.Option - - -enum class CommandLineOption(val option: Option, val required: Boolean = false) { - HEALTH_CHECK_API_PORT(Option.builder("H") - .longOpt("health-check-api-port") - .hasArg() - .desc("Health check rest api listen port") - .build() - ), - LISTEN_PORT(Option.builder("p") - .longOpt("listen-port") - .hasArg() - .desc("Listen port") - .build(), - required = true - ), - CONSUL_CONFIG_URL(Option.builder("c") - .longOpt("config-url") - .hasArg() - .desc("URL of ves configuration on consul") - .build(), - required = true - ), - CONSUL_FIRST_REQUEST_DELAY(Option.builder("d") - .longOpt("first-request-delay") - .hasArg() - .desc("Delay of first request to consul in seconds") - .build() - ), - CONSUL_REQUEST_INTERVAL(Option.builder("I") - .longOpt("request-interval") - .hasArg() - .desc("Interval of consul configuration requests in seconds") - .build() - ), - VES_HV_PORT(Option.builder("v") - .longOpt("ves-port") - .hasArg() - .desc("VesHvCollector port") - .build(), - required = true - ), - VES_HV_HOST(Option.builder("h") - .longOpt("ves-host") - .hasArg() - .desc("VesHvCollector host") - .build(), - required = true - ), - KAFKA_SERVERS(Option.builder("s") - .longOpt("kafka-bootstrap-servers") - .hasArg() - .desc("Comma-separated Kafka bootstrap servers in <host>:<port> format") - .build(), - required = true - ), - KAFKA_TOPICS(Option.builder("f") - .longOpt("kafka-topics") - .hasArg() - .desc("Comma-separated Kafka topics") - .build(), - required = true - ), - SSL_DISABLE(Option.builder("l") - .longOpt("ssl-disable") - .desc("Disable SSL encryption") - .build() - ), - KEY_STORE_FILE(Option.builder("k") - .longOpt("key-store") - .hasArg() - .desc("Key store in PKCS12 format") - .build() - ), - KEY_STORE_PASSWORD(Option.builder("kp") - .longOpt("key-store-password") - .hasArg() - .desc("Key store password") - .build() - ), - TRUST_STORE_FILE(Option.builder("t") - .longOpt("trust-store") - .hasArg() - .desc("File with trusted certificate bundle in PKCS12 format") - .build() - ), - TRUST_STORE_PASSWORD(Option.builder("tp") - .longOpt("trust-store-password") - .hasArg() - .desc("Trust store password") - .build() - ), - IDLE_TIMEOUT_SEC(Option.builder("i") - .longOpt("idle-timeout-sec") - .hasArg() - .desc("""Idle timeout for remote hosts. After given time without any data exchange the - |connection might be closed.""".trimMargin()) - .build() - ), - MAXIMUM_PAYLOAD_SIZE_BYTES(Option.builder("m") - .longOpt("max-payload-size") - .hasArg() - .desc("Maximum supported payload size in bytes") - .build() - ), - DUMMY_MODE(Option.builder("u") - .longOpt("dummy") - .desc("If present will start in dummy mode (dummy external services)") - .build() - ); - - fun environmentVariableName(prefix: String = DEFAULT_ENV_PREFIX): String = - option.longOpt.toUpperCase().replace('-', '_').let { mainPart -> - "${prefix}_${mainPart}" - } - - companion object { - private const val DEFAULT_ENV_PREFIX = "VESHV" - } -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt deleted file mode 100644 index 9c2a20c1..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/WrongArgumentError.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.commandline - -import arrow.core.Option -import org.apache.commons.cli.HelpFormatter -import org.apache.commons.cli.Options - - -data class WrongArgumentError( - val message: String, - val cause: Throwable? = null, - val cmdLineOptionsList: List<CommandLineOption>) { - - constructor(par: Throwable, cmdLineOptionsList: List<CommandLineOption>) : - this(par.message ?: "", - par, - cmdLineOptionsList) - - fun printMessage() { - println(message) - } - - fun printHelp(programName: String) { - val formatter = HelpFormatter() - val footer = "All parameters can be specified as environment variables using upper-snake-case full " + - "name with prefix `VESHV_`." - - formatter.printHelp( - programName, - generateRequiredParametersNote(cmdLineOptionsList), - getOptions(), - footer) - } - - private fun getOptions() = cmdLineOptionsList.map { it.option }.fold(Options(), Options::addOption) - - companion object { - fun generateRequiredParametersNote(cmdLineOptionsList: List<CommandLineOption>): String { - val requiredParams = Option.fromNullable(cmdLineOptionsList.filter { it.required } - .takeUnless { it.isEmpty() }) - return requiredParams.fold( - { "" }, - { - it.map { commandLineOption -> commandLineOption.option.opt } - .joinToString(prefix = "Required parameters: ", separator = ", ") - } - ) - } - } - -} - diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/extensions.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/extensions.kt deleted file mode 100644 index a8414472..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/commandline/extensions.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.commandline - -import arrow.core.Option -import arrow.core.getOrElse -import arrow.effects.IO -import arrow.syntax.function.curried -import org.apache.commons.cli.CommandLine -import org.onap.dcae.collectors.veshv.utils.arrow.ExitFailure -import org.onap.dcae.collectors.veshv.utils.arrow.fromNullablesChain - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since June 2018 - */ - -fun handleWrongArgumentError(programName: String, err: WrongArgumentError): IO<Unit> = IO { - err.printMessage() - err.printHelp(programName) -}.flatMap { ExitFailure(2).io() } - -val handleWrongArgumentErrorCurried = ::handleWrongArgumentError.curried() - -fun CommandLine.longValue(cmdLineOpt: CommandLineOption, default: Long): Long = - longValue(cmdLineOpt).getOrElse { default } - -fun CommandLine.stringValue(cmdLineOpt: CommandLineOption, default: String): String = - optionValue(cmdLineOpt).getOrElse { default } - -fun CommandLine.intValue(cmdLineOpt: CommandLineOption, default: Int): Int = - intValue(cmdLineOpt).getOrElse { default } - -fun CommandLine.intValue(cmdLineOpt: CommandLineOption): Option<Int> = - optionValue(cmdLineOpt).map(String::toInt) - -fun CommandLine.longValue(cmdLineOpt: CommandLineOption): Option<Long> = - optionValue(cmdLineOpt).map(String::toLong) - -fun CommandLine.stringValue(cmdLineOpt: CommandLineOption): Option<String> = - optionValue(cmdLineOpt) - -fun CommandLine.hasOption(cmdLineOpt: CommandLineOption): Boolean = - this.hasOption(cmdLineOpt.option.opt) || - System.getenv(cmdLineOpt.environmentVariableName()) != null - -private fun CommandLine.optionValue(cmdLineOpt: CommandLineOption) = Option.fromNullablesChain( - getOptionValue(cmdLineOpt.option.opt), - { System.getenv(cmdLineOpt.environmentVariableName()) }) diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/http.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/http.kt deleted file mode 100644 index c5c46397..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/http.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.http - -import arrow.typeclasses.Show -import java.util.* -import javax.json.Json - -/** - * @author Jakub Dudycz <jakub.dudycz@nokia.com> - * @since August 2018 - */ -object HttpConstants { - const val STATUS_OK = 200 - const val STATUS_ACCEPTED = 202 - const val STATUS_BAD_REQUEST = 400 - const val STATUS_NOT_FOUND = 404 - const val STATUS_INTERNAL_SERVER_ERROR = 500 - const val STATUS_SERVICE_UNAVAILABLE = 503 - - const val CONTENT_TYPE_JSON = "application/json" - const val CONTENT_TYPE_TEXT = "text/plain" -} - -enum class HttpStatus(val number: Int) { - OK(HttpConstants.STATUS_OK), - ACCEPTED(HttpConstants.STATUS_ACCEPTED), - BAD_REQUEST(HttpConstants.STATUS_BAD_REQUEST), - NOT_FOUND(HttpConstants.STATUS_NOT_FOUND), - INTERNAL_SERVER_ERROR(HttpConstants.STATUS_INTERNAL_SERVER_ERROR), - SERVICE_UNAVAILABLE(HttpConstants.STATUS_SERVICE_UNAVAILABLE) -} - - -enum class ContentType(val value: String) { - JSON(HttpConstants.CONTENT_TYPE_JSON), - TEXT(HttpConstants.CONTENT_TYPE_TEXT) -} - -data class Response(val status: HttpStatus, val content: Content<Any>) -data class Content<T>(val type: ContentType, val value: T, val serializer: Show<T> = Show.any()) - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since September 2018 - */ -object Responses { - - fun acceptedResponse(id: UUID): Response { - return Response( - HttpStatus.ACCEPTED, - Content(ContentType.TEXT, id) - ) - } - - fun statusResponse(name: String, message: String, httpStatus: HttpStatus = HttpStatus.OK): Response { - return Response(httpStatus, - Content(ContentType.JSON, - Json.createObjectBuilder() - .add("status", name) - .add("message", message) - .build())) - } -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/ratpack.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/ratpack.kt deleted file mode 100644 index 0282d0c7..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/ratpack.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.http - -import arrow.core.Either -import arrow.effects.IO -import org.onap.dcae.collectors.veshv.utils.logging.Logger -import javax.json.Json - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since August 2018 - */ - -private val logger = Logger("org.onap.dcae.collectors.veshv.utils.arrow.ratpack") - -fun ratpack.http.Response.sendOrError(action: IO<Unit>) { - sendAndHandleErrors(action.map { - Response( - HttpStatus.OK, - Content( - ContentType.JSON, - Json.createObjectBuilder().add("response", "Request accepted").build())) - }) -} - -fun <A> ratpack.http.Response.sendEitherErrorOrResponse(response: Either<A, Response>) { - when(response) { - is Either.Left -> send(errorResponse(response.a.toString())) - is Either.Right -> sendAndHandleErrors(IO.just(response.b)) - } -} - -fun ratpack.http.Response.sendAndHandleErrors(response: IO<Response>) { - response.attempt().unsafeRunSync().fold( - { err -> - logger.warn("Error occurred. Sending .", err) - val message = err.message - send(errorResponse(message)) - }, - ::send - ) -} - -private fun errorResponse(message: String?): Response { - return Response( - HttpStatus.INTERNAL_SERVER_ERROR, - Content( - ContentType.JSON, - Json.createObjectBuilder().add("error", message).build())) -} - -fun ratpack.http.Response.send(response: Response) { - val respWithStatus = status(response.status.number) - response.content.apply { - respWithStatus.send( - type.value, - serializer.run { value.show() }) - } -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt deleted file mode 100644 index e8b9f439..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Logger.kt +++ /dev/null @@ -1,137 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.logging - -import kotlin.reflect.KClass -import org.slf4j.LoggerFactory - -@Suppress("TooManyFunctions") -class Logger(val logger: org.slf4j.Logger) { - constructor(clazz: KClass<out Any>) : this(LoggerFactory.getLogger(clazz.java)) - constructor(name: String) : this(LoggerFactory.getLogger(name)) - - // - // TRACE - // - - val traceEnabled: Boolean - get() = logger.isTraceEnabled - - fun trace(messageProvider: () -> String) { - if (logger.isTraceEnabled) { - logger.trace(messageProvider()) - } - } - - // - // DEBUG - // - - fun debug(message: String) { - logger.debug(message) - } - - fun debug(message: String, t: Throwable) { - logger.debug(message, t) - } - - fun debug(messageProvider: () -> String) { - if (logger.isDebugEnabled) { - logger.debug(messageProvider()) - } - } - - fun debug(t: Throwable, messageProvider: () -> String) { - if (logger.isDebugEnabled) { - logger.debug(messageProvider(), t) - } - } - - // - // INFO - // - fun info(message: String) { - logger.info(message) - } - - fun info(messageProvider: () -> String) { - if (logger.isInfoEnabled) { - logger.info(messageProvider()) - } - } - - fun info(message: String, t: Throwable) { - logger.info(message, t) - } - - fun info(t: Throwable, messageProvider: () -> String) { - if (logger.isInfoEnabled) { - logger.info(messageProvider(), t) - } - } - - // - // WARN - // - - fun warn(message: String) { - logger.warn(message) - } - - fun warn(message: String, t: Throwable) { - logger.warn(message, t) - } - - fun warn(messageProvider: () -> String) { - if (logger.isWarnEnabled) { - logger.warn(messageProvider()) - } - } - - fun warn(t: Throwable, messageProvider: () -> String) { - if (logger.isWarnEnabled) { - logger.warn(messageProvider(), t) - } - } - - // - // ERROR - // - - fun error(message: String) { - logger.error(message) - } - - fun error(message: String, t: Throwable) { - logger.error(message, t) - } - - fun error(messageProvider: () -> String) { - if (logger.isErrorEnabled) { - logger.error(messageProvider()) - } - } - - fun error(t: Throwable, messageProvider: () -> String) { - if (logger.isErrorEnabled) { - logger.error(messageProvider(), t) - } - } -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt deleted file mode 100644 index 714702d3..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/reactive_logging.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.logging - -import reactor.core.publisher.Flux - -fun <T> Logger.handleReactiveStreamError(ex: Throwable, returnFlux: Flux<T> = Flux.empty()): Flux<T> { - logger.warn("Error while handling message stream: ${ex::class.qualifiedName} (${ex.message})") - logger.debug("Detailed stack trace", ex) - return returnFlux -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt deleted file mode 100644 index bdb63b68..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils - -import arrow.effects.IO -import reactor.netty.DisposableServer - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since August 2018 - */ -abstract class ServerHandle(val host: String, val port: Int) { - abstract fun shutdown(): IO<Unit> - abstract fun await(): IO<Unit> -} - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since August 2018 - */ -class NettyServerHandle(private val ctx: DisposableServer) : ServerHandle(ctx.host(), ctx.port()) { - override fun shutdown() = IO { - ctx.disposeNow() - } - - override fun await() = IO<Unit> { - ctx.channel().closeFuture().sync() - } -} |