Skip to content

Commit

Permalink
Address feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Apr 22, 2024
1 parent c2eb0ea commit cf50158
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ship/src/main/resources/ship-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ ship {
}

input {
original-base = "http://localhost:8080/v1"
target-base = "http://localhost:8080/v1"
original-base-uri = "http://localhost:8080/v1"
target-base-uri = "http://localhost:8080/v1"

event-log {
query-config = {
Expand Down
10 changes: 5 additions & 5 deletions ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ object RunShip {
val fetchContext = FetchContext(ApiMappings.empty, xas, Quotas.disabled)
val originalProjectContext = new OriginalProjectContext(xas)
val eventLogConfig = config.eventLog
val originalBase = config.originalBase
val targetBase = config.targetBase
val originalBaseUri = config.originalBaseUri
val targetBaseUri = config.targetBaseUri
val projectMapper = ProjectMapper(config.projectMapping)
for {
// Provision organizations
Expand All @@ -52,11 +52,11 @@ object RunShip {
rcr = ContextWiring.resolverContextResolution(fetchResource, fetchContext, remoteContextResolution, eventLogConfig, eventClock, xas)
schemaImports = SchemaWiring.schemaImports(fetchResource, fetchSchema, fetchContext, eventLogConfig, eventClock, xas)
// Processors
projectProcessor <- ProjectProcessor(fetchActiveOrg, fetchContext, rcr, originalProjectContext, projectMapper, config, eventClock, xas)(targetBase, jsonLdApi)
projectProcessor <- ProjectProcessor(fetchActiveOrg, fetchContext, rcr, originalProjectContext, projectMapper, config, eventClock, xas)(targetBaseUri, jsonLdApi)
resolverProcessor = ResolverProcessor(fetchContext, projectMapper, eventLogConfig, eventClock, xas)
schemaProcessor = SchemaProcessor(schemaLog, fetchContext, schemaImports, rcr, projectMapper, eventClock)
fileSelf = FileSelf(originalProjectContext)(originalBase)
distributionPatcher = new DistributionPatcher(fileSelf, projectMapper, targetBase)
fileSelf = FileSelf(originalProjectContext)(originalBaseUri)
distributionPatcher = new DistributionPatcher(fileSelf, projectMapper, targetBaseUri)
resourceProcessor = ResourceProcessor(resourceLog, rcr, projectMapper, fetchContext, distributionPatcher, eventClock)
esViewsProcessor = ElasticSearchViewProcessor(fetchContext, rcr, projectMapper, eventLogConfig, eventClock, xas)
bgViewsProcessor = BlazegraphViewProcessor(fetchContext, rcr, projectMapper, eventLogConfig, eventClock, xas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import pureconfig.error.{CannotConvert, FailureReason}
import pureconfig.generic.semiauto.deriveReader

final case class InputConfig(
originalBase: BaseUri,
targetBase: BaseUri,
originalBaseUri: BaseUri,
targetBaseUri: BaseUri,
eventLog: EventLogConfig,
organizations: OrganizationCreationConfig,
projectMapping: ProjectMapping = Map.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DistributionPatcher(fileSelfParser: FileSelf, projectMapper: Project
}
}(_)

def single: Json => IO[Json] = (json: Json) => fileContentUrl(json).map(toS3Location)
private[resources] def single: Json => IO[Json] = (json: Json) => fileContentUrl(json).map(toS3Location)

private def toS3Location: Json => Json = root.atLocation.store.json.replace(targetStorage)

Expand Down
2 changes: 1 addition & 1 deletion ship/src/test/resources/config/external.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ship {
input {
target-base = "https://bbp.epfl.ch/v1"
target-base-uri = "https://bbp.epfl.ch/v1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ShipConfigSuite extends NexusSuite with ShipConfigFixtures with LocalStack

test("Default configuration should be parsed and loaded") {
val expectedBaseUri = BaseUri("http://localhost:8080", Label.unsafe("v1"))
ShipConfig.load(None).map(_.input.targetBase).assertEquals(expectedBaseUri)
ShipConfig.load(None).map(_.input.targetBaseUri).assertEquals(expectedBaseUri)
}

test("The defaults (name/description) for views should be correct") {
Expand All @@ -39,7 +39,7 @@ class ShipConfigSuite extends NexusSuite with ShipConfigFixtures with LocalStack
val expectedBaseUri = BaseUri("https://bbp.epfl.ch", Label.unsafe("v1"))
for {
externalConfigPath <- loader.absolutePath("config/external.conf")
_ <- ShipConfig.load(Some(Path(externalConfigPath))).map(_.input.targetBase).assertEquals(expectedBaseUri)
_ <- ShipConfig.load(Some(Path(externalConfigPath))).map(_.input.targetBaseUri).assertEquals(expectedBaseUri)
} yield ()
}

Expand Down Expand Up @@ -87,7 +87,7 @@ class ShipConfigSuite extends NexusSuite with ShipConfigFixtures with LocalStack
for {
_ <- uploadFileToS3(fs2S3client, bucket, configPath)
shipConfig <- ShipConfig.loadFromS3(s3Client, bucket, configPath)
_ = assertEquals(shipConfig.input.targetBase.toString, "https://bbp.epfl.ch/v1")
_ = assertEquals(shipConfig.input.targetBaseUri.toString, "https://bbp.epfl.ch/v1")
} yield ()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,34 @@ class DistributionPatcherSuite extends NexusSuite {

private val resourceIri: Iri = nxv + "resourceId"

private val originalBase = BaseUri(uri"http://bbp.epfl.ch/nexus", Label.unsafe("v1"))
private val targetBase = BaseUri(uri"https://www.openbrainplatform.org/api/nexus", Label.unsafe("v1"))
private val prefix = Label.unsafe("v1")
private val originalBaseUri = BaseUri(uri"http://bbp.epfl.ch/nexus", prefix)
private val targetBaseUri = BaseUri(uri"https://www.openbrainplatform.org/api/nexus", prefix)

private val validFileSelfUri = buildFileSelfUri(project1, resourceIri).accessUri(originalBase)
private val validFileSelfUri = buildFileSelfUri(project1, resourceIri).accessUri(originalBaseUri)

private def buildFileSelfUri(project: ProjectRef, id: Iri) =
ResourceUris("files", project, id)

private val fileSelf = new FileSelf {
override def parse(input: IriOrBNode.Iri): IO[(ProjectRef, ResourceRef)] =
input match {
case value if value.startsWith(originalBase.iriEndpoint) => IO.pure(project1 -> ResourceRef.Latest(resourceIri))
case value => IO.raiseError(InvalidFileId(value))
case value if value.startsWith(originalBaseUri.iriEndpoint) =>
IO.pure(project1 -> ResourceRef.Latest(resourceIri))
case value => IO.raiseError(InvalidFileId(value))
}
}

private val patcherNoProjectMapping = new DistributionPatcher(fileSelf, ProjectMapper(Map.empty), targetBase)
private val patcherNoProjectMapping = new DistributionPatcher(fileSelf, ProjectMapper(Map.empty), targetBaseUri)
private val patcherWithProjectMapping =
new DistributionPatcher(fileSelf, ProjectMapper(Map(project1 -> targetProject1)), targetBase)
new DistributionPatcher(fileSelf, ProjectMapper(Map(project1 -> targetProject1)), targetBaseUri)

test("Do nothing on a distribution payload without fields to patch") {
val input = json"""{ "anotherField": "XXX" }"""
patcherNoProjectMapping.single(input).assertEquals(input)
}

test("Patch location on a distribution") {
test("Patch location on a distribution to point to the new unique S3 storage") {
val input =
json"""{
"atLocation": {
Expand Down Expand Up @@ -75,14 +77,14 @@ class DistributionPatcherSuite extends NexusSuite {

test("Patch a valid file self on a distribution without project mapping") {
val input = json"""{ "contentUrl": "$validFileSelfUri" }"""
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBase)
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBaseUri)
val expected = json"""{ "contentUrl": "$expectedContentUri" }"""
patcherNoProjectMapping.single(input).assertEquals(expected)
}

test("Patch a valid file self on a distribution with project mapping") {
val input = json"""{ "contentUrl": "$validFileSelfUri" }"""
val expectedContentUri = buildFileSelfUri(targetProject1, resourceIri).accessUri(targetBase)
val expectedContentUri = buildFileSelfUri(targetProject1, resourceIri).accessUri(targetBaseUri)
val expected = json"""{ "contentUrl": "$expectedContentUri" }"""
patcherWithProjectMapping.single(input).assertEquals(expected)
}
Expand All @@ -94,14 +96,14 @@ class DistributionPatcherSuite extends NexusSuite {

test("Patch a valid file self on a distribution as an object") {
val input = json"""{ "distribution": { "contentUrl": "$validFileSelfUri" } }"""
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBase)
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBaseUri)
val expected = json"""{ "distribution": { "contentUrl": "$expectedContentUri" } }"""
patcherNoProjectMapping.singleOrArray(input).assertEquals(expected)
}

test("Patch a valid file self on a distribution as an array") {
val input = json"""{ "distribution": [{ "contentUrl": "$validFileSelfUri" }] }"""
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBase)
val expectedContentUri = buildFileSelfUri(project1, resourceIri).accessUri(targetBaseUri)
val expected = json"""{ "distribution": [{ "contentUrl": "$expectedContentUri" }] }"""
patcherNoProjectMapping.singleOrArray(input).assertEquals(expected)
}
Expand Down

0 comments on commit cf50158

Please sign in to comment.