all routes wired together
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Torma Kristóf 2020-04-05 11:14:02 +02:00
parent af4307c6a4
commit b5be06848e
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
9 changed files with 69 additions and 53 deletions

View File

@ -6,7 +6,6 @@ steps:
- name: test
image: openjdk:8-jdk
commands:
- echo "test"
- ./gradlew build
- name: build
@ -20,6 +19,7 @@ steps:
DOCKER_PASSWORD:
from_secret: DOCKER_PASSWORD
commands:
- ./gradlew build
- 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" .

View File

@ -8,7 +8,7 @@ RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./build/libs/my-application.jar /app/my-application.jar
COPY ./build/libs/output-service-rdb.jar /app/output-service-rdb.jar
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", "my-application.jar"]
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"]

18
docker-compose.yml Normal file
View File

@ -0,0 +1,18 @@
version: '3'
services:
postgres:
image: "postgres:12"
restart: "always"
volumes:
- "ktor-data:/var/lib/postgresql/data"
ports:
- "127.0.0.1:54321:5432"
environment:
POSTGRES_USER: "output-service-rdb"
POSTGRES_PASSWORD: "output-service-rdb"
POSTGRES_DB: "output-service-rdb"
volumes:
ktor-data:

View File

@ -13,9 +13,12 @@ import io.ktor.auth.*
import kotlin.reflect.*
import java.util.*
import org.apache.http.HttpException
import com.kmalbz.database.DatabaseFactory
import io.ktor.util.KtorExperimentalAPI
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@KtorExperimentalAPI
@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
@ -30,6 +33,8 @@ fun Application.module(testing: Boolean = false) {
install(Authentication) {
}
DatabaseFactory.init()
routing {
get("/") {
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
@ -40,15 +45,15 @@ fun Application.module(testing: Boolean = false) {
}
install(StatusPages) {
exception<AuthenticationException> { cause ->
exception<AuthenticationException> { _ ->
call.respond(HttpStatusCode.Unauthorized)
}
exception<AuthorizationException> { cause ->
exception<AuthorizationException> { _ ->
call.respond(HttpStatusCode.Forbidden)
}
exception<HttpException> { cause ->
exception<HttpException> { _ ->
call.respond(HttpStatusCode.BadRequest)
}
}

View File

@ -1,14 +1,5 @@
package com.kmalbz
import java.util.*
data class OutputObject(
val tag: String,
val decison: Boolean,
val date: Date,
val confidence: Double
)
data class ApiResponse(
val status: String,
val message: String

View File

@ -3,6 +3,7 @@ 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
@ -16,8 +17,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
* @return Array of decision objects
*/
suspend fun getallnegative(
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/negative") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/negative") {
}
}
@ -27,8 +28,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
* @return Array of decision objects
*/
suspend fun getallpositive(
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/positive") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/filter/positive") {
}
}
@ -41,8 +42,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getallafter(
dateAfter: Date // PATH
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/after/$dateAfter") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/after/$dateAfter") {
}
}
@ -55,8 +56,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getallbefore(
dateBefore: Date // PATH
): List<OutputObject> {
return client.get<List<OutputObject>>("$endpoint/output/before/$dateBefore") {
): List<ResultObject> {
return client.get<List<ResultObject>>("$endpoint/output/before/$dateBefore") {
}
}
@ -69,8 +70,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
*/
suspend fun getDecision(
tagID: Int // PATH
): OutputObject {
return client.get<OutputObject>("$endpoint/output/$tagID") {
): ResultObject {
return client.get<ResultObject>("$endpoint/output/$tagID") {
}
}
}

View File

@ -3,8 +3,10 @@ package com.kmalbz
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.routing.*
import java.util.*
import io.ktor.http.*
import com.kmalbz.database.service.ResultObjectService
import java.time.LocalDate
import java.time.format.DateTimeFormatter
/**
* Output Service - RDB
@ -15,46 +17,47 @@ class OutputServiceRDBServer() {
/**
* output
*/
private val resultObjectService = ResultObjectService()
fun Routing.registerOutput() {
get("/output/filter/negative") {
if (false) error(HttpStatusCode.NotFound)
get("/output"){
call.respond(resultObjectService.getAllResultObjects())
}
call.respond(listOf())
get("/output/filter/negative") {
val resultList = resultObjectService.getResultObjectbyDecision(false) ?: error(HttpStatusCode.NotFound)
call.respond(resultList)
}
get("/output/filter/positive") {
if (false) error(HttpStatusCode.NotFound)
val resultList = resultObjectService.getResultObjectbyDecision(true) ?: error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/after/{dateAfter}") {
val dateAfter = call.parameters["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.getResultObjectbeforeDate(localDateAfter) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/before/{dateBefore}") {
val dateBefore = call.parameters["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.getResultObjectafterDate(localDateBefore) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(listOf())
call.respond(resultList)
}
get("/output/{tagID}") {
val tagID = call.parameters["tagID"]
val tagID = call.parameters["tagID"] ?: error(HttpStatusCode.NotAcceptable)
val resultObject = resultObjectService.getResultObjectbyTag(tagID) ?: error(HttpStatusCode.NotFound)
if (false) error(HttpStatusCode.NotFound)
call.respond(OutputObject(
tag = "tag",
decison = false,
date = Date(),
confidence = 0.0
))
call.respond(resultObject)
}
}
}

View File

@ -9,16 +9,15 @@ import io.ktor.gson.*
import io.ktor.features.*
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import com.fasterxml.jackson.databind.*
import io.ktor.jackson.*
import io.ktor.auth.*
import kotlin.reflect.*
import java.util.*
import io.ktor.swagger.experimental.*
import kotlin.test.*
import io.ktor.server.testing.*
import io.ktor.util.KtorExperimentalAPI
class ApplicationTest {
@KtorExperimentalAPI
@Test
fun testRoot() {
withTestApplication({ module(testing = true) }) {

View File

@ -5,7 +5,6 @@ import io.ktor.config.*
import io.ktor.http.*
import io.ktor.request.*
import io.ktor.server.testing.*
import io.ktor.swagger.experimental.*
import kotlin.test.*
class SwaggerRoutesTest {
@ -94,5 +93,5 @@ class SwaggerRoutesTest {
}
}
fun TestApplicationRequest.setBodyJson(value: Any?) = setBody(Json.stringify(value))
//fun TestApplicationRequest.setBodyJson(value: Any?) = setBody(Gson.stringify(value))
}