From f1c99d251d79a6588486cf7b1c4137a628ea0963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Fri, 26 Apr 2024 10:43:19 +0200 Subject: [PATCH] chore: Remove startup dependency on Sipi, remove checking iiif server available on startup (#3218) --- .../knora/sipi/SipiClientTestDelegator.scala | 7 --- .../scala/org/knora/webapi/CoreSpec.scala | 8 +--- .../test/scala/org/knora/webapi/E2ESpec.scala | 11 ++--- .../scala/org/knora/webapi/E2EZSpec.scala | 2 +- .../org/knora/webapi/ITKnoraLiveSpec.scala | 2 +- .../test/scala/org/knora/webapi/R2RSpec.scala | 7 +-- .../store/iiif/impl/SipiServiceMock.scala | 2 - .../org/knora/webapi/core/AppServer.scala | 43 ++----------------- .../knora/webapi/core/domain/AppState.scala | 2 - .../store/sipimessages/SipiMessages.scala | 25 ----------- .../api/ManagementEndpoints.scala | 2 - .../iiif/IIIFRequestMessageHandler.scala | 2 - .../webapi/store/iiif/api/SipiService.scala | 5 --- .../store/iiif/impl/SipiServiceLive.scala | 9 ---- .../valuemessages/ValueContentV2Spec.scala | 3 -- 15 files changed, 12 insertions(+), 118 deletions(-) diff --git a/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala b/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala index 32cd860eba..1fb5691cab 100644 --- a/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala +++ b/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala @@ -12,7 +12,6 @@ import zio.nio.file.Path import org.knora.webapi.config.AppConfig import org.knora.webapi.messages.store.sipimessages.DeleteTemporaryFileRequest -import org.knora.webapi.messages.store.sipimessages.IIIFServiceStatusResponse import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse @@ -99,12 +98,6 @@ case class SipiServiceTestDelegator( override def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = sipiService.getTextFileRequest(textFileRequest) - /** - * Tries to access the IIIF Service. - */ - override def getStatus(): Task[IIIFServiceStatusResponse] = - sipiService.getStatus() - /** * Downloads an asset from Sipi. * diff --git a/integration/src/test/scala/org/knora/webapi/CoreSpec.scala b/integration/src/test/scala/org/knora/webapi/CoreSpec.scala index 21cddab470..7c2f6670fd 100644 --- a/integration/src/test/scala/org/knora/webapi/CoreSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/CoreSpec.scala @@ -101,14 +101,8 @@ abstract class CoreSpec /* Here we start our app and initialize the repository before each suit runs */ Unsafe.unsafe { implicit u => runtime.unsafe - .run( - (for { - _ <- AppServer.testWithoutSipi - _ <- prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo") - } yield ()), - ) + .run(AppServer.test *> prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo")) .getOrThrow() - } final override def afterAll(): Unit = diff --git a/integration/src/test/scala/org/knora/webapi/E2ESpec.scala b/integration/src/test/scala/org/knora/webapi/E2ESpec.scala index 7234eaa55e..07d521a4da 100644 --- a/integration/src/test/scala/org/knora/webapi/E2ESpec.scala +++ b/integration/src/test/scala/org/knora/webapi/E2ESpec.scala @@ -7,6 +7,9 @@ package org.knora.webapi import com.typesafe.scalalogging._ import org.apache.pekko +import org.apache.pekko.http.scaladsl.client.RequestBuilding +import org.apache.pekko.http.scaladsl.model._ +import org.apache.pekko.testkit.TestKitBase import org.scalatest.BeforeAndAfterAll import org.scalatest.concurrent.ScalaFutures import org.scalatest.matchers.should.Matchers @@ -38,10 +41,6 @@ import org.knora.webapi.testservices.TestClientService import org.knora.webapi.util.FileUtil import org.knora.webapi.util.LogAspect -import pekko.http.scaladsl.client.RequestBuilding -import pekko.http.scaladsl.model._ -import pekko.testkit.TestKitBase - /** * This class can be used in End-to-End testing. It starts the DSP stack * and provides access to settings and logging. @@ -110,9 +109,7 @@ abstract class E2ESpec final override def beforeAll(): Unit = /* Here we start our app and initialize the repository before each suit runs */ - UnsafeZioRun.runOrThrow( - AppServer.testWithoutSipi *> (prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo")), - ) + UnsafeZioRun.runOrThrow(AppServer.test *> (prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo"))) final override def afterAll(): Unit = /* Stop ZIO runtime and release resources (e.g., running docker containers) */ diff --git a/integration/src/test/scala/org/knora/webapi/E2EZSpec.scala b/integration/src/test/scala/org/knora/webapi/E2EZSpec.scala index 6f63173197..62919879a6 100644 --- a/integration/src/test/scala/org/knora/webapi/E2EZSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/E2EZSpec.scala @@ -28,7 +28,7 @@ abstract class E2EZSpec extends ZIOSpecDefault with TestStartupUtils { private def prepare: ZIO[AppServer.AppServerEnvironment, Throwable, AppServer] = for { appServer <- AppServer.init() - _ <- appServer.start(requiresAdditionalRepositoryChecks = false, requiresIIIFService = false).orDie + _ <- appServer.start(requiresAdditionalRepositoryChecks = false).orDie _ <- prepareRepository(rdfDataObjects) } yield appServer diff --git a/integration/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala b/integration/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala index 2f57f19d13..eb43e66605 100644 --- a/integration/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala @@ -104,7 +104,7 @@ abstract class ITKnoraLiveSpec runtime.unsafe .run( for { - _ <- AppServer.testWithSipi + _ <- AppServer.test _ <- prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo") } yield (), ) diff --git a/integration/src/test/scala/org/knora/webapi/R2RSpec.scala b/integration/src/test/scala/org/knora/webapi/R2RSpec.scala index ce65cf96c8..e38b16a282 100644 --- a/integration/src/test/scala/org/knora/webapi/R2RSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/R2RSpec.scala @@ -83,12 +83,7 @@ abstract class R2RSpec /* Here we start our app and initialize the repository before each suit runs */ Unsafe.unsafe { implicit u => runtime.unsafe - .run( - for { - _ <- AppServer.testWithoutSipi - _ <- prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo") - } yield (), - ) + .run(AppServer.test *> prepareRepository(rdfDataObjects) @@ LogAspect.logSpan("prepare-repo")) .getOrThrow() } diff --git a/integration/src/test/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala b/integration/src/test/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala index 2b7efd57c6..f58cfd175f 100644 --- a/integration/src/test/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala +++ b/integration/src/test/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala @@ -61,8 +61,6 @@ case class SipiServiceMock() extends SipiService { override def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = ??? - override def getStatus(): Task[IIIFServiceStatusResponse] = ZIO.succeed(IIIFServiceStatusOK) - override def downloadAsset(asset: Asset, targetDir: Path, user: User): Task[Option[Path]] = ??? override def getFileMetadataFromDspIngest( diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala index 44bbef5be4..2299af9d68 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppServer.scala @@ -10,8 +10,6 @@ import zio._ import org.knora.webapi.config.AppConfig import org.knora.webapi.core.domain.AppState -import org.knora.webapi.messages.store.sipimessages.IIIFServiceStatusNOK -import org.knora.webapi.messages.store.sipimessages.IIIFServiceStatusOK import org.knora.webapi.messages.util.KnoraSystemInstances import org.knora.webapi.slice.ontology.repo.service.OntologyCache import org.knora.webapi.store.iiif.api.SipiService @@ -74,27 +72,6 @@ final case class AppServer( _ <- state.set(AppState.OntologiesReady) } yield () - /** - * Checks if the IIIF service is running - * - * @param requiresIIIFService If `true`, checks the status of the IIIFService instance, otherwise returns () - */ - private def checkIIIFService(requiresIIIFService: Boolean): UIO[Unit] = - for { - _ <- state.set(AppState.WaitingForIIIFService) - _ <- sipiService - .getStatus() - .flatMap { - case IIIFServiceStatusOK => - ZIO.logInfo("IIIF service running") - case IIIFServiceStatusNOK => - ZIO.logError("IIIF service not running") *> ZIO.die(new Exception("IIIF service not running")) - } - .when(requiresIIIFService) - .orDie - _ <- state.set(AppState.IIIFServiceReady) - } yield () - /** * Initiates the startup of the DSP-API server. * @@ -104,14 +81,12 @@ final case class AppServer( */ def start( requiresAdditionalRepositoryChecks: Boolean, - requiresIIIFService: Boolean, ): Task[Unit] = for { _ <- ZIO.logInfo("=> Startup checks initiated") _ <- checkTriplestoreService _ <- upgradeRepository(requiresAdditionalRepositoryChecks) _ <- populateOntologyCaches(requiresAdditionalRepositoryChecks) - _ <- checkIIIFService(requiresIIIFService) _ <- ZIO.logInfo("=> Startup checks finished") _ <- ZIO.logInfo(s"DSP-API Server started: ${appConfig.knoraApi.internalKnoraApiBaseUrl}") _ <- ZIO.logWarning("Resetting DB over HTTP is turned ON").when(appConfig.allowReloadOverHttp) @@ -146,26 +121,16 @@ object AppServer { val make: URIO[AppServerEnvironment, Unit] = for { appServer <- AppServer.init() - _ <- appServer.start(requiresAdditionalRepositoryChecks = true, requiresIIIFService = true).orDie - } yield () - - /** - * The test AppServer with Sipi, which initiates the startup checks. Before this effect does what it does, - * the complete server should have already been started. - */ - val testWithSipi: ZIO[AppServerEnvironment, Nothing, Unit] = - for { - appServer <- AppServer.init() - _ <- appServer.start(requiresAdditionalRepositoryChecks = false, requiresIIIFService = true).orDie + _ <- appServer.start(requiresAdditionalRepositoryChecks = true).orDie } yield () /** - * The test AppServer without Sipi, which initiates the startup checks. Before this effect does what it does, + * The test AppServer with or without Sipi, which initiates the startup checks. Before this effect does what it does, * the complete server should have already been started. */ - val testWithoutSipi: ZIO[AppServerEnvironment, Nothing, Unit] = + val test: ZIO[AppServerEnvironment, Nothing, Unit] = for { appServer <- AppServer.init() - _ <- appServer.start(requiresAdditionalRepositoryChecks = false, requiresIIIFService = false).orDie + _ <- appServer.start(requiresAdditionalRepositoryChecks = false).orDie } yield () } diff --git a/webapi/src/main/scala/org/knora/webapi/core/domain/AppState.scala b/webapi/src/main/scala/org/knora/webapi/core/domain/AppState.scala index 3666ab7c49..14367b8a08 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/domain/AppState.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/domain/AppState.scala @@ -17,8 +17,6 @@ object AppState { case object RepositoryUpToDate extends AppState case object LoadingOntologies extends AppState case object OntologiesReady extends AppState - case object WaitingForIIIFService extends AppState - case object IIIFServiceReady extends AppState case object MaintenanceMode extends AppState case object Running extends AppState } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala b/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala index dd419b6db5..be462ef352 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala @@ -57,31 +57,6 @@ case class SipiGetTextFileRequest(fileUrl: String, requestingUser: User, senderN */ case class SipiGetTextFileResponse(content: String) -////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// IIIF Request ADM - -sealed trait IIIFRequestADM extends IIIFRequest - -/** - * Queries IIIF Service status. - */ -case object IIIFServiceGetStatus extends IIIFRequestADM - -/** - * Represents a response for [[IIIFServiceGetStatus]]. - */ -sealed trait IIIFServiceStatusResponse - -/** - * Represents a positive response for [[IIIFServiceGetStatus]]. - */ -case object IIIFServiceStatusOK extends IIIFServiceStatusResponse - -/** - * Represents a negative response for [[IIIFServiceGetStatus]]. - */ -case object IIIFServiceStatusNOK extends IIIFServiceStatusResponse - /** * Represents the information that Sipi returns about each file that has been uploaded. * diff --git a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/api/ManagementEndpoints.scala b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/api/ManagementEndpoints.scala index 097a9fc79f..c9a9724063 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/api/ManagementEndpoints.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/api/ManagementEndpoints.scala @@ -67,8 +67,6 @@ object HealthResponse { case AppState.RepositoryUpToDate => unhealthy("Repository up to date. Please retry later.") case AppState.LoadingOntologies => unhealthy("Loading ontologies. Please retry later.") case AppState.OntologiesReady => unhealthy("Ontologies ready. Please retry later.") - case AppState.WaitingForIIIFService => unhealthy("Waiting for IIIF service. Please retry later.") - case AppState.IIIFServiceReady => unhealthy("IIIF service ready. Please retry later.") case AppState.MaintenanceMode => unhealthy("Application is in maintenance mode. Please retry later.") case AppState.Running => healthy } diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala index 1f189de86d..7ea2914232 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala @@ -12,7 +12,6 @@ import org.knora.webapi.core.MessageRelay import org.knora.webapi.messages.ResponderRequest import org.knora.webapi.messages.store.sipimessages.DeleteTemporaryFileRequest import org.knora.webapi.messages.store.sipimessages.IIIFRequest -import org.knora.webapi.messages.store.sipimessages.IIIFServiceGetStatus import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.store.iiif.api.SipiService @@ -28,7 +27,6 @@ final case class IIIFRequestMessageHandlerLive(iiifService: SipiService) extends case req: MoveTemporaryFileToPermanentStorageRequest => iiifService.moveTemporaryFileToPermanentStorage(req) case req: DeleteTemporaryFileRequest => iiifService.deleteTemporaryFile(req) case req: SipiGetTextFileRequest => iiifService.getTextFileRequest(req) - case IIIFServiceGetStatus => iiifService.getStatus() case other => ZIO.logError(s"IIIFServiceManager received an unexpected message: $other") } } diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala index 7e519ead12..959bcbabbf 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala @@ -103,11 +103,6 @@ trait SipiService { */ def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] - /** - * Tries to access the IIIF Service. - */ - def getStatus(): Task[IIIFServiceStatusResponse] - /** * Downloads an asset from Sipi. * diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala index 158908286a..034fec0b14 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala @@ -234,15 +234,6 @@ final case class SipiServiceLive( } yield SipiGetTextFileResponse(responseStr) } - /** - * Tries to access the IIIF Service to check if Sipi is running. - */ - def getStatus(): Task[IIIFServiceStatusResponse] = - for { - request <- ZIO.succeed(new HttpGet(sipiConfig.internalBaseUrl + "/server/test.html")) - response <- doSipiRequest(request).fold(_ => IIIFServiceStatusNOK, _ => IIIFServiceStatusOK) - } yield response - /** * Makes an HTTP request to Sipi and returns the response. * diff --git a/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala b/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala index 414199f004..f166e9f68d 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala @@ -17,7 +17,6 @@ import zio.test.assertTrue import dsp.errors.AssertionException import org.knora.webapi.messages.store.sipimessages.DeleteTemporaryFileRequest -import org.knora.webapi.messages.store.sipimessages.IIIFServiceStatusResponse import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse @@ -95,8 +94,6 @@ object ValueContentV2Spec extends ZIOSpecDefault { ZIO.dieMessage("unsupported operation") def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = ZIO.dieMessage("unsupported operation") - def getStatus(): Task[IIIFServiceStatusResponse] = - ZIO.dieMessage("unsupported operation") def downloadAsset(asset: Asset, targetDir: Path, user: User): Task[Option[Path]] = ZIO.dieMessage("unsupported operation") })