Skip to content

Commit

Permalink
Merge pull request #33388 from gsmet/2.13.8-backports-2
Browse files Browse the repository at this point in the history
2.13 - Upgrade to Infinispan 14.0.9.Final
  • Loading branch information
gsmet authored May 23, 2023
2 parents da8ce14 + ec4fa13 commit d9b66a0
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 30 deletions.
9 changes: 7 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
<junit.jupiter.version>5.9.1</junit.jupiter.version>
<junit-pioneer.version>1.5.0</junit-pioneer.version>
<testng.version>6.14.2</testng.version>
<infinispan.version>13.0.11.Final</infinispan.version>
<infinispan.protostream.version>4.4.3.Final</infinispan.protostream.version>
<infinispan.version>14.0.9.Final</infinispan.version>
<infinispan.protostream.version>4.6.2.Final</infinispan.protostream.version>
<caffeine.version>2.9.3</caffeine.version>
<netty.version>4.1.86.Final</netty.version>
<brotli4j.version>1.8.0</brotli4j.version>
Expand Down Expand Up @@ -5214,6 +5214,11 @@
<version>${smallrye-reactive-messaging.version}</version>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-api</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
Expand Down
129 changes: 115 additions & 14 deletions docs/src/main/asciidoc/infinispan-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ This command adds the following dependency to your build file:
.build.gradle
----
implementation 'io.quarkus:quarkus-infinispan-client'
annotationProcessor 'org.infinispan.protostream:protostream-processor:4.5.0.Final' <1>
annotationProcessor 'org.infinispan.protostream:protostream-processor:4.5.1.Final' <1>
----
<1> Mandatory in the gradle build to enable the generation of the files in the annotation based serialization
<1> Mandatory in the Gradle build to enable the generation of the files in the annotation based serialization

== Configuring the Infinispan client

Expand Down Expand Up @@ -100,7 +100,7 @@ to create it on first access, use one of the following properties:

[source,properties]
----
quarkus.infinispan-client.cache.books.configuration-uri=cacheConfig.xml <1>
quarkus.infinispan-client.cache.books.configuration-uri=cacheConfig.json <1>
quarkus.infinispan-client.cache.magazine.configuration=<distributed-cache><encoding media-type="application/x-protostream"/></distributed-cache> <2>
----
<1> The file name located under the `resources` folder that contains the configuration of the 'books' cache
Expand All @@ -109,15 +109,42 @@ quarkus.infinispan-client.cache.magazine.configuration=<distributed-cache><encod
If both `configuration-uri` and `configuration` are configured for the same cache with the same Quarkus profile,
`configuration-uri` gets preference over `configuration`.

[TIP]
====
Cache configuration can be provided in XML, JSON or YAML. Use the Infinispan Console and the cache configuration Wizard
to learn more about Infinispan Caches and create guided configurations.
====

If nothing is configured for a particular cache, it will be created with the following basic configuration:

[source, xml]
.XML
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
<distributed-cache>
<encoding media-type="application/x-protostream"/>
</distributed-cache>
----

.JSON
[source,json,options="nowrap",subs=attributes+,role="secondary"]
----
{
"distributed-cache": {
"encoding": {
"media-type": "application/x-protostream"
}
}
}
----

.YAML
[source,yaml,options="nowrap",subs=attributes+,role="secondary"]
----
distributedCache:
encoding:
mediaType: "application/x-protostream"
----

=== Authentication mechanisms

You can use the following authentication mechanisms with the Infinispan client:
Expand All @@ -130,10 +157,7 @@ Other authentication mechanisms, such as SCRAM and GSSAPI, are not yet verified

You can find more information on configuring authentication in https://infinispan.org/docs/stable/titles/hotrod_java/hotrod_java.html#hotrod_endpoint_auth-hotrod-client-configuration[Hot Rod Endpoint Authentication Mechanisms].

[NOTE]
====
You must configure authentication in the `hotrod-client.properties` file if you use Dependency Injection.
====
NOTE: You must configure authentication in the `hotrod-client.properties` file if you use Dependency Injection.

== Serialization (Key Value types support)

Expand Down Expand Up @@ -267,10 +291,12 @@ interface BookStoreSchema extends GeneratedSchema {
----

[TIP]
====
Protostream provides default Protobuf mappers for commonly used types as `BigDecimal`, included in the `org.infinispan.protostream.types` package.
====

So in this case we will automatically generate the marshaller and schemas for the included classes and
place them in the schema package automatically. The package does not have to be provided, but if you use Infinispan query capabilities, you must know the generated package.
place them in the schema package automatically. The package does not have to be provided, but if you use Infinispan search capabilities, you must know the generated package.

NOTE: In Quarkus the `schemaFileName` and `schemaFilePath` attributes should NOT be set on the `AutoProtoSchemaBuilder` annotation. Setting either attributes causes native runtime errors.

Expand Down Expand Up @@ -439,7 +465,8 @@ the field, constructor or method. In the below code we utilize field and constru
this.remoteCacheManager = remoteCacheManager;
}
@Inject @Remote("myCache")
@Inject
@Remote("myCache")
RemoteCache<String, Book> cache;
RemoteCacheManager remoteCacheManager;
Expand Down Expand Up @@ -470,23 +497,97 @@ for Kubernetes deployments, Infinispan Console,
https://infinispan.org/docs/stable/titles/rest/rest.html#rest_v2_protobuf_schemas[REST API] or the
https://infinispan.org/docs/stable/titles/encoding/encoding.html#registering-sci-remote-caches_marshalling[Hot Rod Java Client].


== Querying

The Infinispan client supports both indexed and non-indexed querying as long as the
The Infinispan client supports both indexed and non-indexed search as long as the
`ProtoStreamMarshaller` is configured above. This allows the user to query based on the
properties of the proto schema.
properties of the proto schema. *Indexed queries are preferred for performance reasons*.

.XML
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
<distributed-cache name="books" statistics="true">
<!-- other configuration -->
<indexing enabled="true" storage="filesystem" startup-mode="PURGE">
<indexed-entities>
<indexed-entity>book_sample.Book</indexed-entity>
</indexed-entities>
</indexing>
</distributed-cache>
----

.JSON
[source,json,options="nowrap",subs=attributes+,role="secondary"]
----
{
"books": {
"distributed-cache": {
...
"indexing": {
"enabled": true,
"storage": "filesystem",
"startupMode": "PURGE",
"indexed-entities": [
"book_sample.Book"
]
}
}
}
}
----

.YAML
[source,yaml,options="nowrap",subs=attributes+,role="secondary"]
----
distributedCache:
# other configuration
indexing:
enabled: "true"
storage: "filesystem"
startupMode: "PURGE"
indexedEntities:
- "book_sample.Book"
----

Query builds upon the proto definitions you can configure when setting up the `ProtoStreamMarshaller`.
Either method of Serialization above will automatically register the schema with the server at
startup, meaning that you will automatically gain the ability to query objects stored in the
remote Infinispan Server.

You can read more about https://infinispan.org/docs/stable/titles/developing/developing.html#creating_ickle_queries-querying[querying] in the Infinispan documentation.
.Book.java
[source,java]
----
@Indexed <1>
public class Book {
@ProtoFactory
public Book(String title, String description, int publicationYear, Set<Author> authors) {
...
}
@ProtoField(number = 1)
@Text <2>
public String getTitle() {
return title;
}
@ProtoField(number = 2)
@Keyword(projectable = true, sortable = true, normalizer = "lowercase", indexNullAs = "unnamed", norms = false) <3>
public String getDescription() {
return description;
}
...
----
<1> `@Indexed` annotation makes the POJO indexable
<2> `@Basic` annotation is used for indexed fields without any special transformation
<3> `@Keyword` annotation is used to apply a normalizer to a text field

You can use either the Query DSL or the Ickle Query language with the Quarkus Infinispan client
extension.

NOTE: You can read more about https://infinispan.org/docs/stable/titles/query/query.html[querying] in the Infinispan documentation.


== Counters

Infinispan also has a notion of counters and the Quarkus Infinispan client supports them out of
Expand Down
4 changes: 4 additions & 0 deletions extensions/infinispan-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/infinispan-client/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
<artifactId>opentelemetry-api</artifactId>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-api</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@
<!-- Includes its own copy of an old version of the servlet API-->
<exclude>org.apache.tomcat.embed:tomcat-embed-core</exclude>
<exclude>org.jboss.modules:jboss-modules</exclude>
<!-- We prefer ByteBuddy where possible -->
<exclude>org.javassist:javassist</exclude>
<!-- We prefer ByteBuddy where possible
but Protostream requires Javassist and moving away from it will be hard)-->
<!--<exclude>org.javassist:javassist</exclude>-->
</excludes>
<includes>
<!-- this is for REST Assured -->
<include>jakarta.xml.bind:jakarta.xml.bind-api:*:*:test</include>
</includes>
</bannedDependencies>
</rules>
</enforcer>
</enforcer>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import java.util.Objects;
import java.util.Set;

import org.infinispan.api.annotations.indexing.Indexed;
import org.infinispan.api.annotations.indexing.Keyword;
import org.infinispan.api.annotations.indexing.Text;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;

/**
* @author William Burns
*/
@Indexed
public class Book {
private final String title;
private final String description;
Expand All @@ -29,11 +33,13 @@ public Book(String title, String description, int publicationYear, Set<Author> a
}

@ProtoField(number = 1)
@Text
public String getTitle() {
return title;
}

@ProtoField(number = 2)
@Keyword(projectable = true, sortable = true, normalizer = "lowercase", indexNullAs = "unnamed", norms = false)
public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

Expand All @@ -25,11 +28,14 @@
import org.infinispan.counter.api.CounterConfiguration;
import org.infinispan.counter.api.CounterManager;
import org.infinispan.counter.api.CounterType;
import org.infinispan.counter.api.Storage;
import org.infinispan.counter.api.StrongCounter;
import org.infinispan.counter.api.WeakCounter;
import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory;

import io.quarkus.infinispan.client.Remote;
import io.smallrye.common.annotation.Blocking;

@Path("/test")
public class TestServlet {
Expand Down Expand Up @@ -111,16 +117,38 @@ public String ickleQueryAuthorSurname(@PathParam("id") String name) {
.collect(Collectors.joining(",", "[", "]"));
}

@Path("counter/{id}")
@POST
@Produces(MediaType.TEXT_PLAIN)
@Blocking
public boolean defineCounter(@PathParam("id") String id, @QueryParam("type") String type,
@QueryParam("storage") String storage) {
cacheSetup.ensureStarted();
CounterConfiguration configuration = counterManager.getConfiguration(id);
if (configuration == null) {
configuration = CounterConfiguration.builder(CounterType.valueOf(type)).storage(Storage.valueOf(storage)).build();
return counterManager.defineCounter(id, configuration);
}
return true;
}

@Path("incr/{id}")
@GET
@Produces(MediaType.TEXT_PLAIN)
@Blocking
public CompletionStage<Long> incrementCounter(@PathParam("id") String id) {
cacheSetup.ensureStarted();
CounterConfiguration configuration = counterManager.getConfiguration(id);
if (configuration == null) {
configuration = CounterConfiguration.builder(CounterType.BOUNDED_STRONG).build();
counterManager.defineCounter(id, configuration);
return CompletableFuture.completedFuture(0L);
}

if (configuration.type() == CounterType.WEAK) {
WeakCounter weakCounter = counterManager.getWeakCounter(id);
weakCounter.sync().increment();
return CompletableFuture.completedFuture(weakCounter.getValue());
}

StrongCounter strongCounter = counterManager.getStrongCounter(id);
return strongCounter.incrementAndGet();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
quarkus.infinispan-client.cache.default.configuration-uri=cacheConfig.xml
quarkus.infinispan-client.cache.books.configuration-uri=booksIndexedConfig.json
quarkus.infinispan-client.cache.magazine.configuration=<distributed-cache><encoding media-type="application/x-protostream"/></distributed-cache>
quarkus.infinispan-client.cache.default.near-cache-mode=INVALIDATED
quarkus.infinispan-client.cache.default.near-cache-max-entries=2
quarkus.infinispan-client.cache.default.near-cache-use-bloom-filter=false
quarkus.infinispan-client.cache.magazine.near-cache-mode=INVALIDATED
quarkus.infinispan-client.cache.magazine.near-cache-max-entries=2
quarkus.infinispan-client.cache.magazine.near-cache-use-bloom-filter=false
quarkus.native.resources.includes=cacheConfig.xml
quarkus.native.resources.includes=cacheConfig.xml,booksIndexedConfig.json
Loading

0 comments on commit d9b66a0

Please sign in to comment.