use of org.wildfly.extras.creaper.core.CommandFailedException in project keycloak by keycloak.
the class KeycloakContainerEventsController method deployAndDropAllTables.
/**
* Drop all KeycloakDS database tables using liquibase dropAll method.
* @param restartContainer to pass more information from test annotation
*/
private void deployAndDropAllTables(RestartContainer restartContainer) {
for (Container c : containerRegistry.get().getContainers()) {
String containerName = c.getName();
log.infof("Deploy and dropAll at '%s'", containerName);
if (containerName == null || !containerName.startsWith("auth-server")) {
log.infof("Skipping deployAndDropAllTables for '%s'", containerName);
continue;
}
ContainerDef conf = c.getContainerConfiguration();
String mgmtPort = conf.getContainerProperty("managementPort");
if (mgmtPort == null || mgmtPort.isEmpty()) {
log.warnf("Skipping deployAndDropAllTables for '%s' due to not defined 'managementPort' property.", containerName);
continue;
}
OnlineManagementClient client = null;
try {
client = ManagementClient.online(OnlineOptions.standalone().hostAndPort("localhost", Integer.valueOf(mgmtPort).intValue()).build());
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
WebArchive war = ShrinkWrap.create(WebArchive.class, DropAllServlet.WAR_NAME).addClass(DropAllServlet.class).addAsWebInfResource(new StringAsset(DropAllServlet.jbossDeploymentStructureContent), "jboss-deployment-structure.xml");
client.apply(new Deploy.Builder(war.as(ZipExporter.class).exportAsInputStream(), DropAllServlet.WAR_NAME, true).build());
if (restartContainer.intializeDatabaseWait() > 0) {
try {
Thread.sleep(restartContainer.intializeDatabaseWait());
} catch (InterruptedException e) {
log.warn(e);
}
}
client.apply(new Undeploy.Builder(DropAllServlet.WAR_NAME).build());
} catch (CommandFailedException e) {
log.error(e);
throw new RuntimeException(e);
}
}
}
Aggregations