Skip to content

Commit

Permalink
Merge pull request #30065 from karesti/deprecate-service-list-in-favo…
Browse files Browse the repository at this point in the history
…r-of-url

Infinispan Configuration enchancements
  • Loading branch information
geoand authored Jan 5, 2023
2 parents 670ef8a + 00dd66d commit 8bfeb9d
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 23 deletions.
37 changes: 31 additions & 6 deletions docs/src/main/asciidoc/infinispan-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ If you modify `application.properties` or `hotrod-client.properties`, you must r

== Connecting to Infinispan clusters

Add the following properties to connect to Infinispan Server:
If you are running an Infinispan Server add the following properties to connect:

[source,properties]
----
quarkus.infinispan-client.server-list=localhost:11222 <1>
quarkus.infinispan-client.hosts=localhost:11222 <1>
quarkus.infinispan-client.auth-username=admin <2>
quarkus.infinispan-client.auth-password=password <3>
quarkus.infinispan-client.username=admin <2>
quarkus.infinispan-client.password=password <3>
quarkus.infinispan-client.client-intelligence=BASIC <4>
----
Expand All @@ -77,6 +77,20 @@ quarkus.infinispan-client.client-intelligence=BASIC <4>
<3> Sets the authentication password
<4> Sets the client intelligence. Use BASIC as a workaround if using Docker for Mac.

Alternatively, you can use uri connection by providing a single connection property
[source,properties]
----
quarkus.infinispan-client.uri=hotrod://admin:password@localhost:11222 <1>
quarkus.infinispan-client.client-intelligence=BASIC <2>
----
<1> Sets Infinispan URI connection. The following properties will be ignored: hosts, username and password.
<2> Sets the client intelligence. Use BASIC as a workaround if using Docker for Mac

[TIP]
====
Use Infinispan Dev Services to run a server and connect without configuration.
====

.Running Infinispan Server

To use the Infinispan client extension, you need at least one running instance of Infinispan Server.
Expand All @@ -93,6 +107,14 @@ Infinispan Server also enables authentication and security authorization by defa
$ ./bin/cli.sh user create admin -p password
----

=== Infinispan Health Check
If you are using the quarkus-smallrye-health extension, the Infinispan client extensions will automatically add a readiness health check to validate the connection.

When you access the `/q/health/ready` endpoint of your application you will have information about the server connection and available caches.

This behavior can be disabled via the property `quarkus.infinispan-client.health.enabled`.


=== Creating caches from the client

When a cache is accessed from the client, if the cache does not exist in the Infinispan Server and you want
Expand Down Expand Up @@ -483,8 +505,10 @@ You need to register the generated Protobuf schemas with Infinispan Server to pe
`Protobuf` to other media types such as `JSON`.

[TIP]
====
You can check the schemas that exist under the `Schemas` tab by logging into
Infinispan Console at `http://localhost:11222`
====

By default, Protobuf schemas generated this way will be registered by this extension when the client first connects.
However, it might be required to handle the registration manually as a schema may evolve over time when used in
Expand Down Expand Up @@ -691,11 +715,12 @@ When you use the infinispan-client extension in dev mode or in test, Quarkus aut
Dev Services for Infinispan is automatically enabled unless:

- `quarkus.infinispan-client.devservices.enabled` is set to `false`
- the `quarkus.infinispan-client.server-list` is configured
- the `quarkus.infinispan-client.hosts` is configured
- the `quarkus.infinispan-client.uri` is configured

Dev Services for Infinispan relies on Docker to start the broker.
If your environment does not support Docker, you will need to start the broker manually, or connect to an already running broker.
You can configure the broker address using `quarkus.infinispan-client.server-list`.
You can configure the broker address using `quarkus.infinispan-client.hosts`.

== Shared server

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/kogito.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Add following into the src/main/resources/application.properties file (create th

[source,plain]
----
quarkus.infinispan-client.server-list=localhost:11222
quarkus.infinispan-client.hosts=localhost:11222
----

NOTE: Adjust the host and port number according to your Infinispan server installation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public List<DevServicesResultBuildItem> startInfinispanContainers(LaunchModeBuil
}
newDevServices.add(devService);
log.infof("The infinispan server is ready to accept connections on %s",
devService.getConfig().get(getConfigPrefix() + "server-list"));
devService.getConfig().get(getConfigPrefix() + "hosts"));
compressor.close();
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
Expand Down Expand Up @@ -144,14 +144,17 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild

String configPrefix = getConfigPrefix();

boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + "server-list");
boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + "hosts")
&& !ConfigUtils.isPropertyPresent(configPrefix + "server-list");

if (!needToStart) {
log.debug("Not starting devservices for Infinispan as 'server-list' have been provided");
log.debug("Not starting devservices for Infinispan as 'hosts', 'uri' or 'server-list' have been provided");
return null;
}

if (!dockerStatusBuildItem.isDockerAvailable()) {
log.warn("Please configure 'quarkus.infinispan-client.server-list' or get a working docker instance");
log.warn(
"Please configure 'quarkus.infinispan-client.hosts' or 'quarkus.infinispan-client.uri' or get a working docker instance");
return null;
}

Expand All @@ -176,10 +179,10 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
private RunningDevService getRunningDevService(String containerId, Closeable closeable, String serverList,
String username, String password) {
Map<String, String> config = new HashMap<>();
config.put(getConfigPrefix() + "server-list", serverList);
config.put(getConfigPrefix() + "hosts", serverList);
config.put(getConfigPrefix() + "client-intelligence", "BASIC");
config.put(getConfigPrefix() + "auth-username", username);
config.put(getConfigPrefix() + "auth-password", password);
config.put(getConfigPrefix() + "username", username);
config.put(getConfigPrefix() + "password", password);
return new RunningDevService(Feature.INFINISPAN_CLIENT.getName(), containerId, closeable, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,38 @@ private ConfigurationBuilder builderFromProperties(Properties properties) {
}
InfinispanClientRuntimeConfig infinispanClientRuntimeConfig = this.infinispanClientRuntimeConfig.get();

if (infinispanClientRuntimeConfig.serverList.isPresent()) {
properties.put(ConfigurationProperties.SERVER_LIST, infinispanClientRuntimeConfig.serverList.get());
if (infinispanClientRuntimeConfig.uri.isPresent()) {
properties.put(ConfigurationProperties.URI, infinispanClientRuntimeConfig.uri.get());
} else {
if (infinispanClientRuntimeConfig.serverList.isPresent()) {
log.warn(
"Use 'quarkus.infinispan-client.hosts' instead of the deprecated 'quarkus.infinispan-client.server-list'");
properties.put(ConfigurationProperties.SERVER_LIST, infinispanClientRuntimeConfig.serverList.get());
}

if (infinispanClientRuntimeConfig.hosts.isPresent()) {
properties.put(ConfigurationProperties.SERVER_LIST, infinispanClientRuntimeConfig.hosts.get());
}

if (infinispanClientRuntimeConfig.authUsername.isPresent()) {
log.warn(
"Use 'quarkus.infinispan-client.username' instead of the deprecated 'quarkus.infinispan-client.auth-username'");
properties.put(ConfigurationProperties.AUTH_USERNAME, infinispanClientRuntimeConfig.authUsername.get());
}

if (infinispanClientRuntimeConfig.username.isPresent()) {
properties.put(ConfigurationProperties.AUTH_USERNAME, infinispanClientRuntimeConfig.username.get());
}

if (infinispanClientRuntimeConfig.authPassword.isPresent()) {
log.warn(
"Use 'quarkus.infinispan-client.password' instead of the deprecated 'quarkus.infinispan-client.auth-password'");
properties.put(ConfigurationProperties.AUTH_PASSWORD, infinispanClientRuntimeConfig.authPassword.get());
}

if (infinispanClientRuntimeConfig.password.isPresent()) {
properties.put(ConfigurationProperties.AUTH_PASSWORD, infinispanClientRuntimeConfig.password.get());
}
}

if (infinispanClientRuntimeConfig.clientIntelligence.isPresent()) {
Expand All @@ -191,21 +221,19 @@ private ConfigurationBuilder builderFromProperties(Properties properties) {
if (infinispanClientRuntimeConfig.useAuth.isPresent()) {
properties.put(ConfigurationProperties.USE_AUTH, infinispanClientRuntimeConfig.useAuth.get());
}
if (infinispanClientRuntimeConfig.authUsername.isPresent()) {
properties.put(ConfigurationProperties.AUTH_USERNAME, infinispanClientRuntimeConfig.authUsername.get());
}
if (infinispanClientRuntimeConfig.authPassword.isPresent()) {
properties.put(ConfigurationProperties.AUTH_PASSWORD, infinispanClientRuntimeConfig.authPassword.get());
}

if (infinispanClientRuntimeConfig.authRealm.isPresent()) {
properties.put(ConfigurationProperties.AUTH_REALM, infinispanClientRuntimeConfig.authRealm.get());
}

if (infinispanClientRuntimeConfig.authServerName.isPresent()) {
properties.put(ConfigurationProperties.AUTH_SERVER_NAME, infinispanClientRuntimeConfig.authServerName.get());
}

if (infinispanClientRuntimeConfig.authClientSubject.isPresent()) {
properties.put(ConfigurationProperties.AUTH_CLIENT_SUBJECT, infinispanClientRuntimeConfig.authClientSubject.get());
}

if (infinispanClientRuntimeConfig.authCallbackHandler.isPresent()) {
properties.put(ConfigurationProperties.AUTH_CALLBACK_HANDLER,
infinispanClientRuntimeConfig.authCallbackHandler.get());
Expand All @@ -226,6 +254,18 @@ private ConfigurationBuilder builderFromProperties(Properties properties) {
properties.put(ConfigurationProperties.TRUST_STORE_TYPE, infinispanClientRuntimeConfig.trustStoreType.get());
}

if (infinispanClientRuntimeConfig.sslProvider.isPresent()) {
properties.put(ConfigurationProperties.SSL_PROVIDER, infinispanClientRuntimeConfig.sslProvider.get());
}

if (infinispanClientRuntimeConfig.sslProtocol.isPresent()) {
properties.put(ConfigurationProperties.SSL_PROTOCOL, infinispanClientRuntimeConfig.sslProtocol.get());
}

if (infinispanClientRuntimeConfig.sslCiphers.isPresent()) {
properties.put(ConfigurationProperties.SSL_CIPHERS, infinispanClientRuntimeConfig.sslCiphers.get().toArray());
}

builder.withProperties(properties);

for (Map.Entry<String, InfinispanClientRuntimeConfig.RemoteCacheConfig> cache : infinispanClientRuntimeConfig.cache
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.infinispan.client.runtime;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand All @@ -21,10 +22,31 @@
@ConfigRoot(name = "infinispan-client", phase = ConfigPhase.RUN_TIME)
public class InfinispanClientRuntimeConfig {

// @formatter:off
/**
* Sets the URI of the running Infinispan server to connect to. hotrod://localhost:11222@admin:password
* If provided {@link #hosts}, {@link #username} and {@link #password} will be ignored.
*/
// @formatter:on
@ConfigItem
public Optional<String> uri;

// @formatter:off
/**
* Sets the host name/port to connect to. Each one is separated by a semicolon (eg. host1:11222;host2:11222).
*/
// @formatter:on
@ConfigItem
public Optional<String> hosts;

// @formatter:off
/**
* Sets the host name/port to connect to. Each one is separated by a semicolon (eg. host1:11222;host2:11222).
* @deprecated {@link #hosts} should be used to configure the list or uri for an uri connection string.
*/
// @formatter:on
@ConfigItem
@Deprecated
public Optional<String> serverList;

// @formatter:off
Expand Down Expand Up @@ -66,12 +88,30 @@ public class InfinispanClientRuntimeConfig {
* Sets username used by authentication.
*/
@ConfigItem
Optional<String> username;

/**
* Sets username used by authentication.
*
* @deprecated {@link #username} should be used to configure the credentials username.
*/
@ConfigItem
@Deprecated
Optional<String> authUsername;

/**
* Sets password used by authentication.
*/
@ConfigItem
Optional<String> password;

/**
* Sets password used by authentication
*
* @deprecated {@link #password} should be used to configure the credentials password.
*/
@ConfigItem
@Deprecated
Optional<String> authPassword;

/**
Expand Down Expand Up @@ -133,6 +173,27 @@ public class InfinispanClientRuntimeConfig {
@ConfigItem
Optional<String> trustStoreType;

/**
* Configures the secure socket protocol.
* Setting this property implicitly enables SSL/TLS.
*/
@ConfigItem
Optional<String> sslProtocol;

/**
* Sets the ssl provider. For example BCFIPS
* Setting this implicitly enables SSL/TLS.
*/
@ConfigItem
Optional<String> sslProvider;

/**
* Configures the ciphers.
* Setting this property implicitly enables SSL/TLS.
*/
@ConfigItem
Optional<List<String>> sslCiphers;

/**
* Configures caches from the client with the provided configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Map<String, String> start() {
INFINISPAN.start();

final String hosts = INFINISPAN.getHost() + ":" + INFINISPAN.getMappedPort(HOTROD_PORT);
return Collections.singletonMap("quarkus.infinispan-client.server-list", hosts);
return Collections.singletonMap("quarkus.infinispan-client.hosts", hosts);
}

@Override
Expand Down

0 comments on commit 8bfeb9d

Please sign in to comment.