-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to list indexing errors for Blazegraph (#4111)
Co-authored-by: Simon Dumas <[email protected]>
- Loading branch information
Showing
24 changed files
with
843 additions
and
566 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
.../epfl/bluebrain/nexus/delta/plugins/blazegraph/routes/BlazegraphViewsIndexingRoutes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes | ||
|
||
import akka.http.scaladsl.server.Directives._ | ||
import akka.http.scaladsl.server.Route | ||
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.indexing.IndexingViewDef.ActiveViewDef | ||
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.BlazegraphViewRejection._ | ||
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model._ | ||
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.model.permissions.{write => Write} | ||
import ch.epfl.bluebrain.nexus.delta.plugins.blazegraph.routes.BlazegraphViewsIndexingRoutes.FetchIndexingView | ||
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.contexts | ||
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords | ||
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.sdk.acls.AclCheck | ||
import ch.epfl.bluebrain.nexus.delta.sdk.circe.CirceUnmarshalling | ||
import ch.epfl.bluebrain.nexus.delta.sdk.directives.{AuthDirectives, DeltaDirectives, DeltaSchemeDirectives} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.identities.Identities | ||
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._ | ||
import ch.epfl.bluebrain.nexus.delta.sdk.marshalling.RdfMarshalling | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.SearchResults.searchResultsJsonLdEncoder | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.search.{PaginationConfig, SearchResults} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.{BaseUri, IdSegment} | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.ProgressStatistics | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.FailedElemLogRow.FailedElemData | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{FailedElemLogRow, ProjectRef} | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Projections} | ||
import io.circe.Encoder | ||
import io.circe.generic.semiauto.deriveEncoder | ||
import io.circe.syntax._ | ||
import monix.bio.IO | ||
import monix.execution.Scheduler | ||
class BlazegraphViewsIndexingRoutes( | ||
fetch: FetchIndexingView, | ||
identities: Identities, | ||
aclCheck: AclCheck, | ||
projections: Projections, | ||
projectionErrors: ProjectionErrors, | ||
schemeDirectives: DeltaSchemeDirectives | ||
)(implicit | ||
baseUri: BaseUri, | ||
s: Scheduler, | ||
cr: RemoteContextResolution, | ||
ordering: JsonKeyOrdering, | ||
pc: PaginationConfig | ||
) extends AuthDirectives(identities, aclCheck) | ||
with CirceUnmarshalling | ||
with DeltaDirectives | ||
with RdfMarshalling | ||
with BlazegraphViewsDirectives { | ||
|
||
import schemeDirectives._ | ||
|
||
implicit private val viewStatisticEncoder: Encoder.AsObject[ProgressStatistics] = | ||
deriveEncoder[ProgressStatistics].mapJsonObject(_.add(keywords.tpe, "ViewStatistics".asJson)) | ||
|
||
implicit private val viewStatisticJsonLdEncoder: JsonLdEncoder[ProgressStatistics] = | ||
JsonLdEncoder.computeFromCirce(ContextValue(contexts.statistics)) | ||
|
||
def routes: Route = | ||
pathPrefix("views") { | ||
extractCaller { implicit caller => | ||
resolveProjectRef.apply { implicit ref => | ||
idSegment { id => | ||
concat( | ||
// Fetch a blazegraph view statistics | ||
(pathPrefix("statistics") & get & pathEndOrSingleSlash) { | ||
authorizeFor(ref, permissions.read).apply { | ||
emit( | ||
fetch(id, ref) | ||
.flatMap(v => projections.statistics(ref, v.resourceTag, v.projection)) | ||
.rejectOn[ViewNotFound] | ||
) | ||
} | ||
}, | ||
// Fetch balzegraph view indexing failures | ||
(pathPrefix("failures") & get) { | ||
authorizeFor(ref, Write).apply { | ||
concat( | ||
(pathPrefix("sse") & lastEventId) { offset => | ||
emit( | ||
fetch(id, ref) | ||
.map { view => | ||
projectionErrors.sses(view.ref.project, view.ref.viewId, offset) | ||
} | ||
) | ||
}, | ||
(fromPaginated & timeRange("instant") & extractUri & pathEndOrSingleSlash) { | ||
(pagination, timeRange, uri) => | ||
implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[FailedElemData]] = | ||
searchResultsJsonLdEncoder(FailedElemLogRow.context, pagination, uri) | ||
emit( | ||
fetch(id, ref) | ||
.flatMap { view => | ||
projectionErrors.search(view.ref, pagination, timeRange) | ||
} | ||
) | ||
} | ||
) | ||
} | ||
}, | ||
// Manage an blazegraph view offset | ||
(pathPrefix("offset") & pathEndOrSingleSlash) { | ||
concat( | ||
// Fetch a blazegraph view offset | ||
(get & authorizeFor(ref, permissions.read)) { | ||
emit( | ||
fetch(id, ref) | ||
.flatMap(v => projections.offset(v.projection)) | ||
.rejectOn[ViewNotFound] | ||
) | ||
}, | ||
// Remove an blazegraph view offset (restart the view) | ||
(delete & authorizeFor(ref, Write)) { | ||
emit( | ||
fetch(id, ref) | ||
.flatMap { r => projections.scheduleRestart(r.projection) } | ||
.as(Offset.start) | ||
.rejectOn[ViewNotFound] | ||
) | ||
} | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
object BlazegraphViewsIndexingRoutes { | ||
|
||
type FetchIndexingView = (IdSegment, ProjectRef) => IO[BlazegraphViewRejection, ActiveViewDef] | ||
|
||
/** | ||
* @return | ||
* the [[Route]] for BlazegraphViews | ||
*/ | ||
def apply( | ||
fetch: FetchIndexingView, | ||
identities: Identities, | ||
aclCheck: AclCheck, | ||
projections: Projections, | ||
projectionErrors: ProjectionErrors, | ||
schemeDirectives: DeltaSchemeDirectives | ||
)(implicit | ||
baseUri: BaseUri, | ||
s: Scheduler, | ||
cr: RemoteContextResolution, | ||
ordering: JsonKeyOrdering, | ||
pc: PaginationConfig | ||
): Route = { | ||
new BlazegraphViewsIndexingRoutes( | ||
fetch, | ||
identities, | ||
aclCheck, | ||
projections, | ||
projectionErrors: ProjectionErrors, | ||
schemeDirectives | ||
).routes | ||
} | ||
} |
Oops, something went wrong.