Skip to content

Commit

Permalink
Fix cached resources deserialization
Browse files Browse the repository at this point in the history
- for startup with resources from previous deployment
  • Loading branch information
Querela committed Mar 28, 2024
1 parent 8bee029 commit c9928fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

# WIP - 2024-03-28

- Bug Fixes:
- Fix cached resources (`fcsAggregatorResources.json`) deserialization (invisible non-default constructor of external FCS libraries)

# [3.9.1](https://github.com/clarin-eric/fcs-sru-aggregator/releases/tag/3.9.1) - 2024-02-05

- Bug Fixes:
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.clarin.sru.fcs.aggregator.app;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.optimaize.langdetect.LanguageDetector;
import com.optimaize.langdetect.LanguageDetectorBuilder;
Expand All @@ -15,6 +16,7 @@
import eu.clarin.sru.fcs.aggregator.scan.Resources;
import eu.clarin.sru.client.SRUVersion;
import eu.clarin.sru.client.fcs.ClarinFCSClientBuilder;
import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescription;
import eu.clarin.sru.client.fcs.ClarinFCSEndpointDescriptionParser;
import eu.clarin.sru.fcs.aggregator.client.MaxConcurrentRequestsCallback;
import eu.clarin.sru.fcs.aggregator.client.ThrottledClient;
Expand Down Expand Up @@ -295,15 +297,20 @@ public int getMaxConcurrentRequest(URI baseURI) {

// init resources from file
{
ObjectMapper mapper = new ObjectMapper()
.addMixIn(ClarinFCSEndpointDescription.DataView.class,
ClarinFCSEndpointDescriptionDataViewMixin.class)
.addMixIn(ClarinFCSEndpointDescription.Layer.class, ClarinFCSEndpointDescriptionLayerMixin.class);

Resources resources = null;
try {
resources = new ObjectMapper().readValue(resourcesCacheFile, Resources.class);
resources = mapper.readValue(resourcesCacheFile, Resources.class);
} catch (Exception xc) {
log.error("Failed to load cached resources from primary file:", xc);
}
if (resources == null) {
try {
resources = new ObjectMapper().readValue(resourcesOldCacheFile, Resources.class);
resources = mapper.readValue(resourcesOldCacheFile, Resources.class);
} catch (Exception e) {
log.error("Failed to load cached resources from backup file:", e);
}
Expand Down Expand Up @@ -333,6 +340,26 @@ public int getMaxConcurrentRequest(URI baseURI) {
log.info("Aggregator initialization finished.");
}

// Definitions for Jackson Deserializer due to non-public non-default
// constructors
private static abstract class ClarinFCSEndpointDescriptionDataViewMixin {
@SuppressWarnings("unused")
ClarinFCSEndpointDescriptionDataViewMixin(@JsonProperty("identifier") String identifier,
@JsonProperty("mimeType") String mimeType,
@JsonProperty("deliveryPolicy") ClarinFCSEndpointDescription.DataView.DeliveryPolicy deliveryPolicy) {
}
}

private static abstract class ClarinFCSEndpointDescriptionLayerMixin {
@SuppressWarnings("unused")
ClarinFCSEndpointDescriptionLayerMixin(@JsonProperty("identifier") String identifier,
@JsonProperty("resultId") URI resultId, @JsonProperty("layerType") String layerType,
@JsonProperty("encoding") ClarinFCSEndpointDescription.Layer.ContentEncoding encoding,
@JsonProperty("qualifier") String qualifier, @JsonProperty("altValueInfo") String altValueInfo,
@JsonProperty("altValueInfoURI") URI altValueInfoURI) {
}
}

public void shutdown(AggregatorConfiguration config) {
log.info("Aggregator is shutting down.");
for (Search search : activeSearches.values()) {
Expand Down

0 comments on commit c9928fa

Please sign in to comment.