Search in sources :

Example 1 with TransactionalProtocolClient

use of org.jboss.as.controller.remote.TransactionalProtocolClient in project wildfly-core by wildfly.

the class ServerInventoryImpl method serverCommunicationRegistered.

@Override
public ProxyController serverCommunicationRegistered(final String serverProcessName, final ManagementChannelHandler channelAssociation) {
    if (shutdown || connectionFinished) {
        throw HostControllerLogger.ROOT_LOGGER.hostAlreadyShutdown();
    }
    final String serverName = ManagedServer.getServerName(serverProcessName);
    final ManagedServer server = servers.get(serverName);
    if (server == null) {
        ROOT_LOGGER.noServerAvailable(serverName);
        return null;
    }
    try {
        final TransactionalProtocolClient client = server.channelRegistered(channelAssociation);
        final Channel channel = channelAssociation.getChannel();
        channel.addCloseHandler(new CloseHandler<Channel>() {

            public void handleClose(final Channel closed, final IOException exception) {
                final boolean shuttingDown = shutdown || connectionFinished;
                // Unregister right away
                if (server.callbackUnregistered(client, shuttingDown)) {
                    domainController.unregisterRunningServer(server.getServerName());
                }
            }
        });
        return server.getProxyController();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient) Channel(org.jboss.remoting3.Channel) IOException(java.io.IOException)

Example 2 with TransactionalProtocolClient

use of org.jboss.as.controller.remote.TransactionalProtocolClient in project wildfly-core by wildfly.

the class ManagedServerProxy method execute.

@Override
public <T extends Operation> AsyncFuture<OperationResponse> execute(final TransactionalOperationListener<T> listener, final T operation) throws IOException {
    final TransactionalProtocolClient remoteClient = this.remoteClient;
    final ModelNode op = operation.getOperation();
    if (remoteClient == DISCONNECTED) {
        // Handle the restartRequired operation also when disconnected
        final String operationName = op.get(OP).asString();
        if (ServerProcessStateHandler.REQUIRE_RESTART_OPERATION.equals(operationName)) {
            server.requireReload();
        }
    }
    AsyncFuture<OperationResponse> future = remoteClient.execute(listener, operation);
    registerFuture(remoteClient, future);
    return future;
}
Also used : TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse)

Example 3 with TransactionalProtocolClient

use of org.jboss.as.controller.remote.TransactionalProtocolClient in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method testSimpleRequest.

@Test
public void testSimpleRequest() throws Exception {
    // 
    final TestUpdateWrapper update = createTestClient(0);
    final TransactionalProtocolClient client = update.getClient();
    final BlockingOperationListener listener = new BlockingOperationListener();
    client.execute(listener, update);
    // 
    final TransactionalProtocolClient.PreparedOperation<TestUpdateWrapper> prepared = listener.retrievePreparedOperation();
    assert !prepared.isFailed();
    assert !prepared.isDone();
    // Commit
    prepared.commit();
    // Block until we have the result
    final ModelNode result = prepared.getFinalResult().get().getResponseNode();
    assert result.hasDefined(ModelDescriptionConstants.OUTCOME);
    assert prepared.isDone();
}
Also used : TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 4 with TransactionalProtocolClient

use of org.jboss.as.controller.remote.TransactionalProtocolClient in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method createClient.

/**
 * Create the protocol client to talk to the remote controller.
 *
 * @param channel the remoting channel
 * @return the client
 * @throws Exception
 */
TransactionalProtocolClient createClient(final Channel channel) {
    channels.add(channel);
    final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
    final ManagementChannelHandler channelAssociation = new ManagementChannelHandler(strategy, clientExecutor);
    final TransactionalProtocolClient client = TransactionalProtocolHandlers.createClient(channelAssociation);
    channel.addCloseHandler(channelAssociation);
    channel.receiveMessage(channelAssociation.getReceiver());
    return client;
}
Also used : ManagementClientChannelStrategy(org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy) ManagementChannelHandler(org.jboss.as.protocol.mgmt.ManagementChannelHandler) TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient)

Example 5 with TransactionalProtocolClient

use of org.jboss.as.controller.remote.TransactionalProtocolClient in project wildfly-core by wildfly.

the class TransactionalProtocolClientTestCase method testConcurrentGroup.

@Test
public void testConcurrentGroup() throws Exception {
    // 
    final BlockingOperationListener listener = new BlockingOperationListener(CLIENTS);
    final List<TestUpdateWrapper> wrappers = createTestClients(CLIENTS);
    // First execute all operations
    for (final TestUpdateWrapper update : wrappers) {
        final TransactionalProtocolClient client = update.getClient();
        client.execute(listener, update);
    }
    // Now wait for all operations to be prepared
    final List<TransactionalProtocolClient.PreparedOperation<TestUpdateWrapper>> preparedOps = new ArrayList<TransactionalProtocolClient.PreparedOperation<TestUpdateWrapper>>();
    for (int i = 0; i < CLIENTS; i++) {
        // Wait for 10 prepared results
        final TransactionalProtocolClient.PreparedOperation<TestUpdateWrapper> prepared = listener.retrievePreparedOperation();
        assert !prepared.isFailed();
        assert !prepared.isDone();
        // Check that the controller is locked in the prepared state
        final MockController controller = prepared.getOperation().getController();
        assert controller.lock.isLocked();
        // Commit all
        prepared.commit();
        preparedOps.add(prepared);
    }
    final ModelNode result = new ModelNode();
    // Now we just need to get the final results
    for (final TransactionalProtocolClient.PreparedOperation<TestUpdateWrapper> prepared : preparedOps) {
        // Block until we have the result
        final ModelNode finalResult = prepared.getFinalResult().get().getResponseNode();
        final MockController controller = prepared.getOperation().getController();
        assert prepared.isDone();
        assert !controller.lock.isLocked();
        final int id = prepared.getOperation().getId();
        result.get("" + id).set(finalResult);
    }
    for (int i = 0; i < CLIENTS; i++) {
        assert result.hasDefined("" + i);
        assert result.get("" + i).hasDefined(ModelDescriptionConstants.OUTCOME);
    }
}
Also used : TransactionalProtocolClient(org.jboss.as.controller.remote.TransactionalProtocolClient) ArrayList(java.util.ArrayList) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

TransactionalProtocolClient (org.jboss.as.controller.remote.TransactionalProtocolClient)11 ModelNode (org.jboss.dmr.ModelNode)7 IOException (java.io.IOException)4 Test (org.junit.Test)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 OperationResponse (org.jboss.as.controller.client.OperationResponse)2 OperationTransformer (org.jboss.as.controller.transform.OperationTransformer)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 PathElement (org.jboss.as.controller.PathElement)1 ProxyController (org.jboss.as.controller.ProxyController)1 TransformingProxyController (org.jboss.as.controller.TransformingProxyController)1 OperationAttachments (org.jboss.as.controller.client.OperationAttachments)1 OperationMessageHandler (org.jboss.as.controller.client.OperationMessageHandler)1 Resource (org.jboss.as.controller.registry.Resource)1 OperationResultTransformer (org.jboss.as.controller.transform.OperationResultTransformer)1