Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic AMQP interface and integrate transformation functionality #1

Merged
merged 8 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
insert_final_newline = false

[build.gradle]
indent_style = tab
22 changes: 22 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check

on:
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

- name: Run check
run: ./gradlew check
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
},
"[gradle]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
}
},
"java.compile.nullAnalysis.mode": "automatic"
}
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# hale-transformer-api

Spring Boot application that runs hale transformations based on requests read from a AMQP message queue.
The message queue needs to be provided externally, e.g. by a RabbitMQ instance.

## Build

To build the application, run

./gradlew build

To start an instance, run

./gradlew bootRun

## RabbitMQ

To start a local RabbitMQ instance that can be used for debugging purposes, run

docker compose up

in the root directory of this project.

The local instance can be also used to send messages to the queue that are then
processed by the application. When the application is running, an example message
like the following can be sent to the queue:

```bash
$ docker exec -ti hale-transformer-api-rabbitmq-1 bash
root@123456789abc:/# rabbitmqadmin publish \
> exchange=hale-transformer-exchange \
> routing_key=hale.transformation.foo \
> properties='{"content_type":"application/json"}' payload='{"projectUrl": "http://example.org/proj", "sourceDataUrl": "http://example.org/data"}'
Message published
root@123456789abc:/#
```
60 changes: 55 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,63 @@ group = 'to.wetransform.hale'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

repositories {
// mavenLocal() //XXX for testing
maven {
// wetransform release repository (hale releases and Eclipse dependencies)
url 'https://artifactory.wetransform.to/artifactory/local'
}
// this needs to be defined before jcenter/MavenCentral for retrieving JAI
maven {
url 'https://repo.osgeo.org/repository/release/'
}
mavenCentral()
}

project.ext {
haleVersion = '5.1.0-SNAPSHOT'
cliVersion = '5.1.0-SNAPSHOT'
groovyVersion = '2.5.19'
}

dependencies {
// Spring
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.github.docker-java:docker-java-core:3.3.3'
implementation 'com.github.docker-java:docker-java-transport-httpclient5:3.3.3'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'

// hale
implementation 'eu.esdihumboldt.unpuzzled:org.eclipse.equinox.nonosgi.registry:1.0.0'
implementation "to.wetransform:hale-cli:$cliVersion", {
/*
* XXX The dependencies introduced by the schematron bundle cause some problems.
*/
exclude group: 'eu.esdihumboldt.hale', module: 'eu.esdihumboldt.hale.io.schematron'
}

implementation "eu.esdihumboldt.hale:eu.esdihumboldt.hale.app.cli.commands:$haleVersion"
implementation "org.codehaus.groovy:groovy-all:$groovyVersion"
implementation 'org.json:json:20190722'
implementation 'org.slf4j:jul-to-slf4j:1.7.21'
implementation 'org.apache.httpcomponents:httpmime:4.5.14'

//developmentOnly 'org.springframework.boot:spring-boot-docker-compose'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Logging
testRuntimeOnly 'ch.qos.logback:logback-core:1.4.11'
testRuntimeOnly 'ch.qos.logback:logback-classic:1.4.11'
}

configurations.all {
// ensure SNAPSHOTs are updated every time if needed
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

tasks.named('test') {
Expand All @@ -34,13 +74,23 @@ tasks.named('test') {

spotless {
java {
importOrder('groovy', 'java', 'javax', '')
palantirJavaFormat()
importOrder('java', 'javax', '')
removeUnusedImports()
indentWithSpaces(4)
trimTrailingWhitespace()
endWithNewline()

target 'src/*/java/**/*.java'
}
groovyGradle {
target '*.gradle' // default target of groovyGradle
greclipse()
}
}

/*
* Gradle wrapper
*/
wrapper {
gradleVersion = '8.4'
}
5 changes: 5 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
services:
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/to/wetransform/hale/transformer/CustomTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package to.wetransform.hale.transformer;

import java.util.HashMap;
import java.util.Map;

import eu.esdihumboldt.hale.common.core.io.Value;

public record CustomTarget(String providerId, Map<String, Value> settings) {

public CustomTarget(String providerId) {
this(providerId, new HashMap<>());
}
}
17 changes: 17 additions & 0 deletions src/main/java/to/wetransform/hale/transformer/SourceConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package to.wetransform.hale.transformer;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import eu.esdihumboldt.hale.common.core.io.Value;

public record SourceConfig(
URI location, String providerId, Map<String, Value> settings, boolean transform, List<String> attachments) {

public SourceConfig(URI location, String providerId) {
this(location, providerId, new HashMap<>(), true, new ArrayList<>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package to.wetransform.hale.transformer;

public record TargetConfig(String filename, String preset, CustomTarget customTarget) {}
80 changes: 80 additions & 0 deletions src/main/java/to/wetransform/hale/transformer/Transformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package to.wetransform.hale.transformer;

import java.io.InputStream;
import java.net.URI;
import java.text.MessageFormat;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import eu.esdihumboldt.hale.app.transform.ExecContext;
import eu.esdihumboldt.hale.common.core.HalePlatform;
import eu.esdihumboldt.hale.common.core.io.project.model.Project;
import eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier;
import eu.esdihumboldt.util.io.IOUtils;
import org.osgi.framework.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import to.wetransform.halecli.internal.Init;

public class Transformer {

private static final Logger LOG = LoggerFactory.getLogger(Transformer.class);

private CountDownLatch latch = new CountDownLatch(1);

public void transform(/* TODO add parameters for data and project sources */ ) {
// TODO setup log files for reports and transformation log

long heapMaxSize = Runtime.getRuntime().maxMemory();
LOG.info("Maximum heap size configured as " + IOUtils.humanReadableByteCount(heapMaxSize, false));

Init.init();

Version version = HalePlatform.getCoreVersion();
LOG.info(MessageFormat.format("Launching hale-transformer {0}...", version.toString()));

ExecContext context = new ExecContext();

// URI projectUri = ....
// context.setProject(projectUri);
// Project project = loadProject(projectUri);

// context.setSources(...)
// context.setSourceProviderIds(...)
// context.setSourcesSettings(...)

// Value sourceCrs = null;
// TODO determine source CRS

// TargetConfig targetConfig = configureTarget(project, sourceCrs);

try {
// run the transformation

LOG.info("Transforming...");
TimeUnit.SECONDS.sleep(30);
// new ExecTransformation().run(context);

LOG.info("Transformation complete.");
} catch (Throwable t) {
LOG.error("Failed to execute transformation: " + t.getMessage(), t);
} finally {
latch.countDown();
}
}

private Project loadProject(URI projectUri) {
DefaultInputSupplier supplier = new DefaultInputSupplier(projectUri);
Project result = null;
try (InputStream in = supplier.getInput()) {
result = Project.load(in);
} catch (Exception e) {
LOG.warn("Could not load project file to determine presets: " + e.getStackTrace());
}
return result;
}

public CountDownLatch getLatch() {
return latch;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package to.wetransform.hale.transformer;

public class TransformerConfig {

// empty for now
}

This file was deleted.

Loading