Search in sources :

Example 1 with WildflyAppState

use of org.guvnor.ala.wildfly.access.WildflyAppState in project kie-wb-common by kiegroup.

the class WildflyRuntimeTest method waitForAppBuildTest.

@Test
public void waitForAppBuildTest() {
    final Optional<Source> _source = new GitConfigExecutor(new InMemorySourceRegistry()).apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", gitUrl, "drools-workshop-build", "true"));
    assertTrue(_source.isPresent());
    final Source source = _source.get();
    assertNotNull(source);
    List<String> goals = new ArrayList<>();
    goals.add("package");
    Properties properties = new Properties();
    properties.setProperty("failIfNoTests", "false");
    final Path projectRoot = source.getPath();
    final InputStream pomStream = org.uberfire.java.nio.file.Files.newInputStream(projectRoot.resolve("pom.xml"));
    final MavenProject project = MavenProjectLoader.parseMavenPom(pomStream);
    RepositoryVisitor repositoryVisitor = new RepositoryVisitor(projectRoot, project.getName());
    final String expectedBinary = project.getArtifact().getArtifactId() + "-" + project.getArtifact().getVersion() + "." + project.getArtifact().getType();
    final org.guvnor.ala.build.maven.model.MavenProject mavenProject = new MavenProjectImpl(project.getId(), project.getArtifact().getType(), project.getName(), expectedBinary, source.getPath(), source.getPath(), source.getPath().resolve("target").resolve(expectedBinary).toAbsolutePath(), repositoryVisitor.getRoot().getAbsolutePath(), null);
    final File pom = new File(mavenProject.getTempDir(), "pom.xml");
    MavenBuildExecutor.executeMaven(pom, properties, goals.toArray(new String[0]));
    final File file = new File(repositoryVisitor.getRoot().getAbsolutePath() + "/target/" + mavenProject.getExpectedBinary());
    WildflyClient wildflyClient = new WildflyClient("", "admin", "Admin#70365", ip, 8080, 9990);
    wildflyClient.deploy(file);
    final String id = file.getName();
    WildflyAppState appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(RUNNING));
    wildflyClient.undeploy(id);
    appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(UNKNOWN));
    wildflyClient.deploy(file);
    appState = wildflyClient.getAppState(id);
    assertNotNull(appState);
    assertTrue(appState.getState().equals(RUNNING));
}
Also used : Path(org.uberfire.java.nio.file.Path) GitConfigImpl(org.guvnor.ala.source.git.config.impl.GitConfigImpl) InputStream(java.io.InputStream) RepositoryVisitor(org.guvnor.ala.build.maven.util.RepositoryVisitor) ArrayList(java.util.ArrayList) WildflyClient(org.guvnor.ala.wildfly.access.WildflyClient) MavenProjectImpl(org.guvnor.ala.build.maven.model.impl.MavenProjectImpl) Properties(java.util.Properties) WildflyAppState(org.guvnor.ala.wildfly.access.WildflyAppState) Source(org.guvnor.ala.source.Source) GitConfigExecutor(org.guvnor.ala.source.git.executor.GitConfigExecutor) InMemorySourceRegistry(org.guvnor.ala.registry.inmemory.InMemorySourceRegistry) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) Test(org.junit.Test)

Example 2 with WildflyAppState

use of org.guvnor.ala.wildfly.access.WildflyAppState in project kie-wb-common by kiegroup.

the class WildflyRuntimeManager method refresh.

@Override
public void refresh(RuntimeId runtimeId) throws RuntimeOperationException {
    WildflyRuntime runtime = (WildflyRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        WildflyAppState appState = wildfly.getWildflyClient(runtime.getProviderId()).getAppState(runtime.getId());
        WildflyRuntime newRuntime = new WildflyRuntime(runtime.getId(), runtime.getName(), runtime.getConfig(), runtime.getProviderId(), runtime.getEndpoint(), runtime.getInfo(), new WildflyRuntimeState(appState.getState(), runtime.getState().getStartedAt()));
        runtimeRegistry.registerRuntime(newRuntime);
    } catch (WildflyClientException ex) {
        throw new RuntimeOperationException("Error Refreshing container: " + runtimeId.getId() + "\n\t There as a problem with refreshing your application, please check into the Wildfly Logs for more information.", ex);
    }
}
Also used : WildflyRuntime(org.guvnor.ala.wildfly.model.WildflyRuntime) WildflyClientException(org.guvnor.ala.wildfly.access.exceptions.WildflyClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException) WildflyRuntimeState(org.guvnor.ala.wildfly.model.WildflyRuntimeState) WildflyAppState(org.guvnor.ala.wildfly.access.WildflyAppState)

Example 3 with WildflyAppState

use of org.guvnor.ala.wildfly.access.WildflyAppState in project kie-wb-common by kiegroup.

the class WildflyRuntimeExecExecutor method create.

private Optional<WildflyRuntime> create(final WildflyRuntimeConfiguration runtimeConfig) throws ProvisioningException {
    String warPath = runtimeConfig.getWarPath();
    final Optional<WildflyProvider> _wildflyProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), WildflyProvider.class);
    if (!_wildflyProvider.isPresent()) {
        throw new ProvisioningException("No Wildfly provider was found for providerId: " + runtimeConfig.getProviderId());
    }
    WildflyProvider wildflyProvider = _wildflyProvider.get();
    File file = new File(warPath);
    final String id = file.getName();
    WildflyAppState appState = wildfly.getWildflyClient(wildflyProvider).getAppState(id);
    if (UNKNOWN.equals(appState.getState())) {
        int result = wildfly.getWildflyClient(wildflyProvider).deploy(file);
        if (result != 200) {
            throw new ProvisioningException("Deployment to Wildfly Failed with error code: " + result);
        }
    } else if ((RUNNING.equals(appState.getState()) || STOPPED.equals(appState.getState())) && (isNullOrEmpty(runtimeConfig.getRedeployStrategy()) || "auto".equals(runtimeConfig.getRedeployStrategy()))) {
        wildfly.getWildflyClient(wildflyProvider).undeploy(id);
        int result = wildfly.getWildflyClient(wildflyProvider).deploy(file);
        if (result != 200) {
            throw new ProvisioningException("Deployment to Wildfly Failed with error code: " + result);
        }
    } else {
        throw new ProvisioningException("A runtime with the given identifier: " + id + " is already deployed");
    }
    String appContext = id.substring(0, id.lastIndexOf(".war"));
    WildflyRuntimeEndpoint endpoint = new WildflyRuntimeEndpoint();
    endpoint.setHost(wildfly.getWildflyClient(wildflyProvider).getHost());
    endpoint.setPort(wildfly.getWildflyClient(wildflyProvider).getPort());
    endpoint.setContext(appContext);
    return Optional.of(new WildflyRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, wildflyProvider, endpoint, new WildflyRuntimeInfo(), new WildflyRuntimeState(RUNNING, new Date().toString())));
}
Also used : WildflyRuntimeEndpoint(org.guvnor.ala.wildfly.model.WildflyRuntimeEndpoint) WildflyRuntime(org.guvnor.ala.wildfly.model.WildflyRuntime) WildflyRuntimeInfo(org.guvnor.ala.wildfly.model.WildflyRuntimeInfo) ProvisioningException(org.guvnor.ala.exceptions.ProvisioningException) WildflyRuntimeState(org.guvnor.ala.wildfly.model.WildflyRuntimeState) File(java.io.File) WildflyAppState(org.guvnor.ala.wildfly.access.WildflyAppState) WildflyRuntimeEndpoint(org.guvnor.ala.wildfly.model.WildflyRuntimeEndpoint) Date(java.util.Date) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider)

Aggregations

WildflyAppState (org.guvnor.ala.wildfly.access.WildflyAppState)3 File (java.io.File)2 WildflyRuntime (org.guvnor.ala.wildfly.model.WildflyRuntime)2 WildflyRuntimeState (org.guvnor.ala.wildfly.model.WildflyRuntimeState)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Properties (java.util.Properties)1 MavenProject (org.apache.maven.project.MavenProject)1 MavenProjectImpl (org.guvnor.ala.build.maven.model.impl.MavenProjectImpl)1 RepositoryVisitor (org.guvnor.ala.build.maven.util.RepositoryVisitor)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 RuntimeOperationException (org.guvnor.ala.exceptions.RuntimeOperationException)1 InMemorySourceRegistry (org.guvnor.ala.registry.inmemory.InMemorySourceRegistry)1 Source (org.guvnor.ala.source.Source)1 GitConfigImpl (org.guvnor.ala.source.git.config.impl.GitConfigImpl)1 GitConfigExecutor (org.guvnor.ala.source.git.executor.GitConfigExecutor)1 WildflyClient (org.guvnor.ala.wildfly.access.WildflyClient)1 WildflyClientException (org.guvnor.ala.wildfly.access.exceptions.WildflyClientException)1 WildflyProvider (org.guvnor.ala.wildfly.model.WildflyProvider)1