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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.kmalbz
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.request.* import io.ktor.client.request.*
import java.util.* import java.util.*
import com.kmalbz.database.model.ResultObject
/** /**
* Output Service - RDB Client * Output Service - RDB Client
@ -16,8 +17,8 @@ open class OutputServiceRDBClient(val endpoint: String, val client: HttpClient =
* @return Array of decision objects * @return Array of decision objects
*/ */
suspend fun getallnegative( suspend fun getallnegative(
): List<OutputObject> { ): List<ResultObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/negative") { 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 * @return Array of decision objects
*/ */
suspend fun getallpositive( suspend fun getallpositive(
): List<OutputObject> { ): List<ResultObject> {
return client.get<List<OutputObject>>("$endpoint/output/filter/positive") { 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( suspend fun getallafter(
dateAfter: Date // PATH dateAfter: Date // PATH
): List<OutputObject> { ): List<ResultObject> {
return client.get<List<OutputObject>>("$endpoint/output/after/$dateAfter") { 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( suspend fun getallbefore(
dateBefore: Date // PATH dateBefore: Date // PATH
): List<OutputObject> { ): List<ResultObject> {
return client.get<List<OutputObject>>("$endpoint/output/before/$dateBefore") { 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( suspend fun getDecision(
tagID: Int // PATH tagID: Int // PATH
): OutputObject { ): ResultObject {
return client.get<OutputObject>("$endpoint/output/$tagID") { return client.get<ResultObject>("$endpoint/output/$tagID") {
} }
} }
} }

View File

@ -3,8 +3,10 @@ package com.kmalbz
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 java.util.*
import io.ktor.http.* import io.ktor.http.*
import com.kmalbz.database.service.ResultObjectService
import java.time.LocalDate
import java.time.format.DateTimeFormatter
/** /**
* Output Service - RDB * Output Service - RDB
@ -15,46 +17,47 @@ class OutputServiceRDBServer() {
/** /**
* output * output
*/ */
private val resultObjectService = ResultObjectService()
fun Routing.registerOutput() { fun Routing.registerOutput() {
get("/output/filter/negative") { get("/output"){
if (false) error(HttpStatusCode.NotFound) 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") { 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}") { 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(resultList)
call.respond(listOf())
} }
get("/output/before/{dateBefore}") { 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(resultList)
call.respond(listOf())
} }
get("/output/{tagID}") { 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(resultObject)
call.respond(OutputObject(
tag = "tag",
decison = false,
date = Date(),
confidence = 0.0
))
} }
} }
} }

View File

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

View File

@ -5,7 +5,6 @@ import io.ktor.config.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.request.* import io.ktor.request.*
import io.ktor.server.testing.* import io.ktor.server.testing.*
import io.ktor.swagger.experimental.*
import kotlin.test.* import kotlin.test.*
class SwaggerRoutesTest { 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))
} }