Skip to content

Commit

Permalink
Added wildfly12 profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Lukas committed Mar 15, 2018
1 parent 3b30daf commit 3161f04
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 34 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Dependencies for `creaper-core`:
</dependency>

<!-- see https://issues.jboss.org/browse/WFCORE-1580 -->
<!-- not required if the dependency on wildfly-patching below is also added ->
<!-- not required if the dependency on wildfly-patching below is also added -->
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
Expand Down Expand Up @@ -198,6 +198,29 @@ Dependencies for `creaper-commands`:
<version>3.0.8.Final</version>
</dependency>

#### WildFly 12 (based on WildFly Core 4)

Dependencies for `creaper-core`:

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller-client</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-cli</artifactId>
<version>4.0.0.Final</version>
</dependency>

Dependencies for `creaper-commands`:

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-patching</artifactId>
<version>4.0.0.Final</version>
</dependency>

### Transitive Dependencies

These are the dependencies that you will get transitively when you depend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public final class ServerVersion {
public static final ServerVersion VERSION_4_1_0 = new ServerVersion(4, 1, 0);
/** WF 10.1.0.Final */
public static final ServerVersion VERSION_4_2_0 = new ServerVersion(4, 2, 0);
/** WF 11 (not yet final) */
/** WF 11.0.0.Final */
public static final ServerVersion VERSION_5_0_0 = new ServerVersion(5, 0, 0);
/** WF 12.0.0.Final */
public static final ServerVersion VERSION_6_0_0 = new ServerVersion(6, 0, 0);

private static final ServerVersion[] KNOWN_VERSIONS = {
VERSION_0_0_0,
Expand All @@ -90,6 +92,7 @@ public final class ServerVersion {
VERSION_4_1_0,
VERSION_4_2_0,
VERSION_5_0_0,
VERSION_6_0_0,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@
import org.jboss.as.controller.client.OperationResponse;
import org.jboss.dmr.ModelNode;
import org.jboss.threads.AsyncFuture;
import org.jboss.threads.AsyncFutureTask;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
* Controller provides execution of {@link ModelNode} or {@link Operation} over HTTP.
* Asynchronous execution is not provided. Controller does not inform about any progress, therefore, there is no point
* in using {@link OperationMessageHandler}.
* Controller does not inform about any progress, therefore, there is no point in using {@link OperationMessageHandler}.
* If an error occurs (server does not respond 401 or header does not contain WWW-Authenticate field after
* first request) {@code IllegalStateException is thrown} (if username and password is provided)
* Execution on {@link Operation} is allowed with <b>no attachments</b>.
Expand All @@ -47,10 +55,13 @@ final class HttpModelControllerClient implements ModelControllerClient {
private final RequestConfig requestConfig;
private final Registry<ConnectionSocketFactory> registry;
private final CloseableHttpClient client;
private final int timeout;
private ExecutorService executorService;

HttpModelControllerClient(String host, int port, String username, String password, int timeoutMillis,
SslOptions ssl) throws IOException {
// timeout configuration
this.timeout = timeoutMillis;
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (timeoutMillis != NO_TIMEOUT) {
requestConfigBuilder
Expand Down Expand Up @@ -124,33 +135,43 @@ public OperationResponse executeOperation(Operation operation, OperationMessageH
return OperationResponse.Factory.createSimple(execute(operation));
}

/**
* <b>Not supported!</b>
*/
@Override
public AsyncFuture<ModelNode> executeAsync(ModelNode modelNode, OperationMessageHandler handler) {
throw new UnsupportedOperationException("Asynchronous execution is not supported by " + getClass().getName());
ExecutorService executor = obtainExecutorService();
Future<ModelNode> submit = executor.submit(new ModelNodeFromModelNodeCallable(modelNode));
ModelNode result = getFutureResult(submit);
return new HttpModelControllerClientAsyncFutureTask(executor, result);
}

/**
* <b>Not supported!</b>
*/
@Override
public AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler handler) {
throw new UnsupportedOperationException("Asynchronous execution is not supported by " + getClass().getName());
ExecutorService executor = obtainExecutorService();
Future<ModelNode> submit = executor.submit(new ModelNodeFromOperationCallable(operation));
ModelNode result = getFutureResult(submit);
return new HttpModelControllerClientAsyncFutureTask(executor, result);
}

/**
* <b>Not supported!</b>
*/
@Override
public AsyncFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler handler) {
throw new UnsupportedOperationException("Asynchronous execution is not supported by " + getClass().getName());
ExecutorService executor = obtainExecutorService();
Future<OperationResponse> submit = executor.submit(new OperationResponseFromOperationCallable(operation));
OperationResponse result = getFutureResult(submit);
return new HttpModelControllerClientAsyncFutureTask(executor, result);
}

@Override
public void close() throws IOException {
client.close();
if (executorService != null) {
executorService.shutdown();
}
}

private ExecutorService obtainExecutorService() {
if (executorService == null) {
executorService = Executors.newCachedThreadPool();
}
return executorService;
}

private ModelNode parseResponse(CloseableHttpResponse response) throws IOException {
Expand Down Expand Up @@ -214,4 +235,73 @@ private String getManagementRealm(String url) throws IOException {
}
throw new IllegalStateException("Failed to obtain management realm name. Digest realm not found in WWW-Authenticate header.");
}

private <T> T getFutureResult(Future<T> submit) {
T get = null;
try {
if (timeout == NO_TIMEOUT) {
get = submit.get();
} else {
get = submit.get(timeout, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
} catch (ExecutionException ex) {
throw new RuntimeException(ex);
} catch (TimeoutException ex) {
throw new RuntimeException(ex);
}
return get;
}

private static class HttpModelControllerClientAsyncFutureTask<T> extends AsyncFutureTask<T> {

public HttpModelControllerClientAsyncFutureTask(Executor executor, T result) {
super(executor);
super.setResult(result);
}

}

private class ModelNodeFromModelNodeCallable implements Callable<ModelNode> {

private final ModelNode modelNode;

public ModelNodeFromModelNodeCallable(ModelNode modelNode) {
this.modelNode = modelNode;
}

@Override
public ModelNode call() throws Exception {
return execute(modelNode);
}
}

private class ModelNodeFromOperationCallable implements Callable<ModelNode> {

private final Operation operation;

public ModelNodeFromOperationCallable(Operation operation) {
this.operation = operation;
}

@Override
public ModelNode call() throws Exception {
return execute(operation);
}
}

private class OperationResponseFromOperationCallable implements Callable<OperationResponse> {

private final Operation operation;

public OperationResponseFromOperationCallable(Operation operation) {
this.operation = operation;
}

@Override
public OperationResponse call() throws Exception {
return executeOperation(operation, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public void referenceEquality() {
assertSame(ServerVersion.VERSION_3_0_0, ServerVersion.from(3, 0, 0));
assertSame(ServerVersion.VERSION_4_0_0, ServerVersion.from(4, 0, 0));
assertSame(ServerVersion.VERSION_4_1_0, ServerVersion.from(4, 1, 0));
assertSame(ServerVersion.VERSION_4_2_0, ServerVersion.from(4, 2, 0));
assertSame(ServerVersion.VERSION_5_0_0, ServerVersion.from(5, 0, 0));
assertSame(ServerVersion.VERSION_6_0_0, ServerVersion.from(6, 0, 0));

assertNotSame(ServerVersion.from(42, 42, 42), ServerVersion.from(42, 42, 42));
}
Expand All @@ -49,6 +52,9 @@ public void equality() {
assertEquals(ServerVersion.VERSION_3_0_0, ServerVersion.from(3, 0, 0));
assertEquals(ServerVersion.VERSION_4_0_0, ServerVersion.from(4, 0, 0));
assertEquals(ServerVersion.VERSION_4_1_0, ServerVersion.from(4, 1, 0));
assertEquals(ServerVersion.VERSION_4_2_0, ServerVersion.from(4, 2, 0));
assertEquals(ServerVersion.VERSION_5_0_0, ServerVersion.from(5, 0, 0));
assertEquals(ServerVersion.VERSION_6_0_0, ServerVersion.from(6, 0, 0));

assertEquals(ServerVersion.from(42, 42, 42), ServerVersion.from(42, 42, 42));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ public class OfflineServerVersionTest {
private static final String EAP6_LOGGING = "1.5";
private static final String EAP6_EE = "1.2";

private static final String EAP7_ROOT = "4.0";
private static final String EAP70_ROOT = "4.0";
private static final String EAP71_ROOT = "5.0";
private static final String EAP7_LOGGING = "3.0";
private static final String EAP7_EE = "4.0";

private static final String WFLY12_ROOT = "6.0";

@Rule
public final TemporaryFolder tmp = new TemporaryFolder();

Expand Down Expand Up @@ -81,8 +84,18 @@ public void discoverStandaloneXml_eap6() throws IOException {
}

@Test
public void discoverStandaloneXml_eap7() throws IOException {
test(ServerVersion.VERSION_4_0_0, STANDALONE_XML, EAP7_ROOT, EAP7_LOGGING, EAP7_EE);
public void discoverStandaloneXml_eap70() throws IOException {
test(ServerVersion.VERSION_4_0_0, STANDALONE_XML, EAP70_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverStandaloneXml_eap71() throws IOException {
test(ServerVersion.VERSION_5_0_0, STANDALONE_XML, EAP71_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverStandaloneXml_wfly12() throws IOException {
test(ServerVersion.VERSION_6_0_0, STANDALONE_XML, WFLY12_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
Expand All @@ -91,8 +104,18 @@ public void discoverHostXml_eap6() throws IOException {
}

@Test
public void discoverHostXml_eap7() throws IOException {
test(ServerVersion.VERSION_4_0_0, HOST_XML, EAP7_ROOT, EAP7_LOGGING, EAP7_EE);
public void discoverHostXml_eap70() throws IOException {
test(ServerVersion.VERSION_4_0_0, HOST_XML, EAP70_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverHostXml_eap71() throws IOException {
test(ServerVersion.VERSION_5_0_0, HOST_XML, EAP71_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverHostXml_wfly12() throws IOException {
test(ServerVersion.VERSION_6_0_0, HOST_XML, WFLY12_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
Expand All @@ -101,8 +124,18 @@ public void discoverDomainXml_eap6() throws IOException {
}

@Test
public void discoverDomainXml_eap7() throws IOException {
test(ServerVersion.VERSION_4_0_0, DOMAIN_XML, EAP7_ROOT, EAP7_LOGGING, EAP7_EE);
public void discoverDomainXml_eap70() throws IOException {
test(ServerVersion.VERSION_4_0_0, DOMAIN_XML, EAP70_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverDomainXml_eap71() throws IOException {
test(ServerVersion.VERSION_5_0_0, DOMAIN_XML, EAP71_ROOT, EAP7_LOGGING, EAP7_EE);
}

@Test
public void discoverDomainXml_wfly12() throws IOException {
test(ServerVersion.VERSION_6_0_0, DOMAIN_XML, WFLY12_ROOT, EAP7_LOGGING, EAP7_EE);
}

private void test(ServerVersion expected, String xmlPattern,
Expand Down
Loading

0 comments on commit 3161f04

Please sign in to comment.