Skip to content

Commit 4852425

Browse files
suboticirinaschubert
andauthored
refactor: application actor (DEV-956) (#2166)
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
1 parent 33f638e commit 4852425

166 files changed

Lines changed: 2916 additions & 4087 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![Github](https://img.shields.io/github/v/tag/dasch-swiss/dsp-api?include_prereleases&label=Github%20tag)](https://github.com/dasch-swiss/dsp-api)
44
[![Docker](https://img.shields.io/docker/v/daschswiss/knora-api?label=Docker%20image)](https://hub.docker.com/r/daschswiss/knora-api)
55
[![CI](https://github.com/dasch-swiss/dsp-app/workflows/CI/badge.svg)](https://github.com/dasch-swiss/dsp-api/actions?query=workflow%3ACI)
6+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4c8f6736facf4e3ab6b0436c0c1ff197)](https://www.codacy.com/gh/dasch-swiss/dsp-api/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=dasch-swiss/dsp-api&amp;utm_campaign=Badge_Grade)
7+
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/4c8f6736facf4e3ab6b0436c0c1ff197)](https://www.codacy.com/gh/dasch-swiss/dsp-api/dashboard?utm_source=github.com&utm_medium=referral&utm_content=dasch-swiss/dsp-api&utm_campaign=Badge_Coverage)
68

79
[DSP](https://admin.dasch.swiss/) is a server application for storing, sharing, and working with primary sources and data in the humanities.
810

‎build.sbt‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
209209
// add 'config' directory to the classpath of the start script,
210210
Universal / scriptClasspath := Seq("webapi/scripts", "knora-ontologies", "../config/") ++ scriptClasspath.value,
211211
// need this here, so that the Manifest inside the jars has the correct main class set.
212-
Compile / mainClass := Some("org.knora.webapi.app.Main"),
212+
Compile / mainClass := Some("org.knora.webapi.Main"),
213213
// add dockerCommands used to create the image
214214
// docker:stage, docker:publishLocal, docker:publish, docker:clean
215215
Docker / dockerRepository := Some("daschswiss"),
@@ -241,17 +241,9 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
241241
.dependsOn(shared, schemaCore)
242242

243243
lazy val webapiJavaRunOptions = Seq(
244-
// "-showversion",
245244
"-Xms1G",
246245
"-Xmx1G",
247-
// "-verbose:gc",
248-
// "-XX:+UseG1GC",
249-
// "-XX:MaxGCPauseMillis=500"
250-
"-Dcom.sun.management.jmxremote",
251-
// "-Dcom.sun.management.jmxremote.port=1617",
252-
"-Dcom.sun.management.jmxremote.authenticate=false",
253-
"-Dcom.sun.management.jmxremote.ssl=false"
254-
// "-agentpath:/Applications/YourKit-Java-Profiler-2018.04.app/Contents/Resources/bin/mac/libyjpagent.jnilib"
246+
"-Xss6M"
255247
)
256248

257249
lazy val webapiJavaTestOptions = Seq(

‎k6/health.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import http from "k6/http";
2+
import { sleep } from "k6";
3+
export const options = {
4+
vus: 10,
5+
duration: "30s",
6+
};
7+
export default function () {
8+
http.get("http://0.0.0.0:3333/health");
9+
sleep(1);
10+
}

‎project/Dependencies.scala‎

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,33 @@ object Dependencies {
1616

1717
val ScalaVersion = "2.13.8"
1818

19-
val AkkaHttpVersion = "10.2.9"
20-
val AkkaActorVersion = "2.6.19"
19+
val AkkaActorVersion = "2.6.20"
20+
val AkkaHttpVersion = "10.2.10"
2121
val JenaVersion = "4.6.0"
2222

23-
val ZioVersion = "2.0.2"
24-
val ZioHttpVersion = "2.0.0-RC4"
25-
val ZioJsonVersion = "0.3.0-RC11"
26-
val ZioConfigVersion = "3.0.2"
27-
val ZioSchemaVersion = "0.2.0"
28-
val ZioLoggingVersion = "2.1.0"
29-
val ZioZmxVersion = "2.0.0-RC4"
30-
val ZioPreludeVersion = "1.0.0-RC15"
23+
val ZioVersion = "2.0.2"
24+
val ZioHttpVersion = "2.0.0-RC4"
25+
val ZioJsonVersion = "0.3.0-RC11"
26+
val ZioConfigVersion = "3.0.2"
27+
val ZioSchemaVersion = "0.2.0"
28+
val ZioLoggingVersion = "2.1.0"
29+
val ZioMetricsConnectorsVersion = "2.0.0"
30+
val ZioPreludeVersion = "1.0.0-RC15"
3131

3232
// ZIO - all Scala 3 compatible
33-
val zio = "dev.zio" %% "zio" % ZioVersion
34-
val zioMacros = "dev.zio" %% "zio-macros" % ZioVersion
35-
val zioHttp = "io.d11" %% "zhttp" % ZioHttpVersion
36-
val zioJson = "dev.zio" %% "zio-json" % ZioJsonVersion
37-
val zioPrelude = "dev.zio" %% "zio-prelude" % ZioPreludeVersion
38-
val zioLogging = "dev.zio" %% "zio-logging" % ZioLoggingVersion
39-
val zioLoggingSlf4j = "dev.zio" %% "zio-logging-slf4j" % ZioLoggingVersion
40-
val zioConfig = "dev.zio" %% "zio-config" % ZioConfigVersion
41-
val zioConfigMagnolia = "dev.zio" %% "zio-config-magnolia" % ZioConfigVersion
42-
val zioConfigTypesafe = "dev.zio" %% "zio-config-typesafe" % ZioConfigVersion
43-
val zioTest = "dev.zio" %% "zio-test" % "2.0.2"
44-
val zioTestSbt = "dev.zio" %% "zio-test-sbt" % "2.0.2"
33+
val zio = "dev.zio" %% "zio" % ZioVersion
34+
val zioMacros = "dev.zio" %% "zio-macros" % ZioVersion
35+
val zioHttp = "io.d11" %% "zhttp" % ZioHttpVersion
36+
val zioJson = "dev.zio" %% "zio-json" % ZioJsonVersion
37+
val zioPrelude = "dev.zio" %% "zio-prelude" % ZioPreludeVersion
38+
val zioLogging = "dev.zio" %% "zio-logging" % ZioLoggingVersion
39+
val zioLoggingSlf4j = "dev.zio" %% "zio-logging-slf4j" % ZioLoggingVersion
40+
val zioConfig = "dev.zio" %% "zio-config" % ZioConfigVersion
41+
val zioConfigMagnolia = "dev.zio" %% "zio-config-magnolia" % ZioConfigVersion
42+
val zioConfigTypesafe = "dev.zio" %% "zio-config-typesafe" % ZioConfigVersion
43+
val zioTest = "dev.zio" %% "zio-test" % ZioVersion
44+
val zioTestSbt = "dev.zio" %% "zio-test-sbt" % ZioVersion
45+
val zioMetricsConnectors = "dev.zio" %% "zio-metrics-connectors" % ZioMetricsConnectorsVersion
4546

4647
// akka
4748
val akkaActor = "com.typesafe.akka" %% "akka-actor" % AkkaActorVersion // Scala 3 compatible
@@ -55,9 +56,9 @@ object Dependencies {
5556
val jenaText = "org.apache.jena" % "jena-text" % JenaVersion
5657

5758
// logging
58-
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.11"
5959
val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5" // Scala 3 compatible
60-
val slf4j = "org.slf4j" % "slf4j-simple" % "2.0.0"
60+
val slf4jApi = "org.slf4j" % "slf4j-api" % "2.0.0" // the logging interface
61+
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.4.0" // the logging implementation
6162

6263
// Metrics
6364
val aspectjweaver = "org.aspectj" % "aspectjweaver" % "1.9.9.1"
@@ -115,8 +116,8 @@ object Dependencies {
115116
akkaHttp,
116117
akkaHttpCors,
117118
akkaHttpSprayJson,
119+
akkaSlf4j,
118120
akkaHttpTestkit % Test,
119-
akkaSlf4j % Runtime,
120121
akkaStream,
121122
akkaStreamTestkit % Test,
122123
akkaTestkit % Test,
@@ -136,14 +137,15 @@ object Dependencies {
136137
jwtSprayJson,
137138
kamonCore,
138139
kamonScalaFuture,
139-
logbackClassic % Runtime,
140-
rdf4jClient % Test,
140+
logbackClassic,
141+
rdf4jClient % Test,
141142
rdf4jShacl,
142143
saxonHE,
143144
scalaGraph,
144145
scalaLogging,
145146
scalaTest % Test,
146147
scallop,
148+
slf4jApi,
147149
springSecurityCore,
148150
bouncyCastle,
149151
swaggerAkkaHttp,
@@ -159,6 +161,7 @@ object Dependencies {
159161
zioLogging,
160162
zioLoggingSlf4j,
161163
zioMacros,
164+
zioMetricsConnectors,
162165
zioPrelude,
163166
zioTest % Test,
164167
zioTestSbt % Test
@@ -194,70 +197,78 @@ object Dependencies {
194197

195198
// user projects dependencies
196199
val userInterfaceLibraryDependencies = Seq(
197-
slf4j % Test,
198200
zio,
199201
zioMacros,
200202
zioTest % Test,
201-
zioTestSbt % Test
203+
zioTestSbt % Test,
204+
zioLogging,
205+
zioLoggingSlf4j
202206
)
203207
val userHandlerLibraryDependencies = Seq(
204208
bouncyCastle,
205-
slf4j % Test,
206209
springSecurityCore,
207210
zio,
208211
zioMacros,
209212
zioTest % Test,
210-
zioTestSbt % Test
213+
zioTestSbt % Test,
214+
zioLogging,
215+
zioLoggingSlf4j
211216
)
212217
val userCoreLibraryDependencies = Seq(
213218
bouncyCastle,
214-
slf4j % Test,
215219
springSecurityCore,
216220
zio,
217221
zioMacros,
218222
zioTest % Test,
219-
zioTestSbt % Test
223+
zioTestSbt % Test,
224+
zioLogging,
225+
zioLoggingSlf4j
220226
)
221227
val userRepoLibraryDependencies = Seq(
222-
slf4j % Test,
223228
zio,
224229
zioMacros,
225230
zioTest % Test,
226-
zioTestSbt % Test
231+
zioTestSbt % Test,
232+
zioLogging,
233+
zioLoggingSlf4j
227234
)
228235

229236
// role projects dependencies
230237
val roleInterfaceLibraryDependencies = Seq(
231-
slf4j % Test,
232238
zio,
233239
zioMacros,
234240
zioTest % Test,
235-
zioTestSbt % Test
241+
zioTestSbt % Test,
242+
zioLogging,
243+
zioLoggingSlf4j
236244
)
237245
val roleHandlerLibraryDependencies = Seq(
238246
bouncyCastle,
239-
slf4j % Test,
240247
springSecurityCore,
241248
zio,
242249
zioMacros,
243250
zioTest % Test,
244-
zioTestSbt % Test
251+
zioTestSbt % Test,
252+
zioLogging,
253+
zioLoggingSlf4j
245254
)
246255
val roleCoreLibraryDependencies = Seq(
247256
bouncyCastle,
248-
slf4j % Test,
249257
springSecurityCore,
250258
zio,
251259
zioMacros,
252260
zioTest % Test,
253-
zioTestSbt % Test
261+
zioTestSbt % Test,
262+
zioLogging,
263+
zioLoggingSlf4j
254264
)
255265
val roleRepoLibraryDependencies = Seq(
256-
slf4j % Test,
257266
zio,
258267
zioMacros,
259268
zioTest % Test,
260-
zioTestSbt % Test
269+
zioTestSbt % Test,
270+
zioLogging,
271+
zioLoggingSlf4j
261272
)
262273

263274
// shared project dependencies
@@ -267,11 +278,12 @@ object Dependencies {
267278
commonsValidator,
268279
gwtServlet,
269280
scalaLogging,
270-
slf4j % Test,
271281
springSecurityCore,
272282
zioPrelude,
273283
zioTest % Test,
274-
zioTestSbt % Test
284+
zioTestSbt % Test,
285+
zioLogging,
286+
zioLoggingSlf4j
275287
)
276288

277289
// project project dependencies

‎webapi/src/main/resources/application.conf‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ akka {
4040
# Must be smaller then idle-timeout
4141
request-timeout = 120 minutes
4242

43+
# The time period within which the TCP binding process must be completed.
44+
bind-timeout = 5 seconds
45+
4346
# The maximum number of concurrently accepted connections when using the
4447
# `Http().bindAndHandle` methods.
4548
#
@@ -231,13 +234,6 @@ akka-http-cors {
231234
}
232235

233236
app {
234-
235-
shacl {
236-
# The directory that SHACL shapes are loaded from.
237-
shapes-dir = "../test_data/shacl"
238-
shapes-dir = ${?KNORA_WEBAPI_SHACLE_SHAPES_DIR}
239-
}
240-
241237
print-extended-config = false // If true, an extended list of configuration parameters will be printed out at startup.
242238
print-extended-config = ${?KNORA_WEBAPI_PRINT_EXTENDED_CONFIG}
243239

@@ -484,6 +480,12 @@ app {
484480
profile-queries = false
485481
}
486482

483+
shacl {
484+
# The directory that SHACL shapes are loaded from.
485+
shapes-dir = "../test_data/shacl"
486+
shapes-dir = ${?KNORA_WEBAPI_SHACLE_SHAPES_DIR}
487+
}
488+
487489
cache-service {
488490

489491
enabled = true

‎webapi/src/main/resources/logback.xml‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE configuration>
23

3-
<!-- For assistance related to logback-translator or configuration -->
4-
<!-- files in general, please contact the logback user mailing list -->
5-
<!-- at http://www.qos.ch/mailman/listinfo/logback-user -->
6-
<!-- -->
7-
<!-- For professional support please see -->
8-
<!-- http://www.qos.ch/shop/products/professionalSupport -->
9-
<!-- -->
10-
<configuration scan="false" debug="false">
11-
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
12-
<encoder>
13-
<pattern>%d{yyyy-MM-dd HH:mm:ss} | %-5level | %logger{0} | %msg%n</pattern>
4+
<configuration>
5+
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
6+
<import class="ch.qos.logback.core.ConsoleAppender"/>
7+
8+
<appender name="STDOUT" class="ConsoleAppender">
9+
<encoder class="PatternLayoutEncoder">
10+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
1411
</encoder>
1512
</appender>
1613

17-
<!--<conversionRule conversionWord="traceID" converterClass="kamon.instrumentation.logback.tools.LogbackTraceIDConverter" />
18-
19-
<appender name="STDOUTMETRICS" class="ch.qos.logback.core.ConsoleAppender">
20-
<encoder>
21-
<pattern>%d{yyyy-MM-dd HH:mm:ss} | %-5level | %traceID | %c{0} -> %m%n</pattern>
22-
</encoder>
23-
</appender>-->
14+
<root level="ERROR">
15+
<appender-ref ref="STDOUT"/>
16+
</root>
2417

2518
<logger name="org.eclipse.rdf4j.rio.RDFParserRegistry" level="ERROR"/>
2619
<logger name="org.apache.jena.riot" level="ERROR"/>
@@ -40,6 +33,7 @@
4033

4134
<logger name="org.knora" level="INFO"/>
4235
<logger name="org.knora.webapi" level="INFO"/>
36+
<logger name="org.knora.webapi.core" level="INFO"/>
4337
<logger name="org.knora.webapi.app.ApplicationActor" level="INFO"/>
4438
<logger name="org.knora.webapi.util.cache" level="ERROR"/>
4539
<logger name="org.knora.webapi.util.PermissionUtilADM" level="INFO"/>
@@ -73,7 +67,5 @@
7367

7468
<!-- for logging during tests, please see/use logback-test.xml under test/resources -->
7569

76-
<root level="ERROR">
77-
<appender-ref ref="stdout"/>
78-
</root>
70+
7971
</configuration>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.knora.webapi
7+
8+
import zio._
9+
import zio.logging.backend.SLF4J
10+
11+
import org.knora.webapi.core.AppServer
12+
13+
object Main extends ZIOApp {
14+
15+
/**
16+
* The `Environment` that we require to exist at startup.
17+
*/
18+
override type Environment = core.LayersLive.DspEnvironmentLive
19+
20+
/**
21+
* `Bootstrap` will ensure that everything is instantiated when the Runtime is created
22+
* and cleaned up when the Runtime is shutdown.
23+
*/
24+
override val bootstrap: ZLayer[
25+
ZIOAppArgs with Scope,
26+
Any,
27+
Environment
28+
] = ZLayer.empty ++ Runtime.removeDefaultLoggers ++ SLF4J.slf4j ++ core.LayersLive.dspLayersLive
29+
30+
/* Needed for ZIO type magic */
31+
override val environmentTag: EnvironmentTag[Environment] = EnvironmentTag[Environment]
32+
33+
/* Here we start our Application */
34+
override val run =
35+
(for {
36+
never <- ZIO.never
37+
} yield never).provideLayer(AppServer.live)
38+
39+
}

0 commit comments

Comments
 (0)