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

Add a configuration loader #28

Merged
merged 19 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e17e7bd
build: remove dependency in core and cartago module to websub module
cake-lier Dec 15, 2023
7ba0af8
refactor: de-singletonize NotificationSubscriberRegistry, transform m…
cake-lier Dec 15, 2023
8f1cab3
test: fix tests after refactor
cake-lier Dec 15, 2023
67ce637
refactor: update configuration specification to separate notification…
cake-lier Dec 16, 2023
e3230e6
build: remove dependency of root project from websub and cartago modules
cake-lier Dec 16, 2023
57a4b84
build: update reference configurations
cake-lier Dec 19, 2023
6fd7039
feat: add parser for environment definition, disable message sending …
cake-lier Dec 19, 2023
0efe553
test: adapt tests to specify proper configuration
cake-lier Dec 19, 2023
50966eb
fix: add creation of resources given the configuration both for dynam…
cake-lier Dec 19, 2023
83cba4c
test: fix tests for new configuration loading in verticles
cake-lier Dec 19, 2023
480456a
test: add tests for configuration loading
cake-lier Dec 19, 2023
de3ae4d
fix: re-add configuration loading after removal due to rebase
cake-lier Jan 20, 2024
c66af70
refactor: remove yggdrasil agent name as variable
cake-lier Jan 20, 2024
eadb21a
fix: load representations in static configuration as file paths
cake-lier Jan 20, 2024
98a38ec
build: change subproject type of core to library, re-add dependencies…
cake-lier Jan 21, 2024
3fa8ab8
test: fix configuration parameters in all files
cake-lier Jan 23, 2024
c51ad0c
test: fix hMAS ontology URL
cake-lier Jan 23, 2024
b84fefa
test: refactor tests and add missing configuration in body http handl…
cake-lier Jan 23, 2024
27ebe3e
fix: add missing parameter in http notification action messages seria…
cake-lier Jan 23, 2024
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ allprojects {
}

dependencies {
implementation(project(":yggdrasil-utils"))
implementation(project(":yggdrasil-core"))
implementation(project(":yggdrasil-cartago"))
implementation(project(":yggdrasil-websub"))
Expand All @@ -68,7 +69,6 @@ dependencies {
testImplementation(libs.wot.td.java)
testImplementation(libs.rdf4j.model)
testImplementation(files("libs/cartago-3.1.jar"))
testImplementation(project(":yggdrasil-utils"))

testCompileOnly(libs.spotbugs.annotations)
}
Expand Down
46 changes: 46 additions & 0 deletions conf/cartago_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"http-config" : {
"host" : "localhost",
"port" : 8080,
"base-uri" : "http://localhost:8080/"
},
"notification-config" : {
"enabled" : true
},
"environment-config" : {
"known-artifacts" : [
{
"class" : "http://example.org/Counter",
"template" : "org.hyperagents.yggdrasil.cartago.artifacts.Counter"
}
],
"workspaces" : [
{
"name" : "w1"
},
{
"name" : "w0",
"parent-name" : "w1",
"artifacts" : [
{
"name" : "c0",
"class" : "http://example.org/Counter",
"init-params" : [
5
],
"focused-by" : [
{
"agent-uri" : "http://localhost:8080/agents/test",
"callback-uri" : "http://localhost:8081/"
}
]
}
],
"agents" : [
"http://localhost:8080/agents/test"
]
}
],
"enabled" : true
}
}
10 changes: 8 additions & 2 deletions conf/docker_disk_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"http-config" : {
"host" : "0.0.0.0",
"port" : 8080,
"base-uri" : "http://localhost:8899/",
"websub-hub-uri" : "https://yggdrasil.interactions.ics.unisg.ch/hub/"
"base-uri" : "http://localhost:8899/"
},
"rdf-store" : {
"in-memory" : false,
"store-path" : "data/"
},
"notification-config" : {
"websub-hub-base-uri" : "https://yggdrasil.interactions.ics.unisg.ch/",
"enabled" : true
},
"environment-config" : {
"enabled" : true
}
}
9 changes: 7 additions & 2 deletions conf/localhost_memory_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"http-config" : {
"host" : "localhost",
"port" : 8080,
"base-uri" : "http://localhost:8080/",
"websub-hub-uri" : "http://localhost:8080/hub/"
"base-uri" : "http://localhost:8080/"
},
"notification-config" : {
"enabled" : true
},
"environment-config" : {
"enabled" : true
}
}
26 changes: 26 additions & 0 deletions conf/static_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"http-config" : {
"host" : "localhost",
"port" : 8080,
"base-uri" : "http://localhost:8080/"
},
"environment-config" : {
"workspaces" : [
{
"name" : "test",
"representation" : "test_workspace_td.ttl"
},
{
"name" : "sub",
"parent-name" : "test",
"artifacts" : [
{
"name" : "c0",
"representation" : "c0_counter_artifact.ttl"
}
],
"representation" : "sub_workspace_td.ttl"
}
]
}
}
68 changes: 48 additions & 20 deletions src/main/java/org/hyperagents/yggdrasil/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,63 @@
import io.vertx.config.ConfigRetriever;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import org.hyperagents.yggdrasil.cartago.CartagoVerticle;
import org.hyperagents.yggdrasil.http.HttpServerVerticle;
import org.hyperagents.yggdrasil.model.Environment;
import org.hyperagents.yggdrasil.model.impl.EnvironmentParser;
import org.hyperagents.yggdrasil.store.RdfStoreVerticle;
import org.hyperagents.yggdrasil.websub.HttpNotificationVerticle;
import org.hyperagents.yggdrasil.utils.EnvironmentConfig;
import org.hyperagents.yggdrasil.utils.HttpInterfaceConfig;
import org.hyperagents.yggdrasil.utils.WebSubConfig;
import org.hyperagents.yggdrasil.utils.impl.EnvironmentConfigImpl;
import org.hyperagents.yggdrasil.utils.impl.HttpInterfaceConfigImpl;
import org.hyperagents.yggdrasil.utils.impl.WebSubConfigImpl;

public class MainVerticle extends AbstractVerticle {
private static final String DEFAULT_CONF_VALUE = "default";

@Override
public void start(final Promise<Void> startPromise) {
ConfigRetriever.create(this.vertx)
.getConfig()
.compose(c ->
this.vertx.deployVerticle(
new HttpServerVerticle(),
new DeploymentOptions().setConfig(c)
)
.compose(v -> this.vertx.deployVerticle(
new RdfStoreVerticle(),
new DeploymentOptions().setConfig(c)
))
.compose(v -> this.vertx.deployVerticle(
new HttpNotificationVerticle(),
new DeploymentOptions().setConfig(c)
))
.compose(v -> this.vertx.deployVerticle(
new CartagoVerticle(),
new DeploymentOptions().setConfig(c)
))
)
.compose(c -> {
final var httpConfig = new HttpInterfaceConfigImpl(c);
this.vertx.sharedData()
.<String, HttpInterfaceConfig>getLocalMap("http-config")
.put(DEFAULT_CONF_VALUE, httpConfig);
final var environmentConfig = new EnvironmentConfigImpl(c);
this.vertx.sharedData()
.<String, EnvironmentConfig>getLocalMap("environment-config")
.put(DEFAULT_CONF_VALUE, environmentConfig);
final var notificationConfig = new WebSubConfigImpl(c, httpConfig);
this.vertx.sharedData()
.<String, WebSubConfig>getLocalMap("notification-config")
.put(DEFAULT_CONF_VALUE, notificationConfig);
this.vertx.sharedData()
.<String, Environment>getLocalMap("environment")
.put(DEFAULT_CONF_VALUE, EnvironmentParser.parse(c));
return this.vertx
.deployVerticle(new HttpServerVerticle())
.compose(v -> this.vertx.deployVerticle(
new RdfStoreVerticle(),
new DeploymentOptions().setConfig(c)
))
.compose(v ->
notificationConfig.isEnabled()
? this.vertx.deployVerticle(
"org.hyperagents.yggdrasil.websub.HttpNotificationVerticle"
)
: Future.succeededFuture()
)
.compose(v ->
new EnvironmentConfigImpl(c).isEnabled()
? this.vertx.deployVerticle(
"org.hyperagents.yggdrasil.cartago.CartagoVerticle"
)
: Future.succeededFuture()
);
})
.<Void>mapEmpty()
.onComplete(startPromise);
}
Expand Down
32 changes: 20 additions & 12 deletions src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public class BodyNotificationTest {
private static final String TEST_AGENT_NAME = "test_agent";
private static final String TEST_AGENT_ID = "http://localhost:8080/agents/" + TEST_AGENT_NAME;
private static final String AGENT_ID_HEADER = "X-Agent-WebID";
private static final String HINT_HEADER = "Slug";
private static final String MAIN_WORKSPACE_NAME = "test";
private static final String COUNTER_ARTIFACT_NAME = "c0";
private static final String COUNTER_ARTIFACT_CLASS = "http://example.org/Counter";
private static final int TEST_PORT = 8080;
private static final int CALLBACK_PORT = 8081;
private static final String TEST_HOST = "localhost";
private static final String OK_STATUS_MESSAGE = "Status code should be OK";
private static final String CREATED_STATUS_MESSAGE = "Status code should be CREATED";
Expand All @@ -53,7 +51,7 @@ public class BodyNotificationTest {
private static final String WORKSPACES_PATH = "/workspaces/";
private static final String ARTIFACTS_PATH = "/artifacts/";
private static final String BODIES_PATH = "/agents/";
private static final String CALLBACK_URL = "http://" + TEST_HOST + ":" + CALLBACK_PORT + "/";
private static final String CALLBACK_URL = "http://" + TEST_HOST + ":" + 8081 + "/";

private final List<Promise<Map.Entry<String, String>>> callbackMessages;
private WebClient client;
Expand Down Expand Up @@ -89,16 +87,26 @@ public void setUp(final Vertx vertx, final VertxTestContext ctx) {
"host",
TEST_HOST,
"port",
TEST_PORT,
"websub-hub-uri",
this.getUrl(HUB_PATH),
"cartago-port",
8088
TEST_PORT
),
"known-artifacts",
"notification-config",
JsonObject.of(
COUNTER_ARTIFACT_CLASS,
"org.hyperagents.yggdrasil.artifacts.Counter"
"enabled",
true
),
"environment-config",
JsonObject.of(
"enabled",
true,
"known-artifacts",
JsonArray.of(
JsonObject.of(
"class",
COUNTER_ARTIFACT_CLASS,
"template",
"org.hyperagents.yggdrasil.artifacts.Counter"
)
)
)
))
)
Expand Down Expand Up @@ -136,7 +144,7 @@ public void testRun(final VertxTestContext ctx) throws URISyntaxException, IOExc
this.client
.post(TEST_PORT, TEST_HOST, WORKSPACES_PATH)
.putHeader(AGENT_ID_HEADER, TEST_AGENT_ID)
.putHeader(HINT_HEADER, MAIN_WORKSPACE_NAME)
.putHeader("Slug", MAIN_WORKSPACE_NAME)
.send()
.onSuccess(r -> {
Assertions.assertEquals(
Expand Down
Loading