Skip to content

Commit

Permalink
Infinispan 15.0.3.Final
Browse files Browse the repository at this point in the history
Closes #29068

Signed-off-by: Pedro Ruivo <pruivo@redhat.com>
  • Loading branch information
pruivo committed May 8, 2024
1 parent 2172741 commit bc23439
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 302 deletions.
6 changes: 1 addition & 5 deletions adapters/saml/wildfly-elytron-jakarta/pom.xml
Expand Up @@ -92,16 +92,12 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
<artifactId>infinispan-core</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-cachestore-remote</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod-jakarta</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions adapters/saml/wildfly-elytron/pom.xml
Expand Up @@ -88,11 +88,6 @@
<groupId>org.infinispan</groupId>
<artifactId>infinispan-cachestore-remote</artifactId>
</dependency>
<dependency>
<!-- adding it explictly, as Keycloak's parent excludes it to have full control over Jakarta EE vs. Java EE -->
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Expand Up @@ -16,21 +16,21 @@
*/
package org.keycloak.adapters.saml.elytron.infinispan;

import org.keycloak.adapters.saml.AdapterConstants;
import org.keycloak.adapters.spi.SessionIdMapper;
import org.keycloak.adapters.spi.SessionIdMapperUpdater;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.factories.ComponentRegistry;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.persistence.manager.PersistenceManager;
import org.infinispan.persistence.remote.RemoteStore;
import org.jboss.logging.Logger;
import org.keycloak.adapters.saml.AdapterConstants;
import org.keycloak.adapters.spi.SessionIdMapper;
import org.keycloak.adapters.spi.SessionIdMapperUpdater;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import java.util.Set;

/**
Expand Down Expand Up @@ -94,21 +94,19 @@ public static SessionIdMapperUpdater addTokenStoreUpdaters(ServletContext servle
}

Cache<String, String[]> ssoCache = cacheManager.getCache(cacheName, true);
final SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper);
SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper);
ssoCache.addListener(listener);

addSsoCacheCrossDcListener(ssoCache, listener);

LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName);

SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater) {
return new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater) {
@Override
public void close() throws Exception {
public void close() {
ssoCache.stop();
}
};

return updater;
} catch (NamingException ex) {
LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup);
return previousIdMapperUpdater;
Expand Down Expand Up @@ -137,7 +135,7 @@ private static void addSsoCacheCrossDcListener(Cache<String, String[]> ssoCache,
return;
}

final Set<RemoteStore> stores = getRemoteStores(ssoCache);
Set<RemoteStore> stores = getRemoteStores(ssoCache);
if (stores == null || stores.isEmpty()) {
return;
}
Expand All @@ -149,7 +147,7 @@ private static void addSsoCacheCrossDcListener(Cache<String, String[]> ssoCache,
}
}

public static Set<RemoteStore> getRemoteStores(Cache ispnCache) {
return ispnCache.getAdvancedCache().getComponentRegistry().getComponent(PersistenceManager.class).getStores(RemoteStore.class);
public static Set<RemoteStore> getRemoteStores(Cache<?, ?> ispnCache) {
return ComponentRegistry.componentOf(ispnCache, PersistenceManager.class).getStores(RemoteStore.class);
}
}
Expand Up @@ -224,7 +224,7 @@ spec:
expose:
type: Route
configMapName: "cluster-config"
image: quay.io/infinispan/server:14.0.27.Final
image: quay.io/infinispan/server:15.0.3.Final
configListener:
enabled: false
container:
Expand Down
Expand Up @@ -363,7 +363,7 @@ spec:
expose:
type: Route
configMapName: "cluster-config"
image: quay.io/infinispan/server:14.0.27.Final
image: quay.io/infinispan/server:15.0.3.Final
configListener:
enabled: false
container:
Expand Down
Expand Up @@ -363,7 +363,7 @@ spec:
expose:
type: Route
configMapName: "cluster-config"
image: quay.io/infinispan/server:14.0.27.Final
image: quay.io/infinispan/server:15.0.3.Final
configListener:
enabled: false
container:
Expand Down
6 changes: 1 addition & 5 deletions model/infinispan/pom.xml
Expand Up @@ -59,11 +59,7 @@
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod-jakarta</artifactId>
<artifactId>infinispan-core</artifactId>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
Expand Down
Expand Up @@ -20,13 +20,11 @@
import org.infinispan.Cache;
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
import org.infinispan.persistence.remote.RemoteStore;
import org.infinispan.remoting.transport.Address;
import org.infinispan.remoting.transport.Transport;
import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.cluster.ClusterProvider;
Expand All @@ -35,10 +33,10 @@
import org.keycloak.common.util.Time;
import org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory;
import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
import org.keycloak.connections.infinispan.InfinispanUtil;
import org.keycloak.connections.infinispan.TopologyInfo;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.connections.infinispan.InfinispanUtil;

import java.io.Serializable;
import java.util.Collection;
Expand All @@ -47,7 +45,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
Expand All @@ -72,7 +69,7 @@ public class InfinispanClusterProviderFactory implements ClusterProviderFactory
// Just to extract notifications related stuff to separate class
private InfinispanNotificationsManager notificationsManager;

private ExecutorService localExecutor = Executors.newCachedThreadPool(r -> {
private final ExecutorService localExecutor = Executors.newCachedThreadPool(r -> {
Thread thread = Executors.defaultThreadFactory().newThread(r);
thread.setName(this.getClass().getName() + "-" + thread.getName());
return thread;
Expand Down Expand Up @@ -140,7 +137,7 @@ protected int initClusterStartupTime(KeycloakSession session) {
static <V extends Serializable> V putIfAbsentWithRetries(CrossDCAwareCacheFactory crossDCAwareCacheFactory, String key, V value, int taskTimeoutInSeconds) {
AtomicReference<V> resultRef = new AtomicReference<>();

Retry.executeWithBackoff((int iteration) -> {
Retry.executeWithBackoff(iteration -> {

try {
V result;
Expand Down Expand Up @@ -196,17 +193,14 @@ public class ViewChangeListener {

@ViewChanged
public void viewChanged(ViewChangedEvent event) {
final Set<String> removedNodesAddresses = convertAddresses(event.getOldMembers());
final Set<String> newAddresses = convertAddresses(event.getNewMembers());
Set<String> removedNodesAddresses = convertAddresses(event.getOldMembers());
Set<String> newAddresses = convertAddresses(event.getNewMembers());

// Use separate thread to avoid potential deadlock
localExecutor.execute(() -> {
try {
EmbeddedCacheManager cacheManager = workCache.getCacheManager();
Transport transport = cacheManager.getTransport();

// Coordinator makes sure that entries for outdated nodes are cleaned up
if (transport != null && transport.isCoordinator()) {
if (workCache.getCacheManager().isCoordinator()) {

removedNodesAddresses.removeAll(newAddresses);

Expand All @@ -230,14 +224,7 @@ public void viewChanged(ViewChangedEvent event) {
}

private Set<String> convertAddresses(Collection<Address> addresses) {
return addresses.stream().map(new Function<Address, String>() {

@Override
public String apply(Address address) {
return address.toString();
}

}).collect(Collectors.toSet());
return addresses.stream().map(Object::toString).collect(Collectors.toSet());
}

}
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.keycloak.connections.infinispan;

import org.infinispan.Cache;
import org.infinispan.factories.ComponentRegistry;
import org.infinispan.persistence.manager.PersistenceManager;
import org.jboss.logging.Logger;
import org.keycloak.health.LoadBalancerCheckProvider;
Expand Down Expand Up @@ -60,9 +61,7 @@ public boolean isDown() {
return true; // no need to check other caches
}

PersistenceManager persistenceManager = cache.getAdvancedCache()
.getComponentRegistry()
.getComponent(PersistenceManager.class);
var persistenceManager = ComponentRegistry.componentOf(cache, PersistenceManager.class);

if (persistenceManager != null && !persistenceManager.isAvailable()) {
LOG.debugf("PersistenceManager for cache '%s' is down.", cacheName);
Expand Down
Expand Up @@ -17,11 +17,6 @@

package org.keycloak.connections.infinispan;

import java.time.Instant;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.infinispan.Cache;
import org.infinispan.client.hotrod.ProtocolVersion;
import org.infinispan.client.hotrod.RemoteCache;
Expand All @@ -34,7 +29,7 @@
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.configuration.global.TransportConfigurationBuilder;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.eviction.EvictionType;
import org.infinispan.factories.ComponentRegistry;
import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.factories.impl.BasicComponentRegistry;
import org.infinispan.factories.impl.ComponentRef;
Expand All @@ -48,6 +43,11 @@
import org.keycloak.common.util.Time;
import org.keycloak.models.KeycloakSession;

import java.time.Instant;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
Expand All @@ -58,12 +58,12 @@ public class InfinispanUtil {
public static final int MAXIMUM_REPLACE_RETRIES = 25;

// See if we have RemoteStore (external JDG) configured for cross-Data-Center scenario
public static Set<RemoteStore> getRemoteStores(Cache ispnCache) {
return ispnCache.getAdvancedCache().getComponentRegistry().getComponent(PersistenceManager.class).getStores(RemoteStore.class);
public static Set<RemoteStore> getRemoteStores(Cache<?, ?> ispnCache) {
return ComponentRegistry.componentOf(ispnCache, PersistenceManager.class).getStores(RemoteStore.class);
}


public static RemoteCache getRemoteCache(Cache ispnCache) {
public static RemoteCache getRemoteCache(Cache<?, ?> ispnCache) {
Set<RemoteStore> remoteStores = getRemoteStores(ispnCache);
if (remoteStores.isEmpty()) {
return null;
Expand All @@ -88,10 +88,9 @@ public static TopologyInfo getTopologyInfo(KeycloakSession session) {
* @param lifespanOrigMs
* @return
*/
public static long toHotrodTimeMs(BasicCache ispnCache, long lifespanOrigMs) {
if (ispnCache instanceof RemoteCache && lifespanOrigMs > 2592000000L) {
RemoteCache remoteCache = (RemoteCache) ispnCache;
ProtocolVersion protocolVersion = remoteCache.getRemoteCacheManager().getConfiguration().version();
public static long toHotrodTimeMs(BasicCache<?, ?> ispnCache, long lifespanOrigMs) {
if (ispnCache instanceof RemoteCache<?, ?> remoteCache && lifespanOrigMs > 2592000000L) {
ProtocolVersion protocolVersion = remoteCache.getRemoteCacheContainer().getConfiguration().version();
if (ProtocolVersion.PROTOCOL_VERSION_30.compareTo(protocolVersion) > 0) {
return Time.currentTimeMillis() + lifespanOrigMs;
}
Expand All @@ -103,7 +102,7 @@ public static long toHotrodTimeMs(BasicCache ispnCache, long lifespanOrigMs) {
private static final Object CHANNEL_INIT_SYNCHRONIZER = new Object();

public static void configureTransport(GlobalConfigurationBuilder gcb, String nodeName, String siteName, String jgroupsUdpMcastAddr,
String jgroupsConfigPath) {
String jgroupsConfigPath) {
if (nodeName == null) {
gcb.transport().defaultTransport();
} else {
Expand Down Expand Up @@ -166,9 +165,8 @@ public static ConfigurationBuilder getActionTokenCacheConfig() {
ConfigurationBuilder cb = createCacheConfigurationBuilder();

cb.memory()
.evictionStrategy(EvictionStrategy.NONE)
.evictionType(EvictionType.COUNT)
.size(InfinispanConnectionProvider.ACTION_TOKEN_CACHE_DEFAULT_MAX);
.whenFull(EvictionStrategy.MANUAL)
.maxCount(InfinispanConnectionProvider.ACTION_TOKEN_CACHE_DEFAULT_MAX);
cb.expiration()
.maxIdle(InfinispanConnectionProvider.ACTION_TOKEN_MAX_IDLE_SECONDS, TimeUnit.SECONDS)
.wakeUpInterval(InfinispanConnectionProvider.ACTION_TOKEN_WAKE_UP_INTERVAL_SECONDS, TimeUnit.SECONDS);
Expand Down Expand Up @@ -209,7 +207,7 @@ public static Runnable setTimeServiceToKeycloakTime(EmbeddedCacheManager cacheMa
* @return the original component that was replaced
*/
private static <T> T replaceComponent(EmbeddedCacheManager cacheMgr, Class<T> componentType, T replacementComponent, boolean rewire) {
GlobalComponentRegistry cr = cacheMgr.getGlobalComponentRegistry();
GlobalComponentRegistry cr = GlobalComponentRegistry.of(cacheMgr);
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
ComponentRef<T> old = bcr.getComponent(componentType);
bcr.replaceComponent(componentType.getName(), replacementComponent, true);
Expand Down

0 comments on commit bc23439

Please sign in to comment.