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 6 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
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"
}
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.

Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
package to.wetransform.hale.transformer.api;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class TransformerApiApplication {

// TODO Should be configurable
private static final String ROUTING_KEY = "hale.transformation.#";

// TODO Should be configurable
public static final String TOPIC_EXCHANGE_NAME = "hale-transformer-exchange";

// TODO Should be configurable
public static final String QUEUE_NAME = "hale-transformation";

@Bean
Queue queue() {
// TODO Queue should be declared passively, i.e. it should be created
// outside of this application
return new Queue(QUEUE_NAME, false);
}

@Bean
TopicExchange exchange() {
// TODO Exchange should be declared passively, i.e. it should be created
// outside of this application
return new TopicExchange(TOPIC_EXCHANGE_NAME);
}

@Bean
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY);
}

@Bean
public MessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}

@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
final var rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(jsonMessageConverter());
return rabbitTemplate;
}

public static void main(String[] args) {
SpringApplication.run(TransformerApiApplication.class, args);
}

}
Loading