Skip to content

Commit

Permalink
chore: prepare 2.32.0 (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro authored May 2, 2023
2 parents 7bf7e52 + ad98364 commit d2e1db5
Show file tree
Hide file tree
Showing 140 changed files with 4,074 additions and 1,755 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CommitHistoryChangesSpec

sleep((10 seconds).toMillis)

`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

eventually {
EventLog.findEvents(project.id, events.EventStatus.TriplesStore).toSet shouldBe newCommits.toList.toSet
Expand Down Expand Up @@ -125,7 +125,7 @@ class CommitHistoryChangesSpec

sleep((1 second).toMillis)

`check no hook exists`(project.id)
`check no hook exists`(project.id, user.accessToken)

Then("the project and its datasets should be removed from the knowledge-graph")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CommitSyncFlowsSpec extends AcceptanceSpec with ApplicationServices with T
.status shouldBe Accepted

And("relevant commit events are processed")
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

Then("the non missed events should be in the Triples Store")
eventually {
Expand All @@ -83,7 +83,7 @@ class CommitSyncFlowsSpec extends AcceptanceSpec with ApplicationServices with T
EventLog.forceCategoryEventTriggering(CategoryName("COMMIT_SYNC"), project.id)

And("commit events for the missed event are created and processed")
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

Then("triples for both of the project's commits should be in the Triples Store")
eventually {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EventFlowsSpec extends AcceptanceSpec with ApplicationServices with TSProv
.status shouldBe Accepted

And("commit events are processed")
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

Then(s"all the events should get the $TriplesStore status in the Event Log")
EventLog.findEvents(project.id).map(_._2).toSet shouldBe Set(TriplesStore)
Expand Down Expand Up @@ -89,7 +89,7 @@ class EventFlowsSpec extends AcceptanceSpec with ApplicationServices with TSProv
.status shouldBe Accepted

And("relevant commit events are processed")
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

And(s"all the events should get the $GenerationNonRecoverableFailure status in the Event Log")
EventLog.findEvents(project.id).map(_._2).toSet shouldBe Set(GenerationNonRecoverableFailure)
Expand Down Expand Up @@ -151,7 +151,7 @@ class EventFlowsSpec extends AcceptanceSpec with ApplicationServices with TSProv
.status shouldBe Accepted

And("relevant commit events are processed")
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

Then(s"all the events should get the $TransformationNonRecoverableFailure status in the Event Log")
EventLog.findEvents(project.id).map(_._2).toSet shouldBe Set(TransformationNonRecoverableFailure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

package io.renku.graph.acceptancetests

import cats.syntax.all._
import data.Project.Statistics.CommitsCount
import data._
import data.Project.Statistics.CommitsCount
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Positive
Expand Down Expand Up @@ -57,35 +56,39 @@ class EventsProcessingStatusSpec
CommitsCount(numberOfEvents.value)
).map(addMemberWithId(user.id)).generateOne

gitLabStub.addAuthenticated(user)

When("there's no webhook for a given project in GitLab")
Then("the status endpoint should return NOT_FOUND")
webhookServiceClient.fetchProcessingStatus(project.id).status shouldBe NotFound
Then("the status endpoint should return OK with 'activated' = false")

val response = webhookServiceClient.fetchProcessingStatus(project.id, user.accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe false

When("there is a webhook created")
When("a webhook created for the project")
And("there are events under processing")
val allCommitIds = commitIds.generateNonEmptyList(min = numberOfEvents, max = numberOfEvents)
gitLabStub.addAuthenticated(user)
gitLabStub.setupProject(project, allCommitIds.toList: _*)
mockCommitDataOnTripleGenerator(project, toPayloadJsonLD(project), allCommitIds)
`data in the Triples Store`(project, allCommitIds, user.accessToken)

Then("the status endpoint should return OK with some progress info")
eventually {
val response = webhookServiceClient.fetchProcessingStatus(project.id)
val response = webhookServiceClient.fetchProcessingStatus(project.id, user.accessToken)

response.status shouldBe Ok

val responseJson = response.jsonBody.hcursor
responseJson.downField("activated").as[Boolean] shouldBe true.asRight
responseJson.downField("activated").as[Boolean].value shouldBe true

val progressObjCursor = responseJson.downField("progress").as[Json].fold(throw _, identity).hcursor
progressObjCursor.downField("done").as[Int] shouldBe EventStatusProgress.Stage.Final.value.asRight
progressObjCursor.downField("total").as[Int] shouldBe EventStatusProgress.Stage.Final.value.asRight
progressObjCursor.downField("percentage").as[Float] shouldBe 100f.asRight
progressObjCursor.downField("done").as[Int].value shouldBe EventStatusProgress.Stage.Final.value
progressObjCursor.downField("total").as[Int].value shouldBe EventStatusProgress.Stage.Final.value
progressObjCursor.downField("percentage").as[Float].value shouldBe 100f

val detailsObjCursor = responseJson.downField("details").as[Json].fold(throw _, identity).hcursor
detailsObjCursor.downField("status").as[String] shouldBe "success".asRight
detailsObjCursor.downField("message").as[String] shouldBe "triples store".asRight
detailsObjCursor.downField("status").as[String].value shouldBe "success"
detailsObjCursor.downField("message").as[String].value shouldBe "triples store"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ProjectReProvisioningSpec extends AcceptanceSpec with ApplicationServices

Then("the old data in the TS should be replaced with the new")
sleep((10 seconds).toMillis)
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, user.accessToken)

eventually {
knowledgeGraphClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import io.renku.http.client.AccessToken
import io.renku.testtools.IOSpec
import io.renku.webhookservice.model.HookToken
import org.http4s.Status._
import org.scalatest.Assertion
import org.scalatest.{Assertion, EitherValues}
import org.scalatest.concurrent.Eventually
import org.scalatest.matchers.should

Expand All @@ -46,7 +46,9 @@ trait TSProvisioning
with AccessTokenPresence
with Eventually
with AcceptanceTestPatience
with should.Matchers {
with should.Matchers
with EitherValues {

self: ApplicationServices with IOSpec =>

def `data in the Triples Store`(
Expand All @@ -72,21 +74,25 @@ trait TSProvisioning
sleep((5 seconds).toMillis)
}

`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, accessToken)
}

def `wait for events to be processed`(projectId: projects.GitLabId): Assertion = eventually {
val response = fetchProcessingStatus(projectId)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("progress").downField("percentage").as[Double] shouldBe Right(100d)
}
def `wait for events to be processed`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion =
eventually {
val response = fetchProcessingStatus(projectId, accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe true
response.jsonBody.hcursor.downField("progress").downField("percentage").as[Double].value shouldBe 100d
}

def `check no hook exists`(projectId: projects.GitLabId): Assertion = eventually {
fetchProcessingStatus(projectId).status shouldBe NotFound
def `check no hook exists`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion = eventually {
val response = fetchProcessingStatus(projectId, accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe false
}

private def fetchProcessingStatus(projectId: projects.GitLabId) =
webhookServiceClient.fetchProcessingStatus(projectId)
private def fetchProcessingStatus(projectId: projects.GitLabId, accessToken: AccessToken) =
webhookServiceClient.fetchProcessingStatus(projectId, accessToken)

def `wait for the Fast Tract event`(projectId: projects.GitLabId)(implicit ioRuntime: IORuntime): Unit = eventually {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ class DatasetsResourcesSpec
gitLabStub.setupProject(project, commitId)
mockCommitDataOnTripleGenerator(project, toPayloadJsonLD(project), commitId)
`data in the Triples Store`(project, commitId, creator.accessToken)
`wait for events to be processed`(project.id)
`wait for events to be processed`(project.id, creator.accessToken)

When("an authenticated and authorised user fetches dataset details through GET knowledge-graph/datasets/:id")
val detailsResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class LineageResourcesSpec extends AcceptanceSpec with ApplicationServices with

Then("they should get Ok response with project lineage in Json")
response.status shouldBe Ok
val lineageJson = response.jsonBody.hcursor

val lineageJson = response.jsonBody.hcursor
lineageJson.downField("edges").as[List[Json]].map(_.toSet) shouldBe theExpectedEdges(exemplarData)
lineageJson.downField("nodes").as[List[Json]].map(_.toSet) shouldBe theExpectedNodes(exemplarData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ final class GitLabApiStub[F[_]: Async: Logger](private val stateRef: Ref[F, Stat
case GET -> Root / ProjectId(id) =>
query(findProjectById(id, maybeAuthedReq)).flatMap(OkOrNotFound(_))

case HEAD -> Root / ProjectId(id) =>
query(findProjectById(id, maybeAuthedReq)).flatMap(EmptyOkOrNotFound(_))

case GET -> Root / ProjectPath(path) =>
query(findProjectByPath(path, maybeAuthedReq)).flatMap(OkOrNotFound(_))

case GET -> Root / ProjectPath(path) / ("users" | "members") =>
case HEAD -> Root / ProjectPath(path) =>
query(findProjectByPath(path, maybeAuthedReq)).flatMap(EmptyOkOrNotFound(_))

case GET -> Root / ProjectPath(path) / "members" / "all" =>
query(findProjectByPath(path, maybeAuthedReq))
.map(_.toList.flatMap(_.members.toList))
.flatMap(Ok(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.renku.graph.model.{persons, projects}
import io.renku.graph.model.events.CommitId
import io.renku.http.rest.paging.{PagingRequest, PagingResponse}
import io.renku.http.rest.paging.PagingRequest.Decoders.{page, perPage}
import org.http4s.{EntityEncoder, Header, HttpApp, HttpRoutes, QueryParamDecoder, Request, Response}
import org.http4s.{EntityEncoder, Header, HttpApp, HttpRoutes, QueryParamDecoder, Request, Response, Status}
import org.http4s.circe.CirceEntityCodec._
import org.http4s.dsl.Http4sDsl
import org.http4s.dsl.impl.{OptionalQueryParamDecoderMatcher, QueryParamDecoderMatcher}
Expand Down Expand Up @@ -76,6 +76,9 @@ private[gitlab] trait Http4sDslUtils {
payload.map(Ok(_)).getOrElse(Response.notFound[F].pure[F])
}

def EmptyOkOrNotFound[F[_]: Applicative](payload: Option[Any]): F[Response[F]] =
Response[F](payload.map(_ => Status.Ok).getOrElse(Status.NotFound)).pure[F]

object Membership extends QueryParamDecoderMatcher[Boolean]("membership")

implicit val accessLevelDecoder: QueryParamDecoder[AccessLevel] = QueryParamDecoder[Int].map(pv =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ object WebhookServiceClient {
} yield response
}.unsafeRunSync()

def fetchProcessingStatus(projectId: projects.GitLabId)(implicit ioRuntime: IORuntime): ClientResponse =
GET((uri"projects" / projectId / "events" / "status").renderString)
def fetchProcessingStatus(projectId: projects.GitLabId, accessToken: AccessToken)(implicit
ior: IORuntime
): ClientResponse =
GET((uri"projects" / projectId / "events" / "status").renderString, accessToken)
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ lazy val triplesGenerator = project
.dependsOn(
triplesGeneratorApi % "compile->compile; test->test",
entitiesSearch,
entitiesViewingsCollector
entitiesViewingsCollector % "compile->compile; test->test"
)
.enablePlugins(
JavaAppPackaging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private class EntitiesFinderImpl[F[_]: Async: NonEmptyParallel: Logger: SparqlQu
)(implicit encoder: SparqlEncoder[OrderBy]): String = {
def mapPropertyName(property: Criteria.Sort.SortProperty) = property match {
case Criteria.Sort.ByName => OrderBy.Property("LCASE(?name)")
case Criteria.Sort.ByDate => OrderBy.Property("?date")
case Criteria.Sort.ByDate => OrderBy.Property("xsd:dateTime(?date)")
case Criteria.Sort.ByMatchingScore => OrderBy.Property("?matchingScore")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ private trait DSInfoFinder[F[_]] {
private final case class DSInfo(projectPath: projects.Path, dataset: Dataset)

private object DSInfoFinder {

def apply[F[_]: Async: Logger: SparqlQueryTimeRecorder]: F[DSInfoFinder[F]] =
ProjectsConnectionConfig[F]().map(TSClient[F](_)).map(new DSInfoFinderImpl[F](_))
ProjectsConnectionConfig[F]().map(TSClient[F](_)).map(apply(_))

def apply[F[_]: MonadThrow](tsClient: TSClient[F]): DSInfoFinder[F] =
new DSInfoFinderImpl[F](tsClient)
}

private class DSInfoFinderImpl[F[_]: MonadThrow](tsClient: TSClient[F]) extends DSInfoFinder[F] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,32 @@
package io.renku.entities.viewings.collector
package datasets

import cats.effect.Async
import cats.syntax.all._
import cats.MonadThrow
import cats.data.OptionT
import cats.effect.Async
import cats.syntax.all._
import io.renku.entities.viewings.collector.persons.{GLUserViewedDataset, PersonViewedDatasetPersister}
import io.renku.entities.viewings.collector.projects.viewed.EventPersister
import io.renku.graph.model.projects
import io.renku.triplesgenerator.api.events.{DatasetViewedEvent, ProjectViewedEvent, UserId}
import io.renku.triplesstore.SparqlQueryTimeRecorder
import io.renku.triplesstore.{SparqlQueryTimeRecorder, TSClient}
import org.typelevel.log4cats.Logger

private trait EventUploader[F[_]] {
private[viewings] trait EventUploader[F[_]] {
def upload(event: DatasetViewedEvent): F[Unit]
}

private object EventUploader {
private[viewings] object EventUploader {

def apply[F[_]: Async: Logger: SparqlQueryTimeRecorder]: F[EventUploader[F]] =
(DSInfoFinder[F], EventPersister[F], PersonViewedDatasetPersister[F])
.mapN(new EventUploaderImpl[F](_, _, _))

def apply[F[_]: MonadThrow](tsClient: TSClient[F]): EventUploader[F] =
new EventUploaderImpl[F](DSInfoFinder[F](tsClient),
EventPersister[F](tsClient),
PersonViewedDatasetPersister[F](tsClient)
)
}

private class EventUploaderImpl[F[_]: MonadThrow](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private object Encoder {
private lazy val viewedProjectEncoder: JsonLDEncoder[PersonViewedProject] =
JsonLDEncoder.instance { case PersonViewedProject(userId, Project(id, path), date) =>
JsonLD.entity(
EntityId.of(s"$userId/$path"),
EntityId of s"$userId/$path",
EntityTypes of PersonViewedProjectOntology.classType,
PersonViewedProjectOntology.projectProperty -> id.asJsonLD,
PersonViewedProjectOntology.dateViewedProperty.id -> date.asJsonLD
Expand All @@ -68,7 +68,7 @@ private object Encoder {
private lazy val viewedDatasetEncoder: JsonLDEncoder[PersonViewedDataset] =
JsonLDEncoder.instance { case PersonViewedDataset(userId, Dataset(id, identifier), date) =>
JsonLD.entity(
EntityId.of(s"$userId/datasets/$identifier"),
EntityId of s"$userId/datasets/$identifier",
EntityTypes of PersonViewedProjectOntology.classType,
PersonViewedDatasetOntology.datasetProperty -> id.asJsonLD,
PersonViewedDatasetOntology.dateViewedProperty.id -> date.asJsonLD
Expand Down
Loading

0 comments on commit d2e1db5

Please sign in to comment.