Merge improvements #1

Merged
tormakris merged 5 commits from kotlin-hazi into master 2020-05-29 13:23:32 +02:00
8 changed files with 47 additions and 70 deletions

View File

@ -3,42 +3,11 @@ type: docker
name: default
steps:
- name: restore-cache-with-filesystem
image: meltwater/drone-cache
settings:
backend: "filesystem"
restore: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- 'build'
- '.gradle'
volumes:
- name: cache
path: /tmp/cache
- name: build_application
image: openjdk:11-jdk
commands:
- ./gradlew build -x test
- name: rebuild-cache-with-filesystem
image: meltwater/drone-cache:dev
pull: true
settings:
backend: "filesystem"
rebuild: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- 'build'
- '.gradle'
volumes:
- name: cache
path: /tmp/cache
- name: kaniko
image: banzaicloud/drone-kaniko
settings:
@ -51,16 +20,3 @@ steps:
tags:
- latest
- ${DRONE_BUILD_NUMBER}
- name: ms-teams
image: kuperiu/drone-teams
settings:
webhook:
from_secret: TEAMS_WEBHOOK
when:
status: [ failure ]
volumes:
- name: cache
host:
path: "/tmp/cache"

View File

@ -1,8 +1,7 @@
package com.kmalbz
import com.google.gson.Gson
import com.kmalbz.api.model.ApiObject
import com.kmalbz.api.route.OutputServiceRDBServer
import com.kmalbz.consumer.DatabaseConsumer
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
@ -12,15 +11,10 @@ import io.ktor.features.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import com.kmalbz.database.dao.ResultObjects
import com.kmalbz.database.service.ResultObjectService
import io.ktor.util.KtorExperimentalAPI
import com.rabbitmq.client.*
import com.typesafe.config.ConfigFactory
import io.ktor.config.HoconApplicationConfig
import com.viartemev.thewhiterabbit.channel.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import org.koin.ktor.ext.Koin
@ -60,20 +54,7 @@ fun Application.module() {
val queueName = channel.queueDeclare().queue
channel.queueBind(queueName, rabbitExchangeName, "")
GlobalScope.launch(Dispatchers.Default) {
connection.channel {
consume(queueName) {
consumeMessageWithConfirm({
val resultObjectService = ResultObjectService()
val rawJson = String(it.body)
val gson = Gson()
val apiObject = gson.fromJson(rawJson,ApiObject::class.java)
resultObjectService.addOne(apiObject)
})
}
}
}
channel.basicConsume(queueName, true, DatabaseConsumer())
routing {
install(StatusPages) {

View File

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

View File

@ -9,6 +9,7 @@ import io.ktor.routing.get
import org.koin.ktor.ext.inject
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
/**
* Output Service - RDB
@ -63,7 +64,7 @@ class OutputServiceRDBServer {
get("/output/{tagID}") {
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: call.respond(HttpStatusCode.NotFound)
val resultObject = resultObjectService.getResultObjectbyTag(UUID.fromString(tagID)) ?: call.respond(HttpStatusCode.NotFound)
call.respond(resultObject)
}

View File

@ -0,0 +1,35 @@
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

@ -4,9 +4,10 @@ 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.*
object ResultObjects : IntIdTable() {
val tag: Column<String> = varchar("tag",32)
val tag: Column<UUID> = uuid("tag")
val date: Column<LocalDate> = date("date").default(LocalDate.now())
val probability: Column<Double> = double("probability")
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")

View File

@ -2,11 +2,12 @@ package com.kmalbz.database.service
import com.kmalbz.api.model.ApiObject
import java.time.LocalDate
import java.util.*
interface IResultObjectService{
fun addOne(apiObject: ApiObject)
suspend fun getAllResultObjects(): List<ApiObject>
suspend fun getResultObjectbyTag(tag: String): 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>?

View File

@ -9,6 +9,7 @@ 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 {
@ -26,7 +27,7 @@ class ResultObjectService : IResultObjectService {
ResultObjects.selectAll().map { toResultObject(it) }
}
override suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
override suspend fun getResultObjectbyTag(tag: UUID): ApiObject? = dbQuery {
ResultObjects.select {
(ResultObjects.tag eq tag)
}.mapNotNull { toResultObject(it) }