diff --git a/ship/src/main/resources/ship-default.conf b/ship/src/main/resources/ship-default.conf index c696547ef9..261d435892 100644 --- a/ship/src/main/resources/ship-default.conf +++ b/ship/src/main/resources/ship-default.conf @@ -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 = { diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala index 4a0a6be615..18ecd56f98 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala @@ -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 @@ -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) diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/config/InputConfig.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/config/InputConfig.scala index 0afa116b9a..c469556291 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/config/InputConfig.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/config/InputConfig.scala @@ -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, diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcher.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcher.scala index 8ede5c87bd..d8a086ada4 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcher.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcher.scala @@ -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) diff --git a/ship/src/test/resources/config/external.conf b/ship/src/test/resources/config/external.conf index 3c7748793d..ab56f2e472 100644 --- a/ship/src/test/resources/config/external.conf +++ b/ship/src/test/resources/config/external.conf @@ -1,5 +1,5 @@ ship { input { - target-base = "https://bbp.epfl.ch/v1" + target-base-uri = "https://bbp.epfl.ch/v1" } } \ No newline at end of file diff --git a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/config/ShipConfigSuite.scala b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/config/ShipConfigSuite.scala index 6f0d6ac960..66f8f00558 100644 --- a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/config/ShipConfigSuite.scala +++ b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/config/ShipConfigSuite.scala @@ -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") { @@ -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 () } @@ -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 () } diff --git a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcherSuite.scala b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcherSuite.scala index c3fef2dec9..d39666ede5 100644 --- a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcherSuite.scala +++ b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/resources/DistributionPatcherSuite.scala @@ -19,10 +19,11 @@ 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) @@ -30,21 +31,22 @@ class DistributionPatcherSuite extends NexusSuite { 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": { @@ -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) } @@ -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) }