Skip to content

Commit 3083fe8

Browse files
committed
Decouple the runtime from the service
This simplifies adding Java runtimes that don't leverage Camel. This resolves issue #189
1 parent a1cd420 commit 3083fe8

File tree

24 files changed

+212
-46
lines changed

24 files changed

+212
-46
lines changed

archetypes/wanaku-provider-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<defaultValue>${project.version}</defaultValue>
99
</requiredProperty>
1010
<requiredProperty key="wanaku-version" />
11+
<requiredProperty key="wanaku-service-type" />
1112
</requiredProperties>
1213
<fileSets>
1314
<fileSet filtered="true" packaged="true" encoding="UTF-8">

archetypes/wanaku-provider-archetype/src/main/resources/archetype-resources/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363
<version>${project.version}</version>
6464
</dependency>
6565

66+
#if ( $wanaku-service-type == "camel")
67+
<dependency>
68+
<groupId>ai.wanaku</groupId>
69+
<artifactId>core-runtime-camel</artifactId>
70+
<version>${project.version}</version>
71+
</dependency>
72+
#end
73+
6674
<dependency>
6775
<groupId>ai.wanaku</groupId>
6876
<artifactId>core-service-discovery</artifactId>

archetypes/wanaku-tool-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<defaultValue>${project.version}</defaultValue>
99
</requiredProperty>
1010
<requiredProperty key="wanaku-version" />
11+
<requiredProperty key="wanaku-service-type" />
1112
</requiredProperties>
1213
<fileSets>
1314
<fileSet filtered="true" packaged="true" encoding="UTF-8">

archetypes/wanaku-tool-service-archetype/src/main/resources/archetype-resources/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@
6363
<version>${project.version}</version>
6464
</dependency>
6565

66+
#if ( $wanaku-service-type == "camel")
67+
<dependency>
68+
<groupId>ai.wanaku</groupId>
69+
<artifactId>core-runtime-camel</artifactId>
70+
<version>${project.version}</version>
71+
</dependency>
72+
#end
73+
6674
<dependency>
6775
<groupId>ai.wanaku</groupId>
6876
<artifactId>core-service-discovery</artifactId>

cli/src/main/java/ai/wanaku/cli/main/commands/services/ServicesBase.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ public abstract class ServicesBase extends BaseCommand {
2020
@CommandLine.Option(names = {"--path"}, description = "The project path", defaultValue = ".", arity = "0..1")
2121
protected String path;
2222

23+
@CommandLine.Option(names = { "--type" }, description = "The service type (camel, quarkus, etc)", defaultValue = "camel", required = true, arity = "0..1")
24+
protected String type;
25+
2326
protected void createProject(String baseCmd) {
24-
String cmd = String.format("%s -DartifactId=wanaku-routing-%s-service -Dname=%s -Dwanaku-version=%s",
25-
baseCmd, name.toLowerCase(), name, VersionHelper.VERSION);
27+
String cmd = String.format("%s -DartifactId=wanaku-routing-%s-service -Dname=%s -Dwanaku-version=%s -Dwanaku-service-type=%s",
28+
baseCmd, name.toLowerCase(), name, wanakuVersion != null ? wanakuVersion : VersionHelper.VERSION, type);
2629

2730
String[] split = cmd.split(" ");
2831
final File projectDir = new File(path);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>ai.wanaku</groupId>
8+
<artifactId>core-runtimes</artifactId>
9+
<version>0.0.4-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>core-runtime-camel</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>ai.wanaku</groupId>
17+
<artifactId>core-services</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.apache.camel.quarkus</groupId>
23+
<artifactId>camel-quarkus-core</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.apache.camel</groupId>
28+
<artifactId>camel-catalog</artifactId>
29+
</dependency>
30+
</dependencies>
31+
32+
</project>

core/core-services/src/main/java/ai/wanaku/core/services/provider/DefaultResourceConsumer.java core/core-runtimes/core-runtime-camel/src/main/java/ai/wanaku/core/runtime/camel/DefaultResourceConsumer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package ai.wanaku.core.services.provider;
1+
package ai.wanaku.core.runtime.camel;
22

33
import jakarta.enterprise.context.ApplicationScoped;
44

55
import ai.wanaku.core.exchange.ResourceRequest;
6+
import ai.wanaku.core.services.provider.ResourceConsumer;
67
import org.apache.camel.CamelContext;
78
import org.apache.camel.ConsumerTemplate;
89

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ai.wanaku.core.runtime.camel;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
5+
import ai.wanaku.core.services.common.ServiceOptions;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.Objects;
9+
import org.apache.camel.catalog.CamelCatalog;
10+
import org.apache.camel.catalog.DefaultCamelCatalog;
11+
import org.apache.camel.tooling.model.BaseOptionModel;
12+
import org.apache.camel.tooling.model.ComponentModel;
13+
import org.jboss.logging.Logger;
14+
15+
@ApplicationScoped
16+
public class EndpointOptions implements ServiceOptions {
17+
private static final Logger LOG = Logger.getLogger(EndpointOptions.class);
18+
19+
@Override
20+
public Map<String, String> merge(String serviceName, Map<String, String> staticOpt) {
21+
Objects.requireNonNull(serviceName, "The component name must not be null");
22+
23+
CamelCatalog catalog = new DefaultCamelCatalog(true);
24+
25+
final ComponentModel componentModel = catalog.componentModel(serviceName);
26+
if (componentModel == null) {
27+
LOG.warnf("No component model found for component: %s", serviceName);
28+
return Map.of();
29+
}
30+
final List<ComponentModel.EndpointOptionModel> options = componentModel.getEndpointParameterOptions();
31+
for (BaseOptionModel option : options) {
32+
if (option.getLabel().contains("consumer") || option.getLabel().contains("common") ||
33+
option.getGroup().contains("common") || option.getLabel().contains("security")) {
34+
staticOpt.put(option.getName(), option.getDescription());
35+
}
36+
}
37+
38+
return staticOpt;
39+
}
40+
41+
}

core/core-runtimes/core-runtime-camel/src/main/resources/META-INF/beans.xml

Whitespace-only changes.

core/core-runtimes/pom.xml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>ai.wanaku</groupId>
8+
<artifactId>core</artifactId>
9+
<version>0.0.4-SNAPSHOT</version>
10+
</parent>
11+
12+
<packaging>pom</packaging>
13+
<artifactId>core-runtimes</artifactId>
14+
<name>Wanaku :: Core :: Runtimes</name>
15+
16+
<modules>
17+
<module>core-runtime-camel</module>
18+
</modules>
19+
</project>

core/core-services/pom.xml

-10
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@
2929
<version>${project.version}</version>
3030
</dependency>
3131

32-
<dependency>
33-
<groupId>org.apache.camel.quarkus</groupId>
34-
<artifactId>camel-quarkus-core</artifactId>
35-
</dependency>
36-
37-
<dependency>
38-
<groupId>org.apache.camel</groupId>
39-
<artifactId>camel-catalog</artifactId>
40-
</dependency>
41-
4232
<dependency>
4333
<groupId>io.quarkus</groupId>
4434
<artifactId>quarkus-scheduler</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ai.wanaku.core.services.common;
2+
3+
import java.util.Map;
4+
5+
public interface ServiceOptions {
6+
7+
/**
8+
* Merge runtime configurations defined in the configurations file with other configurations defined in runtime. Options will
9+
* be merged into the provided map (i.e.: must not be an unmodifiable map).
10+
* @param serviceName the name of the service
11+
* @param staticOpt the static options map
12+
* @return The merged map with the static and runtime options merged
13+
*/
14+
Map<String, String> merge(String serviceName, Map<String, String> staticOpt);
15+
}

core/core-services/src/main/java/ai/wanaku/core/services/provider/AbstractResourceDelegate.java

-26
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
import java.util.HashMap;
1717
import java.util.List;
1818
import java.util.Map;
19-
import java.util.Objects;
20-
import org.apache.camel.catalog.CamelCatalog;
21-
import org.apache.camel.catalog.DefaultCamelCatalog;
22-
import org.apache.camel.tooling.model.BaseOptionModel;
23-
import org.apache.camel.tooling.model.ComponentModel;
2419
import org.eclipse.microprofile.config.ConfigProvider;
2520
import org.jboss.logging.Logger;
2621

@@ -132,27 +127,6 @@ private void addToRequestParams(Map<String, String> requestParams, Map<String, S
132127
}
133128
}
134129

135-
protected Map<String, String> componentOptions(String name, Map<String, String> opt) {
136-
Objects.requireNonNull(name, "The component name must not be null");
137-
138-
CamelCatalog catalog = new DefaultCamelCatalog(true);
139-
140-
final ComponentModel componentModel = catalog.componentModel(name);
141-
if (componentModel == null) {
142-
LOG.warnf("No component model found for component: %s", name);
143-
return Map.of();
144-
}
145-
final List<ComponentModel.EndpointOptionModel> options = componentModel.getEndpointParameterOptions();
146-
for (BaseOptionModel option : options) {
147-
if (option.getLabel().contains("consumer") || option.getLabel().contains("common") ||
148-
option.getGroup().contains("common") || option.getLabel().contains("security")) {
149-
opt.put(option.getName(), option.getDescription());
150-
}
151-
}
152-
153-
return opt;
154-
}
155-
156130
private void tryRegistering(String service, String address, int port) {
157131
int retries = config.registration().retries();
158132
boolean registered = false;

core/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>core-exchange</module>
2020
<module>core-services</module>
2121
<module>core-service-discovery</module>
22+
<module>core-runtimes</module>
2223
</modules>
2324

2425

docs/contributing.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ Here are some examples:
1717

1818
**NOTE**: this is a generic explanation and the distinction may be specific to the problem domain. Therefore, there may be cases where this doesn't apply.
1919

20+
### Service types
21+
22+
You can create services using [Apache Camel](https://camel.apache.org) or plain [Quarkus](https://quarkus.io). To do so, just
23+
provide the desired type when creating the project (i.e.; via `--type=quarkus` when using `wanaku` or `-Dwanaku-service-type` when
24+
using the Maven archetype).
25+
2026
## Creating New Tools
2127

22-
To create a new tool for Wanaku, you can start by creating a new project. For instance, to create one for Kafka:
28+
To create a new tool for Wanaku, you can start by creating a new project.
29+
30+
For instance, to create one for Kafka:
31+
32+
```shell
33+
wanaku services create tool --name kafka
34+
```
35+
36+
Alternatively, if you don't have the CLI instanced, you can do so using Maven:
2337

2438
```shell
25-
mvn -B archetype:generate -DarchetypeGroupId=ai.wanaku -DarchetypeArtifactId=wanaku-tool-service-archetype -DarchetypeVersion=0.0.2 -DgroupId=ai.wanaku -Dpackage=ai.wanaku.routing.service -DartifactId=wanaku-routing-kafka-service -Dname=Kafka -Dwanaku-version=0.0.2
39+
mvn -B archetype:generate -DarchetypeGroupId=ai.wanaku -DarchetypeArtifactId=wanaku-tool-service-archetype -DarchetypeVersion=0.0.2 -DgroupId=ai.wanaku -Dpackage=ai.wanaku.routing.service -DartifactId=wanaku-routing-kafka-service -Dname=Kafka -Dwanaku-version=0.0.2 -Dwanaku-service-type=camel
2640
```
2741

2842
**NOTE**: this can be used both to create a core tool, part of the Wanaku MCP router project, or to create a custom one for your own needs.
@@ -63,13 +77,21 @@ wanaku targets tools link --service=kafka --target=localhost:9190
6377

6478
**NOTE**: make sure to replace `kafka` with the actual service type you are exposing.
6579

66-
## Creating new Providers
80+
## Creating new Resource Providers
81+
82+
83+
To create a new resource for Wanaku, you can start by creating a new project.
6784

85+
For instance, to create one for S3:
86+
87+
```shell
88+
wanaku services create resource --name s3
89+
```
6890

69-
To create a new resource for Wanaku, you can start by creating a new project. For instance, to create one for S3:
91+
Alternatively, if you don't have the CLI instanced, you can do so using Maven:
7092

7193
```shell
72-
mvn -B archetype:generate -DarchetypeGroupId=ai.wanaku -DarchetypeArtifactId=wanaku-provider-archetype -DarchetypeVersion=0.0.2 -DgroupId=ai.wanaku -Dpackage=ai.wanaku.provider -DartifactId=wanaku-provider-s3 -Dname=S3 -Dwanaku-version=0.0.2
94+
mvn -B archetype:generate -DarchetypeGroupId=ai.wanaku -DarchetypeArtifactId=wanaku-provider-archetype -DarchetypeVersion=0.0.2 -DgroupId=ai.wanaku -Dpackage=ai.wanaku.provider -DartifactId=wanaku-provider-s3 -Dname=S3 -Dwanaku-version=0.0.2 -Dwanaku-service-type=camel
7395
```
7496

7597
**NOTE**: this can be used both to create a core provider, part of the Wanaku MCP router project, or to create a custom one for your own needs.

services/providers/wanaku-provider-file/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<version>${project.version}</version>
2525
</dependency>
2626

27+
<dependency>
28+
<groupId>ai.wanaku</groupId>
29+
<artifactId>core-runtime-camel</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
2733
<dependency>
2834
<groupId>ai.wanaku</groupId>
2935
<artifactId>core-service-discovery</artifactId>

services/providers/wanaku-provider-ftp/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<version>${project.version}</version>
2525
</dependency>
2626

27+
<dependency>
28+
<groupId>ai.wanaku</groupId>
29+
<artifactId>core-runtime-camel</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
2733
<dependency>
2834
<groupId>io.quarkus</groupId>
2935
<artifactId>quarkus-arc</artifactId>

services/providers/wanaku-provider-ftp/src/main/java/ai/wanaku/provider/ftp/FTPResourceDelegate.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ai.wanaku.provider.ftp;
22

3+
import ai.wanaku.core.services.common.ServiceOptions;
34
import java.util.List;
45
import java.util.Map;
56

@@ -20,6 +21,9 @@
2021
public class FTPResourceDelegate extends AbstractResourceDelegate {
2122
private static final Logger LOG = Logger.getLogger(FTPResourceDelegate.class);
2223

24+
@Inject
25+
ServiceOptions serviceOptions;
26+
2327
@Inject
2428
WanakuProviderConfig config;
2529

@@ -47,6 +51,6 @@ protected List<String> coerceResponse(Object response) throws InvalidResponseTyp
4751
public Map<String, String> serviceConfigurations() {
4852
Map<String, String> configurations = config.service().configurations();
4953

50-
return componentOptions(config.name(), configurations);
54+
return serviceOptions.merge(config.name(), configurations);
5155
}
5256
}

services/providers/wanaku-provider-s3/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<version>${project.version}</version>
2424
</dependency>
2525

26+
<dependency>
27+
<groupId>ai.wanaku</groupId>
28+
<artifactId>core-runtime-camel</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
2632
<dependency>
2733
<groupId>io.quarkus</groupId>
2834
<artifactId>quarkus-arc</artifactId>

services/providers/wanaku-provider-s3/src/main/java/ai/wanaku/provider/s3/S3ResourceDelegate.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ai.wanaku.api.exceptions.InvalidResponseTypeException;
44
import ai.wanaku.api.exceptions.ResourceNotFoundException;
55
import ai.wanaku.core.exchange.ResourceRequest;
6+
import ai.wanaku.core.services.common.ServiceOptions;
67
import ai.wanaku.core.services.config.WanakuProviderConfig;
78
import ai.wanaku.core.services.provider.AbstractResourceDelegate;
89
import jakarta.enterprise.context.ApplicationScoped;
@@ -19,6 +20,9 @@ public class S3ResourceDelegate extends AbstractResourceDelegate {
1920
@Inject
2021
WanakuProviderConfig config;
2122

23+
@Inject
24+
ServiceOptions serviceOptions;
25+
2226
@Override
2327
protected String getEndpointUri(ResourceRequest request, Map<String, String> parameters) {
2428
String[] locations = request.getLocation().split("/");
@@ -50,6 +54,6 @@ protected List<String> coerceResponse(Object response) throws InvalidResponseTyp
5054
public Map<String, String> serviceConfigurations() {
5155
Map<String, String> configurations = config.service().configurations();
5256

53-
return componentOptions(config.name(), configurations);
57+
return serviceOptions.merge(config.name(), configurations);
5458
}
5559
}

0 commit comments

Comments
 (0)