KEYCLOAK-1678 Fixed app-server containers' handling.
This commit is contained in:
parent
3a51b3530d
commit
58084d5ee5
7 changed files with 225 additions and 135 deletions
|
@ -4,7 +4,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import org.jboss.arquillian.container.spi.Container;
|
||||
import org.jboss.arquillian.container.spi.event.container.BeforeDeploy;
|
||||
import org.jboss.arquillian.container.test.api.ContainerController;
|
||||
import org.jboss.arquillian.core.api.Instance;
|
||||
import org.jboss.arquillian.core.api.InstanceProducer;
|
||||
|
@ -34,16 +34,15 @@ public class AppServerTestEnricher {
|
|||
private InstanceProducer<TestContext> testContextProducer;
|
||||
private TestContext testContext;
|
||||
|
||||
@Inject
|
||||
private Instance<ContainerController> containerController;
|
||||
|
||||
public static String getAppServerQualifier(Class testClass) {
|
||||
Class<? extends AuthServerTestEnricher> annotatedClass = getNearestSuperclassWithAnnotation(testClass, AppServerContainer.class);
|
||||
|
||||
String appServerQ = (annotatedClass == null ? null
|
||||
: annotatedClass.getAnnotation(AppServerContainer.class).value());
|
||||
|
||||
return appServerQ;
|
||||
return appServerQ == null || appServerQ.isEmpty()
|
||||
? getAuthServerQualifier() // app server == auth server
|
||||
: appServerQ;
|
||||
}
|
||||
|
||||
public static String getAppServerContextRoot() {
|
||||
|
@ -60,12 +59,26 @@ public class AppServerTestEnricher {
|
|||
: "http://localhost:" + (httpPort + clusterPortOffset);
|
||||
}
|
||||
|
||||
private ContainerInfo initializeAppServerInfo(Container appServerContainer) {
|
||||
return initializeAppServerInfo(appServerContainer, 0);
|
||||
public void updateTestContextWithAppServerInfo(@Observes(precedence = 1) BeforeClass event) {
|
||||
testContext = testContextProducer.get();
|
||||
String appServerQualifier = getAppServerQualifier(testContext.getTestClass());
|
||||
for (ContainerInfo container : testContext.getSuiteContext().getContainers()) {
|
||||
if (container.getQualifier().equals(appServerQualifier)) {
|
||||
testContext.setAppServerInfo(updateWithAppServerInfo(container));
|
||||
}
|
||||
}
|
||||
// validate app server
|
||||
if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
|
||||
throw new RuntimeException(String.format("No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.", appServerQualifier));
|
||||
}
|
||||
log.info("\n\n" + testContext);
|
||||
}
|
||||
|
||||
private ContainerInfo initializeAppServerInfo(Container appServerContainer, int clusterPortOffset) {
|
||||
ContainerInfo appServerInfo = new ContainerInfo(appServerContainer);
|
||||
private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo) {
|
||||
return updateWithAppServerInfo(appServerInfo, 0);
|
||||
}
|
||||
|
||||
private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo, int clusterPortOffset) {
|
||||
try {
|
||||
|
||||
String appServerContextRootStr = isRelative(testContext.getTestClass())
|
||||
|
@ -80,67 +93,74 @@ public class AppServerTestEnricher {
|
|||
return appServerInfo;
|
||||
}
|
||||
|
||||
public void updateTestContextWithAppServerInfo(@Observes BeforeClass event) {
|
||||
testContext = testContextProducer.get();
|
||||
String appServerQualifier = getAppServerQualifier(testContext.getTestClass());
|
||||
for (Container container : testContext.getSuiteContext().getArquillianContainers()) {
|
||||
if (container.getContainerConfiguration().getContainerName().equals(appServerQualifier)) {
|
||||
testContext.setAppServerInfo(initializeAppServerInfo(container));
|
||||
}
|
||||
}
|
||||
// validate app server
|
||||
if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
|
||||
throw new RuntimeException(String.format("No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.", appServerQualifier));
|
||||
}
|
||||
log.info("\n\n" + testContext);
|
||||
}
|
||||
@Inject
|
||||
private Instance<ContainerController> containerConrollerInstance;
|
||||
|
||||
public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException {
|
||||
ContainerController controller = containerController.get();
|
||||
if (testContext.isAdapterTest()) {
|
||||
String appServerQualifier = testContext.getAppServerInfo().getQualifier();
|
||||
if (!controller.isStarted(appServerQualifier)) {
|
||||
controller.start(appServerQualifier);
|
||||
ContainerController controller = containerConrollerInstance.get();
|
||||
if (!controller.isStarted(testContext.getAppServerInfo().getQualifier())) {
|
||||
controller.start(testContext.getAppServerInfo().getQualifier());
|
||||
}
|
||||
log.info("\n\n\nAPP SERVER STARTED\n\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
public void installAdapterLibs(@Observes BeforeDeploy event) {
|
||||
log.info("BEFORE DEPLOY");
|
||||
if (testContext.isAdapterTest()) {
|
||||
// install adapter libs on JBoss-based container via CLI
|
||||
// if (testContext.getAppServerInfo().isJBossBased()) {
|
||||
installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo());
|
||||
// }
|
||||
if (testContext.getAppServerInfo().isJBossBased()) {
|
||||
try {
|
||||
installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo());
|
||||
} catch (InterruptedException | IOException ex) {
|
||||
throw new RuntimeException("Failed to install adapter libs.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void installAdapterLibsUsingJBossCLIClient(ContainerInfo appServerInfo) throws InterruptedException, IOException {
|
||||
if (!appServerInfo.isAdapterLibsInstalled()) {
|
||||
|
||||
log.info("Installing adapter via CLI client");
|
||||
if (!appServerInfo.isJBossBased()) {
|
||||
throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client.");
|
||||
}
|
||||
|
||||
if (!appServerInfo.isJBossBased()) {
|
||||
throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client.");
|
||||
}
|
||||
String jbossHomePath = appServerInfo.getProperties().get("jbossHome");
|
||||
|
||||
String jbossHomePath = appServerInfo.getProperties().get("jbossHome");
|
||||
File bin = new File(jbossHomePath + "/bin");
|
||||
|
||||
File bin = new File(jbossHomePath + "/bin");
|
||||
String command = "java -jar " + jbossHomePath + "/bin/client/jboss-cli-client.jar";
|
||||
String adapterScript = "adapter-install.cli";
|
||||
String samlAdapterScript = "adapter-install-saml.cli";
|
||||
String managementPort = appServerInfo.getProperties().get("managementPort");
|
||||
File clientJar = new File(jbossHomePath + "/bin/client/jboss-cli-client.jar");
|
||||
if (!clientJar.exists()) {
|
||||
clientJar = new File(jbossHomePath + "/bin/client/jboss-client.jar"); // AS7
|
||||
}
|
||||
if (!clientJar.exists()) {
|
||||
throw new IOException("JBoss CLI client JAR not found.");
|
||||
}
|
||||
|
||||
String controllerArg = " --controller=localhost:" + managementPort;
|
||||
if (new File(bin, adapterScript).exists()) {
|
||||
log.info("Installing adapter to app server via cli script");
|
||||
execCommand(command + " --connect --file=" + adapterScript + controllerArg, bin);
|
||||
}
|
||||
if (new File(bin, samlAdapterScript).exists()) {
|
||||
log.info("Installing saml adapter to app server via cli script");
|
||||
execCommand(command + " --connect --file=" + samlAdapterScript + controllerArg, bin);
|
||||
}
|
||||
if (new File(bin, adapterScript).exists() || new File(bin, samlAdapterScript).exists()) {
|
||||
log.info("Restarting container");
|
||||
execCommand(command + " --connect --command=reload" + controllerArg, bin);
|
||||
log.info("Container restarted");
|
||||
pause(5000);
|
||||
LogChecker.checkJBossServerLog(jbossHomePath);
|
||||
String command = "java -jar " + clientJar.getAbsolutePath();
|
||||
String adapterScript = "adapter-install.cli";
|
||||
String samlAdapterScript = "adapter-install-saml.cli";
|
||||
String managementPort = appServerInfo.getProperties().get("managementPort");
|
||||
|
||||
String controllerArg = " --controller=localhost:" + managementPort;
|
||||
if (new File(bin, adapterScript).exists()) {
|
||||
log.info("Installing adapter to app server via cli script");
|
||||
execCommand(command + " --connect --file=" + adapterScript + controllerArg, bin);
|
||||
}
|
||||
if (new File(bin, samlAdapterScript).exists()) {
|
||||
log.info("Installing saml adapter to app server via cli script");
|
||||
execCommand(command + " --connect --file=" + samlAdapterScript + controllerArg, bin);
|
||||
}
|
||||
if (new File(bin, adapterScript).exists() || new File(bin, samlAdapterScript).exists()) {
|
||||
log.info("Restarting container");
|
||||
execCommand(command + " --connect --command=reload" + controllerArg, bin);
|
||||
log.info("Container restarted");
|
||||
pause(5000);
|
||||
LogChecker.checkJBossServerLog(jbossHomePath);
|
||||
}
|
||||
|
||||
appServerInfo.setAdapterLibsInstalled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ package org.keycloak.testsuite.arquillian;
|
|||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.arquillian.container.spi.Container;
|
||||
import org.jboss.arquillian.container.spi.ContainerRegistry;
|
||||
|
@ -93,7 +94,13 @@ public class AuthServerTestEnricher {
|
|||
}
|
||||
|
||||
public void initializeSuiteContext(@Observes(precedence = 2) BeforeSuite event) {
|
||||
suiteContext = new SuiteContext(new ArrayList<>(containerRegistry.get().getContainers()));
|
||||
|
||||
Set<ContainerInfo> containers = new LinkedHashSet<>();
|
||||
for (Container c : containerRegistry.get().getContainers()) {
|
||||
containers.add(new ContainerInfo(c));
|
||||
}
|
||||
|
||||
suiteContext = new SuiteContext(containers);
|
||||
|
||||
String authServerQualifier = getAuthServerQualifier();
|
||||
String migratedAuthServerQualifier = getMigratedAuthServerQualifier();
|
||||
|
@ -109,14 +116,16 @@ public class AuthServerTestEnricher {
|
|||
: authServerQualifier; // single-node mode
|
||||
String authServerBackend = "auth-server-" + authServerType + "-backend";
|
||||
int backends = 0;
|
||||
for (Container container : suiteContext.getArquillianContainers()) {
|
||||
for (ContainerInfo container : suiteContext.getContainers()) {
|
||||
// frontend
|
||||
if (container.getContainerConfiguration().getContainerName().equals(authServerFrontend)) {
|
||||
suiteContext.setAuthServerInfo(initializeAuthServerInfo(container));
|
||||
if (container.getQualifier().equals(authServerFrontend)) {
|
||||
updateWithAuthServerInfo(container);
|
||||
suiteContext.setAuthServerInfo(container);
|
||||
}
|
||||
// backends
|
||||
if (container.getContainerConfiguration().getContainerName().startsWith(authServerBackend)) {
|
||||
suiteContext.getAuthServerBackendsInfo().add(initializeAuthServerInfo(container, ++backends));
|
||||
if (container.getQualifier().startsWith(authServerBackend)) {
|
||||
updateWithAuthServerInfo(container, ++backends);
|
||||
suiteContext.getAuthServerBackendsInfo().add(container);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,10 +144,11 @@ public class AuthServerTestEnricher {
|
|||
if (migratedAuthServerQualifier != null) {
|
||||
// init migratedAuthServerInfo
|
||||
if (migratedAuthServerQualifier.startsWith("migrated-auth-server-")) {
|
||||
for (Container container : suiteContext.getArquillianContainers()) {
|
||||
for (ContainerInfo container : suiteContext.getContainers()) {
|
||||
// migrated auth server
|
||||
if (container.getContainerConfiguration().getContainerName().equals(migratedAuthServerQualifier)) {
|
||||
suiteContext.setMigratedAuthServerInfo(initializeAuthServerInfo(container));
|
||||
if (container.getQualifier().equals(migratedAuthServerQualifier)) {
|
||||
updateWithAuthServerInfo(container);
|
||||
suiteContext.setMigratedAuthServerInfo(container);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -155,17 +165,11 @@ public class AuthServerTestEnricher {
|
|||
log.info("\n\n" + suiteContext);
|
||||
}
|
||||
|
||||
public void initializeTestContext(@Observes(precedence = 1) BeforeClass event) {
|
||||
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
|
||||
testContextProducer.set(testContext);
|
||||
private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo) {
|
||||
return updateWithAuthServerInfo(authServerInfo, 0);
|
||||
}
|
||||
|
||||
private ContainerInfo initializeAuthServerInfo(Container authServerContainer) {
|
||||
return initializeAuthServerInfo(authServerContainer, 0);
|
||||
}
|
||||
|
||||
private ContainerInfo initializeAuthServerInfo(Container authServerContainer, int clusterPortOffset) {
|
||||
ContainerInfo authServerInfo = new ContainerInfo(authServerContainer);
|
||||
private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo, int clusterPortOffset) {
|
||||
try {
|
||||
authServerInfo.setContextRoot(new URL(getAuthServerContextRoot(clusterPortOffset)));
|
||||
} catch (MalformedURLException ex) {
|
||||
|
@ -195,4 +199,9 @@ public class AuthServerTestEnricher {
|
|||
}
|
||||
}
|
||||
|
||||
public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) {
|
||||
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
|
||||
testContextProducer.set(testContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.keycloak.testsuite.arquillian;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.jboss.arquillian.container.spi.Container;
|
||||
|
||||
/**
|
||||
|
@ -12,6 +13,7 @@ public class ContainerInfo {
|
|||
|
||||
private URL contextRoot;
|
||||
private Container arquillianContainer;
|
||||
private boolean adapterLibsInstalled;
|
||||
|
||||
public ContainerInfo(Container arquillianContainer) {
|
||||
if (arquillianContainer == null) {
|
||||
|
@ -41,15 +43,15 @@ public class ContainerInfo {
|
|||
}
|
||||
|
||||
public boolean isAS7() {
|
||||
return getQualifier().contains("as7");
|
||||
return getQualifier().toLowerCase().contains("as7");
|
||||
}
|
||||
|
||||
public boolean isWildfly() {
|
||||
return getQualifier().contains("Wildfly");
|
||||
return getQualifier().toLowerCase().contains("wildfly");
|
||||
}
|
||||
|
||||
public boolean isEAP() {
|
||||
return getQualifier().contains("eap");
|
||||
return getQualifier().toLowerCase().contains("eap");
|
||||
}
|
||||
|
||||
public boolean isJBossBased() {
|
||||
|
@ -61,4 +63,33 @@ public class ContainerInfo {
|
|||
return getQualifier();
|
||||
}
|
||||
|
||||
public boolean isAdapterLibsInstalled() {
|
||||
return adapterLibsInstalled;
|
||||
}
|
||||
|
||||
public void setAdapterLibsInstalled(boolean adapterLibsInstalled) {
|
||||
this.adapterLibsInstalled = adapterLibsInstalled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 97 * hash + Objects.hashCode(this.arquillianContainer);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ContainerInfo other = (ContainerInfo) obj;
|
||||
return Objects.equals(
|
||||
this.arquillianContainer.getContainerConfiguration().getContainerName(),
|
||||
other.arquillianContainer.getContainerConfiguration().getContainerName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jboss.arquillian.container.spi.Container;
|
||||
import java.util.Set;
|
||||
import static org.keycloak.testsuite.util.MailServerConfiguration.*;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ import static org.keycloak.testsuite.util.MailServerConfiguration.*;
|
|||
*/
|
||||
public final class SuiteContext {
|
||||
|
||||
private final List<Container> arquillianContainers;
|
||||
private final Set<ContainerInfo> container;
|
||||
|
||||
private ContainerInfo authServerInfo;
|
||||
private final List<ContainerInfo> authServerBackendsInfo = new ArrayList<>();
|
||||
|
@ -39,8 +39,8 @@ public final class SuiteContext {
|
|||
private boolean adminPasswordUpdated;
|
||||
private final Map<String, String> smtpServer = new HashMap<>();
|
||||
|
||||
public SuiteContext(List<Container> arquillianContainers) {
|
||||
this.arquillianContainers = arquillianContainers;
|
||||
public SuiteContext(Set<ContainerInfo> arquillianContainers) {
|
||||
this.container = arquillianContainers;
|
||||
this.adminPasswordUpdated = false;
|
||||
smtpServer.put("from", FROM);
|
||||
smtpServer.put("host", HOST);
|
||||
|
@ -87,8 +87,8 @@ public final class SuiteContext {
|
|||
return migratedAuthServerInfo != null;
|
||||
}
|
||||
|
||||
public List<Container> getArquillianContainers() {
|
||||
return arquillianContainers;
|
||||
public Set<ContainerInfo> getContainers() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.keycloak.representations.idm.ClientRepresentation;
|
|||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.AbstractAuthTest;
|
||||
import org.keycloak.testsuite.adapter.page.AppServerContextRoot;
|
||||
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
|
||||
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -286,13 +286,6 @@
|
|||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>auth-server-wildfly</id>
|
||||
<modules>
|
||||
<module>wildfly-relative</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>app-server-eap6</id>
|
||||
<modules>
|
||||
|
@ -311,6 +304,12 @@
|
|||
<module>wildfly</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>app-server-wildfly-relative</id>
|
||||
<modules>
|
||||
<module>wildfly-relative</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>app-server-wildfly8</id>
|
||||
<modules>
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
~ Copyright 2016 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.
|
||||
-->
|
||||
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
@ -54,7 +54,39 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-auth-server-wildfly-profile</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireActiveProfile>
|
||||
<profiles>auth-server-wildfly</profiles>
|
||||
</requireActiveProfile>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>auth-server-wildfly</id>
|
||||
<!--dummy profile for the enforcer plugin to work-->
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>adapter-libs-bundled</id>
|
||||
<activation>
|
||||
|
|
Loading…
Reference in a new issue