Search in sources :

Example 1 with TopologyInfo

use of org.keycloak.connections.infinispan.TopologyInfo in project keycloak by keycloak.

the class SessionClusterEvent method setData.

void setData(KeycloakSession session, String eventKey, String realmId, boolean resendingEvent) {
    this.realmId = realmId;
    this.eventKey = eventKey;
    this.resendingEvent = resendingEvent;
    TopologyInfo topology = InfinispanUtil.getTopologyInfo(session);
    this.siteId = topology.getMySiteName();
    this.nodeId = topology.getMyNodeName();
}
Also used : TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo)

Example 2 with TopologyInfo

use of org.keycloak.connections.infinispan.TopologyInfo in project keycloak by keycloak.

the class AbstractUserSessionClusterListener method shouldResendEvent.

private boolean shouldResendEvent(KeycloakSession session, SessionClusterEvent event) {
    if (!event.isResendingEvent()) {
        return false;
    }
    // Just the initiator will re-send the event after receiving it
    TopologyInfo topology = InfinispanUtil.getTopologyInfo(session);
    String myNode = topology.getMyNodeName();
    String mySite = topology.getMySiteName();
    return (event.getNodeId() != null && event.getNodeId().equals(myNode) && event.getSiteId() != null && event.getSiteId().equals(mySite));
}
Also used : TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo)

Example 3 with TopologyInfo

use of org.keycloak.connections.infinispan.TopologyInfo in project keycloak by keycloak.

the class InfinispanClusterProviderFactory method lazyInit.

private void lazyInit(KeycloakSession session) {
    if (workCache == null) {
        synchronized (this) {
            if (workCache == null) {
                InfinispanConnectionProvider ispnConnections = session.getProvider(InfinispanConnectionProvider.class);
                workCache = ispnConnections.getCache(InfinispanConnectionProvider.WORK_CACHE_NAME);
                workCacheListener = new ViewChangeListener();
                workCache.getCacheManager().addListener(workCacheListener);
                // See if we have RemoteStore (external JDG) configured for cross-Data-Center scenario
                Set<RemoteStore> remoteStores = InfinispanUtil.getRemoteStores(workCache);
                crossDCAwareCacheFactory = CrossDCAwareCacheFactory.getFactory(workCache, remoteStores);
                clusterStartupTime = initClusterStartupTime(session);
                TopologyInfo topologyInfo = InfinispanUtil.getTopologyInfo(session);
                String myAddress = topologyInfo.getMyNodeName();
                String mySite = topologyInfo.getMySiteName();
                notificationsManager = InfinispanNotificationsManager.create(session, workCache, myAddress, mySite, remoteStores);
            }
        }
    }
}
Also used : InfinispanConnectionProvider(org.keycloak.connections.infinispan.InfinispanConnectionProvider) TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo) RemoteStore(org.infinispan.persistence.remote.RemoteStore)

Example 4 with TopologyInfo

use of org.keycloak.connections.infinispan.TopologyInfo in project keycloak by keycloak.

the class RemoteCacheInvoker method runTask.

public <K, V extends SessionEntity> void runTask(KeycloakSession kcSession, RealmModel realm, String cacheName, K key, MergedUpdate<V> task, SessionEntityWrapper<V> sessionWrapper) {
    RemoteCacheContext context = remoteCaches.get(cacheName);
    if (context == null) {
        return;
    }
    V session = sessionWrapper.getEntity();
    SessionUpdateTask.CacheOperation operation = task.getOperation(session);
    SessionUpdateTask.CrossDCMessageStatus status = task.getCrossDCMessageStatus(sessionWrapper);
    if (status == SessionUpdateTask.CrossDCMessageStatus.NOT_NEEDED) {
        if (logger.isTraceEnabled()) {
            logger.tracef("Skip writing to remoteCache for entity '%s' of cache '%s' and operation '%s'", key, cacheName, operation);
        }
        return;
    }
    long loadedMaxIdleTimeMs = context.maxIdleTimeLoader.getMaxIdleTimeMs(realm);
    // Increase the timeout to ensure that entry won't expire on remoteCache in case that write of some entities to remoteCache is postponed (eg. userSession.lastSessionRefresh)
    final long maxIdleTimeMs = loadedMaxIdleTimeMs + 1800000;
    if (logger.isTraceEnabled()) {
        logger.tracef("Running task '%s' on remote cache '%s' . Key is '%s'", operation, cacheName, key);
    }
    TopologyInfo topology = InfinispanUtil.getTopologyInfo(kcSession);
    Retry.executeWithBackoff((int iteration) -> {
        try {
            runOnRemoteCache(topology, context.remoteCache, maxIdleTimeMs, key, task, sessionWrapper);
        } catch (HotRodClientException re) {
            if (logger.isDebugEnabled()) {
                logger.debugf(re, "Failed running task '%s' on remote cache '%s' . Key: '%s', iteration '%s'. Will try to retry the task", operation, cacheName, key, iteration);
            }
            // Rethrow the exception. Retry will take care of handle the exception and eventually retry the operation.
            throw re;
        }
    }, 10, 10);
}
Also used : HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) SessionUpdateTask(org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask) TopologyInfo(org.keycloak.connections.infinispan.TopologyInfo)

Aggregations

TopologyInfo (org.keycloak.connections.infinispan.TopologyInfo)4 HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)1 RemoteStore (org.infinispan.persistence.remote.RemoteStore)1 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 SessionUpdateTask (org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask)1