Skip to content

Commit

Permalink
Migrate from dc-commons-file 4 to 5 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
datazuul authored May 15, 2020
1 parent 1a25cb7 commit 5f4e426
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 53 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Hymir is a Java based IIIF Server. It is based on our [IIIF API Java Libraries](
## Prerequisites

- Server with minimum 4GB RAM.
- Java 8
- Java 11

## Installation

Expand Down Expand Up @@ -107,7 +107,7 @@ Application configuration: see [here](src/main/resources/application.yml) (`loca
- in production

```sh
$ java -jar hymir-4.0.0-exec.jar --spring.profiles.active=PROD
$ java -jar hymir-<version>-exec.jar --spring.profiles.active=PROD
```

Logging: to file `./hymir.log` in [Logstash](https://www.elastic.co/de/products/logstash)-JSON format
Expand All @@ -119,7 +119,7 @@ Application configuration: see [here](src/main/resources/application.yml) (`PROD
- in production with custom logging configuration file:

```sh
$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --spring.profiles.active=PROD
$ java -jar hymir-<version>-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --spring.profiles.active=PROD
```

Read <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html> and <https://logback.qos.ch/manual/configuration.html>.
Expand All @@ -129,19 +129,19 @@ Read <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-featur
(Custom `application.yml` placed beside jar-file. No explicit command line option needed.)

```sh
$ java -jar hymir-4.0.0-exec.jar --spring.profiles.active=PROD
$ java -jar hymir-<version>-exec.jar --spring.profiles.active=PROD
```

- in production with a custom server port (e.g. port 8080):

```sh
$ java -jar hymir-4.0.0-exec.jar --server.port=8080 --spring.profiles.active=PROD
$ java -jar hymir-<version>-exec.jar --server.port=8080 --spring.profiles.active=PROD
```

Complete parametrized example:

```sh
$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --server.port=8080 --spring.profiles.active=PROD
$ java -jar hymir-<version>-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml --server.port=8080 --spring.profiles.active=PROD
```

(and `application.yml` beside jar file).
Expand Down Expand Up @@ -171,7 +171,7 @@ You can pass the path to your custom resolving rules with the `--spring.config.a
Example:

```sh
$ java -jar hymir-4.0.0-exec.jar --spring.config.additional-location=file:/etc/hymir/rules.yml
$ java -jar hymir-<version>-exec.jar --spring.config.additional-location=file:/etc/hymir/rules.yml
```

Example file `/etc/hymir/rules.yml`:
Expand Down Expand Up @@ -245,7 +245,7 @@ You can configure another url prefix on server startup using system property `cu
Example:

```sh
$ java -jar target/hymir-4.0.0-exec.jar --custom.iiif.image.urlPrefix='/iiifImage/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local
$ java -jar target/hymir-<version>-exec.jar --custom.iiif.image.urlPrefix='/iiifImage/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local
```

Resulting URL: `http://localhost:9000/iiifImage/00113391_00001/full/300,/0/default.jpg`
Expand Down Expand Up @@ -281,7 +281,7 @@ You can configure another url prefix on server startup using system property `cu
Example:

```sh
$ java -jar hymir-4.0.0-exec.jar --custom.iiif.presentation.urlPrefix='/iiifPresentation/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local
$ java -jar hymir-<version>-exec.jar --custom.iiif.presentation.urlPrefix='/iiifPresentation/' --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local
```

Resulting URL: `http://localhost:9000/iiifPresentation/00113391/manifest`
Expand Down Expand Up @@ -319,7 +319,7 @@ If you want human readable logging to console use `--spring.profiles.active=loca
Example: Custom config file with human readable logging

```sh
$ java -jar hymir-4.0.0-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml
$ java -jar hymir-<version>-exec.jar --logging.config=file:/etc/hymir/logback-spring.xml
```

Example file `/etc/hymir/logback-spring.xml`:
Expand Down Expand Up @@ -380,7 +380,7 @@ Your custom `application.yml` does not have to replace all default properties. I
To get the default configuration file, you should download the `hymir-<release-version>.jar` file (NOT containing `-exec` in filename) from <https://github.com/dbmdz/iiif-server-hymir/releases> and unpack the contained `application.yml` with:

```sh
$ jar xfv hymir-4.0.0.jar application.yml
$ jar xfv hymir-<version>.jar application.yml
```

Now put the file beside the executable Hymir jar and edit it according to your requirements.
Expand Down Expand Up @@ -445,15 +445,15 @@ Monitoring endpoints under http://localhost:9001/monitoring (HAL-Browser-GUI), a
To change monitoring port, e.g. to `8081` use `management.server.port` option:

```sh
$ java -jar hymir-4.0.0-exec.jar --management.server.port=8081
$ java -jar hymir-<version>-exec.jar --management.server.port=8081
```

### Out Of Memory handling

In case the IIIF server runs out of memory it should quit - use java options for this. (To be restarted automatically install it as systemd service, see below.)

```sh
$ java -jar hymir-4.0.0-exec.jar -XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError
$ java -jar hymir-<version>-exec.jar -XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError
```

### Configure IIIF service as systemd service
Expand All @@ -470,7 +470,7 @@ After=syslog.target
[Service]
User=iiif
ExecStart=/usr/bin/java -jar /opt/hymir-4.0.0-exec.jar \
ExecStart=/usr/bin/java -jar /opt/hymir-<version>-exec.jar \
-XX:+ExitOnOutOfMemoryError -XX:+CrashOnOutOfMemoryError \
--spring.config.additional-location=file:/etc/hymir/rules.yml \
--spring.profiles.active=PROD \
Expand All @@ -497,7 +497,7 @@ $ sudo systemctl start iiif-hymir.service
## Development

* Install git client
* Install Java JDK 1.8 or above
* Install Java JDK 11 or above
* Install Apache Maven buildttool

```sh
Expand Down
6 changes: 3 additions & 3 deletions nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.args>-classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand All @@ -59,7 +59,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.args>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
Expand All @@ -74,7 +74,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath de.digitalcollections.iiif.hymir.Application --rules=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.args>-classpath %classpath de.digitalcollections.iiif.hymir.Application --spring.config.additional-location=file:/etc/hymir/rules.yml --spring.profiles.active=local</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand Down
15 changes: 9 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>de.digitalcollections</groupId>
<artifactId>iiif-server-hymir</artifactId>
<version>4.1.4-SNAPSHOT</version>
<version>4.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<url>https://github.com/dbmdz/iiif-server-hymir</url>
Expand Down Expand Up @@ -78,7 +78,10 @@

<version.assertj-json>1.2.0</version.assertj-json>
<version.commons-cli>1.4</version.commons-cli>
<version.dc-commons>4.0.3</version.dc-commons>
<version.dc-commons-file>5.0.1</version.dc-commons-file>
<version.dc-commons-server>4.1.1</version.dc-commons-server>
<version.dc-commons-springboot>4.1.1</version.dc-commons-springboot>
<version.dc-commons-springmvc>4.1.2</version.dc-commons-springmvc>
<version.guava>29.0-jre</version.guava>
<version.iiif-apis>0.3.8</version.iiif-apis>
<version.imageio-jnr>0.4.4</version.imageio-jnr>
Expand Down Expand Up @@ -183,22 +186,22 @@
<dependency>
<groupId>de.digitalcollections.commons</groupId>
<artifactId>dc-commons-file</artifactId>
<version>${version.dc-commons}</version>
<version>${version.dc-commons-file}</version>
</dependency>
<dependency>
<groupId>de.digitalcollections.commons</groupId>
<artifactId>dc-commons-server</artifactId>
<version>${version.dc-commons}</version>
<version>${version.dc-commons-server}</version>
</dependency>
<dependency>
<groupId>de.digitalcollections.commons</groupId>
<artifactId>dc-commons-springboot</artifactId>
<version>${version.dc-commons}</version>
<version>${version.dc-commons-springboot}</version>
</dependency>
<dependency>
<groupId>de.digitalcollections.commons</groupId>
<artifactId>dc-commons-springmvc</artifactId>
<version>${version.dc-commons}</version>
<version>${version.dc-commons-springmvc}</version>
</dependency>
<dependency>
<groupId>de.digitalcollections.imageio</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.digitalcollections.iiif.hymir.config;

import de.digitalcollections.commons.file.config.SpringConfigCommonsFile;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -10,12 +11,12 @@
import javax.imageio.spi.IIORegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/** Backend configuration. */
@Configuration
@ComponentScan(basePackages = {"de.digitalcollections.commons.file.config"})
@Import(SpringConfigCommonsFile.class)
public class SpringConfigBackendImage {

private static final Logger LOGGER = LoggerFactory.getLogger(SpringConfigBackendImage.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package de.digitalcollections.iiif.hymir.config;

import org.springframework.context.annotation.ComponentScan;
import de.digitalcollections.commons.file.config.SpringConfigCommonsFile;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/** Backend configuration. */
@Configuration
@ComponentScan(basePackages = {"de.digitalcollections.commons.file.config"})
@Import(SpringConfigCommonsFile.class)
public class SpringConfigBackendPresentation {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.digitalcollections.iiif.hymir.image.business;

import com.google.common.collect.Streams;
import de.digitalcollections.commons.file.business.impl.resolved.ResolvedFileResourceServiceImpl;
import de.digitalcollections.commons.file.business.api.FileResourceService;
import de.digitalcollections.iiif.hymir.image.business.api.ImageSecurityService;
import de.digitalcollections.iiif.hymir.image.business.api.ImageService;
import de.digitalcollections.iiif.hymir.model.exception.InvalidParametersException;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static boolean containsAlphaChannel(BufferedImage image) {
}

private final ImageSecurityService imageSecurityService;
private final ResolvedFileResourceServiceImpl fileResourceService;
private final FileResourceService fileResourceService;

@Value("${custom.iiif.logo:}")
private String logoUrl;
Expand All @@ -76,7 +76,7 @@ public static boolean containsAlphaChannel(BufferedImage image) {

public ImageServiceImpl(
@Autowired(required = false) ImageSecurityService imageSecurityService,
@Autowired ResolvedFileResourceServiceImpl fileResourceService) {
@Autowired FileResourceService fileResourceService) {
this.imageSecurityService = imageSecurityService;
this.fileResourceService = fileResourceService;
}
Expand Down Expand Up @@ -479,6 +479,6 @@ protected DecodedImage(BufferedImage img, Dimension targetSize, int rotation) {
this.img = img;
this.targetSize = targetSize;
this.rotation = rotation;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.digitalcollections.iiif.hymir.presentation.backend;

import de.digitalcollections.commons.file.business.impl.resolved.ResolvedFileResourceServiceImpl;
import de.digitalcollections.commons.file.business.api.FileResourceService;
import de.digitalcollections.iiif.hymir.model.exception.InvalidDataException;
import de.digitalcollections.iiif.hymir.model.exception.ResolvingException;
import de.digitalcollections.iiif.hymir.presentation.backend.api.PresentationRepository;
Expand All @@ -13,12 +13,9 @@
import de.digitalcollections.model.api.identifiable.resource.exceptions.ResourceIOException;
import de.digitalcollections.model.api.identifiable.resource.exceptions.ResourceNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -36,21 +33,22 @@ public class PresentationRepositoryImpl implements PresentationRepository {

@Autowired private IiifObjectMapper objectMapper;

@Autowired private ResolvedFileResourceServiceImpl resourceService;
@Autowired private FileResourceService fileResourceService;

@Override
public AnnotationList getAnnotationList(String identifier, String name, String canvasId)
throws ResolvingException, ResourceNotFoundException, InvalidDataException {
String annotationListName = name + "-" + identifier + "_" + canvasId;
FileResource resource;
try {
resource = resourceService.find(annotationListName, MimeType.MIME_APPLICATION_JSON);
resource = fileResourceService.find(annotationListName, MimeType.MIME_APPLICATION_JSON);
} catch (ResourceIOException ex) {
LOGGER.error("Error getting annotation list for name {}", annotationListName, ex);
throw new ResolvingException("No annotation list for name " + annotationListName);
}
try {
return objectMapper.readValue(getResourceJson(resource.getUri()), AnnotationList.class);
return objectMapper.readValue(
fileResourceService.getAsString(resource, StandardCharsets.UTF_8), AnnotationList.class);
} catch (IOException ex) {
LOGGER.error("Could not retrieve annotation list {}", annotationListName, ex);
throw new InvalidDataException(
Expand All @@ -65,13 +63,14 @@ public Collection getCollection(String name)
String collectionName = COLLECTION_PREFIX + name;
FileResource resource;
try {
resource = resourceService.find(collectionName, MimeType.MIME_APPLICATION_JSON);
resource = fileResourceService.find(collectionName, MimeType.MIME_APPLICATION_JSON);
} catch (ResourceIOException ex) {
LOGGER.error("Error getting manifest for collection {}", name, ex);
throw new ResolvingException("No collection for name " + name);
}
try {
return objectMapper.readValue(getResourceJson(resource.getUri()), Collection.class);
return objectMapper.readValue(
fileResourceService.getAsString(resource, StandardCharsets.UTF_8), Collection.class);
} catch (IOException ex) {
LOGGER.info("Could not retrieve collection {}", collectionName, ex);
throw new InvalidDataException(
Expand All @@ -84,13 +83,14 @@ public Manifest getManifest(String identifier)
throws ResolvingException, ResourceNotFoundException, InvalidDataException {
FileResource resource;
try {
resource = resourceService.find(identifier, MimeType.MIME_APPLICATION_JSON);
resource = fileResourceService.find(identifier, MimeType.MIME_APPLICATION_JSON);
} catch (ResourceIOException ex) {
LOGGER.error("Error getting manifest for identifier {}", identifier, ex);
throw new ResolvingException("No manifest for identifier " + identifier);
}
try {
return objectMapper.readValue(getResourceJson(resource.getUri()), Manifest.class);
return objectMapper.readValue(
fileResourceService.getAsString(resource, StandardCharsets.UTF_8), Manifest.class);
} catch (IOException ex) {
LOGGER.error("Manifest {} can not be parsed", identifier, ex);
throw new InvalidDataException("Manifest " + identifier + " can not be parsed", ex);
Expand All @@ -112,21 +112,12 @@ public Instant getCollectionModificationDate(String identifier)
private Instant getResourceModificationDate(String identifier)
throws ResolvingException, ResourceNotFoundException {
try {
FileResource resource = resourceService.find(identifier, MimeType.MIME_APPLICATION_JSON);
FileResource resource = fileResourceService.find(identifier, MimeType.MIME_APPLICATION_JSON);
return resource.getLastModified().toInstant(ZoneOffset.UTC);
} catch (ResourceIOException ex) {
LOGGER.error(
"Error getting resource for identifier '{}', message '{}'", identifier, ex.getMessage());
throw new ResolvingException("No manifest for identifier " + identifier);
}
}

protected String getResourceJson(URI resourceUri)
throws ResolvingException, ResourceNotFoundException {
try (InputStream is = resourceService.getInputStream(resourceUri)) {
return IOUtils.toString(is, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new ResolvingException(e);
}
}
}

0 comments on commit 5f4e426

Please sign in to comment.