Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: responder manager as plain case class #2073

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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