Skip to content

Commit

Permalink
Do not index views anymore (#5288)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Dumas <simon.dumas@frontiersin.org>
  • Loading branch information
imsdu and Simon Dumas authored Feb 24, 2025
1 parent 6629daa commit 84fbc22
Show file tree
Hide file tree
Showing 48 changed files with 243 additions and 651 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ch.epfl.bluebrain.nexus.delta.wiring

import cats.data.NonEmptyList
import cats.effect.{Clock, IO, Sync}
import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShifts
import ch.epfl.bluebrain.nexus.delta.sdk.stream.GraphResourceStream
Expand All @@ -22,7 +21,7 @@ object StreamModule extends ModuleDef {

make[ElemStreaming].from {
(xas: Transactors, shifts: ResourceShifts, queryConfig: ElemQueryConfig, activitySignals: ProjectActivitySignals) =>
new ElemStreaming(xas, NonEmptyList.fromList(shifts.entityTypes.toList), queryConfig, activitySignals)
new ElemStreaming(xas, shifts.entityTypes, queryConfig, activitySignals)
}

make[GraphResourceStream].from { (elemStreaming: ElemStreaming, shifts: ResourceShifts) =>
Expand All @@ -44,8 +43,8 @@ object StreamModule extends ModuleDef {
registry
}

make[Projections].from { (xas: Transactors, cfg: ProjectionConfig, clock: Clock[IO]) =>
Projections(xas, cfg.query, clock)
make[Projections].from { (xas: Transactors, shifts: ResourceShifts, cfg: ProjectionConfig, clock: Clock[IO]) =>
Projections(xas, shifts.entityTypes, cfg.query, clock)
}

make[ProjectionErrors].from { (xas: Transactors, clock: Clock[IO], cfg: ProjectionConfig) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SchemaJobRoutesSpec extends BaseRouteSpec {

private val aclCheck = AclSimpleCheck((alice, Root, Set(Permissions.schemas.run))).accepted

private lazy val projections = Projections(xas, queryConfig, clock)
private lazy val projections = Projections(xas, None, queryConfig, clock)
private lazy val projectionErrors = ProjectionErrors(xas, queryConfig, clock)

private val progress = ProjectionProgress(Offset.at(15L), Instant.EPOCH, 9000L, 400L, 30L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import ch.epfl.bluebrain.nexus.delta.kernel.utils.{ClasspathResourceLoader, UUID
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.client.BlazegraphClient
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.config.BlazegraphViewsConfig
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.indexing.BlazegraphCoordinator
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, schema => viewsSchemaId, BlazegraphView, BlazegraphViewEvent, DefaultProperties}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.{contexts, BlazegraphViewEvent, DefaultProperties}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes.{BlazegraphSupervisionRoutes, BlazegraphViewsIndexingRoutes, BlazegraphViewsRoutes, BlazegraphViewsRoutesHandler}
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.slowqueries.{BlazegraphSlowQueryDeleter, BlazegraphSlowQueryLogger, BlazegraphSlowQueryStore}
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution}
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction.AggregateIndexingAction
import ch.epfl.bluebrain.nexus.delta.sdk._
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.deletion.ProjectDeletionTask
Expand All @@ -22,15 +21,13 @@ import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.ServiceAccount
import ch.epfl.bluebrain.nexus.delta.sdk.model._
import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.stream.GraphResourceStream
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Label
import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Projections}
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{ReferenceRegistry, Supervisor}
import izumi.distage.model.definition.{Id, ModuleDef}
Expand All @@ -52,11 +49,7 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
HttpClient()(cfg.indexingClient, as)
}

make[BlazegraphSlowQueryStore].from { (xas: Transactors) =>
BlazegraphSlowQueryStore(
xas
)
}
make[BlazegraphSlowQueryStore].from { (xas: Transactors) => BlazegraphSlowQueryStore(xas) }

make[BlazegraphSlowQueryDeleter].fromEffect {
(supervisor: Supervisor, store: BlazegraphSlowQueryStore, cfg: BlazegraphViewsConfig, clock: Clock[IO]) =>
Expand Down Expand Up @@ -183,8 +176,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
aclCheck: AclCheck,
views: BlazegraphViews,
viewsQuery: BlazegraphViewsQuery,
indexingAction: AggregateIndexingAction,
shift: BlazegraphView.Shift,
baseUri: BaseUri,
cfg: BlazegraphViewsConfig,
cr: RemoteContextResolution @Id("aggregate"),
Expand All @@ -195,8 +186,7 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
views,
viewsQuery,
identities,
aclCheck,
indexingAction(_, _, _)(shift)
aclCheck
)(
baseUri,
cr,
Expand Down Expand Up @@ -256,8 +246,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {

many[SseEncoder[_]].add { base: BaseUri => BlazegraphViewEvent.sseEncoder(base) }

many[ScopedEventMetricEncoder[_]].add { BlazegraphViewEvent.bgViewMetricEncoder }

many[RemoteContextResolution].addEffect(
for {
blazegraphCtx <- ContextValue.fromFile("contexts/sparql.json")
Expand All @@ -268,10 +256,6 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
)
)

many[ResourceToSchemaMappings].add(
ResourceToSchemaMappings(Label.unsafe("views") -> viewsSchemaId.iri)
)

many[ApiMappings].add(BlazegraphViews.mappings)

many[PriorityRoute].add {
Expand Down Expand Up @@ -308,11 +292,4 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
) =>
BlazegraphIndexingAction(views, registry, client, config.syncIndexingTimeout)(baseUri)
}

make[BlazegraphView.Shift].from { (views: BlazegraphViews, base: BaseUri) =>
BlazegraphView.shift(views)(base)
}

many[ResourceShift[_, _, _]].ref[BlazegraphView.Shift]

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model

import cats.data.NonEmptySet
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.BlazegraphViews
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphView.Metadata
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.ResourceShift
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdContent
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegmentRef}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission
import ch.epfl.bluebrain.nexus.delta.sdk.syntax._
import ch.epfl.bluebrain.nexus.delta.sdk.views.ViewRef
Expand Down Expand Up @@ -94,8 +90,6 @@ object BlazegraphView {
* whether to consider deprecated resources for indexing
* @param permission
* the permission required for querying this view
* @param tags
* the collection of tags for this resource
* @param source
* the original json value provided by the caller
*/
Expand Down Expand Up @@ -128,8 +122,6 @@ object BlazegraphView {
* a reference to the parent project
* @param views
* the collection of views where queries will be delegated (if necessary permissions are met)
* @param tags
* the collection of tags for this resource
* @param source
* the original json value provided by the caller
*/
Expand Down Expand Up @@ -180,14 +172,4 @@ object BlazegraphView {

implicit val blazegraphMetadataJsonLdEncoder: JsonLdEncoder[Metadata] =
JsonLdEncoder.computeFromCirce(ContextValue(contexts.blazegraphMetadata))

type Shift = ResourceShift[BlazegraphViewState, BlazegraphView, Metadata]

def shift(views: BlazegraphViews)(implicit baseUri: BaseUri): Shift =
ResourceShift.withMetadata[BlazegraphViewState, BlazegraphView, Metadata](
BlazegraphViews.entityType,
(ref, project) => views.fetch(IdSegmentRef(ref), project),
state => state.toResource,
value => JsonLdContent(value, value.value.source, Some(value.value.metadata))
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords
import ch.epfl.bluebrain.nexus.delta.sdk.instances._
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri
import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._
import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.sse.{resourcesSelector, SseEncoder}
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.Serializer
import ch.epfl.bluebrain.nexus.delta.sourcing.event.Event.ScopedEvent
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject
Expand Down Expand Up @@ -238,34 +236,12 @@ object BlazegraphViewEvent {
Serializer.dropNulls()
}

val bgViewMetricEncoder: ScopedEventMetricEncoder[BlazegraphViewEvent] =
new ScopedEventMetricEncoder[BlazegraphViewEvent] {
override def databaseDecoder: Decoder[BlazegraphViewEvent] = serializer.codec

override def entityType: EntityType = BlazegraphViews.entityType

override def eventToMetric: BlazegraphViewEvent => ProjectScopedMetric = event =>
ProjectScopedMetric.from(
event,
event match {
case _: BlazegraphViewCreated => Created
case _: BlazegraphViewUpdated => Updated
case _: BlazegraphViewTagAdded => Tagged
case _: BlazegraphViewDeprecated => Deprecated
case _: BlazegraphViewUndeprecated => Undeprecated
},
event.id,
event.tpe.types,
JsonObject.empty
)
}

def sseEncoder(implicit base: BaseUri): SseEncoder[BlazegraphViewEvent] = new SseEncoder[BlazegraphViewEvent] {
override val databaseDecoder: Decoder[BlazegraphViewEvent] = serializer.codec

override def entityType: EntityType = BlazegraphViews.entityType

override val selectors: Set[Label] = Set(Label.unsafe("views"), resourcesSelector)
override val selectors: Set[Label] = Set(Label.unsafe("views"))

override val sseEncoder: Encoder.AsObject[BlazegraphViewEvent] = {
val context = ContextValue(Vocabulary.contexts.metadata, contexts.blazegraph)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteCon
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.encoder.JsonLdEncoder
import ch.epfl.bluebrain.nexus.delta.rdf.query.SparqlQuery
import ch.epfl.bluebrain.nexus.delta.rdf.utils.JsonKeyOrdering
import ch.epfl.bluebrain.nexus.delta.sdk.IndexingAction
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck
import ch.epfl.bluebrain.nexus.delta.sdk.directives.{AuthDirectives, DeltaDirectives}
import ch.epfl.bluebrain.nexus.delta.sdk.fusion.FusionConfig
Expand All @@ -39,15 +38,12 @@ import io.circe.Json
* the identity module
* @param aclCheck
* to check the acls
* @param index
* the indexing action on write operations
*/
class BlazegraphViewsRoutes(
views: BlazegraphViews,
viewsQuery: BlazegraphViewsQuery,
identities: Identities,
aclCheck: AclCheck,
index: IndexingAction.Execute[BlazegraphView]
aclCheck: AclCheck
)(implicit
baseUri: BaseUri,
cr: RemoteContextResolution,
Expand Down Expand Up @@ -95,28 +91,27 @@ class BlazegraphViewsRoutes(
pathPrefix("views") {
extractCaller { implicit caller =>
projectRef { implicit project =>
val authorizeRead = authorizeFor(project, Read)
val authorizeWrite = authorizeFor(project, Write)
// Create a view without id segment
concat(
(pathEndOrSingleSlash & post & entity(as[Json]) & noParameter("rev") & indexingMode) { (source, mode) =>
authorizeFor(project, Write).apply {
emitMetadataOrReject(
Created,
views.create(project, source).flatTap(index(project, _, mode))
)
(pathEndOrSingleSlash & post & entity(as[Json]) & noParameter("rev")) { source =>
authorizeWrite {
emitMetadataOrReject(Created, views.create(project, source))
}
},
(idSegment & indexingMode) { (id, mode) =>
idSegment { id =>
concat(
pathEndOrSingleSlash {
concat(
put {
authorizeFor(project, Write).apply {
authorizeWrite {
(parameter("rev".as[Int].?) & pathEndOrSingleSlash & entity(as[Json])) {
case (None, source) =>
// Create a view with id segment
emitMetadataOrReject(
Created,
views.create(id, project, source).flatTap(index(project, _, mode))
views.create(id, project, source)
)
case (Some(rev), source) =>
// Update a view
Expand All @@ -128,9 +123,9 @@ class BlazegraphViewsRoutes(
},
(delete & parameter("rev".as[Int])) { rev =>
// Deprecate a view
authorizeFor(project, Write).apply {
authorizeWrite {
emitMetadataOrReject(
views.deprecate(id, project, rev).flatTap(index(project, _, mode))
views.deprecate(id, project, rev)
)
}
},
Expand All @@ -139,7 +134,7 @@ class BlazegraphViewsRoutes(
emitOrFusionRedirect(
project,
id,
authorizeFor(project, Read).apply {
authorizeRead {
emitFetch(views.fetch(id, project))
}
)
Expand All @@ -148,9 +143,9 @@ class BlazegraphViewsRoutes(
},
// Undeprecate a blazegraph view
(pathPrefix("undeprecate") & put & parameter("rev".as[Int]) &
authorizeFor(project, Write) & pathEndOrSingleSlash) { rev =>
authorizeWrite & pathEndOrSingleSlash) { rev =>
emitMetadataOrReject(
views.undeprecate(id, project, rev).flatTap(index(project, _, mode))
views.undeprecate(id, project, rev)
)
},
// Query a blazegraph view
Expand All @@ -171,7 +166,7 @@ class BlazegraphViewsRoutes(
},
// Fetch a view original source
(pathPrefix("source") & get & pathEndOrSingleSlash & idSegmentRef(id)) { id =>
authorizeFor(project, Read).apply {
authorizeRead {
emitSource(views.fetch(id, project))
}
},
Expand Down Expand Up @@ -202,29 +197,30 @@ class BlazegraphViewsRoutes(
if (condition) idSegment.flatMap(_ => pass)
else pass

private def incomingOutgoing(id: IdSegment, ref: ProjectRef)(implicit caller: Caller) =
private def incomingOutgoing(id: IdSegment, project: ProjectRef)(implicit caller: Caller) = {
val authorizeRead = authorizeFor(project, Read)
val metadataContext = ContextValue(Vocabulary.contexts.metadata)
concat(
(pathPrefix("incoming") & fromPaginated & pathEndOrSingleSlash & get & extractUri) { (pagination, uri) =>
implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] =
searchResultsJsonLdEncoder(ContextValue(Vocabulary.contexts.metadata), pagination, uri)

authorizeFor(ref, Read).apply {
emit(viewsQuery.incoming(id, ref, pagination).attemptNarrow[BlazegraphViewRejection])
searchResultsJsonLdEncoder(metadataContext, pagination, uri)
authorizeRead {
emit(viewsQuery.incoming(id, project, pagination).attemptNarrow[BlazegraphViewRejection])
}
},
(pathPrefix("outgoing") & fromPaginated & pathEndOrSingleSlash & get & extractUri & parameter(
"includeExternalLinks".as[Boolean] ? true
)) { (pagination, uri, includeExternal) =>
implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] =
searchResultsJsonLdEncoder(ContextValue(Vocabulary.contexts.metadata), pagination, uri)

authorizeFor(ref, Read).apply {
searchResultsJsonLdEncoder(metadataContext, pagination, uri)
authorizeRead {
emit(
viewsQuery.outgoing(id, ref, pagination, includeExternal).attemptNarrow[BlazegraphViewRejection]
viewsQuery.outgoing(id, project, pagination, includeExternal).attemptNarrow[BlazegraphViewRejection]
)
}
}
)
}
}

object BlazegraphViewsRoutes {
Expand All @@ -237,8 +233,7 @@ object BlazegraphViewsRoutes {
views: BlazegraphViews,
viewsQuery: BlazegraphViewsQuery,
identities: Identities,
aclCheck: AclCheck,
index: IndexingAction.Execute[BlazegraphView]
aclCheck: AclCheck
)(implicit
baseUri: BaseUri,
cr: RemoteContextResolution,
Expand All @@ -250,8 +245,7 @@ object BlazegraphViewsRoutes {
views,
viewsQuery,
identities,
aclCheck,
index
aclCheck
).routes
}
}
Loading

0 comments on commit 84fbc22

Please sign in to comment.