Skip to content

Commit

Permalink
Move service dependency to kernel module
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Oct 31, 2024
1 parent 804ff77 commit bba7e1e
Show file tree
Hide file tree
Showing 31 changed files with 92 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ch.epfl.bluebrain.nexus.delta.dependency

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import doobie.syntax.all._

Expand All @@ -14,7 +13,7 @@ import doobie.syntax.all._
class PostgresServiceDependency(xas: Transactors) extends ServiceDependency {

private val regex = "( ?PostgreSQL )([^ ]+)(.*)".r
private val serviceName = Name.unsafe("postgres")
private val serviceName = "postgres"
override def serviceDescription: IO[ServiceDescription] =
sql"select version()"
.query[String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package ch.epfl.bluebrain.nexus.delta.routes
import akka.http.scaladsl.server.Route
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.config.DescriptionConfig
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.{PluginDescription, ServiceDescription}
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.{ComponentDescription, ServiceDependency}
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.routes.VersionRoutes.VersionBundle
import ch.epfl.bluebrain.nexus.delta.sdk.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.acls.model.AclAddress
import ch.epfl.bluebrain.nexus.delta.sdk.directives.AuthDirectives
import ch.epfl.bluebrain.nexus.delta.sdk.directives.DeltaDirectives._
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.{HttpResponseFields, RdfMarshalling}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.{PluginDescription, ServiceDescription}
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, ComponentDescription, Name}
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, Name}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.version
import io.circe.syntax._
import io.circe.{Encoder, JsonObject}
import io.circe.syntax._

import scala.collection.immutable.Iterable

Expand Down Expand Up @@ -63,15 +63,15 @@ object VersionRoutes {

private[routes] object VersionBundle {
private def toMap(values: Iterable[ComponentDescription]): Map[String, String] =
values.map(desc => desc.name.value -> desc.version).toMap
values.map(desc => desc.name -> desc.version).toMap

implicit private val versionBundleEncoder: Encoder.AsObject[VersionBundle] =
Encoder.encodeJsonObject.contramapObject { case VersionBundle(main, dependencies, plugins, env) =>
JsonObject(
main.name.value -> main.version.asJson,
"dependencies" -> toMap(dependencies).asJson,
"plugins" -> toMap(plugins).asJson,
"environment" -> env.asJson
main.name -> main.version.asJson,
"dependencies" -> toMap(dependencies).asJson,
"plugins" -> toMap(plugins).asJson,
"environment" -> env.asJson
)
}

Expand All @@ -95,6 +95,13 @@ object VersionRoutes {
cr: RemoteContextResolution,
ordering: JsonKeyOrdering
): VersionRoutes = {
new VersionRoutes(identities, aclCheck, ServiceDescription(cfg.name, cfg.version), plugins, dependencies, cfg.env)
new VersionRoutes(
identities,
aclCheck,
ServiceDescription(cfg.name.value, cfg.version),
plugins,
dependencies,
cfg.env
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cats.data.NonEmptyList
import cats.effect.{Clock, IO, Resource, Sync}
import ch.epfl.bluebrain.nexus.delta.Main.pluginsMaxPriority
import ch.epfl.bluebrain.nexus.delta.config.AppConfig
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.kernel.utils.{ClasspathResourceLoader, IOFuture, UUIDF}
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.contexts
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdJavaApi}
Expand All @@ -23,7 +24,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.http.StrictEntity
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.ServiceAccount
import ch.epfl.bluebrain.nexus.delta.sdk.jws.JWSPayloadHelper
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.{RdfExceptionHandler, RdfRejectionHandler}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model._
import ch.epfl.bluebrain.nexus.delta.sdk.plugin.PluginDef
import ch.epfl.bluebrain.nexus.delta.sdk.projects.{OwnerPermissionsScopeInitialization, ProjectsConfig, ScopeInitializationErrorStore}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package ch.epfl.bluebrain.nexus.delta.wiring
import ch.epfl.bluebrain.nexus.delta.Main.pluginsMaxPriority
import ch.epfl.bluebrain.nexus.delta.config.AppConfig
import ch.epfl.bluebrain.nexus.delta.dependency.PostgresServiceDependency
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.RemoteContextResolution
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.routes.VersionRoutes
import ch.epfl.bluebrain.nexus.delta.sdk.PriorityRoute
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.{PriorityRoute, ServiceDependency}
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import izumi.distage.model.definition.{Id, ModuleDef}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.dependency

import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.{DoobieScalaTestFixture, PostgresDocker}
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec

Expand All @@ -10,8 +9,7 @@ class PostgresServiceDependencySpec extends CatsEffectSpec with DoobieScalaTestF
"PostgresServiceDependency" should {

"fetch its service name and version" in {
new PostgresServiceDependency(xas).serviceDescription.accepted shouldEqual
ServiceDescription(Name.unsafe("postgres"), "16.4")
new PostgresServiceDependency(xas).serviceDescription.accepted shouldEqual ServiceDescription("postgres", "16.4")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import akka.http.scaladsl.model.headers.OAuth2BearerToken
import akka.http.scaladsl.server.Route
import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.config.DescriptionConfig
import ch.epfl.bluebrain.nexus.delta.sdk.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.{PluginDescription, ServiceDescription}
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclSimpleCheck
import ch.epfl.bluebrain.nexus.delta.sdk.acls.model.AclAddress
import ch.epfl.bluebrain.nexus.delta.sdk.identities.IdentitiesDummy
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.{PluginDescription, ServiceDescription}
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.{events, version}
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
Expand All @@ -24,17 +24,14 @@ class VersionRoutesSpec extends BaseRouteSpec {

private val asAlice = addCredentials(OAuth2BearerToken("alice"))

private val pluginsInfo =
List(PluginDescription(Name.unsafe("pluginA"), "1.0"), PluginDescription(Name.unsafe("pluginB"), "2.0"))
private val pluginsInfo = List(PluginDescription("pluginA", "1.0"), PluginDescription("pluginB", "2.0"))

private val dependency1 = new ServiceDependency {
override def serviceDescription: IO[ServiceDescription] =
IO.pure(ServiceDescription.unresolved(Name.unsafe("elasticsearch")))
override def serviceDescription: IO[ServiceDescription] = IO.pure(ServiceDescription.unresolved("elasticsearch"))
}

private val dependency2 = new ServiceDependency {
override def serviceDescription: IO[ServiceDescription] =
IO.pure(ServiceDescription(Name.unsafe("remoteStorage"), "1.0.0"))
override def serviceDescription: IO[ServiceDescription] = IO.pure(ServiceDescription("remoteStorage", "1.0.0"))
}

private val descriptionConfig = DescriptionConfig(Name.unsafe("delta"), Name.unsafe("dev"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ch.epfl.bluebrain.nexus.delta.sdk.model
package ch.epfl.bluebrain.nexus.delta.kernel.dependency

/**
* The description of a component of the system (service or plugin)
Expand All @@ -9,7 +9,7 @@ sealed trait ComponentDescription extends Product with Serializable {
* @return
* the name of the component
*/
def name: Name
def name: String

/**
* @return
Expand All @@ -28,28 +28,28 @@ object ComponentDescription {
sealed trait ServiceDescription extends ComponentDescription

object ServiceDescription {
final case class ResolvedServiceDescription private (name: Name, version: String) extends ServiceDescription
final case class UnresolvedServiceDescription private (name: Name) extends ServiceDescription {
final case class ResolvedServiceDescription private (name: String, version: String) extends ServiceDescription
final case class UnresolvedServiceDescription private (name: String) extends ServiceDescription {
override val version: String = unknownVersion
}

/**
* Creates a [[ResolvedServiceDescription]] from the passed ''name'' and ''version''.
*/
def apply(name: Name, version: String): ResolvedServiceDescription =
def apply(name: String, version: String): ResolvedServiceDescription =
ResolvedServiceDescription(name, version)

/**
* Creates a [[UnresolvedServiceDescription]] with the passed ''name''.
*/
def unresolved(name: Name): UnresolvedServiceDescription =
def unresolved(name: String): UnresolvedServiceDescription =
UnresolvedServiceDescription(name)
}

/**
* The description of a plugin
*/
final case class PluginDescription(name: Name, version: String) extends ComponentDescription {
final case class PluginDescription(name: String, version: String) extends ComponentDescription {
override def toString: String = s"$name-$version"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.epfl.bluebrain.nexus.delta.sdk
package ch.epfl.bluebrain.nexus.delta.kernel.dependency

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription

/**
* A description of a service that is used by the system
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ch.epfl.bluebrain.nexus.delta.plugins.archive

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.plugin.{Plugin, PluginDef}
import izumi.distage.model.Locator
import izumi.distage.model.definition.ModuleDef
class ArchivePluginDef extends PluginDef {

override val module: ModuleDef = ArchivePluginModule

override val info: PluginDescription = PluginDescription(Name.unsafe("archive"), BuildInfo.version)
override val info: PluginDescription = PluginDescription("archive", BuildInfo.version)

override def initialize(locator: Locator): IO[Plugin] = IO.pure(ArchivePlugin)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.plugin.{Plugin, PluginDef}
import izumi.distage.model.Locator
import izumi.distage.model.definition.ModuleDef
Expand All @@ -11,7 +10,7 @@ class BlazegraphPluginDef extends PluginDef {

override def module: ModuleDef = new BlazegraphPluginModule(priority)

override val info: PluginDescription = PluginDescription(Name.unsafe("blazegraph"), BuildInfo.version)
override val info: PluginDescription = PluginDescription("blazegraph", BuildInfo.version)

override def initialize(locator: Locator): IO[Plugin] = IO.pure(BlazegraphPlugin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import akka.actor.ActorSystem
import cats.effect.{Clock, IO}
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.kernel.utils.{ClasspathResourceLoader, UUIDF}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.config.BlazegraphViewsConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.sdk.ServiceDependency
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription

/**
* Describes the remote storage [[ServiceDependency]] providing a way to extract the [[ServiceDescription]] from a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import akka.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import akka.http.scaladsl.unmarshalling.PredefinedFromEntityUnmarshallers.stringUnmarshaller
import cats.effect.IO
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription.ResolvedServiceDescription
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient.timeoutHeader
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.SparqlClientError.{InvalidCountRequest, WrappedHttpClientError}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.SparqlQueryResponseType.{Aux, SparqlResultsJson}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.config.BlazegraphViewsConfig.Credentials
import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery
import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery.SparqlConstructQuery
import ch.epfl.bluebrain.nexus.delta.sdk.http.{HttpClient, HttpClientError}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription.ResolvedServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._

import scala.concurrent.duration._
Expand All @@ -36,7 +35,7 @@ class BlazegraphClient(
extends SparqlClient(client, SparqlQueryEndpoint.blazegraph(endpoint)) {

private val serviceVersion = """(buildVersion">)([^<]*)""".r
private val serviceName = Name.unsafe("blazegraph")
private val serviceName = "blazegraph"

override def query[R <: SparqlQueryResponse](
indices: Iterable[String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client
import akka.actor.ActorSystem
import akka.http.scaladsl.model.Uri
import akka.testkit.TestKit
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.Fixtures.defaultProperties
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.PatchStrategy._
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.SparqlClientError.WrappedHttpClientError
Expand All @@ -19,8 +20,6 @@ import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery.SparqlConstructQuery
import ch.epfl.bluebrain.nexus.delta.sdk.ConfigFixtures
import ch.epfl.bluebrain.nexus.delta.sdk.http.HttpClientError.{HttpClientStatusError, HttpServerStatusError}
import ch.epfl.bluebrain.nexus.delta.sdk.http.{HttpClient, HttpClientConfig}
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.ServiceDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._
import ch.epfl.bluebrain.nexus.testkit.blazegraph.BlazegraphDocker
import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
Expand Down Expand Up @@ -114,7 +113,7 @@ class BlazegraphClientSpec(docker: BlazegraphDocker)
"A Blazegraph Client" should {

"fetch the service description" in {
client.serviceDescription.accepted shouldEqual ServiceDescription(Name.unsafe("blazegraph"), "2.1.6-SNAPSHOT")
client.serviceDescription.accepted shouldEqual ServiceDescription("blazegraph", "2.1.6-SNAPSHOT")
}

"verify a namespace does not exist" in {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ch.epfl.bluebrain.nexus.delta.plugins.compositeviews

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.plugin.{Plugin, PluginDef}
import izumi.distage.model.Locator
import izumi.distage.model.definition.ModuleDef
Expand All @@ -11,7 +10,7 @@ class CompositeViewsPluginDef extends PluginDef {

override def module: ModuleDef = new CompositeViewsPluginModule(priority)

override val info: PluginDescription = PluginDescription(Name.unsafe("composite-views"), BuildInfo.version)
override val info: PluginDescription = PluginDescription("composite-views", BuildInfo.version)

override def initialize(locator: Locator): IO[Plugin] = IO.pure(CompositeViewsPlugin)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package ch.epfl.bluebrain.nexus.delta.plugins.elasticsearch

import cats.effect.IO
import ch.epfl.bluebrain.nexus.delta.sdk.model.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.model.Name
import ch.epfl.bluebrain.nexus.delta.kernel.dependency.ComponentDescription.PluginDescription
import ch.epfl.bluebrain.nexus.delta.sdk.plugin.{Plugin, PluginDef}
import izumi.distage.model.Locator
import izumi.distage.model.definition.ModuleDef
Expand All @@ -11,7 +10,7 @@ class ElasticSearchPluginDef extends PluginDef {

override def module: ModuleDef = new ElasticSearchPluginModule(priority)

override val info: PluginDescription = PluginDescription(Name.unsafe("elasticsearch"), BuildInfo.version)
override val info: PluginDescription = PluginDescription("elasticsearch", BuildInfo.version)

override def initialize(locator: Locator): IO[Plugin] = IO.pure(ElasticSearchPlugin)
}
Loading

0 comments on commit bba7e1e

Please sign in to comment.