Skip to content

Commit 933f91e

Browse files
authored
chore(deps): bump ZIO version (DEV-893) (#2056)
1 parent 2a695ec commit 933f91e

19 files changed

Lines changed: 92 additions & 78 deletions

File tree

‎build.sbt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
133133
Test / exportJars := true
134134
)
135135
.settings(
136-
scalacOptions ++= Seq("-feature", "-unchecked", "-deprecation", "-Yresolve-term-conflict:package"),
136+
scalacOptions ++= Seq(
137+
"-feature",
138+
"-unchecked",
139+
"-deprecation",
140+
"-Yresolve-term-conflict:package",
141+
"-Ymacro-annotations"
142+
),
137143
logLevel := Level.Info,
138144
run / javaOptions := webapiJavaRunOptions,
139145
javaAgents += Dependencies.aspectjweaver,

‎project/Dependencies.scala‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ object Dependencies {
2020
val jenaVersion = "4.4.0"
2121
val metricsVersion = "4.0.1"
2222
val scalaVersion = "2.13.8"
23-
val ZioVersion = "2.0.0-RC5"
23+
val ZioVersion = "2.0.0-RC6"
2424
val ZioHttpVersion = "2.0.0-RC4"
2525
val ZioJsonVersion = "0.3.0-RC3"
26-
val ZioConfigVersion = "3.0.0-RC8"
26+
val ZioConfigVersion = "3.0.0-RC9"
2727
val ZioSchemaVersion = "0.2.0-RC5"
28-
val ZioLoggingVersion = "2.0.0-RC8"
28+
val ZioLoggingVersion = "2.0.0-RC9"
2929
val ZioZmxVersion = "2.0.0-RC4"
3030
val ZioPreludeVersion = "1.0.0-RC13"
3131

3232
// ZIO - all Scala 3 compatible
3333
val zio = "dev.zio" %% "zio" % ZioVersion
34+
val zioMacros = "dev.zio" %% "zio-macros" % ZioVersion
3435
val zioHttp = "io.d11" %% "zhttp" % ZioHttpVersion
3536
val zioJson = "dev.zio" %% "zio-json" % ZioJsonVersion
3637
val zioPrelude = "dev.zio" %% "zio-prelude" % ZioPreludeVersion
@@ -145,13 +146,15 @@ object Dependencies {
145146
zioHttp,
146147
zioJson,
147148
zioLogging,
149+
zioMacros,
148150
zioPrelude,
149151
zioTest % Test,
150152
zioTestSbt % Test
151153
)
152154

153155
val dspApiMainLibraryDependencies = Seq(
154-
zio
156+
zio,
157+
zioMacros
155158
)
156159

157160
val schemaApiLibraryDependencies = Seq(

‎webapi/src/main/scala/org/knora/webapi/app/Main.scala‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ import java.util.concurrent.TimeUnit
2525
*/
2626
object Main extends scala.App with LiveCore {
2727

28-
// The ZIO runtime used to run functional effects
29-
val runtime = Runtime(ZEnvironment.empty, RuntimeConfig.default @@ Logging.fromInfo)
28+
/**
29+
* Unsafely creates a `Runtime` from a `ZLayer` whose resources will be
30+
* allocated immediately, and not released until the `Runtime` is shut down or
31+
* the end of the application.
32+
*/
33+
val runtime = Runtime.unsafeFromLayer(Logging.fromInfo)
3034

3135
// The effect for building a cache service manager, a IIIF service manager, and AppConfig.
3236
val managers = for {

‎webapi/src/main/scala/org/knora/webapi/core/Logging.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.knora.webapi.core
22

33
import zio.LogLevel
4-
import zio.RuntimeConfigAspect
54
import zio.logging.LogFormat._
65
import zio.logging._
6+
import zio.ZLayer
77

88
object Logging {
99
val logFormat = "[correlation-id = %s] %s"
@@ -12,14 +12,14 @@ object Logging {
1212
val textFormat: LogFormat =
1313
timestamp.fixed(32).color(LogColor.BLUE) |-| level.highlight.fixed(14) |-| line.highlight
1414

15-
val fromDebug: RuntimeConfigAspect = {
15+
val fromDebug: ZLayer[Any, Nothing, Unit] = {
1616
console(
1717
logLevel = LogLevel.Debug,
1818
format = textFormat
1919
)
2020
}
2121

22-
val fromInfo: RuntimeConfigAspect = {
22+
val fromInfo: ZLayer[Any, Nothing, Unit] = {
2323
console(
2424
logLevel = LogLevel.Info,
2525
format = textFormat

‎webapi/src/main/scala/org/knora/webapi/store/cacheservice/api/CacheService.scala‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import org.knora.webapi.messages.admin.responder.usersmessages.UserADM
1111
import org.knora.webapi.messages.admin.responder.usersmessages.UserIdentifierADM
1212
import org.knora.webapi.messages.store.cacheservicemessages.CacheServiceStatusResponse
1313
import zio._
14+
import zio.macros.accessible
1415

1516
/**
1617
* Cache Service Interface
1718
*/
19+
@accessible
1820
trait CacheService {
1921
def putUserADM(value: UserADM): Task[Unit]
2022
def getUserADM(identifier: UserIdentifierADM): Task[Option[UserADM]]
@@ -46,4 +48,3 @@ trait CacheService {
4648
* } yield ()
4749
* }}}
4850
*/
49-
object CacheService extends Accessible[CacheService]

‎webapi/src/main/scala/org/knora/webapi/store/cacheservice/impl/CacheServiceInMemImpl.scala‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ case class CacheServiceInMemImpl(
157157
val emptyValueError = EmptyValue("The string value is empty. Aborting write to cache.")
158158

159159
(for {
160-
key <- if (key.isEmpty()) Task.fail(emptyKeyError) else Task.succeed(key)
161-
value <- if (value.isEmpty()) Task.fail(emptyValueError) else Task.succeed(value)
160+
key <- if (key.isEmpty()) ZIO.fail(emptyKeyError) else ZIO.succeed(key)
161+
value <- if (value.isEmpty()) ZIO.fail(emptyValueError) else ZIO.succeed(value)
162162
_ <- lut.put(key, value).commit
163163
} yield ()).tap(_ => ZIO.logDebug(s"Wrote key: $key with value: $value to cache."))
164164
}
@@ -196,7 +196,7 @@ case class CacheServiceInMemImpl(
196196
* Pings the in-memory cache to see if it is available.
197197
*/
198198
def ping(): Task[CacheServiceStatusResponse] =
199-
Task.succeed(CacheServiceStatusOK)
199+
ZIO.succeed(CacheServiceStatusOK)
200200
}
201201

202202
/**

‎webapi/src/main/scala/org/knora/webapi/store/cacheservice/impl/CacheServiceRedisImpl.scala‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
147147
* @param key the key.
148148
* @param value the value.
149149
*/
150-
def putStringValue(key: String, value: String): Task[Unit] = Task.attempt {
150+
def putStringValue(key: String, value: String): Task[Unit] = ZIO.attempt {
151151

152152
if (key.isEmpty)
153153
throw EmptyKey("The key under which the value should be written is empty. Aborting writing to redis.")
@@ -176,18 +176,18 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
176176
conn <- ZIO.attempt(pool.getResource)
177177
value <- ZIO.attemptBlocking(conn.get(key))
178178
res <-
179-
if (value == "nil".getBytes) Task.succeed(None)
180-
else Task.succeed(Some(value))
179+
if (value == "nil".getBytes) ZIO.succeed(None)
180+
else ZIO.succeed(Some(value))
181181
_ = conn.close()
182182
} yield res
183-
}.catchAll(ex => ZIO.logError(s"Reading string from Redis failed: ${ex.getMessage}") *> Task.succeed(None))
183+
}.catchAll(ex => ZIO.logError(s"Reading string from Redis failed: ${ex.getMessage}") *> ZIO.succeed(None))
184184

185185
/**
186186
* Removes values for the provided keys. Any invalid keys are ignored.
187187
*
188188
* @param keys the keys.
189189
*/
190-
def removeValues(keys: Set[String]): Task[Unit] = Task.attemptBlocking {
190+
def removeValues(keys: Set[String]): Task[Unit] = ZIO.attemptBlocking {
191191

192192
// del takes a vararg so I nee to convert the set to a swq and then to vararg
193193
val conn: Jedis = pool.getResource
@@ -206,7 +206,7 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
206206
* @param key the key.
207207
* @param value the value.
208208
*/
209-
private def putBytesValue(key: String, value: Array[Byte]): Task[Unit] = Task.attemptBlocking {
209+
private def putBytesValue(key: String, value: Array[Byte]): Task[Unit] = ZIO.attemptBlocking {
210210

211211
if (key.isEmpty)
212212
throw EmptyKey("The key under which the value should be written is empty. Aborting writing to redis.")
@@ -236,15 +236,15 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
236236
conn <- ZIO.attempt(pool.getResource).onError(ZIO.logErrorCause(_)).orDie
237237
value <- ZIO.attemptBlocking(conn.get(key.getBytes))
238238
res <-
239-
if (value == "nil".getBytes) Task.succeed(None)
240-
else Task.succeed(Some(value))
239+
if (value == "nil".getBytes) ZIO.succeed(None)
240+
else ZIO.succeed(Some(value))
241241
_ = conn.close()
242242
} yield res
243243

244244
/**
245245
* Flushes (removes) all stored content from the Redis store.
246246
*/
247-
def flushDB(requestingUser: UserADM): Task[Unit] = Task.attemptBlocking {
247+
def flushDB(requestingUser: UserADM): Task[Unit] = ZIO.attemptBlocking {
248248

249249
if (!requestingUser.isSystemUser) {
250250
throw ForbiddenException("Only the system user is allowed to perform this operation.")
@@ -265,7 +265,7 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
265265
/**
266266
* Pings the Redis store to see if it is available.
267267
*/
268-
def ping(): Task[CacheServiceStatusResponse] = Task.attemptBlocking {
268+
def ping(): Task[CacheServiceStatusResponse] = ZIO.attemptBlocking {
269269

270270
val conn: Jedis = pool.getResource
271271
try {
@@ -274,7 +274,7 @@ case class CacheServiceRedisImpl(pool: JedisPool) extends CacheService {
274274
} finally {
275275
conn.close()
276276
}
277-
}.catchAll(ex => ZIO.logError(s"Ping failed: ${ex.getMessage}") *> Task.succeed(CacheServiceStatusNOK))
277+
}.catchAll(ex => ZIO.logError(s"Ping failed: ${ex.getMessage}") *> ZIO.succeed(CacheServiceStatusNOK))
278278
}
279279

280280
object CacheServiceRedisImpl {

‎webapi/src/main/scala/org/knora/webapi/store/iiif/api/IIIFService.scala‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest
99
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse
1010
import org.knora.webapi.messages.v2.responder.SuccessResponseV2
1111
import zio._
12+
import zio.macros.accessible
1213

14+
@accessible
1315
trait IIIFService {
1416

1517
/**
@@ -50,5 +52,3 @@ trait IIIFService {
5052
*/
5153
def getStatus(): Task[IIIFServiceStatusResponse]
5254
}
53-
54-
object IIIFService extends Accessible[IIIFService]

‎webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ import scala.util.Try
2525

2626
object ActorUtil {
2727

28+
/**
29+
* Unsafely creates a `Runtime` from a `ZLayer` whose resources will be
30+
* allocated immediately, and not released until the `Runtime` is shut down or
31+
* the end of the application.
32+
*/
33+
private val runtime = Runtime.unsafeFromLayer(Logging.fromInfo)
34+
2835
/**
2936
* Transforms ZIO Task returned to the receive method of an actor to a message. Used mainly during the refactoring
3037
* phase, to be able to return ZIO inside an Actor.
@@ -37,7 +44,7 @@ object ActorUtil {
3744
* Since this is the "edge" of the ZIO world for now, we need to log all errors that ZIO has potentially accumulated
3845
*/
3946
def zio2Message[A](sender: ActorRef, zioTask: zio.Task[A], log: LoggingAdapter, appConfig: AppConfig): Unit =
40-
Runtime(ZEnvironment.empty, RuntimeConfig.default @@ Logging.fromInfo)
47+
runtime
4148
.unsafeRunTask(
4249
zioTask.foldCauseZIO(cause => handleCause(cause, sender), success => ZIO.succeed(sender ! success))
4350
)

‎webapi/src/test/scala/org/knora/webapi/AsyncCoreSpec.scala‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import org.scalatest.matchers.should.Matchers
5252
import org.scalatest.wordspec.AsyncWordSpecLike
5353
import zio.&
5454
import zio.Runtime
55-
import zio.RuntimeConfig
5655
import zio.ZEnvironment
5756
import zio.ZIO
5857
import zio.ZLayer
@@ -117,7 +116,7 @@ abstract class AsyncCoreSpec(_system: ActorSystem)
117116
val log: LoggingAdapter = akka.event.Logging(system, this.getClass)
118117

119118
// The ZIO runtime used to run functional effects
120-
val runtime = Runtime(ZEnvironment.empty, RuntimeConfig.default @@ Logging.fromInfo)
119+
val runtime = Runtime.unsafeFromLayer(Logging.fromInfo)
121120

122121
// The effect for building a cache service manager and a IIIF service manager.
123122
val managers = for {

0 commit comments

Comments
 (0)