Skip to content

Commit

Permalink
fix: create broker in DB upon bootstrap start (#630)
Browse files Browse the repository at this point in the history
* fix: create broker in DB upon bootstrap start

* docs(changelog): add fix for bootstrap broker
  • Loading branch information
tmberthold authored Sep 29, 2021
1 parent bbbab26 commit 24195cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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<File> loadBootstrapData() {
try {
final var files = findFilesByExtension(bootstrapPath, FILE_EXT);
Expand Down

0 comments on commit 24195cf

Please sign in to comment.