From 2636793bf47892d04139cf54da9cb688c5a4b788 Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Tue, 8 Nov 2022 11:04:54 +0100 Subject: [PATCH] Integrate the api dependency from Infinispan 14 (#ISPN-14268) * Api dependency * Updates to minor 14.0.2.Final --- bom/application/pom.xml | 7 +- docs/src/main/asciidoc/infinispan-client.adoc | 129 ++++++++++++++++-- extensions/infinispan-client/runtime/pom.xml | 4 + .../io/quarkus/it/infinispan/client/Book.java | 6 + .../src/main/resources/application.properties | 4 +- .../main/resources/booksIndexedConfig.json | 16 +++ 6 files changed, 148 insertions(+), 18 deletions(-) create mode 100644 integration-tests/infinispan-client/src/main/resources/booksIndexedConfig.json diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 8c2f5d8b8047e..88898c85b4b83 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -131,7 +131,7 @@ 5.9.1 1.5.0 6.14.2 - 14.0.1.Final + 14.0.2.Final 4.5.0.Final 3.1.1 4.1.85.Final @@ -5239,6 +5239,11 @@ ${smallrye-reactive-messaging.version} + + org.infinispan + infinispan-api + ${infinispan.version} + org.infinispan infinispan-core diff --git a/docs/src/main/asciidoc/infinispan-client.adoc b/docs/src/main/asciidoc/infinispan-client.adoc index 64713953d81a3..75e343843d1b0 100644 --- a/docs/src/main/asciidoc/infinispan-client.adoc +++ b/docs/src/main/asciidoc/infinispan-client.adoc @@ -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= <2> ---- <1> The file name located under the `resources` folder that contains the configuration of the 'books' cache @@ -109,15 +109,42 @@ quarkus.infinispan-client.cache.magazine.configuration= ---- +.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: @@ -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) @@ -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. @@ -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 cache; RemoteCacheManager remoteCacheManager; @@ -491,10 +518,7 @@ If a value is found in the cache, it is returned and the annotated method is nev If no value is found, the annotated method is invoked and the returned value is stored in the cache using the computed key. This annotation cannot be used on a method returning `void`. -[NOTE] -==== -Infinispan Client extension is not able yet to cache `null` values unlike the Quarkus-Cache extension. -==== +NOTE: Infinispan Client extension is not able yet to cache `null` values unlike the Quarkus-Cache extension. === @CacheInvalidate @@ -510,20 +534,95 @@ When a method annotated with `@CacheInvalidateAll` is invoked, Infinispan will r == 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"] +---- + + + + + book_sample.Book + + + +---- + +.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 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 diff --git a/extensions/infinispan-client/runtime/pom.xml b/extensions/infinispan-client/runtime/pom.xml index fc33f8da818db..f1d52a34bc7a2 100644 --- a/extensions/infinispan-client/runtime/pom.xml +++ b/extensions/infinispan-client/runtime/pom.xml @@ -90,6 +90,10 @@ opentelemetry-api + + org.infinispan + infinispan-api + org.infinispan infinispan-remote-query-client diff --git a/integration-tests/infinispan-client/src/main/java/io/quarkus/it/infinispan/client/Book.java b/integration-tests/infinispan-client/src/main/java/io/quarkus/it/infinispan/client/Book.java index ca404a8f7985c..45dfc48c3a002 100644 --- a/integration-tests/infinispan-client/src/main/java/io/quarkus/it/infinispan/client/Book.java +++ b/integration-tests/infinispan-client/src/main/java/io/quarkus/it/infinispan/client/Book.java @@ -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; @@ -29,11 +33,13 @@ public Book(String title, String description, int publicationYear, Set 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; } diff --git a/integration-tests/infinispan-client/src/main/resources/application.properties b/integration-tests/infinispan-client/src/main/resources/application.properties index 01494bc412da8..c24d2cabbad76 100644 --- a/integration-tests/infinispan-client/src/main/resources/application.properties +++ b/integration-tests/infinispan-client/src/main/resources/application.properties @@ -1,5 +1,5 @@ quarkus.infinispan-client.cache.default.configuration-uri=cacheConfig.xml -quarkus.infinispan-client.cache.books.configuration-uri=cacheConfig.xml +quarkus.infinispan-client.cache.books.configuration-uri=booksIndexedConfig.json quarkus.infinispan-client.cache.magazine.configuration= quarkus.infinispan-client.cache.default.near-cache-mode=INVALIDATED quarkus.infinispan-client.cache.default.near-cache-max-entries=2 @@ -7,4 +7,4 @@ 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 \ No newline at end of file +quarkus.native.resources.includes=cacheConfig.xml,booksIndexedConfig.json \ No newline at end of file diff --git a/integration-tests/infinispan-client/src/main/resources/booksIndexedConfig.json b/integration-tests/infinispan-client/src/main/resources/booksIndexedConfig.json new file mode 100644 index 0000000000000..6f515612766d4 --- /dev/null +++ b/integration-tests/infinispan-client/src/main/resources/booksIndexedConfig.json @@ -0,0 +1,16 @@ +{ + "distributed-cache": { + "statistics": true, + "encoding": { + "media-type": "application/x-protostream" + }, + "indexing": { + "enabled": true, + "storage": "filesystem", + "startup-mode": "Purge", + "indexed-entities": [ + "book_sample.Book" + ] + } + } +} \ No newline at end of file