Merge pull request #2120 from pdrozd/KEYCLOAK-2400

KEYCLOAK-2400 - adapter installation on windows
This commit is contained in:
Stian Thorgersen 2016-01-27 11:38:52 +01:00
commit 003ed1e302

View file

@ -1,5 +1,9 @@
package org.keycloak.testsuite.arquillian; package org.keycloak.testsuite.arquillian;
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
import static org.keycloak.testsuite.util.WaitUtils.pause;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -9,11 +13,13 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ContainerRegistry; import org.jboss.arquillian.container.spi.ContainerRegistry;
import org.jboss.arquillian.container.spi.event.StartSuiteContainers; import org.jboss.arquillian.container.spi.event.StartSuiteContainers;
import org.jboss.arquillian.container.spi.event.StopSuiteContainers; import org.jboss.arquillian.container.spi.event.StopSuiteContainers;
import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.container.test.api.ContainerController; import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.core.api.Event; import org.jboss.arquillian.core.api.Event;
import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.Instance;
@ -22,7 +28,6 @@ import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.core.api.annotation.Observes; import org.jboss.arquillian.core.api.annotation.Observes;
import org.jboss.arquillian.test.spi.annotation.ClassScoped; import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.test.spi.annotation.SuiteScoped; import org.jboss.arquillian.test.spi.annotation.SuiteScoped;
import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.test.spi.event.suite.BeforeClass; import org.jboss.arquillian.test.spi.event.suite.BeforeClass;
import org.jboss.arquillian.test.spi.event.suite.BeforeSuite; import org.jboss.arquillian.test.spi.event.suite.BeforeSuite;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -32,10 +37,6 @@ import org.keycloak.testsuite.arquillian.annotation.AdapterLibsLocationProperty;
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
import org.keycloak.testsuite.util.OAuthClient; import org.keycloak.testsuite.util.OAuthClient;
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
import static org.keycloak.testsuite.util.WaitUtils.pause;
/** /**
* *
* @author tkyjovsk * @author tkyjovsk
@ -126,7 +127,6 @@ public class ContainersTestEnricher {
log.info("\n\n### Starting keycloak current version ###\n"); log.info("\n\n### Starting keycloak current version ###\n");
alreadyStopped = true; alreadyStopped = true;
} }
installAdapters(container); installAdapters(container);
} }
@ -275,20 +275,25 @@ public class ContainersTestEnricher {
private void installAdapters(Container container) throws InterruptedException, IOException { private void installAdapters(Container container) throws InterruptedException, IOException {
if (!alreadyInstalled && !skipInstallAdapters && isJBossBased(container)) { if (!alreadyInstalled && !skipInstallAdapters && isJBossBased(container)) {
String jbossCliPath = jbossHomePath + "/bin/jboss-cli.sh"; File bin = new File(jbossHomePath + "/bin");
String adapterScriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install.cli"; String command = "java -jar " + jbossHomePath + "/bin/client/jboss-cli-client.jar";
String samlAdapterScriptPathArg = "--file=" + jbossHomePath + "/bin/adapter-install-saml.cli"; String adapterScript = "adapter-install.cli";
String samlAdapterScript = "adapter-install-saml.cli";
String managementPort = container.getContainerConfiguration().getContainerProperties().get("managementPort"); String managementPort = container.getContainerConfiguration().getContainerProperties().get("managementPort");
String controllerArg = "--controller=localhost:" + managementPort;
log.info("Installing adapter to app server via cli script"); String controllerArg = " --controller=localhost:" + managementPort;
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", adapterScriptPathArg, controllerArg}); if (new File(bin, adapterScript).exists()) {
log.info("Installing saml adapter to app server via cli script"); log.info("Installing adapter to app server via cli script");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", samlAdapterScriptPathArg, controllerArg}); 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);
}
log.info("Restarting container"); log.info("Restarting container");
execCommand(new String[]{"/bin/sh", jbossCliPath, "--connect", "--command=:reload", controllerArg}); execCommand(command + " --connect --command=reload" + controllerArg, bin);
pause(5000);
log.info("Container restarted"); log.info("Container restarted");
pause(5000);
checkServerLog(jbossHomePath); checkServerLog(jbossHomePath);
if (container.getName().startsWith("app-server")) { if (container.getName().startsWith("app-server")) {
alreadyInstalled = true; alreadyInstalled = true;
@ -296,29 +301,35 @@ public class ContainersTestEnricher {
} }
} }
private void execCommand(String... command) throws IOException, InterruptedException { private void execCommand(String command, File dir) throws IOException, InterruptedException {
Process process = Runtime.getRuntime().exec(command); Process process = Runtime.getRuntime().exec(command, null, dir);
if (process.waitFor(10, TimeUnit.SECONDS)) { if (process.waitFor(10, TimeUnit.SECONDS)) {
if (process.exitValue() != 0) { if (process.exitValue() != 0) {
getOutput("ERROR", process.getErrorStream());
throw new RuntimeException("Adapter installation failed. Process exitValue: " throw new RuntimeException("Adapter installation failed. Process exitValue: "
+ process.exitValue() + "; <error output>\n" + getOutput(process.getErrorStream()) + process.exitValue());
+ "</error output>");
} }
getOutput("OUTPUT", process.getInputStream());
log.debug("process.isAlive(): " + process.isAlive()); log.debug("process.isAlive(): " + process.isAlive());
} else { } else {
process.destroyForcibly(); if (process.isAlive()) {
process.destroyForcibly();
}
throw new RuntimeException("Timeout after 10 seconds."); throw new RuntimeException("Timeout after 10 seconds.");
} }
} }
private String getOutput(InputStream is) throws IOException { private void getOutput(String type, InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<").append(type).append(">");
System.out.println(builder);
builder = new StringBuilder();
while (reader.ready()) { while (reader.ready()) {
builder.append(reader.readLine()); System.out.println(reader.readLine());
} }
return builder.toString(); builder.append("</").append(type).append(">");
System.out.println(builder);
} }
private boolean isJBossBased(Container container) { private boolean isJBossBased(Container container) {