From 6cbfbeca0bce2fe265528debd41c79d15914f0af Mon Sep 17 00:00:00 2001 From: Hynek Mlnarik Date: Fri, 6 Oct 2017 13:20:17 +0200 Subject: [PATCH] KEYCLOAK-5656 Remove KeycloakTcpTransportFactory --- misc/CrossDataCenter.md | 1 - ...ltInfinispanConnectionProviderFactory.java | 15 +-- .../remotestore/KeycloakRemoteStore.java | 16 +-- .../KeycloakTcpTransportFactory.java | 120 ------------------ .../jboss/common/crossdc/cross-dc-setup.cli | 1 - 5 files changed, 10 insertions(+), 143 deletions(-) delete mode 100644 model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakTcpTransportFactory.java diff --git a/misc/CrossDataCenter.md b/misc/CrossDataCenter.md index 7d2d8418d2..aa22128c79 100644 --- a/misc/CrossDataCenter.md +++ b/misc/CrossDataCenter.md @@ -123,7 +123,6 @@ Keycloak servers setup true org.keycloak.cluster.infinispan.KeycloakHotRodMarshallerFactory - org.keycloak.models.sessions.infinispan.remotestore.KeycloakTcpTransportFactory localhost:${remote.cache.port} work false diff --git a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java index 24ef8737bb..0c3b820ffc 100755 --- a/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java +++ b/model/infinispan/src/main/java/org/keycloak/connections/infinispan/DefaultInfinispanConnectionProviderFactory.java @@ -42,7 +42,6 @@ import org.keycloak.cluster.infinispan.KeycloakHotRodMarshallerFactory; import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSessionFactory; import org.keycloak.models.sessions.infinispan.remotestore.KeycloakRemoteStoreConfigurationBuilder; -import org.keycloak.models.sessions.infinispan.remotestore.KeycloakTcpTransportFactory; import javax.naming.InitialContext; @@ -367,10 +366,9 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon .rawValues(true) .forceReturnValues(false) .marshaller(KeycloakHotRodMarshallerFactory.class.getName()) - .transportFactory(KeycloakTcpTransportFactory.class.getName()) -// .addServer() -// .host(jdgServer) -// .port(jdgPort) + .addServer() + .host(jdgServer) + .port(jdgPort) // .connectionPool() // .maxActive(100) // .exhaustedAction(ExhaustedAction.CREATE_NEW) @@ -397,10 +395,9 @@ public class DefaultInfinispanConnectionProviderFactory implements InfinispanCon .rawValues(true) .forceReturnValues(false) .marshaller(KeycloakHotRodMarshallerFactory.class.getName()) - .transportFactory(KeycloakTcpTransportFactory.class.getName()) -// .addServer() -// .host(jdgServer) -// .port(jdgPort) + .addServer() + .host(jdgServer) + .port(jdgPort) .async() .enabled(async); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakRemoteStore.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakRemoteStore.java index 88df0492e6..a6f526dbe9 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakRemoteStore.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakRemoteStore.java @@ -17,7 +17,6 @@ package org.keycloak.models.sessions.infinispan.remotestore; -import java.util.Optional; import java.util.concurrent.Executor; import org.infinispan.commons.CacheException; @@ -62,17 +61,10 @@ public class KeycloakRemoteStore extends RemoteStore { EmbeddedCacheManager cacheManager = ctx.getCache().getCacheManager(); cacheManager.getCache(cacheTemplateName, true); - Optional optional = cacheManager.getCacheConfiguration(cacheTemplateName).persistence().stores().stream().filter((StoreConfiguration storeConfig) -> { - - return storeConfig instanceof KeycloakRemoteStoreConfiguration; - - }).findFirst(); - - if (!optional.isPresent()) { - throw new CacheException("Unable to find remoteStore on cache '" + cacheTemplateName + "."); - } - - KeycloakRemoteStoreConfiguration templateConfig = (KeycloakRemoteStoreConfiguration) optional.get(); + KeycloakRemoteStoreConfiguration templateConfig = (KeycloakRemoteStoreConfiguration) cacheManager.getCacheConfiguration(cacheTemplateName).persistence().stores().stream() + .filter((StoreConfiguration storeConfig) -> storeConfig instanceof KeycloakRemoteStoreConfiguration) + .findFirst() + .orElseThrow(() -> new CacheException("Unable to find remoteStore on cache '" + cacheTemplateName + ".")); // We have template configuration, so create new configuration from it. Override just remoteCacheName and sessionsCache (not pretty, but works for now) PersistenceConfigurationBuilder readPersistenceBuilder = new ConfigurationBuilder().read(ctx.getCache().getCacheConfiguration()).persistence(); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakTcpTransportFactory.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakTcpTransportFactory.java deleted file mode 100644 index a8985f248d..0000000000 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/remotestore/KeycloakTcpTransportFactory.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2017 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.models.sessions.infinispan.remotestore; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -import org.infinispan.client.hotrod.configuration.Configuration; -import org.infinispan.client.hotrod.configuration.ServerConfiguration; -import org.infinispan.client.hotrod.event.ClientListenerNotifier; -import org.infinispan.client.hotrod.impl.protocol.Codec; -import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory; -import org.jboss.logging.Logger; -import org.keycloak.common.util.reflections.Reflections; - -/** - * @author Marek Posolda - */ -public class KeycloakTcpTransportFactory extends TcpTransportFactory { - - protected static final Logger logger = Logger.getLogger(KeycloakTcpTransportFactory.class); - - private Collection kcInitialServers; - - @Override - public void start(Codec codec, Configuration configuration, AtomicInteger defaultCacheTopologyId, ClientListenerNotifier listenerNotifier) { - kcInitialServers = new HashSet<>(); - - for (ServerConfiguration server : configuration.servers()) { - InetSocketAddress hostnameAddress = new InetSocketAddress(server.host(), server.port()); - kcInitialServers.add(hostnameAddress); - - // Retrieve servers by IP addresses too, as we need to compare by IP addresses - try { - String ip = InetAddress.getByName(server.host()).getHostAddress(); - InetSocketAddress ipAddress = new InetSocketAddress(ip, server.port()); - kcInitialServers.add(ipAddress); - - InetSocketAddress unresolved = InetSocketAddress.createUnresolved(ip, server.port()); - kcInitialServers.add(unresolved); - } catch (UnknownHostException uhe) { - logger.warnf(uhe, "Wasn't able to retrieve IP address for host '%s'", server.host()); - } - - } - - logger.debugf("Keycloak initial servers: %s", kcInitialServers); - - super.start(codec, configuration, defaultCacheTopologyId, listenerNotifier); - } - - - @Override - public void updateServers(Collection newServers, byte[] cacheName, boolean quiet) { - try { - logger.debugf("Update servers called: %s, cacheName: %s", newServers, new String(cacheName, "UTF-8")); - - Collection filteredServers = getFilteredNewServers(newServers); - - logger.debugf("Update servers after filter: %s, cacheName: %s", filteredServers, new String(cacheName, "UTF-8")); - - super.updateServers(filteredServers, cacheName, quiet); - - } catch (UnsupportedEncodingException uee) { - throw new RuntimeException(uee); - } - } - - - // Return just those servers, which are part of the originally configured "kcInitialServers". - // Assume that the other JDG servers are part of same cluster, but are in different DC. Hence don't include them in the topology view - private Collection getFilteredNewServers(Collection newServers) { - Collection initialServers = getInitialServers(); - Collection filteredServers = newServers.stream().filter((SocketAddress newAddress) -> { - - boolean presentInInitialServers = initialServers.contains(newAddress); - - if (!presentInInitialServers) { - logger.debugf("Server'%s' not present in initial servers. Probably server from different DC. Will filter it from the view", newAddress); - } - - return presentInInitialServers; - - }).collect(Collectors.toList()); - - return filteredServers; - } - - - protected Collection getInitialServers() { - return kcInitialServers; - } - - - -} diff --git a/testsuite/integration-arquillian/servers/auth-server/jboss/common/crossdc/cross-dc-setup.cli b/testsuite/integration-arquillian/servers/auth-server/jboss/common/crossdc/cross-dc-setup.cli index 836cde1d82..6ad1234b4a 100644 --- a/testsuite/integration-arquillian/servers/auth-server/jboss/common/crossdc/cross-dc-setup.cli +++ b/testsuite/integration-arquillian/servers/auth-server/jboss/common/crossdc/cross-dc-setup.cli @@ -22,7 +22,6 @@ echo ** Update replicated-cache work element ** name=properties, value={ \ rawValues=true, \ marshaller=org.keycloak.cluster.infinispan.KeycloakHotRodMarshallerFactory, \ - transportFactory=org.keycloak.models.sessions.infinispan.remotestore.KeycloakTcpTransportFactory, \ remoteServers=localhost:${remote.cache.port}, \ remoteCacheName=work, \ sessionCache=false \