Compare commits
41 Commits
647242ff37
...
master
Author | SHA1 | Date | |
---|---|---|---|
f7757d31fb | |||
d638b98d1a
|
|||
4fc8db6fa4
|
|||
1997df3da9 | |||
f46386d465
|
|||
4f67c48f7a
|
|||
5f2d88d3d2
|
|||
9c432ae60d
|
|||
ac4e01b1e9
|
|||
3c3beff2e4
|
|||
9793ccc593 | |||
204dfcabbc | |||
f27eec0f8f | |||
264545215b | |||
2b89400168
|
|||
8d7f05d122
|
|||
0615d63610 | |||
597c0a24db
|
|||
9074619914
|
|||
495ebae5f9
|
|||
0e5f4e593f
|
|||
609a90adc2
|
|||
062f2c9ede
|
|||
24692d7635
|
|||
d4a2d9925c
|
|||
d8e0819f00
|
|||
15095f2d9f
|
|||
f2cb3e4e91
|
|||
82f64dcfdf
|
|||
cba0e79b08
|
|||
da708d2347
|
|||
a68abd2c6b
|
|||
c84b4a597e
|
|||
26a52d54e9
|
|||
ab2c0e8f25 | |||
92401f69cb
|
|||
03df50a4fa | |||
5d3bd760b6 | |||
1e3cd454da | |||
cb3f9874a8
|
|||
2bfc385681
|
72
.drone.yml
72
.drone.yml
@ -3,36 +3,48 @@ type: docker
|
|||||||
name: default
|
name: default
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build_application
|
- name: code-analysis
|
||||||
image: openjdk:8-jdk
|
image: aosapps/drone-sonar-plugin
|
||||||
commands:
|
settings:
|
||||||
- ./gradlew build -x test
|
sonar_host:
|
||||||
|
from_secret: SONAR_HOST
|
||||||
|
sonar_token:
|
||||||
|
from_secret: SONAR_CODE
|
||||||
|
|
||||||
- name: build_container
|
- name: build_application
|
||||||
image: docker:stable-dind
|
image: openjdk:11-jdk
|
||||||
volumes:
|
commands:
|
||||||
- name: dockersock
|
- ./gradlew build -x test
|
||||||
path: /var/run
|
|
||||||
environment:
|
|
||||||
DOCKER_USERNAME:
|
|
||||||
from_secret: DOCKER_USERNAME
|
|
||||||
DOCKER_PASSWORD:
|
|
||||||
from_secret: DOCKER_PASSWORD
|
|
||||||
commands:
|
|
||||||
- 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:$DRONE_BUILD_NUMBER" .
|
|
||||||
- docker push "registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME"
|
|
||||||
- docker push "registry.kmlabz.com/$DOCKER_USERNAME/$DRONE_REPO_NAME:$DRONE_BUILD_NUMBER"
|
|
||||||
|
|
||||||
services:
|
- name: kaniko
|
||||||
- name: docker
|
image: banzaicloud/drone-kaniko
|
||||||
image: docker:stable-dind
|
settings:
|
||||||
privileged: true
|
registry: registry.kmlabz.com
|
||||||
volumes:
|
repo: birbnetes/${DRONE_REPO_NAME}
|
||||||
- name: dockersock
|
username:
|
||||||
path: /var/run
|
from_secret: DOCKER_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: DOCKER_PASSWORD
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
volumes:
|
- name: dockerhub
|
||||||
- name: dockersock
|
image: plugins/docker
|
||||||
temp: {}
|
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 ]
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@
|
|||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
|
*.log
|
@ -1,7 +1,7 @@
|
|||||||
FROM openjdk:8-jre-alpine
|
FROM openjdk:11-jre
|
||||||
|
|
||||||
ENV APPLICATION_USER ktor
|
ENV APPLICATION_USER ktor
|
||||||
RUN adduser -D -g '' $APPLICATION_USER
|
RUN useradd $APPLICATION_USER
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
RUN chown -R $APPLICATION_USER /app
|
RUN chown -R $APPLICATION_USER /app
|
||||||
@ -11,4 +11,4 @@ USER $APPLICATION_USER
|
|||||||
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
|
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-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"]
|
37
build.gradle
37
build.gradle
@ -7,10 +7,21 @@ buildscript {
|
|||||||
dependencies {
|
dependencies {
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
|
||||||
|
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: 'kotlin'
|
||||||
|
apply plugin: 'kotlinx-serialization'
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
apply plugin: "com.github.johnrengelman.shadow"
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
@ -32,29 +43,35 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'org.postgresql:postgresql:42.2.2'
|
compile 'org.postgresql:postgresql:42.2.23'
|
||||||
compile 'org.jetbrains.exposed:exposed-core:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-core:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-dao:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-dao:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-jdbc:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-jdbc:0.33.1'
|
||||||
compile 'org.jetbrains.exposed:exposed-java-time:0.23.1'
|
compile 'org.jetbrains.exposed:exposed-java-time:0.33.1'
|
||||||
compile 'com.rabbitmq:amqp-client:2.7.1'
|
compile 'com.zaxxer:HikariCP:5.0.0'
|
||||||
compile 'com.zaxxer:HikariCP:2.7.8'
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
||||||
compile 'com.viartemev:the-white-rabbit:0.0.5'
|
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 "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"
|
||||||
implementation "io.ktor:ktor-server-core:$ktor_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-server-host-common:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-apache:$ktor_version"
|
implementation "io.ktor:ktor-client-apache:$ktor_version"
|
||||||
implementation "io.ktor:ktor-auth:$ktor_version"
|
implementation "io.ktor:ktor-auth:$ktor_version"
|
||||||
testImplementation "io.ktor:ktor-server-tests:$ktor_version"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.experimental.coroutines = 'enable'
|
kotlin.experimental.coroutines = 'enable'
|
||||||
|
|
||||||
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = "11"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
baseName = 'output-service-rdb'
|
baseName = 'output-service-rdb'
|
||||||
|
@ -15,7 +15,7 @@ services:
|
|||||||
POSTGRES_DB: "output-service-rdb"
|
POSTGRES_DB: "output-service-rdb"
|
||||||
|
|
||||||
output-service-rdb:
|
output-service-rdb:
|
||||||
image: "registry.kmlabz.com/tormakris/output-service-rdb"
|
image: "registry.kmlabz.com/birbnetes/output-service-rdb"
|
||||||
restart: "always"
|
restart: "always"
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:8080:8080"
|
- "127.0.0.1:8080:8080"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
ktor_version=1.3.2
|
ktor_version=1.6.2
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin_version=1.3.70
|
kotlin_version=1.5.21
|
||||||
logback_version=1.2.1
|
logback_version=1.2.5
|
||||||
|
koin_version=3.1.2
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
@ -12,4 +12,4 @@ data:
|
|||||||
DB_PASSWORD: output-service-supersecret
|
DB_PASSWORD: output-service-supersecret
|
||||||
MQ_HOST: birb-rabbitmq
|
MQ_HOST: birb-rabbitmq
|
||||||
MQ_USERNAME: user
|
MQ_USERNAME: user
|
||||||
MQ_PASSWORD: 1wZVQnP5vy
|
MQ_PASSWORD: F3ACadDRsT
|
||||||
|
@ -18,7 +18,8 @@ spec:
|
|||||||
app: output-service-rdb
|
app: output-service-rdb
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- image: registry.kmlabz.com/tormakris/output-service-rdb
|
- image: registry.kmlabz.com/birbnetes/output-service-rdb
|
||||||
|
imagePullPolicy: Always
|
||||||
name: output-service-rdb
|
name: output-service-rdb
|
||||||
envFrom:
|
envFrom:
|
||||||
- configMapRef:
|
- configMapRef:
|
||||||
@ -26,4 +27,4 @@ spec:
|
|||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
- name: regcred
|
- name: regcred
|
||||||
|
@ -15,5 +15,7 @@ ktor {
|
|||||||
host = ${MQ_HOST}
|
host = ${MQ_HOST}
|
||||||
username = ${MQ_USERNAME}
|
username = ${MQ_USERNAME}
|
||||||
password = ${MQ_PASSWORD}
|
password = ${MQ_PASSWORD}
|
||||||
|
exchange = "output"
|
||||||
|
exchange = ${?MQ_EXCHANGE}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,48 +1,32 @@
|
|||||||
package com.kmalbz
|
package com.kmalbz
|
||||||
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.kmalbz.api.model.ApiObject
|
|
||||||
import com.kmalbz.api.route.OutputServiceRDBServer
|
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.routing.*
|
import io.ktor.routing.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.gson.*
|
|
||||||
import io.ktor.features.*
|
import io.ktor.features.*
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.engine.apache.*
|
|
||||||
import io.ktor.auth.*
|
|
||||||
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.dao.ResultObjects
|
||||||
import com.kmalbz.database.service.ResultObjectService
|
import io.ktor.serialization.*
|
||||||
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
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import org.koin.ktor.ext.Koin
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
@Suppress("unused") // Referenced in application.conf
|
@Suppress("unused") // Referenced in application.conf
|
||||||
@kotlin.jvm.JvmOverloads
|
fun Application.module() {
|
||||||
fun Application.module(testing: Boolean = false) {
|
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
gson {
|
json()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val client = HttpClient(Apache) {
|
install(Koin) {
|
||||||
}
|
printLogger()
|
||||||
|
modules(com.kmalbz.di.injectionModule)
|
||||||
install(Authentication) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseFactory.init()
|
DatabaseFactory.init()
|
||||||
@ -50,58 +34,13 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
SchemaUtils.create(ResultObjects)
|
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()
|
|
||||||
|
|
||||||
channel.exchangeDeclare(RecieveOutput.EXCHANGE_NAME, BuiltinExchangeType.FANOUT)
|
|
||||||
val queueName = channel.queueDeclare().queue
|
|
||||||
channel.queueBind(queueName, RecieveOutput.EXCHANGE_NAME, "")
|
|
||||||
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
get("/") {
|
|
||||||
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
|
|
||||||
}
|
|
||||||
|
|
||||||
get("/json/gson") {
|
|
||||||
call.respond(mapOf("hello" to "world"))
|
|
||||||
}
|
|
||||||
|
|
||||||
install(StatusPages) {
|
install(StatusPages) {
|
||||||
exception<AuthenticationException> { _ ->
|
exception<HttpException> {
|
||||||
call.respond(HttpStatusCode.Unauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
exception<AuthorizationException> { _ ->
|
|
||||||
call.respond(HttpStatusCode.Forbidden)
|
|
||||||
}
|
|
||||||
|
|
||||||
exception<HttpException> { _ ->
|
|
||||||
call.respond(HttpStatusCode.BadRequest)
|
call.respond(HttpStatusCode.BadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception<IllegalStateException> { _ ->
|
exception<IllegalStateException> {
|
||||||
call.respond(HttpStatusCode.NotAcceptable)
|
call.respond(HttpStatusCode.NotAcceptable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +50,3 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AuthenticationException : RuntimeException()
|
|
||||||
class AuthorizationException : RuntimeException()
|
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package com.kmalbz
|
|
||||||
|
|
||||||
data class ApiResponse(
|
|
||||||
val status: String,
|
|
||||||
val message: String
|
|
||||||
)
|
|
@ -1,77 +0,0 @@
|
|||||||
package com.kmalbz
|
|
||||||
|
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.request.*
|
|
||||||
import java.util.*
|
|
||||||
import com.kmalbz.database.model.ResultObject
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output Service - RDB Client
|
|
||||||
*
|
|
||||||
* This is the feature extraction interface of the Birbnetes system.
|
|
||||||
*/
|
|
||||||
open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient = HttpClient()) {
|
|
||||||
/**
|
|
||||||
* Get all negative decision objects
|
|
||||||
*
|
|
||||||
* @return Array of decision objects
|
|
||||||
*/
|
|
||||||
suspend fun getallnegative(
|
|
||||||
): List<ResultObject> {
|
|
||||||
return client.get<List<ResultObject>>("$endpoint/output/filter/negative") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get positive decision objects
|
|
||||||
*
|
|
||||||
* @return Array of decision objects
|
|
||||||
*/
|
|
||||||
suspend fun getallpositive(
|
|
||||||
): List<ResultObject> {
|
|
||||||
return client.get<List<ResultObject>>("$endpoint/output/filter/positive") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get decision before a date
|
|
||||||
*
|
|
||||||
* @param dateAfter Date of filter
|
|
||||||
*
|
|
||||||
* @return Array of decision objects
|
|
||||||
*/
|
|
||||||
suspend fun getallafter(
|
|
||||||
dateAfter: Date // PATH
|
|
||||||
): List<ResultObject> {
|
|
||||||
return client.get<List<ResultObject>>("$endpoint/output/after/$dateAfter") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get decision before a date
|
|
||||||
*
|
|
||||||
* @param dateBefore Date of filter
|
|
||||||
*
|
|
||||||
* @return Array of decision objects
|
|
||||||
*/
|
|
||||||
suspend fun getallbefore(
|
|
||||||
dateBefore: Date // PATH
|
|
||||||
): List<ResultObject> {
|
|
||||||
return client.get<List<ResultObject>>("$endpoint/output/before/$dateBefore") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get decision by ID
|
|
||||||
*
|
|
||||||
* @param tagID ID of wave file
|
|
||||||
*
|
|
||||||
* @return Decision object
|
|
||||||
*/
|
|
||||||
suspend fun getDecision(
|
|
||||||
tagID: Int // PATH
|
|
||||||
): ResultObject {
|
|
||||||
return client.get<ResultObject>("$endpoint/output/$tagID") {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
package com.kmalbz.api.model
|
package com.kmalbz.api.model
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import kotlinx.serialization.Serializable
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ApiObject(
|
data class ApiObject(
|
||||||
@SerializedName("tag") val tag: String,
|
val tag: String,
|
||||||
@SerializedName("probability") val probability: Double
|
val probability: Double
|
||||||
)
|
)
|
@ -1,60 +1,76 @@
|
|||||||
package com.kmalbz.api.route
|
package com.kmalbz.api.route
|
||||||
|
|
||||||
import io.ktor.application.*
|
import com.kmalbz.database.service.IResultObjectService
|
||||||
import io.ktor.response.*
|
import io.ktor.application.call
|
||||||
import io.ktor.routing.*
|
import io.ktor.http.HttpStatusCode
|
||||||
import io.ktor.http.*
|
import io.ktor.response.respond
|
||||||
import com.kmalbz.database.service.ResultObjectService
|
import io.ktor.routing.Routing
|
||||||
import java.time.LocalDate
|
import io.ktor.routing.get
|
||||||
import java.time.format.DateTimeFormatter
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import org.koin.ktor.ext.inject
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output Service - RDB
|
* Output Service - RDB
|
||||||
*
|
*
|
||||||
* This is the output interface of the Birbnetes system.
|
* This is the output interface of the Birbnetes system.
|
||||||
*/
|
*/
|
||||||
class OutputServiceRDBServer() {
|
class OutputServiceRDBServer {
|
||||||
/**
|
/**
|
||||||
* output
|
* output
|
||||||
*/
|
*/
|
||||||
private val resultObjectService = ResultObjectService()
|
|
||||||
fun Routing.registerOutput() {
|
fun Routing.registerOutput() {
|
||||||
get("/output"){
|
val resultObjectService: IResultObjectService by inject()
|
||||||
|
get("/output") {
|
||||||
call.respond(resultObjectService.getAllResultObjects())
|
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") {
|
get("/output/filter/negative") {
|
||||||
val resultList = resultObjectService.getResultObjecLessthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecLessthanProbability(0.5)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/positive") {
|
get("/output/filter/positive") {
|
||||||
val resultList = resultObjectService.getResultObjecGreaterthanProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecGreaterthanProbability(0.5)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/filter/undecided") {
|
get("/output/filter/undecided") {
|
||||||
val resultList = resultObjectService.getResultObjecEqualsProbability(0.5) ?: call.respond(HttpStatusCode.NotFound)
|
val resultList =
|
||||||
|
resultObjectService.getResultObjecEqualsProbability(0.5)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/after/{dateAfter}") {
|
get("/output/after/{dateAfter}") {
|
||||||
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateAfter"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val localDateAfter: LocalDateTime = LocalDateTime.parse(dateAfter)
|
||||||
val localDateAfter : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val resultList =
|
||||||
val resultList = resultObjectService.getResultObjectbeforeDate(localDateAfter) ?: call.respond(HttpStatusCode.NotFound)
|
resultObjectService.getResultObjectafterDate(localDateAfter)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/output/before/{dateBefore}") {
|
get("/output/before/{dateBefore}") {
|
||||||
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
val dateAfter = call.parameters["dateBefore"] ?: error(HttpStatusCode.NotAcceptable)
|
||||||
val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE
|
val localDateBefore: LocalDateTime = LocalDateTime.parse(dateAfter)
|
||||||
val localDateBefore : LocalDate = LocalDate.parse(dateAfter,dateTimeFormatter)
|
val resultList =
|
||||||
val resultList = resultObjectService.getResultObjectafterDate(localDateBefore) ?: call.respond(HttpStatusCode.NotFound)
|
resultObjectService.getResultObjectbeforeDate(localDateBefore)
|
||||||
|
|
||||||
call.respond(resultList)
|
call.respond(resultList)
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package com.kmalbz.database.dao
|
|||||||
|
|
||||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
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`.datetime
|
||||||
import java.time.LocalDate
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
object ResultObjects : IntIdTable() {
|
object ResultObjects : IntIdTable() {
|
||||||
val tag: Column<String> = varchar("tag",32)
|
val tag: Column<String> = varchar("tag", 32)
|
||||||
val date: Column<LocalDate> = date("date").default(LocalDate.now())
|
val date: Column<LocalDateTime> = datetime("date").default(LocalDateTime.now())
|
||||||
val probability: Column<Double> = double("probability")
|
val probability: Column<Double> = double("probability")
|
||||||
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
|
override val primaryKey = PrimaryKey(id, name = "PK_ResultObject_Id")
|
||||||
}
|
}
|
18
src/database/service/IResultObjectService.kt
Normal file
18
src/database/service/IResultObjectService.kt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.kmalbz.database.service
|
||||||
|
|
||||||
|
import com.kmalbz.api.model.ApiObject
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
|
||||||
|
interface IResultObjectService{
|
||||||
|
fun addOne(apiObject: ApiObject)
|
||||||
|
suspend fun getAllResultObjects(): 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>
|
||||||
|
}
|
@ -4,16 +4,17 @@ 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 com.kmalbz.api.model.ApiObject
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.datetime.toJavaLocalDateTime
|
||||||
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 org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
|
|
||||||
class ResultObjectService {
|
class ResultObjectService : IResultObjectService {
|
||||||
|
|
||||||
fun addOne(apiObject: ApiObject) {
|
override fun addOne(apiObject: ApiObject) {
|
||||||
transaction {
|
transaction {
|
||||||
ResultObject.new {
|
ResultObject.new {
|
||||||
tag = apiObject.tag
|
tag = apiObject.tag
|
||||||
@ -22,48 +23,56 @@ class ResultObjectService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
override suspend fun getAllResultObjects(): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.selectAll().map { toResultObject(it) }
|
ResultObjects.selectAll().map { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyTag(tag: String): 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.select {
|
||||||
(ResultObjects.tag eq tag)
|
(ResultObjects.tag eq tag)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
.singleOrNull()
|
.singleOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbyDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbyDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date eq date)
|
(ResultObjects.date eq date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectbeforeDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectbeforeDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date less date)
|
(ResultObjects.date less date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjectafterDate(date: LocalDate): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjectafterDate(date: LocalDateTime): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.date greater date)
|
(ResultObjects.date greater date.toJavaLocalDateTime())
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecGreaterthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability greater probability)
|
(ResultObjects.probability greater probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecLessthanProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability less probability)
|
(ResultObjects.probability less probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject>? = dbQuery {
|
override suspend fun getResultObjecEqualsProbability(probability: Double): List<ApiObject> = dbQuery {
|
||||||
ResultObjects.select {
|
ResultObjects.select {
|
||||||
(ResultObjects.probability eq probability)
|
(ResultObjects.probability eq probability)
|
||||||
}.mapNotNull { toResultObject(it) }
|
}.mapNotNull { toResultObject(it) }
|
||||||
|
9
src/di/InjectionModule.kt
Normal file
9
src/di/InjectionModule.kt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.kmalbz.di
|
||||||
|
|
||||||
|
import com.kmalbz.database.service.IResultObjectService
|
||||||
|
import com.kmalbz.database.service.ResultObjectService
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val injectionModule = module(createdAtStart = true) {
|
||||||
|
single<IResultObjectService> {ResultObjectService()}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package com.kmalbz.mq
|
|
||||||
|
|
||||||
class RecieveOutput {
|
|
||||||
companion object {
|
|
||||||
const val EXCHANGE_NAME = "output"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.kmalbz
|
|
||||||
|
|
||||||
import io.ktor.application.*
|
|
||||||
import io.ktor.response.*
|
|
||||||
import io.ktor.request.*
|
|
||||||
import io.ktor.routing.*
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.gson.*
|
|
||||||
import io.ktor.features.*
|
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.engine.apache.*
|
|
||||||
import io.ktor.auth.*
|
|
||||||
import kotlin.reflect.*
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.test.*
|
|
||||||
import io.ktor.server.testing.*
|
|
||||||
import io.ktor.util.KtorExperimentalAPI
|
|
||||||
|
|
||||||
class ApplicationTest {
|
|
||||||
@KtorExperimentalAPI
|
|
||||||
@Test
|
|
||||||
fun testRoot() {
|
|
||||||
withTestApplication({ module(testing = true) }) {
|
|
||||||
handleRequest(HttpMethod.Get, "/").apply {
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
assertEquals("HELLO WORLD!", response.content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
package com.kmalbz
|
|
||||||
|
|
||||||
import io.ktor.config.*
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.server.testing.*
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
class SwaggerRoutesTest {
|
|
||||||
/**
|
|
||||||
* @see OutputServiceRDBServer.getallnegative
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetallnegative() {
|
|
||||||
withTestApplication {
|
|
||||||
// @TODO: Adjust path as required
|
|
||||||
handleRequest(HttpMethod.Get, "/output/filter/negative") {
|
|
||||||
}.apply {
|
|
||||||
// @TODO: Your test here
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see OutputServiceRDBServer.getallpositive
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetallpositive() {
|
|
||||||
withTestApplication {
|
|
||||||
// @TODO: Adjust path as required
|
|
||||||
handleRequest(HttpMethod.Get, "/output/filter/positive") {
|
|
||||||
}.apply {
|
|
||||||
// @TODO: Your test here
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see OutputServiceRDBServer.getallafter
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetallafter() {
|
|
||||||
withTestApplication {
|
|
||||||
// @TODO: Adjust path as required
|
|
||||||
handleRequest(HttpMethod.Get, "/output/after/{dateAfter}") {
|
|
||||||
}.apply {
|
|
||||||
// @TODO: Your test here
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see OutputServiceRDBServer.getallbefore
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetallbefore() {
|
|
||||||
withTestApplication {
|
|
||||||
// @TODO: Adjust path as required
|
|
||||||
handleRequest(HttpMethod.Get, "/output/before/{dateBefore}") {
|
|
||||||
}.apply {
|
|
||||||
// @TODO: Your test here
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see OutputServiceRDBServer.getDecision
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
fun testGetDecision() {
|
|
||||||
withTestApplication {
|
|
||||||
// @TODO: Adjust path as required
|
|
||||||
handleRequest(HttpMethod.Get, "/output/{tagID}") {
|
|
||||||
}.apply {
|
|
||||||
// @TODO: Your test here
|
|
||||||
assertEquals(HttpStatusCode.OK, response.status())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <R> withTestApplication(test: TestApplicationEngine.() -> R): R {
|
|
||||||
return withApplication(createTestEnvironment()) {
|
|
||||||
(environment.config as MapApplicationConfig).apply {
|
|
||||||
put("jwt.secret", "TODO-change-this-supersecret-or-use-SECRET-env")
|
|
||||||
}
|
|
||||||
application.module()
|
|
||||||
test()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//fun TestApplicationRequest.setBodyJson(value: Any?) = setBody(Gson.stringify(value))
|
|
||||||
}
|
|
Reference in New Issue
Block a user