Skip to content

Commit

Permalink
KEYCLOAK-5656 Remove remoteServers configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlnarik committed Oct 9, 2017
1 parent c6483f8 commit fe972ce
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 56 deletions.
1 change: 0 additions & 1 deletion misc/CrossDataCenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Keycloak servers setup
<store class="org.keycloak.models.sessions.infinispan.remotestore.KeycloakRemoteStoreConfigurationBuilder" passivation="false" fetch-state="false" purge="false" preload="false" shared="true">
<property name="rawValues">true</property>
<property name="marshaller">org.keycloak.cluster.infinispan.KeycloakHotRodMarshallerFactory</property>
<property name="remoteServers">localhost:${remote.cache.port}</property>
<property name="remoteCacheName">work</property>
<property name="sessionCache">false</property>
</store>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ private void configureRemoteCacheStore(ConfigurationBuilder builder, boolean asy
builder.persistence()
.passivation(false)
.addStore(KeycloakRemoteStoreConfigurationBuilder.class)
.remoteServers(jdgServer + ":" + jdgPort)
.sessionCache(sessionCache)
.fetchPersistentState(false)
.ignoreModifications(false)
Expand Down Expand Up @@ -384,7 +383,6 @@ private void configureRemoteActionTokenCacheStore(ConfigurationBuilder builder,
builder.persistence()
.passivation(false)
.addStore(KeycloakRemoteStoreConfigurationBuilder.class)
.remoteServers(jdgServer + ":" + jdgPort)
.sessionCache(false)
.fetchPersistentState(false)
.ignoreModifications(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
public class KeycloakRemoteStoreConfiguration extends RemoteStoreConfiguration {

static final AttributeDefinition<String> USE_CONFIG_TEMPLATE_FROM_CACHE = AttributeDefinition.builder("useConfigTemplateFromCache", null, String.class).immutable().build();
static final AttributeDefinition<String> REMOTE_SERVERS = AttributeDefinition.builder("remoteServers", null, String.class).immutable().build();
static final AttributeDefinition<Boolean> SESSION_CACHE = AttributeDefinition.builder("sessionCache", null, Boolean.class).immutable().build();

private final Attribute<String> useConfigTemplateFromCache;
private final Attribute<String> remoteServers;
private final Attribute<Boolean> sessionCache;


public KeycloakRemoteStoreConfiguration(RemoteStoreConfiguration other) {
super(other.attributes(), other.async(), other.singletonStore(), other.asyncExecutorFactory(), other.connectionPool());
useConfigTemplateFromCache = attributes.attribute(USE_CONFIG_TEMPLATE_FROM_CACHE.name());
remoteServers = attributes.attribute(REMOTE_SERVERS.name());
sessionCache = attributes.attribute(SESSION_CACHE.name());
}

Expand All @@ -52,11 +49,6 @@ public String useConfigTemplateFromCache() {
}


public String remoteServers() {
return remoteServers.get();
}


public Boolean sessionCache() {
return sessionCache.get()==null ? false : sessionCache.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
package org.keycloak.models.sessions.infinispan.remotestore;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.infinispan.commons.CacheConfigurationException;
import org.infinispan.commons.configuration.attributes.Attribute;
Expand Down Expand Up @@ -49,10 +47,6 @@ public KeycloakRemoteStoreConfigurationBuilder(PersistenceConfigurationBuilder b
Attribute<String> attribute = def.toAttribute();
attributesInternal.put(def.name(), attribute);

def = KeycloakRemoteStoreConfiguration.REMOTE_SERVERS;
attribute = def.toAttribute();
attributesInternal.put(def.name(), attribute);

AttributeDefinition<Boolean> defBool = KeycloakRemoteStoreConfiguration.SESSION_CACHE;
Attribute<Boolean> attributeBool = defBool.toAttribute();
attributesInternal.put(defBool.name(), attributeBool);
Expand All @@ -65,12 +59,6 @@ public KeycloakRemoteStoreConfigurationBuilder(PersistenceConfigurationBuilder b

@Override
public KeycloakRemoteStoreConfiguration create() {
String remoteServersAttr = attributes.attribute(KeycloakRemoteStoreConfiguration.REMOTE_SERVERS).get();
boolean isServersAlreadySet = isServersAlreadySet();
if (remoteServersAttr != null && !isServersAlreadySet) {
parseRemoteServersAttr(remoteServersAttr);
}

RemoteStoreConfiguration cfg = super.create();
KeycloakRemoteStoreConfiguration cfg2 = new KeycloakRemoteStoreConfiguration(cfg);
return cfg2;
Expand All @@ -83,40 +71,8 @@ public KeycloakRemoteStoreConfigurationBuilder useConfigTemplateFromCache(String
}


public KeycloakRemoteStoreConfigurationBuilder remoteServers(String remoteServers) {
attributes.attribute(KeycloakRemoteStoreConfiguration.REMOTE_SERVERS).set(remoteServers);
return this;
}


public KeycloakRemoteStoreConfigurationBuilder sessionCache(Boolean sessionCache) {
attributes.attribute(KeycloakRemoteStoreConfiguration.SESSION_CACHE).set(sessionCache);
return this;
}


private void parseRemoteServersAttr(String remoteServers) {
StringTokenizer st = new StringTokenizer(remoteServers, ",");

while (st.hasMoreElements()) {
String nodeStr = st.nextToken();
String[] node = nodeStr.trim().split(":", 2);

addServer()
.host(node[0].trim())
.port(Integer.parseInt(node[1].trim()));
}
}


private boolean isServersAlreadySet() {
try {
Field f = Reflections.findDeclaredField(RemoteStoreConfigurationBuilder.class, "servers");
f.setAccessible(true);
List originalRemoteServers = (List) f.get(this);
return !originalRemoteServers.isEmpty();
} catch (IllegalAccessException iae) {
throw new RuntimeException(iae);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ echo ** Update replicated-cache work element **
name=properties, value={ \
rawValues=true, \
marshaller=org.keycloak.cluster.infinispan.KeycloakHotRodMarshallerFactory, \
remoteServers=localhost:${remote.cache.port}, \
remoteCacheName=work, \
sessionCache=false \
} \
Expand Down

0 comments on commit fe972ce

Please sign in to comment.