Search in sources :

Example 1 with WildflyRuntimeInfo

use of org.guvnor.ala.wildfly.model.WildflyRuntimeInfo 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

File (java.io.File)1 Date (java.util.Date)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 WildflyAppState (org.guvnor.ala.wildfly.access.WildflyAppState)1 WildflyProvider (org.guvnor.ala.wildfly.model.WildflyProvider)1 WildflyRuntime (org.guvnor.ala.wildfly.model.WildflyRuntime)1 WildflyRuntimeEndpoint (org.guvnor.ala.wildfly.model.WildflyRuntimeEndpoint)1 WildflyRuntimeInfo (org.guvnor.ala.wildfly.model.WildflyRuntimeInfo)1 WildflyRuntimeState (org.guvnor.ala.wildfly.model.WildflyRuntimeState)1