KEYCLOAK-15924 Use 'cluster' instead of 'clustered' option. Execute StartupTest on GH actions.
This commit is contained in:
parent
d266165f63
commit
2ab355f7a2
8 changed files with 27 additions and 44 deletions
|
@ -97,14 +97,12 @@
|
|||
<filtered>true</filtered>
|
||||
</file>
|
||||
<file>
|
||||
<source>target/keycloak-quarkus-server/default-clustered-cache.xml</source>
|
||||
<source>target/keycloak-quarkus-server/cluster-local.xml</source>
|
||||
<outputDirectory>conf</outputDirectory>
|
||||
<destName>clustered-cache.xml</destName>
|
||||
</file>
|
||||
<file>
|
||||
<source>target/keycloak-quarkus-server/default-local-cache.xml</source>
|
||||
<source>target/keycloak-quarkus-server/cluster-default.xml</source>
|
||||
<outputDirectory>conf</outputDirectory>
|
||||
<destName>local-cache.xml</destName>
|
||||
</file>
|
||||
</files>
|
||||
|
||||
|
|
|
@ -96,9 +96,6 @@
|
|||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
http.enabled=true
|
||||
cluster=local
|
||||
db=h2-mem
|
||||
db.username = sa
|
||||
db.password = keycloak
|
|
@ -161,16 +161,18 @@ public final class PropertyMappers {
|
|||
}
|
||||
|
||||
private static void configureClustering() {
|
||||
createWithDefault("clustered", "kc.spi.connections-infinispan.default.clustered", "placeholder", (value, context) -> {
|
||||
if ("true".equals(value) || "false".equals(value)) {
|
||||
return value;
|
||||
createWithDefault("cluster", "kc.spi.connections-infinispan.default.config-file", "placeholder", (value, context) -> {
|
||||
|
||||
if ("placeholder".equals(value)) {
|
||||
// Clustering is disabled by default for the "dev" profile. Otherwise enabled
|
||||
value = ("dev".equalsIgnoreCase(ProfileManager.getActiveProfile())) ? "local" : "default";
|
||||
}
|
||||
|
||||
// Clustering is disabled by default for the "dev" profile. Otherwise enabled
|
||||
value = ("dev".equalsIgnoreCase(ProfileManager.getActiveProfile())) ? "false" : "true";
|
||||
return value;
|
||||
return "cluster-" + value + ".xml";
|
||||
|
||||
}, "Enables Clustering. Possible values are 'true' or 'false'.");
|
||||
}, "Specifies clustering configuration. The specified value points to the infinispan configuration file prefixed with the 'cluster-` "
|
||||
+ "inside the distribution configuration directory. Supported values out of the box are 'local' and 'cluster'. Value 'local' points to the file cluster-local.xml and " +
|
||||
"effectively disables clustering and use infinispan caches in the local mode. Value 'default' points to the file cluster-default.xml, which has clustering enabled for infinispan caches.");
|
||||
}
|
||||
|
||||
static ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
|
||||
|
|
|
@ -40,11 +40,7 @@ import org.keycloak.util.Environment;
|
|||
*/
|
||||
public final class QuarkusCacheManagerProvider implements ManagedCacheManagerProvider {
|
||||
|
||||
private static final Logger log = Logger.getLogger(QuarkusCacheManagerProvider.class);
|
||||
|
||||
// Configuration files from the distribution
|
||||
private static final String DEFAULT_CLUSTER_CONFIGURATION_FILE = "clustered-cache.xml";
|
||||
private static final String DEFAULT_LOCAL_CONFIGURATION_FILE = "local-cache.xml";
|
||||
private static final Logger log = Logger.getLogger(QuarkusCacheManagerProvider.class);
|
||||
|
||||
@Override
|
||||
public <C> C getCacheManager(Config.Scope config) {
|
||||
|
@ -68,15 +64,16 @@ public final class QuarkusCacheManagerProvider implements ManagedCacheManagerPro
|
|||
}
|
||||
|
||||
private InputStream loadConfiguration(Config.Scope config) throws FileNotFoundException {
|
||||
String pathPrefix;
|
||||
String homeDir = Environment.getHomeDir();
|
||||
|
||||
if (homeDir == null) {
|
||||
log.warn("Keycloak home directory not set.");
|
||||
return loadDefaultConfiguration(config, "default-clustered-cache.xml", "default-local-cache.xml");
|
||||
pathPrefix = "";
|
||||
} else {
|
||||
pathPrefix = homeDir + "/conf/";
|
||||
}
|
||||
|
||||
String pathPrefix = homeDir + "/conf/";
|
||||
|
||||
// Always try to use "configFile" if explicitly specified
|
||||
String configFile = config.get("configFile");
|
||||
if (configFile != null) {
|
||||
|
@ -87,24 +84,13 @@ public final class QuarkusCacheManagerProvider implements ManagedCacheManagerPro
|
|||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(configPath.toUri(), Thread.currentThread().getContextClassLoader());
|
||||
} else {
|
||||
log.warnf("Cache configuration file does not exists at %s . Fallback to the default configuration file", configPath);
|
||||
log.infof("Loading cache configuration from %s", configPath);
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(configPath.getFileName().toString(), Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Option 'configFile' needs to be specified");
|
||||
}
|
||||
|
||||
return loadDefaultConfiguration(config, pathPrefix + DEFAULT_CLUSTER_CONFIGURATION_FILE, pathPrefix + DEFAULT_LOCAL_CONFIGURATION_FILE);
|
||||
}
|
||||
|
||||
private InputStream loadDefaultConfiguration(Config.Scope config, String defaultClusterConfigFile, String defaultLocalConfigFile) throws FileNotFoundException {
|
||||
if (config.getBoolean("clustered", false)) {
|
||||
log.infof("Using default clustered cache configuration from file %s", defaultClusterConfigFile);
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(defaultClusterConfigFile, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
log.infof("Using default local cache configuration from file %s", defaultLocalConfigFile);
|
||||
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(defaultLocalConfigFile, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
private void configureTransportStack(Config.Scope config, ConfigurationBuilderHolder builder) {
|
||||
|
|
|
@ -233,18 +233,17 @@ public class ConfigurationTest {
|
|||
@Test
|
||||
public void testClusterConfig() {
|
||||
// Cluster enabled by default, but disabled for the "dev" profile
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
Assert.assertEquals("cluster-default.xml", initConfig("connectionsInfinispan", "default").get("configFile"));
|
||||
System.setProperty("kc.profile", "dev");
|
||||
Assert.assertFalse(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
Assert.assertEquals("cluster-local.xml", initConfig("connectionsInfinispan", "default").get("configFile"));
|
||||
|
||||
// If explicitly set, then it is always used regardless of the profile
|
||||
System.clearProperty("kc.profile");
|
||||
System.setProperty("kc.config.args", "--clustered=true");
|
||||
System.setProperty("kc.config.args", "--cluster=foo");
|
||||
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
Assert.assertEquals("cluster-foo.xml", initConfig("connectionsInfinispan", "default").get("configFile"));
|
||||
System.setProperty("kc.profile", "dev");
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
|
||||
Assert.assertEquals("cluster-foo.xml", initConfig("connectionsInfinispan", "default").get("configFile"));
|
||||
}
|
||||
|
||||
private Config.Scope initConfig(String... scope) {
|
||||
|
|
Loading…
Reference in a new issue