Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with gradle
run: ./gradlew shadowJar
env:
Expand Down
165 changes: 164 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,164 @@
build
# Created by https://www.toptal.com/developers/gitignore/api/kotlin,java,gradle,intellij
# Edit at https://www.toptal.com/developers/gitignore?templates=kotlin,java,gradle,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Kotlin ###
# Compiled class file

# Log file

# BlueJ files

# Mobile Tools for Java (J2ME)

# Package Files #

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml

### Gradle ###
.gradle
build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Gradle Patch ###
**/build/

# End of https://www.toptal.com/developers/gitignore/api/kotlin,java,gradle,intellij
Binary file removed .gradle/6.7/executionHistory/executionHistory.bin
Binary file not shown.
Binary file removed .gradle/6.7/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/6.7/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/6.7/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/6.7/fileHashes/fileHashes.lock
Binary file not shown.
Binary file removed .gradle/6.7/fileHashes/resourceHashesCache.bin
Binary file not shown.
Empty file removed .gradle/6.7/gc.properties
Empty file.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file removed .gradle/checksums/checksums.lock
Binary file not shown.
Binary file removed .gradle/checksums/md5-checksums.bin
Binary file not shown.
Binary file removed .gradle/checksums/sha1-checksums.bin
Binary file not shown.
Empty file.
Empty file removed .gradle/vcs-1/gc.properties
Empty file.
20 changes: 0 additions & 20 deletions .idea/gradle.xml

This file was deleted.

10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.4.21"
kotlin("jvm") version "1.5.21"
id("com.github.johnrengelman.shadow") version "6.0.0"
}

Expand All @@ -11,10 +11,10 @@ repositories {
jcenter()
maven{
name = "GitHub transitdata-common"
url = uri("https://maven.pkg.github.com/hsldevcom/transitdata-common")
url = uri("https://maven.pkg.github.com/hsldevcom/*")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
username = (project.findProperty("github.user") ?: System.getenv("GITHUB_ACTOR")).toString()
password = (project.findProperty("github.token") ?: System.getenv("GITHUB_TOKEN")).toString()
}
}
}
Expand All @@ -34,12 +34,18 @@ val jar by tasks.getting(Jar::class){


dependencies {
testImplementation(kotlin("test-junit"))
implementation ("fi.hsl:transitdata-common:1.3.22")
implementation ("io.github.microutils:kotlin-logging:1.6.22")
implementation ("io.ktor:ktor:1.5.1")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.5.21")

implementation ("fi.hsl:transitdata-common:1.3.25")

implementation ("io.github.microutils:kotlin-logging:2.0.11")

implementation ("io.ktor:ktor:1.6.3")
implementation("io.ktor:ktor-server-netty:1.6.4")

implementation("org.json:json:20210307")

//implementation (fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
implementation("io.ktor:ktor-server-netty:1.5.1")
}

tasks.test {
Expand Down
15 changes: 5 additions & 10 deletions src/main/kotlin/fi/hsl/ekecheck/DataHolder.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package fi.hsl.ekecheck

import fi.hsl.common.transitdata.proto.Eke

object DataHolder {
val dataMap = mutableMapOf<String, MutableMap<String, EkeSummaryDTO>>()
private val dataMap = mutableMapOf<String, MutableMap<String, EkeSummaryDTO>>()

fun getTrainData(unitNumber : String) : MutableMap<String, EkeSummaryDTO>?{
return dataMap[unitNumber]
fun getTrainData(unitNumber: String): Map<String, EkeSummaryDTO>? {
return dataMap[unitNumber]?.toMap()
}

fun putEkeSummary(ekeSummary : EkeSummaryDTO){
if(dataMap[ekeSummary.unitNumber] == null){
dataMap[ekeSummary.unitNumber] = mutableMapOf()
}
dataMap[ekeSummary.unitNumber]!![ekeSummary.topic] = ekeSummary
fun putEkeSummary(ekeSummary: EkeSummaryDTO) {
dataMap.computeIfAbsent(ekeSummary.unitNumber) { mutableMapOf() }[ekeSummary.topic] = ekeSummary
}
}
11 changes: 9 additions & 2 deletions src/main/kotlin/fi/hsl/ekecheck/MessageHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import org.apache.pulsar.client.api.MessageId

const val TOPIC_PREFIX = "eke/v1/sm5/"

class MessageHandler(val context: PulsarApplicationContext) : IMessageHandler {

class MessageHandler(context: PulsarApplicationContext) : IMessageHandler {
private val consumer: Consumer<ByteArray> = context.consumer!!
private val log = KotlinLogging.logger {}

private var messageCounter = 0;

override fun handleMessage(received: Message<Any>) {
if (messageCounter++ >= 10000) {
log.info { "Handled 10000 messages, everything seems fine" }
messageCounter = 0
}

try {
if (TransitdataSchema.hasProtobufSchema(received, TransitdataProperties.ProtobufSchema.EkeSummary)) {
val ekeSummary = Eke.EkeSummary.parseFrom(received.data)
Expand Down
26 changes: 13 additions & 13 deletions src/main/kotlin/fi/hsl/ekecheck/WebsiteController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.response.*
import io.ktor.routing.*
import org.apache.pulsar.shade.com.google.gson.JsonArray
import org.apache.pulsar.shade.com.google.gson.JsonObject
import java.io.File
import org.json.JSONArray
import org.json.JSONObject
import java.time.Instant

object WebsiteController {
Expand All @@ -27,22 +26,23 @@ object WebsiteController {

fun Route.customerRouting(){
route("/api/train/{unitNumber}"){
get{
val jsonArray = JsonArray()
get {
val jsonArray = JSONArray()
val unitNumber = call.parameters["unitNumber"]
if(unitNumber != null){
if (unitNumber != null) {
val trainData = DataHolder.getTrainData(unitNumber)
if(trainData != null && trainData.isNotEmpty()) {
if (trainData != null && trainData.isNotEmpty()) {
trainData.values.forEach {
val jsonObject = JsonObject()
jsonObject.addProperty("unitNumber",it.unitNumber)
jsonObject.addProperty("ekeDate", Instant.ofEpochMilli(it.timestamp).toString())
jsonObject.addProperty("topicPart",it.topic)
jsonArray.add(jsonObject)
val jsonObject = JSONObject()
jsonObject.put("unitNumber", it.unitNumber)
jsonObject.put("ekeDate", Instant.ofEpochMilli(it.timestamp).toString())
jsonObject.put("topicPart", it.topic)

jsonArray.put(jsonObject)
}
}
}
call.respondText(jsonArray.toString(), ContentType.parse("application/json" ))
call.respondText(jsonArray.toString(4), ContentType.parse("application/json" ))
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/resources/environment.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ pulsar {
}
}

doi {
timezone="Europe/Helsinki"
timezone=${?DOI_TIMEZONE}
queryFutureDays=5 #How many days into future to query data for?
queryFutureDays=${?DOI_QUERY_FUTURE_DAYS}
}

application {
blobConnectionString=""
blobConnectionString=${?BLOBSTORAGE_ENDPOINT}
blobContainer="eke-csv"
blobContainer=${?BLOBCONTAINER}
outputformat="csv"
outputformat=${?OUTPUT_FORMAT}
}