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;
}
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());
}
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());
}
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);
}
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())));
}
Aggregations