Skip to content

Commit

Permalink
4.x: archetypes - add coherence caching option (#9824)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvallin authored Feb 25, 2025
1 parent bc24932 commit db6d406
Show file tree
Hide file tree
Showing 20 changed files with 584 additions and 50 deletions.
6 changes: 3 additions & 3 deletions archetypes/archetypes/filters.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
# Copyright (c) 2022, 2025 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,8 +37,8 @@ health=!${health} || (${health.builtin})
metrics=!${metrics} || (${metrics.builtin})

# group extra options
extra=${extra} == [] || ${extra} == ['cors', 'fault-tolerance'] || \
(${flavor} == 'se' && ${extra} == ['webclient', 'cors', 'fault-tolerance'])
extra=${extra} == [] || ${extra} == ['cors', 'fault-tolerance', 'coherence'] || \
(${flavor} == 'se' && ${extra} == ['webclient', 'cors', 'fault-tolerance', 'coherence'])

# group docker, k8s and v8o
packaging=!(${docker} || ${k8s} || ${v8o}) || (${docker} && ${k8s} && ${v8o})
Expand Down
63 changes: 29 additions & 34 deletions archetypes/archetypes/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Copyright (c) 2022, 2025 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -23,14 +23,8 @@
<step name="Extra" optional="true">
<inputs>
<list id="extra" name="Select Additional Components" optional="true">
<option value="webclient" name="WebClient" description="Nima HTTP client" if="${flavor} == 'se'">
<option value="webclient" name="WebClient" description="HTTP client" if="${flavor} == 'se'">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>src/*/java/**/WebClientMain.java.mustache</include>
</includes>
</templates>
<model>
<list key="dependencies">
<map>
Expand Down Expand Up @@ -83,14 +77,6 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
</option>
<option value="fault-tolerance" name="Fault Tolerance" description="System for building resilient applications">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include if="${flavor} == 'mp'">src/*/java/**/FtResource.java.mustache</include>
<include if="${flavor} == 'mp'">src/*/java/**/FtResourceTest.java.mustache</include>
<include if="${flavor} == 'se'">src/*/java/**/FtService.java.mustache</include>
</includes>
</templates>
<model>
<list key="dependencies" if="${flavor} == 'mp'">
<map>
Expand All @@ -102,29 +88,22 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
<value if="${flavor} == 'mp'">io.helidon.microprofile.faulttolerance</value>
</list>
<list key="maven-plugins" if="${flavor} == 'mp'">
<value><![CDATA[
<plugin>
<value><![CDATA[ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<sun.net.http.allowRestrictedHeaders>true</sun.net.http.allowRestrictedHeaders>
</systemPropertyVariables>
</configuration>
</plugin>
]]></value>
</plugin>]]>
</value>
</list>
</model>
</output>
</option>
<option value="cors" name="CORS" description="Cross-Origin Resource Sharing utilities">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>src/*/java/**/TestCORS.java.mustache</include>
</includes>
</templates>
<model>
<list key="dependencies">
<map if="${flavor} == 'mp'">
Expand Down Expand Up @@ -160,8 +139,7 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
<value if="${flavor} == 'mp'">io.helidon.microprofile.cors.CorsCdiExtension</value>
</list>
<list key="SimpleGreetService-methods" if="${flavor} == 'mp'">
<value><![CDATA[
@PUT
<value><![CDATA[ @PUT
public Response getCustomMessage(String greeting) {
String msg = String.format("%s %s!", greeting, "World");
return Response.ok(msg).build();
Expand All @@ -174,7 +152,9 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
@CrossOrigin(value = {"http://foo.com", "http://there.com"},
allowMethods = {HttpMethod.PUT})
public void optionsForGetCustomMessage() {
}]]></value>
}
]]>
</value>
</list>
<list key="readme-sections" if="${flavor} == 'mp'">
<value><![CDATA[
Expand Down Expand Up @@ -271,11 +251,13 @@ restrictive-cors:
# - path-pattern: /greeting
# allow-origins: ["http://foo.com", "http://there.com", "http://other.com"]
# allow-methods: ["PUT", "DELETE"]
]]></value>
]]>
</value>
</list>
<list key="Main-routing-builder" if="${flavor} == 'se'">
<value><![CDATA[ .register("/cors-greet", corsSupportForGreeting(), new GreetService())
]]></value>
]]>
</value>
</list>
<list key="main-class-content" if="${flavor} == 'se'">
<value><![CDATA[
Expand All @@ -300,7 +282,8 @@ restrictive-cors:
return corsBuilder.build();
}
]]></value>
]]>
</value>
</list>
<list key="MainTest-java-imports" if="${flavor} == 'se'">
<value>java.util.Optional</value>
Expand Down Expand Up @@ -336,7 +319,8 @@ restrictive-cors:
assertThat(allowOrigin.get(), is("*"));
}
}
]]></value>
]]>
</value>
</list>
<list key="readme-sections" if="${flavor} == 'se'">
<value><![CDATA[
Expand All @@ -361,7 +345,17 @@ content-length: 27
Hello World
```
]]></value>
]]>
</value>
</list>
</model>
</output>
</option>
<option value="coherence" name="Coherence" description="Cache data with coherence">
<output>
<model>
<list key="readme-exercise-the-application">
<value file="files/README.coherence.exercise.app.md"/>
</list>
</model>
</output>
Expand All @@ -373,6 +367,7 @@ Hello World
<value key="webclient" if="${extra} contains 'webclient'">true</value>
<value key="fault-tolerance" if="${extra} contains 'fault-tolerance'">true</value>
<value key="cors" if="${extra} contains 'cors'">true</value>
<value key="coherence" if="${extra} contains 'coherence'">true</value>
</model>
</output>
</step>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```shell
curl -X POST -H "Content-Type: application/json" \
-d '{"ssn" : "123-45-6789", "firstName" : "Frank", "lastName" : "Helidon", "dateOfBirth" : "02/14/2019"}' \
http://localhost:8080/creditscore
```

You'll notice a short delay as the application computes the credit score.
Now repeat the same request. You'll see the score is returned instantly as it is retrieved from the cache.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,59 @@
<artifactId>{{artifactId}}</artifactId>
<version>{{project-version}}</version>

{{#mainClass}}
{{#pom-properties}}
{{#first}}
<properties>
<mainClass>{{mainClass}}</mainClass>
{{/first}}
<{{key}}>{{value}}</{{key}}>
{{#last}}
</properties>
{{/mainClass}}

{{/last}}
{{/pom-properties}}
{{#dependencies-management}}
{{#first}}
<dependencyManagement>
<dependencies>
{{/first}}
<dependency>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
{{#version}}
<version>{{.}}</version>
{{/version}}
{{#scope}}
<scope>{{.}}</scope>
{{/scope}}
{{#type}}
<type>{{.}}</type>
{{/type}}
{{#optional}}
<optional>{{.}}</optional>
{{/optional}}
{{#exclusions}}
{{#first}}
<exclusions>
{{/first}}
<exclusion>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
</exclusion>
{{#last}}
</exclusions>
{{/last}}
{{/exclusions}}
</dependency>
{{#last}}
</dependencies>
</dependencyManagement>

{{/last}}
{{/dependencies-management}}
{{#dependencies}}
{{#first}}
<dependencies>
{{#dependencies}}
{{/first}}
<dependency>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
Expand All @@ -39,9 +84,11 @@
<optional>{{.}}</optional>
{{/optional}}
</dependency>
{{/dependencies}}
{{#last}}
</dependencies>

{{/last}}
{{/dependencies}}
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">

<output>
<templates transformations="mustache,packaged" engine="mustache">
<directory>files</directory>
<includes>
<include>src/main/java/__pkg__/CoherenceResource.java.mustache</include>
<include>src/main/java/__pkg__/Person.java.mustache</include>
<include>src/test/java/__pkg__/CoherenceResourceTest.java.mustache</include>
</includes>
</templates>
<model>
<list key="pom-properties">
<map>
<value key="key">version.lib.coherence</value>
<value key="value">24.03.1</value>
</map>
</list>
<list key="dependencies-management">
<map>
<value key="groupId">com.oracle.coherence.ce</value>
<value key="artifactId">coherence-bom</value>
<!-- Using template to skip variable resolution -->
<value key="version" template="mustache">${version.lib.coherence}</value>
<value key="type">pom</value>
<value key="scope">import</value>
</map>
</list>
<list key="dependencies">
<map>
<value key="groupId">com.oracle.coherence.ce</value>
<value key="artifactId">coherence-cdi-server</value>
</map>
<map>
<value key="groupId">com.oracle.coherence.ce</value>
<value key="artifactId">coherence-mp-config</value>
<value key="scope">runtime</value>
</map>
<map>
<value key="groupId">org.glassfish.jersey.media</value>
<value key="artifactId">jersey-media-json-binding</value>
<value key="scope">runtime</value>
</map>
</list>
<list key="module-requires" if="${jpms}">
<value>com.oracle.coherence</value>
<value>com.oracle.coherence.cdi</value>
</list>
<list key="microprofile-config-entries">
<value file="files/src/main/resources/META-INF/microprofile-config-coherence.properties.mustache"/>
</list>
</model>
</output>
</archetype-script>
11 changes: 9 additions & 2 deletions archetypes/archetypes/src/main/archetype/mp/custom/custom-mp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
<source src="/common/media-sources.xml"/>
<exec src="/common/security.xml"/>
<exec src="database-input.xml"/>
<source src="/common/extra.xml"/>
<exec src="/common/extra.xml"/>
<source src="extra-output.xml"/>
<source src="/common/observability.xml"/>
<exec src="/common/packaging.xml"/>
<source src="observability.xml"/>
<exec src="database-outputs.xml" if="${db}"/>
<source src="security-outputs.xml" if="${security}"/>
<exec src="coherence-output.xml" if="${extra} contains 'coherence'"/>
<output>
<templates engine="mustache" transformations="mustache" if="${application-yaml}">
<directory>files</directory>
Expand All @@ -43,7 +45,12 @@
</templates>
<model>
<value key="helidon-test">true</value>
<value key="mainClass" if="${jpms}">${package}.Main</value>
<list key="pom-properties" if="${jpms}">
<map order="1">
<value key="key">mainClass</value>
<value key="value">${package}.Main</value>
</map>
</list>
<list key="microprofile-config-entries">
<value file="files/microprofile-config.properties"/>
</list>
Expand Down
Loading

0 comments on commit db6d406

Please sign in to comment.