Search in sources :

Example 1 with WildflyProvider

use of org.guvnor.ala.wildfly.model.WildflyProvider in project kie-wb-common by kiegroup.

the class ContextAwareWildflyRuntimeExecConfig method setContext.

@Override
public void setContext(final Map<String, ?> context) {
    this.context = context;
    MavenBinary binary = (MavenBinary) context.get("binary");
    if (binary != null) {
        this.warPath = binary.getPath().toString();
    }
    WildflyProvider provider = (WildflyProvider) context.get("wildfly-provider");
    this.providerId = provider;
}
Also used : MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider)

Example 2 with WildflyProvider

use of org.guvnor.ala.wildfly.model.WildflyProvider in project kie-wb-common by kiegroup.

the class ContextAwareWildflyRuntimeExecConfigTest method testContextUsingPath.

@Test
public void testContextUsingPath() {
    final ContextAwareWildflyRuntimeExecConfig config = new ContextAwareWildflyRuntimeExecConfig();
    final WildflyProvider provider = mock(WildflyProvider.class);
    final Map<String, Object> context = singletonMap("wildfly-provider", provider);
    config.setContext(context);
    assertEquals(provider, config.getProviderId());
    assertEquals(WAR_PATH_DEFAULT_EXPRESSION, config.getWarPath());
    final WildflyRuntimeExecConfig configClone = config.asNewClone(config);
    assertEquals(provider, configClone.getProviderId());
    assertEquals(WAR_PATH_DEFAULT_EXPRESSION, configClone.getWarPath());
}
Also used : ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) WildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.WildflyRuntimeExecConfig) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider) Test(org.junit.Test)

Example 3 with WildflyProvider

use of org.guvnor.ala.wildfly.model.WildflyProvider in project kie-wb-common by kiegroup.

the class ContextAwareWildflyRuntimeExecConfigTest method testContextUsingMavenBinary.

@Test
public void testContextUsingMavenBinary() {
    final ContextAwareWildflyRuntimeExecConfig config = new ContextAwareWildflyRuntimeExecConfig();
    final Map<String, Object> context = new HashMap<>();
    final WildflyProvider provider = mock(WildflyProvider.class);
    context.put("wildfly-provider", provider);
    final MavenBinary binary = mock(MavenBinary.class);
    final Path path = mock(Path.class);
    when(binary.getPath()).thenReturn(path);
    when(path.toString()).thenReturn(FILE_PATH);
    context.put("binary", binary);
    config.setContext(context);
    assertEquals(provider, config.getProviderId());
    assertEquals(FILE_PATH, config.getWarPath());
    final WildflyRuntimeExecConfig configClone = config.asNewClone(config);
    assertEquals(provider, configClone.getProviderId());
    assertEquals(FILE_PATH, configClone.getWarPath());
}
Also used : Path(org.uberfire.java.nio.file.Path) HashMap(java.util.HashMap) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) WildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.WildflyRuntimeExecConfig) ContextAwareWildflyRuntimeExecConfig(org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig) MavenBinary(org.guvnor.ala.build.maven.model.MavenBinary) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider) Test(org.junit.Test)

Example 4 with WildflyProvider

use of org.guvnor.ala.wildfly.model.WildflyProvider in project kie-wb-common by kiegroup.

the class WildflyProviderConfigExecutor method apply.

@Override
public Optional<WildflyProvider> apply(final WildflyProviderConfig wildflyProviderConfig) {
    if (wildflyProviderConfig.getName() == null || wildflyProviderConfig.getName().isEmpty()) {
        throw new ProvisioningException("No name was provided for the WildflyProviderConfig.getName() " + "configuration parameter. You might probably have to properly set " + "the pipeline input parameter: " + ProviderConfig.PROVIDER_NAME);
    }
    Provider provider = runtimeRegistry.getProvider(wildflyProviderConfig.getName());
    WildflyProvider wildflyProvider;
    if (provider != null) {
        if (!(provider instanceof WildflyProvider)) {
            throw new ProvisioningException("The provider: " + wildflyProviderConfig.getName() + " must be an instance of " + WildflyProviderConfig.class + " but is: " + provider.getClass());
        } else {
            wildflyProvider = (WildflyProvider) provider;
        }
    } else {
        wildflyProvider = new WildflyProviderImpl(new WildflyProviderConfigImpl(wildflyProviderConfig.getName(), wildflyProviderConfig.getHost(), wildflyProviderConfig.getPort(), wildflyProviderConfig.getManagementPort(), wildflyProviderConfig.getUser(), wildflyProviderConfig.getPassword()));
        runtimeRegistry.registerProvider(wildflyProvider);
    }
    return Optional.of(wildflyProvider);
}
Also used : WildflyProviderConfig(org.guvnor.ala.wildfly.config.WildflyProviderConfig) WildflyProviderImpl(org.guvnor.ala.wildfly.model.WildflyProviderImpl) ProvisioningException(org.guvnor.ala.exceptions.ProvisioningException) WildflyProviderConfigImpl(org.guvnor.ala.wildfly.config.impl.WildflyProviderConfigImpl) Provider(org.guvnor.ala.runtime.providers.Provider) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider) WildflyProvider(org.guvnor.ala.wildfly.model.WildflyProvider)

Example 5 with WildflyProvider

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

WildflyProvider (org.guvnor.ala.wildfly.model.WildflyProvider)6 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)3 MavenBinary (org.guvnor.ala.build.maven.model.MavenBinary)2 WildflyRuntimeExecConfig (org.guvnor.ala.wildfly.config.WildflyRuntimeExecConfig)2 ContextAwareWildflyRuntimeExecConfig (org.guvnor.ala.wildfly.config.impl.ContextAwareWildflyRuntimeExecConfig)2 WildflyRuntimeEndpoint (org.guvnor.ala.wildfly.model.WildflyRuntimeEndpoint)2 Test (org.junit.Test)2 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Provider (org.guvnor.ala.runtime.providers.Provider)1 WildflyAppState (org.guvnor.ala.wildfly.access.WildflyAppState)1 WildflyProviderConfig (org.guvnor.ala.wildfly.config.WildflyProviderConfig)1 WildflyProviderConfigImpl (org.guvnor.ala.wildfly.config.impl.WildflyProviderConfigImpl)1 WildflyProviderImpl (org.guvnor.ala.wildfly.model.WildflyProviderImpl)1 WildflyRuntime (org.guvnor.ala.wildfly.model.WildflyRuntime)1 WildflyRuntimeInfo (org.guvnor.ala.wildfly.model.WildflyRuntimeInfo)1 WildflyRuntimeState (org.guvnor.ala.wildfly.model.WildflyRuntimeState)1 Path (org.uberfire.java.nio.file.Path)1