-
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.
Merge branch 'master' into 4076-annotate-schema-source
- Loading branch information
Showing
17 changed files
with
194 additions
and
16 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
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
44 changes: 44 additions & 0 deletions
44
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/DirectoryReader.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,44 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.syntax.all._ | ||
import ch.epfl.bluebrain.nexus.delta.kernel.utils.FileUtils | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import fs2.io.file.Path | ||
|
||
object DirectoryReader { | ||
|
||
final private case class FileResult(headOffset: Option[Offset], head: Option[Path], tail: List[Path]) | ||
|
||
private val empty = FileResult(None, None, List.empty) | ||
|
||
private def filenameAsOffset(path: Path) = | ||
FileUtils | ||
.filenameWithoutExtension(path.fileName.toString) | ||
.flatMap(_.toLongOption.map(Offset.at)) | ||
|
||
/** | ||
* From the given files, filter out the ones where given the filename, no event is candidate by import: | ||
* - All files where the filename is an offset greater than the provided one are conserved | ||
* - The file with the offset immediately lower than the provided one is also conserved as it may contain some | ||
* events to import | ||
* - The conserved paths are sorted by name | ||
*/ | ||
def apply(paths: List[Path], fromOffset: Offset): List[Path] = { | ||
val result = paths.foldLeft(empty) { | ||
case (acc, path) if path.extName == ".json" => | ||
filenameAsOffset(path).fold(acc) { newOffset => | ||
if (newOffset >= fromOffset) { | ||
acc.copy(tail = acc.tail.appended(path)) | ||
} else { | ||
if (acc.headOffset.isEmpty || acc.headOffset.exists(_ < newOffset)) { | ||
acc.copy(headOffset = Some(newOffset), head = Some(path)) | ||
} else acc | ||
} | ||
} | ||
case (acc, _) => acc | ||
} | ||
|
||
(result.head.toList ++ result.tail).sortBy(_.fileName.toString) | ||
} | ||
|
||
} |
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
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions
4
...t-import/2024-04-05T14:38:31.165389Z.json → ...s/import/multi-part-import/002163821.json
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{"ordering":2163821,"type":"project","org":"public","project":"sscx","id":"projects/public/sscx","rev":1,"value":{"rev": 1, "base": "https://bbp.epfl.ch/neurosciencegraph/data/", "uuid": "c7d70522-4305-480a-b190-75d757ed9a49", "@type": "ProjectCreated", "label": "sscx", "vocab": "https://bbp.epfl.ch/nexus/v1/resources/public/sscx/_/", "instant": "2020-01-22T16:03:33.105Z", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}, "apiMappings": {"prov": "http://www.w3.org/ns/prov#", "context": "https://incf.github.io/neuroshapes/contexts/", "schemaorg": "http://schema.org/", "datashapes": "https://neuroshapes.org/dash/", "ontologies": "https://neuroshapes.org/dash/ontology", "taxonomies": "https://neuroshapes.org/dash/taxonomy", "commonshapes": "https://neuroshapes.org/commons/", "provdatashapes": "https://provshapes.org/datashapes/", "provcommonshapes": "https://provshapes.org/commons/"}, "description": "This project contains somatosensorycortex dissemination publication data.", "organizationUuid": "d098a020-508b-4131-a28d-75f73b7f5f0e", "organizationLabel": "public"},"instant":"2020-01-22T17:03:33.105+01:00"} | ||
{"ordering":2163822,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/defaultInProject","rev":1,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/defaultInProject", "rev": 1, "@type": "ResolverCreated", "value": {"name": "Default resolver", "@type": "InProjectValue", "priority": 1, "description": "Resolver created with the project"}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/defaultInProject", "@type": ["InProject", "Resolver"], "@context": "https://bluebrain.github.io/nexus/contexts/resolvers.json", "priority": 1}, "instant": "2020-01-22T16:03:34.841Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-01-22T17:03:34.841+01:00"} | ||
{"ordering":2163826,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject1","rev":1,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject1", "rev": 1, "@type": "ResolverCreated", "value": {"@type": "CrossProjectValue", "priority": 40, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "identityResolution": {"@type": "ProvidedIdentities", "value": [{"@type": "Authenticated", "realm": "bbp"}]}}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/crossProject1", "@type": ["Resolver", "CrossProject"], "@context": "https://bluebrain.github.io/nexus/contexts/resolvers.json", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "identities": [{"@id": "https://bbp.epfl.ch/nexus/v1/realms/bbp/authenticated", "@type": "Authenticated", "realm": "bbp"}]}, "instant": "2020-01-22T16:03:35.040Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-01-22T17:03:35.04+01:00"} | ||
{"ordering":2173453,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject1","rev":2,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject1", "rev": 2, "tpe": "CrossProject", "@type": "ResolverDeprecated", "instant": "2020-01-28T08:23:36.270Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-01-28T09:23:36.27+01:00"} | ||
{"ordering":2408475,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject2","rev":1,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "rev": 1, "@type": "ResolverCreated", "value": {"@type": "CrossProjectValue", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "identityResolution": {"@type": "ProvidedIdentities", "value": [{"@type": "Authenticated", "realm": "bbp"}]}}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "@type": ["CrossProject", "Resolver"], "@context": "https://bluebrain.github.io/nexus/contexts/resolvers.json", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "identities": [{"@id": "https://bbp.epfl.ch/nexus/v1/realms/bbp/authenticated", "@type": "Authenticated", "realm": "bbp"}]}, "instant": "2020-03-09T13:36:19.246Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-03-09T14:36:19.246+01:00"} | ||
{"ordering":4879496,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject2","rev":2,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "rev": 2, "@type": "ResolverUpdated", "value": {"@type": "CrossProjectValue", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "identityResolution": {"@type": "UseCurrentCaller"}}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "@type": ["Resolver", "CrossProject"], "@context": ["https://bluebrain.github.io/nexus/contexts/resolvers.json", "https://bluebrain.github.io/nexus/contexts/metadata.json"], "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "useCurrentCaller": true}, "instant": "2022-11-16T13:42:07.498Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2022-11-16T14:42:07.498+01:00"} | ||
{"ordering":2173453,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject1","rev":2,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject1", "rev": 2, "tpe": "CrossProject", "@type": "ResolverDeprecated", "instant": "2020-01-28T08:23:36.270Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-01-28T09:23:36.27+01:00"} |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
ship/src/test/resources/import/multi-part-import/002408475.json
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,2 @@ | ||
{"ordering":2408475,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject2","rev":1,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "rev": 1, "@type": "ResolverCreated", "value": {"@type": "CrossProjectValue", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "identityResolution": {"@type": "ProvidedIdentities", "value": [{"@type": "Authenticated", "realm": "bbp"}]}}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "@type": ["CrossProject", "Resolver"], "@context": "https://bluebrain.github.io/nexus/contexts/resolvers.json", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "identities": [{"@id": "https://bbp.epfl.ch/nexus/v1/realms/bbp/authenticated", "@type": "Authenticated", "realm": "bbp"}]}, "instant": "2020-03-09T13:36:19.246Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2020-03-09T14:36:19.246+01:00"} | ||
{"ordering":4879496,"type":"resolver","org":"public","project":"sscx","id":"https://bluebrain.github.io/nexus/vocabulary/crossProject2","rev":2,"value":{"id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "rev": 2, "@type": "ResolverUpdated", "value": {"@type": "CrossProjectValue", "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "identityResolution": {"@type": "UseCurrentCaller"}}, "source": {"@id": "https://bluebrain.github.io/nexus/vocabulary/crossProject2", "@type": ["Resolver", "CrossProject"], "@context": ["https://bluebrain.github.io/nexus/contexts/resolvers.json", "https://bluebrain.github.io/nexus/contexts/metadata.json"], "priority": 50, "projects": ["neurosciencegraph/datamodels"], "resourceTypes": [], "useCurrentCaller": true}, "instant": "2022-11-16T13:42:07.498Z", "project": "public/sscx", "subject": {"@type": "User", "realm": "bbp", "subject": "bob"}},"instant":"2022-11-16T14:42:07.498+01:00"} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
75 changes: 75 additions & 0 deletions
75
ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/DirectoryReaderSuite.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,75 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite | ||
import fs2.io.file.Path | ||
|
||
class DirectoryReaderSuite extends NexusSuite { | ||
|
||
test("Filter out non json files") { | ||
val input = List(Path("import/0000.txt")) | ||
assertEquals(DirectoryReader(input, Offset.start), List.empty) | ||
} | ||
|
||
test("Filter out files with non-offset names") { | ||
val input = List(Path("import/f4il.json")) | ||
assertEquals(DirectoryReader(input, Offset.start), List.empty) | ||
} | ||
|
||
test("Sort input files") { | ||
val input = List( | ||
Path("import/004.json"), | ||
Path("import/001.json"), | ||
Path("import/002.json") | ||
) | ||
val expected = List( | ||
Path("import/001.json"), | ||
Path("import/002.json"), | ||
Path("import/004.json") | ||
) | ||
assertEquals(DirectoryReader(input, Offset.start), expected) | ||
} | ||
|
||
test("Skip files with offset 21") { | ||
val input = List( | ||
Path("import/0030.json"), | ||
Path("import/0020.json"), | ||
Path("import/0010.json"), | ||
Path("import/0040.json") | ||
) | ||
val expected = List( | ||
Path("import/0020.json"), | ||
Path("import/0030.json"), | ||
Path("import/0040.json") | ||
) | ||
assertEquals(DirectoryReader(input, Offset.at(21L)), expected) | ||
} | ||
|
||
test("Skip files with offset 31") { | ||
val input = List( | ||
Path("import/0030.json"), | ||
Path("import/0020.json"), | ||
Path("import/0010.json"), | ||
Path("import/0040.json") | ||
) | ||
val expected = List( | ||
Path("import/0030.json"), | ||
Path("import/0040.json") | ||
) | ||
assertEquals(DirectoryReader(input, Offset.at(31L)), expected) | ||
} | ||
|
||
test("Skip files with offset 41") { | ||
val input = List( | ||
Path("import/0030.json"), | ||
Path("import/0020.json"), | ||
Path("import/0010.json"), | ||
Path("import/0040.json") | ||
) | ||
val expected = List( | ||
Path("import/0040.json") | ||
) | ||
assertEquals(DirectoryReader(input, Offset.at(41L)), expected) | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/EventStreamerSuite.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,32 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.kernel.Order | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite | ||
import fs2.Stream | ||
import munit.Location | ||
|
||
class EventStreamerSuite extends NexusSuite { | ||
|
||
private def readFrom(fromOffset: Offset)(expectedMin: Offset, expectedMax: Offset)(implicit location: Location) = { | ||
Stream | ||
.eval(loader.absoluteFs2Path("import/multi-part-import")) | ||
.flatMap { path => | ||
EventStreamer.localStreamer.stream(path, fromOffset) | ||
} | ||
.scan((Offset.at(Long.MaxValue), Offset.at(0L))) { case ((min, max), event) => | ||
(Order.min(min, event.ordering), Order.max(max, event.ordering)) | ||
} | ||
.compile | ||
.lastOrError | ||
.assertEquals((expectedMin, expectedMax)) | ||
} | ||
|
||
test("Streaming from directory and keep the expected min / max from the beginning") { | ||
readFrom(Offset.start)(Offset.at(2163821L), Offset.at(9999999L)) | ||
} | ||
|
||
test("Streaming from directory and keep the expected min / max from offset 2500000L") { | ||
readFrom(Offset.at(2500000L))(Offset.at(4879496L), Offset.at(9999999L)) | ||
} | ||
} |
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