Compare commits

..

16 Commits

Author SHA1 Message Date
f7757d31fb upload to docker hub
All checks were successful
continuous-integration/drone/push Build is passing
2022-01-31 23:16:41 +01:00
d638b98d1a Merge branch 'master' of ssh://git.kmlabz.com:2222/birbnetes/output-service-rdb
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-18 16:44:39 +02:00
4fc8db6fa4 use kotlin serialize 2021-08-18 16:44:29 +02:00
1997df3da9 remove deprecated stuff
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 18:00:11 +02:00
f46386d465 get count from db layer as well
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 16:09:10 +02:00
4f67c48f7a pagination in db layer
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 15:57:58 +02:00
5f2d88d3d2 pajeet nation
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-17 15:34:49 +02:00
9c432ae60d update koin
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-16 14:29:49 +02:00
ac4e01b1e9 update gradle
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-12 12:25:23 +02:00
3c3beff2e4 remove consumer and update deps
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-12 12:24:03 +02:00
9793ccc593 update dependencies
All checks were successful
continuous-integration/drone/push Build is passing
2020-11-19 02:38:15 +01:00
204dfcabbc Update 'k8s/deployment.yml'
All checks were successful
continuous-integration/drone/push Build is passing
2020-08-06 14:57:26 +02:00
f27eec0f8f update manifests
All checks were successful
continuous-integration/drone/push Build is passing
2020-08-02 15:29:22 +00:00
264545215b analysis via sonar
All checks were successful
continuous-integration/drone/push Build is passing
2020-07-07 22:58:09 +02:00
2b89400168 use string instead of uuid
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-29 13:27:53 +02:00
8d7f05d122 add back notification
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-29 13:25:22 +02:00
15 changed files with 125 additions and 129 deletions

View File

@ -3,6 +3,14 @@ type: docker
name: default
steps:
- name: code-analysis
image: aosapps/drone-sonar-plugin
settings:
sonar_host:
from_secret: SONAR_HOST
sonar_token:
from_secret: SONAR_CODE
- name: build_application
image: openjdk:11-jdk
commands:
@ -20,3 +28,23 @@ steps:
tags:
- latest
- ${DRONE_BUILD_NUMBER}
- name: dockerhub
image: plugins/docker
settings:
repo: birbnetes/${DRONE_REPO_NAME}
username:
from_secret: DOCKERHUB_USER
password:
from_secret: DOCKERHUB_PASSWORD
tags:
- latest
- ${DRONE_BUILD_NUMBER}
- name: ms-teams
image: kuperiu/drone-teams
settings:
webhook:
from_secret: TEAMS_WEBHOOK
when:
status: [ failure ]

View File

@ -11,4 +11,4 @@ USER $APPLICATION_USER
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "output-service-rdb.jar"]

View File

@ -7,19 +7,23 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
classpath "org.koin:koin-gradle-plugin:$koin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.21'
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'application'
apply plugin: 'koin'
group 'com.kmalbz'
version '0.0.1'
@ -39,26 +43,26 @@ repositories {
}
dependencies {
compile 'org.postgresql:postgresql:42.2.2'
compile 'org.jetbrains.exposed:exposed-core:0.23.1'
compile 'org.jetbrains.exposed:exposed-dao:0.23.1'
compile 'org.jetbrains.exposed:exposed-jdbc:0.23.1'
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
compile 'com.rabbitmq:amqp-client:2.7.1'
compile 'com.zaxxer:HikariCP:2.7.8'
compile 'com.viartemev:the-white-rabbit:0.0.5'
implementation "org.koin:koin-ktor:$koin_version"
compile 'org.postgresql:postgresql:42.2.23'
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
compile 'com.zaxxer:HikariCP:5.0.0'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.2.1"
implementation "io.insert-koin:koin-core:$koin_version"
implementation "io.insert-koin:koin-ktor:$koin_version"
implementation "io.ktor:ktor-serialization:$ktor_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
implementation "io.ktor:ktor-server-core:$ktor_version"
implementation "io.ktor:ktor-gson:$ktor_version"
implementation "io.ktor:ktor-server-host-common:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
implementation "io.ktor:ktor-client-apache:$ktor_version"
implementation "io.ktor:ktor-auth:$ktor_version"
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}
kotlin.experimental.coroutines = 'enable'

View File

@ -1,5 +1,5 @@
ktor_version=1.3.2
ktor_version=1.6.2
kotlin.code.style=official
kotlin_version=1.3.72
logback_version=1.2.1
koin_version=2.1.5
kotlin_version=1.5.21
logback_version=1.2.5
koin_version=3.1.2

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

View File

@ -12,4 +12,4 @@ data:
DB_PASSWORD: output-service-supersecret
MQ_HOST: birb-rabbitmq
MQ_USERNAME: user
MQ_PASSWORD: 1wZVQnP5vy
MQ_PASSWORD: F3ACadDRsT

View File

@ -18,7 +18,8 @@ spec:
app: output-service-rdb
spec:
containers:
- image: registry.kmlabz.com/tormakris/output-service-rdb
- image: registry.kmlabz.com/birbnetes/output-service-rdb
imagePullPolicy: Always
name: output-service-rdb
envFrom:
- configMapRef:
@ -26,4 +27,4 @@ spec:
ports:
- containerPort: 8080
imagePullSecrets:
- name: regcred
- name: regcred

View File

@ -1,20 +1,16 @@
package com.kmalbz
import com.kmalbz.api.route.OutputServiceRDBServer
import com.kmalbz.consumer.DatabaseConsumer
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.gson.*
import io.ktor.features.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import com.kmalbz.database.dao.ResultObjects
import io.ktor.serialization.*
import io.ktor.util.KtorExperimentalAPI
import com.rabbitmq.client.*
import com.typesafe.config.ConfigFactory
import io.ktor.config.HoconApplicationConfig
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.koin.ktor.ext.Koin
@ -25,8 +21,7 @@ fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // Referenced in application.conf
fun Application.module() {
install(ContentNegotiation) {
gson {
}
json()
}
install(Koin) {
@ -39,23 +34,6 @@ fun Application.module() {
SchemaUtils.create(ResultObjects)
}
val appConfig = HoconApplicationConfig(ConfigFactory.load())
val factory = ConnectionFactory()
factory.host = appConfig.property("ktor.mq.host").getString()
factory.username = appConfig.property("ktor.mq.username").getString()
factory.password = appConfig.property("ktor.mq.password").getString()
val connection = factory.newConnection()
val channel = connection.createChannel()
val rabbitExchangeName = appConfig.property("ktor.mq.exchange").getString()
channel.exchangeDeclare(rabbitExchangeName, BuiltinExchangeType.FANOUT)
val queueName = channel.queueDeclare().queue
channel.queueBind(queueName, rabbitExchangeName, "")
channel.basicConsume(queueName, true, DatabaseConsumer())
routing {
install(StatusPages) {
exception<HttpException> {

View File

@ -1,9 +1,9 @@
package com.kmalbz.api.model
import com.google.gson.annotations.SerializedName
import java.util.*
import kotlinx.serialization.Serializable
@Serializable
data class ApiObject(
@SerializedName("tag") val tag: UUID,
@SerializedName("probability") val probability: Double
val tag: String,
val probability: Double
)

View File

@ -6,65 +6,78 @@ import io.ktor.http.HttpStatusCode
import io.ktor.response.respond
import io.ktor.routing.Routing
import io.ktor.routing.get
import kotlinx.datetime.LocalDateTime
import org.koin.ktor.ext.inject
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
/**
* Output Service - RDB
*
*
* This is the output interface of the Birbnetes system.
*/
class OutputServiceRDBServer {
/**
* output
*/
fun Routing.registerOutput() {
val resultObjectService by inject<IResultObjectService>()
get("/output"){
val resultObjectService: IResultObjectService by inject()
get("/output") {
call.respond(resultObjectService.getAllResultObjects())
}
get("/output/count") {
call.respond(resultObjectService.getCount())
}
get("/output/page/{page}") {
val page = call.parameters["page"] ?: error(HttpStatusCode.NotAcceptable)
val pageNum = page.toLong()
call.respond(resultObjectService.getPage(pageNum))
}
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecLessthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/positive") {
val resultList = resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecGreaterthanProbability(0.5)
call.respond(resultList)
}
get("/output/filter/undecided") {
val resultList = resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
val resultList =
resultObjectService.getResultObjecEqualsProbability(0.5)
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectafterDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
val localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectafterDate(localDateAfter)
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
val resultList = resultObjectService.getResultObjectbeforeDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
val localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
val resultList =
resultObjectService.getResultObjectbeforeDate(localDateBefore)
call.respond(resultList)
}
get("/output/{tagID}") {
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(UUID.fromString(tagID)) ?: call.respond(HttpStatusCode.NotFound)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultObject)
}

View File

@ -1,35 +0,0 @@
package com.kmalbz.consumer
import com.google.gson.Gson
import com.kmalbz.api.model.ApiObject
import com.kmalbz.database.service.ResultObjectService
import com.rabbitmq.client.AMQP.BasicProperties
import com.rabbitmq.client.Consumer
import com.rabbitmq.client.Envelope
import com.rabbitmq.client.ShutdownSignalException
class DatabaseConsumer : Consumer {
private val resultObjectService = ResultObjectService()
private val gson = Gson()
override fun handleConsumeOk(consumerTag : String?) {
}
override fun handleCancelOk(p0 : String?) {
throw UnsupportedOperationException()
}
override fun handleRecoverOk(p0 : String?) {
throw UnsupportedOperationException()
}
override fun handleCancel(p0 : String?) {
throw UnsupportedOperationException()
}
override fun handleDelivery(consumerTag : String?, envelope : Envelope?, basicProperties : BasicProperties?, body : ByteArray?) {
val rawJson = body!!.toString(Charsets.UTF_8)
val apiObject = gson.fromJson(rawJson, ApiObject::class.java)
resultObjectService.addOne(apiObject)
}
override fun handleShutdownSignal(p0 : String?, p1 : ShutdownSignalException?) {
println("got shutdown signal")
}
}

View File

@ -2,13 +2,12 @@ package com.kmalbz.database.dao
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.`java-time`.date
import java.time.LocalDate
import java.util.*
import org.jetbrains.exposed.sql.`java-time`.datetime
import java.time.LocalDateTime
object ResultObjects : IntIdTable() {
val tag: Column<UUID> = uuid("tag")
val date: Column<LocalDate> = date("date").default(LocalDate.now())
val tag: Column<String> = varchar("tag", 32)
val date: Column<LocalDateTime> = datetime("date").default(LocalDateTime.now())
val probability: Column<Double> = double("probability")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
}

View File

@ -1,17 +1,18 @@
package com.kmalbz.database.service
import com.kmalbz.api.model.ApiObject
import java.time.LocalDate
import java.util.*
import kotlinx.datetime.LocalDateTime
interface IResultObjectService{
fun addOne(apiObject: ApiObject)
suspend fun getAllResultObjects(): List<ApiObject>
suspend fun getResultObjectbyTag(tag: UUID): ApiObject?
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>?
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>?
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>?
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>?
suspend fun getCount(): Long
suspend fun getPage(page: Long): List<ApiObject>
suspend fun getResultObjectbyTag(tag: String): ApiObject?
suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject>
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>
}

View File

@ -4,12 +4,12 @@ import com.kmalbz.database.DatabaseFactory.dbQuery
import com.kmalbz.database.model.ResultObject
import com.kmalbz.database.dao.ResultObjects
import com.kmalbz.api.model.ApiObject
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.toJavaLocalDateTime
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDate
import java.util.*
class ResultObjectService : IResultObjectService {
@ -27,44 +27,52 @@ class ResultObjectService : IResultObjectService {
ResultObjects.selectAll().map { toResultObject(it) }
}
override suspend fun getResultObjectbyTag(tag: UUID): ApiObject? = dbQuery {
override suspend fun getCount(): Long = dbQuery {
ResultObjects.selectAll().count()
}
override suspend fun getPage(page: Long): List<ApiObject> = dbQuery {
ResultObjects.selectAll().limit(10,page*10).map { toResultObject(it) }
}
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
ResultObjects.select {
(ResultObjects.tag eq tag)
}.mapNotNull { toResultObject(it) }
.singleOrNull()
}
override suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date eq date)
(ResultObjects.date eq date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
override suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date less date)
(ResultObjects.date less date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
override suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
override suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.date greater date)
(ResultObjects.date greater date.toJavaLocalDateTime())
}.mapNotNull { toResultObject(it) }
}
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability greater probability)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability less probability)
}.mapNotNull { toResultObject(it) }
}
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject> = dbQuery {
ResultObjects.select {
(ResultObjects.probability eq probability)
}.mapNotNull { toResultObject(it) }

View File

@ -3,8 +3,7 @@ package com.kmalbz.di
import com.kmalbz.database.service.IResultObjectService
import com.kmalbz.database.service.ResultObjectService
import org.koin.dsl.module
import org.koin.experimental.builder.singleBy
val injectionModule = module(createdAtStart = true) {
singleBy<IResultObjectService,ResultObjectService>()
single<IResultObjectService> {ResultObjectService()}
}