Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor: responder manager as plain case class (#2073)
* refactor: responder manager as plain case class

* docs: add ADR

* docs: update ADR

* add stumps for architecture documentation with mermaid

* build: add missing library to shared project

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
  • Loading branch information
subotic and irinaschubert committed Jun 9, 2022
1 parent c09392d commit 7f55697
Show file tree
Hide file tree
Showing 154 changed files with 3,888 additions and 3,242 deletions.
@@ -0,0 +1,19 @@
# 4. Change ResponderManager to a simple case class

Date: 2022-06-06

## Status

Accepted

## Context

The `org.knora.webapi.responders.ResponderManager` was implemented as an Akka-Actor.

## Decision

In preparation of the move from `Akka` to `ZIO`, it was decided that the `ResponderManager` is refactored using plain `case` classes.

## Consequences

The actor messages and responses don't change. All calls made previously to the `ResponderManager` and the `StorageManager` are now changed to the `ApplicationActor` which will route the calls to either the `ResponderManager` or the `StorageManager` based on the message type. The `ApplicationActor` is the only actor that is allowed to make calls to either the `ResponderManager` or the `StorageManager`. All requests from routes are now routed to the `ApplicationActor`.
29 changes: 29 additions & 0 deletions docs/architecture/flows/http-request-flow.md
@@ -0,0 +1,29 @@
HTTP Request Flow

V1 / V2 / admin:
```mermaid
sequenceDiagram
autonumber
client ->> route: send http request
route ->> authenticator: authenticate user
authenticator ->> route: user authenticated
route ->> application actor: send message
application actor ->> responder manager: forward message
responder manager ->> responder: forward message
responder ->> responder manager: return result
responder manager ->> application actor: forward result
application actor ->> route: forward result
route ->> client: send http response
```

V3:
```mermaid
sequenceDiagram
autonumber
client ->> route: send http request
route ->> authenticator: authenticate user
authenticator ->> route: user authenticated
route ->> handler: call handler method
handler ->> route: return result
route ->> client: send result as http response
```
2 changes: 1 addition & 1 deletion docs/architecture/workspace.dsl
Expand Up @@ -17,5 +17,5 @@ workspace {
}

!adrs decisions

!docs flows
}
28 changes: 14 additions & 14 deletions dsp-shared/src/main/scala/dsp/errors/Errors.scala
Expand Up @@ -5,7 +5,7 @@

package dsp.errors

import akka.event.LoggingAdapter
import com.typesafe.scalalogging.Logger
import org.apache.commons.lang3.SerializationException
import org.apache.commons.lang3.SerializationUtils

Expand Down Expand Up @@ -194,7 +194,7 @@ case class AuthenticationException(
) extends InternalServerException(message)

object AuthenticationException {
def apply(message: String, e: Throwable, log: LoggingAdapter): AuthenticationException =
def apply(message: String, e: Throwable, log: Logger): AuthenticationException =
AuthenticationException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand Down Expand Up @@ -245,7 +245,7 @@ case class StandoffInternalException(message: String, cause: Option[Throwable] =
extends InternalServerException(message, cause)

object StandoffInternalException {
def apply(message: String, e: Throwable, log: LoggingAdapter): StandoffInternalException =
def apply(message: String, e: Throwable, log: Logger): StandoffInternalException =
StandoffInternalException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -259,7 +259,7 @@ case class AssertionException(message: String, cause: Option[Throwable] = None)
extends InternalServerException(message, cause)

object AssertionException {
def apply(message: String, e: Throwable, log: LoggingAdapter): AssertionException =
def apply(message: String, e: Throwable, log: Logger): AssertionException =
AssertionException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -282,7 +282,7 @@ case class TriplestoreConnectionException(message: String, cause: Option[Throwab
extends TriplestoreException(message, cause)

object TriplestoreConnectionException {
def apply(message: String, e: Throwable, log: LoggingAdapter): TriplestoreConnectionException =
def apply(message: String, e: Throwable, log: Logger): TriplestoreConnectionException =
TriplestoreConnectionException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -296,7 +296,7 @@ case class TriplestoreTimeoutException(message: String, cause: Option[Throwable]
extends TriplestoreException(message, cause)

object TriplestoreTimeoutException {
def apply(message: String, e: Throwable, log: LoggingAdapter): TriplestoreTimeoutException =
def apply(message: String, e: Throwable, log: Logger): TriplestoreTimeoutException =
TriplestoreTimeoutException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -310,7 +310,7 @@ case class TriplestoreUnsupportedFeatureException(message: String, cause: Option
extends TriplestoreException(message, cause)

object TriplestoreUnsupportedFeatureException {
def apply(message: String, e: Throwable, log: LoggingAdapter): TriplestoreUnsupportedFeatureException =
def apply(message: String, e: Throwable, log: Logger): TriplestoreUnsupportedFeatureException =
TriplestoreUnsupportedFeatureException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -324,7 +324,7 @@ case class TriplestoreInternalException(message: String, cause: Option[Throwable
extends TriplestoreException(message, cause)

object TriplestoreInternalException {
def apply(message: String, e: Throwable, log: LoggingAdapter): TriplestoreInternalException =
def apply(message: String, e: Throwable, log: Logger): TriplestoreInternalException =
TriplestoreInternalException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -338,7 +338,7 @@ case class TriplestoreResponseException(message: String, cause: Option[Throwable
extends TriplestoreException(message, cause)

object TriplestoreResponseException {
def apply(message: String, e: Throwable, log: LoggingAdapter): TriplestoreResponseException =
def apply(message: String, e: Throwable, log: Logger): TriplestoreResponseException =
TriplestoreResponseException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -351,7 +351,7 @@ case class InconsistentRepositoryDataException(message: String, cause: Option[Th
extends InternalServerException(message, cause)

object InconsistentRepositoryDataException {
def apply(message: String, e: Throwable, log: LoggingAdapter): InconsistentRepositoryDataException =
def apply(message: String, e: Throwable, log: Logger): InconsistentRepositoryDataException =
InconsistentRepositoryDataException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand All @@ -368,7 +368,7 @@ case class InvalidApiJsonException(message: String, cause: Option[Throwable] = N
extends InternalServerException(message, cause)

object InvalidApiJsonException {
def apply(message: String, e: Throwable, log: LoggingAdapter): InvalidApiJsonException =
def apply(message: String, e: Throwable, log: Logger): InvalidApiJsonException =
InvalidApiJsonException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))
}

Expand Down Expand Up @@ -447,7 +447,7 @@ case class SipiException(message: String, cause: Option[Throwable] = None)
extends InternalServerException(message, cause)

object SipiException {
def apply(message: String, e: Throwable, log: LoggingAdapter): SipiException =
def apply(message: String, e: Throwable, log: Logger): SipiException =
SipiException(message, Some(ExceptionUtil.logAndWrapIfNotSerializable(e, log)))

def apply(message: String, e: Throwable): SipiException =
Expand Down Expand Up @@ -533,11 +533,11 @@ object ExceptionUtil {
* @param e the exception to be checked.
* @return the same exception, or a [[WrapperException]].
*/
def logAndWrapIfNotSerializable(e: Throwable, log: LoggingAdapter): Throwable =
def logAndWrapIfNotSerializable(e: Throwable, log: Logger): Throwable =
if (isSerializable(e)) {
e
} else {
log.error(e, e.toString)
log.error(e.toString)
WrapperException(e)
}
}
1 change: 1 addition & 0 deletions project/Dependencies.scala
Expand Up @@ -180,6 +180,7 @@ object Dependencies {
commonsLang3,
commonsValidator,
gwtServlet,
scalaLogging,
zioPrelude,
zioTest % Test,
zioTestSbt % Test
Expand Down
1 change: 1 addition & 0 deletions webapi/src/main/resources/logback.xml
Expand Up @@ -37,6 +37,7 @@

<logger name="org.knora" level="INFO"/>
<logger name="org.knora.webapi" level="INFO"/>
<logger name="org.knora.webapi.app.ApplicationActor" level="INFO"/>
<logger name="org.knora.webapi.util.cache" level="ERROR"/>
<logger name="org.knora.webapi.util.PermissionUtilADM" level="INFO"/>
<logger name="org.knora.webapi.update.UpdateRepository" level="INFO"/>
Expand Down

0 comments on commit 7f55697

Please sign in to comment.