From 24195cf3ffdb3a3194d29f7483e8526ea78bfbd1 Mon Sep 17 00:00:00 2001 From: Tim Berthold <75306992+tmberthold@users.noreply.github.com> Date: Wed, 29 Sep 2021 10:24:51 +0200 Subject: [PATCH] fix: create broker in DB upon bootstrap start (#630) * fix: create broker in DB upon bootstrap start * docs(changelog): add fix for bootstrap broker --- CHANGELOG.md | 1 + .../extension/bootstrap/Bootstrapper.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ccf130c8..a8c470834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. - Use language code instead of language ID when creating TypedLiterals. - Make SelfLinkHelper non-static, so that it can use Spring properties. - Use only */data* and not request's context path as delimiter for determining additional path for data requests. +- Create broker in database upon bootstrap start. ### Changed - Add `ServiceResolver` to remove some Spring annotations from service classes. diff --git a/src/main/java/io/dataspaceconnector/extension/bootstrap/Bootstrapper.java b/src/main/java/io/dataspaceconnector/extension/bootstrap/Bootstrapper.java index 07807f7f7..c5299a4ae 100644 --- a/src/main/java/io/dataspaceconnector/extension/bootstrap/Bootstrapper.java +++ b/src/main/java/io/dataspaceconnector/extension/bootstrap/Bootstrapper.java @@ -35,11 +35,13 @@ import io.dataspaceconnector.extension.bootstrap.util.BootstrapUtils; import io.dataspaceconnector.model.artifact.ArtifactDesc; import io.dataspaceconnector.model.auth.AuthenticationDesc; +import io.dataspaceconnector.model.broker.BrokerDesc; import io.dataspaceconnector.model.resource.OfferedResourceDesc; import io.dataspaceconnector.model.resource.RequestedResourceDesc; import io.dataspaceconnector.model.template.ResourceTemplate; import io.dataspaceconnector.service.message.GlobalMessageService; import io.dataspaceconnector.service.resource.templatebuilder.CatalogTemplateBuilder; +import io.dataspaceconnector.service.resource.type.BrokerService; import io.dataspaceconnector.service.resource.type.CatalogService; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -143,6 +145,11 @@ public class Bootstrapper { */ private final @NonNull GlobalMessageService brokerSvc; + /** + * Service for the broker. + */ + private final @NotNull BrokerService brokerService; + /** * Bootstrap the connector. Will load JSON-LD files containing IDS catalog entities and register * them in the DSC. Additionally, property files will be loaded and provide information on the @@ -212,6 +219,9 @@ private boolean registerAtBroker(final Properties properties, try { if (!knownBrokers.contains(broker.toString())) { knownBrokers.add(broker.toString()); + + createBroker(broker); + var connectorResponse = brokerSvc .sendConnectorUpdateMessage(broker.toURI()); if (!brokerSvc.checkResponse(connectorResponse)) { @@ -241,6 +251,15 @@ private boolean registerAtBroker(final Properties properties, return true; } + private void createBroker(final URL broker) throws URISyntaxException { + if (brokerService.findByLocation(broker.toURI()).isEmpty()) { + final var brokerDesc = new BrokerDesc(); + brokerDesc.setLocation(broker.toURI()); + brokerDesc.setTitle(broker.toString()); + brokerService.create(brokerDesc); + } + } + private List loadBootstrapData() { try { final var files = findFilesByExtension(bootstrapPath, FILE_EXT);