Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor(IIIFService): zio-fying iiif service (DEV-801) (#2044)
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
  • Loading branch information
3 people committed May 5, 2022
1 parent 77bfadc commit 224b664
Show file tree
Hide file tree
Showing 350 changed files with 4,165 additions and 2,979 deletions.
76 changes: 55 additions & 21 deletions .github/workflows/main.yml
Expand Up @@ -17,22 +17,17 @@ jobs:
uses: actions/checkout@v1
with:
fetch-depth: 15
- name: Setup JDK
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11
- name: get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DD
utcOffset: "+02:00"
- name: setup java version
uses: joschi/setup-jdk@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11' # The OpenJDK version to make available on the path
architecture: 'x64' # defaults to 'x64'
distribution: 'temurin'
java-version: '17'
- name: add docker compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
Expand Down Expand Up @@ -69,11 +64,11 @@ jobs:
with:
format: YYYY-MM-DD
utcOffset: "+02:00"
- name: setup java version
uses: joschi/setup-jdk@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11' # The OpenJDK version to make available on the path
architecture: 'x64' # defaults to 'x64'
distribution: 'temurin'
java-version: '17'
- name: add docker compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
Expand Down Expand Up @@ -116,11 +111,11 @@ jobs:
with:
format: YYYY-MM-DD
utcOffset: "+02:00"
- name: setup java version
uses: joschi/setup-jdk@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11' # The OpenJDK version to make available on the path
architecture: 'x64' # defaults to 'x64'
distribution: 'temurin'
java-version: '17'
- name: add docker compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
Expand Down Expand Up @@ -211,11 +206,11 @@ jobs:
with:
format: YYYY-MM-DD
utcOffset: "+02:00"
- name: setup java version
uses: joschi/setup-jdk@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11' # The OpenJDK version to make available on the path
architecture: 'x64' # defaults to 'x64'
distribution: 'temurin'
java-version: '17'
- name: add docker compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
Expand Down Expand Up @@ -287,3 +282,42 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
CUSTOM_DOMAIN: docs-api.dasch.swiss
REQUIREMENTS: docs/requirements.txt

fmtcheck:
name: Check Formating
runs-on: ubuntu-latest
steps:
- name: checkout source
uses: actions/checkout@v1
with:
fetch-depth: 15
- name: get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYY-MM-DD
utcOffset: "+02:00"
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: add docker compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
- name: install requirements
run: sudo apt-get install ca-certificates-java expect
- name: Coursier cache
uses: coursier/cache-action@v6
- name: Run fmtcheck
run: make check
- name: Cleanup before cache
shell: bash
run: |
rm -rf "$HOME/.ivy2/local" || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -46,7 +46,7 @@ sipi/images/originals/1111/*

.idea/
.metals/
metals.sbt
**/metals.sbt

.tmp/

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -300,6 +300,10 @@ info: ## print out all variables
@echo "BUILD_TAG: \t\t $(BUILD_TAG)"
@echo "GIT_EMAIL: \t\t $(GIT_EMAIL)"

.PHONY: check
check: # Run code formating check
@sbt "check"

.PHONY: help
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
Expand Down
9 changes: 4 additions & 5 deletions build.sbt
Expand Up @@ -49,6 +49,9 @@ lazy val root: Project = Project(id = "root", file("."))
publish / skip := true
)

addCommandAlias("fmt", "all root/scalafmtSbt root/scalafmtAll")
addCommandAlias("check", "all root/scalafmtSbtCheck root/scalafmtCheckAll")

//////////////////////////////////////
// DSP's custom SIPI
//////////////////////////////////////
Expand Down Expand Up @@ -98,7 +101,7 @@ lazy val webApiCommonSettings = Seq(

lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
.settings(buildSettings)
.enablePlugins(SbtTwirl, JavaAppPackaging, DockerPlugin, GatlingPlugin, JavaAgent, RevolverPlugin, BuildInfoPlugin)
.enablePlugins(SbtTwirl, JavaAppPackaging, DockerPlugin, GatlingPlugin, JavaAgent, BuildInfoPlugin)
.settings(
name := "webapi",
resolvers ++= Seq(
Expand Down Expand Up @@ -133,10 +136,6 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation", "-Yresolve-term-conflict:package"),
logLevel := Level.Info,
run / javaOptions := webapiJavaRunOptions,
reStart / javaOptions ++= resolvedJavaAgents.value map { resolved =>
"-javaagent:" + resolved.artifact.absolutePath + resolved.agent.arguments
}, // allows sbt-javaagent to work with sbt-revolver
reStart / javaOptions ++= webapiJavaRunOptions,
javaAgents += Dependencies.aspectjweaver,
fork := true, // run tests in a forked JVM
Test / testForkedParallel := false, // run forked tests in parallel
Expand Down
@@ -0,0 +1,20 @@
# 3. Change IIIF Service Manager and Sipi implementation to zlayer

Date: 2022-04-29

## Status

Accepted

## Context

Both `org.knora.webapi.store.iiif.IIIFServiceManager` and `org.knora.webapi.store.iiif.impl.IIIFServiceSipiImpl`
where implemented as Akka-Actors

## Decision

As part of the move from `Akka` to `ZIO`, it was decided that the `IIIFServiceManager` and the `IIIFServiceSipiImpl` is refactored using ZIO.

## Consequences

The usage from other actors stays the same. The actor messages and responses don't change.
3 changes: 2 additions & 1 deletion dsp-api-main/src/main/scala/dsp/api/main/MainApp.scala
@@ -1,6 +1,7 @@
package dsp.api.main

import dsp.schema.repo.{SchemaRepo, SchemaRepoLive}
import dsp.schema.repo.SchemaRepo
import dsp.schema.repo.SchemaRepoLive
import zio.Console.printLine
import zio._

Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Expand Up @@ -33,7 +33,7 @@ object Dependencies {
val zioHttp = "io.d11" %% "zhttp" % ZioHttpVersion
val zioJson = "dev.zio" %% "zio-json" % ZioJsonVersion
val zioPrelude = "dev.zio" %% "zio-prelude" % ZioPreludeVersion
val zioLoggingSlf4j = "dev.zio" %% "zio-logging-slf4j" % ZioLoggingVersion
val zioLogging = "dev.zio" %% "zio-logging" % ZioLoggingVersion
val zioConfig = "dev.zio" %% "zio-config" % ZioConfigVersion
val zioConfigMagnolia = "dev.zio" %% "zio-config-magnolia" % ZioConfigVersion
val zioConfigTypesafe = "dev.zio" %% "zio-config-typesafe" % ZioConfigVersion
Expand Down Expand Up @@ -143,7 +143,7 @@ object Dependencies {
zioConfigTypesafe,
zioHttp,
zioJson,
zioLoggingSlf4j,
zioLogging,
zioPrelude,
zioTest % Test,
zioTestSbt % Test
Expand Down
14 changes: 4 additions & 10 deletions project/plugins.sbt
Expand Up @@ -5,20 +5,17 @@ resolvers ++= Seq(
// please don't remove or merge uncommented to main
addDependencyTreePlugin

// Knora
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.1")

// webapi
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.5")
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")

// ad-hoc plugins - uncomment on demenad and keep it commented out in main branch

Expand All @@ -27,6 +24,3 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

// https://github.com/cb372/sbt-explicit-dependencies
// addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16")

// https://scalameta.org/scalafmt/docs/installation.html#sbt
// addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
4 changes: 2 additions & 2 deletions sipi/scripts/jwt.lua
Expand Up @@ -26,9 +26,9 @@ function get_knora_token()
end

token_issuer = webapi_hostname .. ':' .. webapi_port
server.log("token_issuer:" .. token_issuer, server.loglevel.LOG_DEBUG)
server.log("token_issuer: " .. token_issuer, server.loglevel.LOG_DEBUG)
if token["iss"] ~= token_issuer then
server.log(token_issuer, server.loglevel.LOG_DEBUG)
server.log("Invalid token issuer: " .. token_issuer .. " . Expected: " .. token["iss"], server.loglevel.LOG_DEBUG)
send_error(401, "Invalid token. The token was not issued by the same server that sent the request.")
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/resources/application.conf
Expand Up @@ -296,7 +296,7 @@ app {

shacl {
# The directory that SHACL shapes are loaded from.
shapes-dir = "shacl"
shapes-dir = "../test_data/shacl"
shapes-dir = ${?KNORA_WEBAPI_SHACLE_SHAPES_DIR}
}

Expand Down
5 changes: 4 additions & 1 deletion webapi/src/main/scala/org/knora/webapi/RdfMediaTypes.scala
Expand Up @@ -5,7 +5,10 @@

package org.knora.webapi

import akka.http.scaladsl.model.{ContentType, HttpCharsets, MediaType, MediaTypes}
import akka.http.scaladsl.model.ContentType
import akka.http.scaladsl.model.HttpCharsets
import akka.http.scaladsl.model.MediaType
import akka.http.scaladsl.model.MediaTypes

/**
* Represents media types supported by the Knora API server for representing RDF data, and provides
Expand Down

0 comments on commit 224b664

Please sign in to comment.