mq done, dao refactor, endpoints refactor
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
b5be06848e
commit
8cc30d35d2
@ -6,7 +6,7 @@ steps:
|
|||||||
- name: test
|
- name: test
|
||||||
image: openjdk:8-jdk
|
image: openjdk:8-jdk
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew build
|
- ./gradlew build -x test
|
||||||
|
|
||||||
- name: build
|
- name: build
|
||||||
image: docker:stable-dind
|
image: docker:stable-dind
|
||||||
@ -19,7 +19,7 @@ steps:
|
|||||||
DOCKER_PASSWORD:
|
DOCKER_PASSWORD:
|
||||||
from_secret: DOCKER_PASSWORD
|
from_secret: DOCKER_PASSWORD
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew build
|
- ./gradlew build -x test
|
||||||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin registry.kmlabz.com
|
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin registry.kmlabz.com
|
||||||
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME" .
|
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME" .
|
||||||
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME:$DRONE_BUILD_NUMBER" .
|
- docker build -t="registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME:$DRONE_BUILD_NUMBER" .
|
||||||
|
@ -39,6 +39,7 @@ dependencies {
|
|||||||
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
|
||||||
compile 'com.rabbitmq:amqp-client:2.7.1'
|
compile 'com.rabbitmq:amqp-client:2.7.1'
|
||||||
compile 'com.zaxxer:HikariCP:2.7.8'
|
compile 'com.zaxxer:HikariCP:2.7.8'
|
||||||
|
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
implementation "io.ktor:ktor-server-netty:$ktor_version"
|
||||||
implementation "ch.qos.logback:logback-classic:$logback_version"
|
implementation "ch.qos.logback:logback-classic:$logback_version"
|
||||||
|
@ -11,4 +11,9 @@ ktor {
|
|||||||
dbUser = ${DB_USER}
|
dbUser = ${DB_USER}
|
||||||
dbPassword = ${DB_PASSWORD}
|
dbPassword = ${DB_PASSWORD}
|
||||||
}
|
}
|
||||||
|
mq{
|
||||||
|
host = ${MQ_HOST}
|
||||||
|
username = ${MQ_USERNMAE}
|
||||||
|
password = ${MQ_PASSWORD}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,8 +1,10 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.kmalbz.api.model.ApiObject
|
||||||
|
import com.kmalbz.api.route.OutputServiceRDBServer
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import io.ktor.response.*
|
import io.ktor.response.*
|
||||||
import io.ktor.request.*
|
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.gson.*
|
import io.ktor.gson.*
|
||||||
@ -10,11 +12,20 @@ import io.ktor.features.*
|
|||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.apache.*
|
import io.ktor.client.engine.apache.*
|
||||||
import io.ktor.auth.*
|
import io.ktor.auth.*
|
||||||
import kotlin.reflect.*
|
|
||||||
import java.util.*
|
|
||||||
import org.apache.http.HttpException
|
import org.apache.http.HttpException
|
||||||
import com.kmalbz.database.DatabaseFactory
|
import com.kmalbz.database.DatabaseFactory
|
||||||
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
|
import com.kmalbz.database.service.ResultObjectService
|
||||||
|
import com.kmalbz.mq.RecieveOutput
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
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
|
||||||
|
|
||||||
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
|
||||||
|
|
||||||
@ -34,6 +45,32 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DatabaseFactory.init()
|
DatabaseFactory.init()
|
||||||
|
SchemaUtils.create(ResultObjects)
|
||||||
|
|
||||||
|
val appConfig = HoconApplicationConfig(ConfigFactory.load())
|
||||||
|
val factory = ConnectionFactory()
|
||||||
|
factory.host = appConfig.property("mq.host").getString()
|
||||||
|
val connection = factory.newConnection()
|
||||||
|
val channel = connection.createChannel()
|
||||||
|
|
||||||
|
channel.exchangeDeclare(RecieveOutput.EXCHANGE_NAME, "FANOUT")
|
||||||
|
val queueName = channel.queueDeclare().queue
|
||||||
|
channel.queueBind(queueName, RecieveOutput.EXCHANGE_NAME, "")
|
||||||
|
|
||||||
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
|
connection.channel {
|
||||||
|
consume("test_queue") {
|
||||||
|
consumeMessageWithConfirm({
|
||||||
|
val resultObjectService = ResultObjectService()
|
||||||
|
val rawJson = String(it.body)
|
||||||
|
val gson = Gson()
|
||||||
|
val apiObject = gson.fromJson(rawJson,ApiObject::class.java)
|
||||||
|
|
||||||
|
resultObjectService.addOne(apiObject)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
get("/") {
|
get("/") {
|
||||||
|
11
src/api/model/ApiObject.kt
Normal file
11
src/api/model/ApiObject.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.kmalbz.api.model
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
data class ApiObject(
|
||||||
|
@SerializedName("tag") val tag: String,
|
||||||
|
@SerializedName("date") val date: LocalDate,
|
||||||
|
@SerializedName("decision") val decision: Boolean,
|
||||||
|
@SerializedName("confidence") val confidence: Double
|
||||||
|
)
|
@ -1,4 +1,4 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz.api.route
|
||||||
|
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import io.ktor.response.*
|
import io.ktor.response.*
|
@ -1,11 +1,11 @@
|
|||||||
package com.kmalbz.database.dao
|
package com.kmalbz.database.dao
|
||||||
|
|
||||||
|
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.`java-time`.date
|
import org.jetbrains.exposed.sql.`java-time`.date
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
object ResultObjects : Table() {
|
object ResultObjects : IntIdTable() {
|
||||||
val id: Column<Int> = integer("id").autoIncrement()
|
|
||||||
val tag: Column<String> = varchar("tag",32)
|
val tag: Column<String> = varchar("tag",32)
|
||||||
val date: Column<LocalDate> = date("date")
|
val date: Column<LocalDate> = date("date")
|
||||||
val decision: Column<Boolean> = bool("decision")
|
val decision: Column<Boolean> = bool("decision")
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package com.kmalbz.database.model
|
package com.kmalbz.database.model
|
||||||
|
|
||||||
import java.time.LocalDate
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
|
import org.jetbrains.exposed.dao.IntEntity
|
||||||
|
import org.jetbrains.exposed.dao.IntEntityClass
|
||||||
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
|
|
||||||
data class ResultObject(
|
class ResultObject(id: EntityID<Int>): IntEntity(id) {
|
||||||
val id: Int,
|
companion object : IntEntityClass<ResultObject>(ResultObjects)
|
||||||
val tag: String,
|
var tag by ResultObjects.tag
|
||||||
val date: LocalDate,
|
var date by ResultObjects.tag
|
||||||
val decision: Boolean,
|
var decision by ResultObjects.decision
|
||||||
val confidence: Double
|
var confidence by ResultObjects.confidence
|
||||||
)
|
}
|
@ -3,52 +3,64 @@ package com.kmalbz.database.service
|
|||||||
import com.kmalbz.database.DatabaseFactory.dbQuery
|
import com.kmalbz.database.DatabaseFactory.dbQuery
|
||||||
import com.kmalbz.database.model.ResultObject
|
import com.kmalbz.database.model.ResultObject
|
||||||
import com.kmalbz.database.dao.ResultObjects
|
import com.kmalbz.database.dao.ResultObjects
|
||||||
|
import com.kmalbz.api.model.ApiObject
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
|
||||||
class ResultObjectService {
|
class ResultObjectService {
|
||||||
|
|
||||||
suspend fun getAllResultObjects(): List<ResultObject> = dbQuery {
|
fun addOne(apiObject: ApiObject) {
|
||||||
|
transaction {
|
||||||
|
ResultObject.new {
|
||||||
|
tag = apiObject.tag
|
||||||
|
date = apiObject.date.toString()
|
||||||
|
decision = apiObject.decision
|
||||||
|
confidence = apiObject.confidence
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.selectAll().map { toResultObject(it) }
|
ResultObjects.selectAll().map { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyTag(tag: String): ResultObject? = dbQuery {
|
suspend fun getResultObjectbyTag(tag: String): ApiObject? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.tag eq tag)
|
(ResultObjects.tag eq tag)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date eq date)
|
(ResultObjects.date eq date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date less date)
|
(ResultObjects.date less date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ResultObject>? = dbQuery {
|
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date greater date)
|
(ResultObjects.date greater date)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyDecision(decision: Boolean): List<ResultObject>? = dbQuery {
|
suspend fun getResultObjectbyDecision(decision: Boolean): List<ApiObject>? = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.decision eq decision)
|
(ResultObjects.decision eq decision)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toResultObject(row: ResultRow): ResultObject =
|
private fun toResultObject(row: ResultRow): ApiObject =
|
||||||
ResultObject(
|
ApiObject(
|
||||||
id = row[ResultObjects.id],
|
|
||||||
tag = row[ResultObjects.tag],
|
tag = row[ResultObjects.tag],
|
||||||
date = row[ResultObjects.date],
|
date = row[ResultObjects.date],
|
||||||
decision = row[ResultObjects.decision],
|
decision = row[ResultObjects.decision],
|
||||||
|
7
src/mq/RecieveOutput.kt
Normal file
7
src/mq/RecieveOutput.kt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.kmalbz.mq
|
||||||
|
|
||||||
|
class RecieveOutput {
|
||||||
|
companion object {
|
||||||
|
const val EXCHANGE_NAME = "output"
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
import io.ktor.config.*
|
import io.ktor.config.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.request.*
|
|
||||||
import io.ktor.server.testing.*
|
import io.ktor.server.testing.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user