Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor(cacheservice): use ZIO (DEV-546) (#2022)
* refactor(cache): remove service from name

* refactor(cacheservice): inmem (ongoing)

* refactor(cacheservice): inmem (ongoing)

* chore(docs): add structurizr (c4)

* refactor(cache): inmem get user

* refactor(cacheservice): in-mem version

* refactor(cacheservice): redis version (ongoing)

* refactor(cacheservice): add zio-config (ongoing)

* refactor(cacheservice): redis implementation (ongoing)

* refactor(cacheservice): redis implementation (ongoing)

* refactor(cacheservice): redis implementation (ongoing)

* refactor(cacheservice): add redis implementation

* refactor(cacheservice): add redis serialization implementation (ongoing)

* refactor: after spartan session (ongoing)

* refactor(cacheservice): remove actor

* refactor(cacheservice): fix tests (ongoing)

* build: fix after merge

* refactor(cacheservice): fix tests

* refactor(cacheservice): add Redis Testcontainers layer

* refactor(cacheservice): moving runtime initialization to main

* refactor(cacheservice): moving runtime initialisation back where it was

* docs: add ADR record

* chore(deps): bump zio libraries

* chore(deps): bump zio libraries

* chore(deps): bump zio libraries

* chore: remove unneeded file

* refactor(cacheservice): ziofy redis testcontainers

* cleanup

* fix redis test container

* fix redis test container

* remove metrics logging

* Update webapi/src/main/scala/org/knora/webapi/store/cacheservice/CacheServiceManager.scala

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* Update webapi/src/main/scala/org/knora/webapi/store/cacheservice/CacheServiceManager.scala

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* Update webapi/src/main/scala/org/knora/webapi/store/cacheservice/CacheServiceManager.scala

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* Update docs/architecture/decisions/0002-change-cache-service-manager-from-akka-actor-to-zlayer.md

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* cleanup

* bumping dependencies

* cleanup

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
  • Loading branch information
subotic and irinaschubert committed Apr 12, 2022
1 parent 5c27eef commit 521150f
Show file tree
Hide file tree
Showing 51 changed files with 2,095 additions and 1,816 deletions.
1 change: 1 addition & 0 deletions .adr-dir
@@ -0,0 +1 @@
docs/architecture/decisions
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -18,6 +18,8 @@ webapi-it
webapi-test
upgrade/project
sipi/test
/docs/architecture/.structurizr
/docs/architecture/workspace.json

**/target/
*.aux
Expand All @@ -31,6 +33,7 @@ sipi/test
*.tdo
*.toc
*.bak
*.rdb
.sbtrc

dependencies.txt
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
@@ -1,6 +1,6 @@
version = "2.7.5"
maxColumn = 120
align.preset = some
align.preset = most
align.multiline = false
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -33,6 +33,11 @@ docs-install-requirements: ## install requirements
docs-clean: ## cleans the project directory
@rm -rf site/

.PHONY: structurizer
structurizer: ## starts the structurizer and serves c4 architecture docs
@docker pull structurizr/lite
@docker run -it --rm -p 8080:8080 -v $(CURRENT_DIR)/docs/architecture:/usr/local/structurizr structurizr/lite

#################################
# Docker targets
#################################
Expand Down
28 changes: 17 additions & 11 deletions build.sbt
Expand Up @@ -100,7 +100,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
.settings(buildSettings)
.enablePlugins(SbtTwirl, JavaAppPackaging, DockerPlugin, GatlingPlugin, JavaAgent, RevolverPlugin, BuildInfoPlugin)
.settings(
webApiCommonSettings,
name := "webapi",
resolvers ++= Seq(
Resolver.bintrayRepo("hseeberger", "maven")
),
Expand All @@ -112,19 +112,19 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
.settings(
// add needed files to production jar
Compile / packageBin / mappings ++= Seq(
(rootBaseDir.value / "knora-ontologies" / "knora-admin.ttl") -> "knora-ontologies/knora-admin.ttl",
(rootBaseDir.value / "knora-ontologies" / "knora-base.ttl") -> "knora-ontologies/knora-base.ttl",
(rootBaseDir.value / "knora-ontologies" / "salsah-gui.ttl") -> "knora-ontologies/salsah-gui.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-data.ttl") -> "knora-ontologies/standoff-data.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-onto.ttl") -> "knora-ontologies/standoff-onto.ttl",
(rootBaseDir.value / "knora-ontologies" / "knora-admin.ttl") -> "knora-ontologies/knora-admin.ttl",
(rootBaseDir.value / "knora-ontologies" / "knora-base.ttl") -> "knora-ontologies/knora-base.ttl",
(rootBaseDir.value / "knora-ontologies" / "salsah-gui.ttl") -> "knora-ontologies/salsah-gui.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-data.ttl") -> "knora-ontologies/standoff-data.ttl",
(rootBaseDir.value / "knora-ontologies" / "standoff-onto.ttl") -> "knora-ontologies/standoff-onto.ttl",
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template" // needed for initialization of triplestore
),
// use packaged jars (through packageBin) on classpaths instead of class directories for production
Compile / exportJars := true,
// add needed files to test jar
Test / packageBin / mappings ++= Seq(
(rootBaseDir.value / "webapi" / "scripts" / "fuseki-repository-config.ttl.template") -> "webapi/scripts/fuseki-repository-config.ttl.template", // needed for initialization of triplestore
(rootBaseDir.value / "sipi" / "config" / "sipi.docker-config.lua") -> "sipi/config/sipi.docker-config.lua"
(rootBaseDir.value / "sipi" / "config" / "sipi.docker-config.lua") -> "sipi/config/sipi.docker-config.lua"
),
// use packaged jars (through packageBin) on classpaths instead of class directories for test
Test / exportJars := true
Expand All @@ -140,12 +140,14 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
javaAgents += Dependencies.aspectjweaver,
fork := true, // run tests in a forked JVM
Test / testForkedParallel := false, // run forked tests in parallel
Test / parallelExecution := false, // run non-forked tests in parallel
Test / parallelExecution := false, // run non-forked tests in parallel
// Global / concurrentRestrictions += Tags.limit(Tags.Test, 1), // restrict the number of concurrently executing tests in all projects
Test / javaOptions ++= Seq("-Dconfig.resource=fuseki.conf") ++ webapiJavaTestOptions,
// Test / javaOptions ++= Seq("-Dakka.log-config-on-start=on"), // prints out akka config
// Test / javaOptions ++= Seq("-Dconfig.trace=loads"), // prints out config locations
Test / testOptions += Tests.Argument("-oDF") // show full stack traces and test case durations
Test / testOptions += Tests.Argument("-oDF"), // show full stack traces and test case durations
// add test framework for running zio-tests
Test / testFrameworks ++= Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.settings(
// prepare for publishing
Expand Down Expand Up @@ -189,8 +191,8 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
name,
version,
"akkaHttp" -> Dependencies.akkaHttpVersion,
"sipi" -> Dependencies.sipiImage,
"fuseki" -> Dependencies.fusekiImage
"sipi" -> Dependencies.sipiImage,
"fuseki" -> Dependencies.fusekiImage
),
buildInfoPackage := "org.knora.webapi.http.version"
)
Expand Down Expand Up @@ -219,6 +221,10 @@ lazy val webapiJavaTestOptions = Seq(
//"-XX:MaxMetaspaceSize=4096m"
)

//////////////////////////////////////
// DSP's new codebase
//////////////////////////////////////

lazy val apiMain = project
.in(file("dsp-api-main"))
.settings(
Expand Down
15 changes: 15 additions & 0 deletions docs/architecture/README.md
@@ -0,0 +1,15 @@
# C4 Model and ADRs

## Installation

```bash
$ brew install adr-tools
```

## Usage

Run the following command from the root directory to start the C4 model browser:

```bash
$ make structurizer
```
19 changes: 19 additions & 0 deletions docs/architecture/decisions/0001-record-architecture-decisions.md
@@ -0,0 +1,19 @@
# 1. Record architecture decisions

Date: 2022-03-14

## Status

Accepted

## Context

We need to record the architectural decisions made on this project.

## Decision

We will use Architecture Decision Records, as [described by Michael Nygard](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions).

## Consequences

See Michael Nygard's article, linked above. For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
@@ -0,0 +1,19 @@
# 2. Change Cache Service Manager from Akka-Actor to ZLayer

Date: 2022-04-06

## Status

Accepted

## Context

The `org.knora.webapi.store.cacheservice.CacheServiceManager` was implemented as an `Akka-Actor`.

## Decision

As part of the move from `Akka` to `ZIO`, it was decided that the `CacheServiceManager` and the whole implementation of the in-memory and Redis backed cache is refactored using ZIO.

## Consequences

The usage from other actors stays the same. The actor messages and responses don't change.
21 changes: 21 additions & 0 deletions docs/architecture/workspace.dsl
@@ -0,0 +1,21 @@
workspace {

model {
user = person "User"
softwareSystem = softwareSystem "Software System"

user -> softwareSystem "Uses"
}

views {
systemContext softwareSystem "Diagram1" {
include *
autoLayout
}

theme default
}

!adrs decisions

}
Expand Up @@ -14,6 +14,6 @@ case class SchemaRepoLive() extends SchemaRepo {

}

object SchemaRepoLive extends (() => SchemaRepo) {
val layer: URLayer[Any, SchemaRepo] = (SchemaRepoLive.apply _).toLayer
object SchemaRepoLive {
val layer: URLayer[Any, SchemaRepo] = ZLayer.succeed(SchemaRepoLive())
}
Expand Up @@ -7,18 +7,18 @@ case class SchemaRepoTest() extends SchemaRepo {
private var map: Map[UserID, UserProfile] = Map()

def setTestData(map0: Map[UserID, UserProfile]): Task[Unit] =
Task { map = map0 }
Task.succeed { map = map0 }

def getTestData: Task[Map[UserID, UserProfile]] =
Task(map)
Task.succeed(map)

def lookup(id: UserID): Task[UserProfile] =
Task(map(id))
Task.succeed(map(id))

def update(id: UserID, profile: UserProfile): Task[Unit] =
Task.attempt { map = map + (id -> profile) }
}

object SchemaRepoTest extends (() => SchemaRepo) {
val layer: URLayer[Any, SchemaRepo] = (SchemaRepoTest.apply _).toLayer
val layer: URLayer[Any, SchemaRepo] = ZLayer.succeed(SchemaRepoTest())
}

0 comments on commit 521150f

Please sign in to comment.