Search in sources :

Example 1 with CommandFailedException

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);
        }
    }
}
Also used : RestartContainer(org.keycloak.testsuite.arquillian.annotation.RestartContainer) Container(org.jboss.arquillian.container.spi.Container) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) DropAllServlet(org.keycloak.helpers.DropAllServlet) OnlineManagementClient(org.wildfly.extras.creaper.core.online.OnlineManagementClient) ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) IOException(java.io.IOException) CommandFailedException(org.wildfly.extras.creaper.core.CommandFailedException)

Aggregations

IOException (java.io.IOException)1 ContainerDef (org.jboss.arquillian.config.descriptor.api.ContainerDef)1 Container (org.jboss.arquillian.container.spi.Container)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1 DropAllServlet (org.keycloak.helpers.DropAllServlet)1 RestartContainer (org.keycloak.testsuite.arquillian.annotation.RestartContainer)1 CommandFailedException (org.wildfly.extras.creaper.core.CommandFailedException)1 OnlineManagementClient (org.wildfly.extras.creaper.core.online.OnlineManagementClient)1