Skip to content

Commit

Permalink
[AS7-4032] add blocking param for server lifecycle operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Muckenhuber authored and Jason Greene committed Mar 9, 2012
1 parent f91009c commit d7da1e5
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 13 deletions.
Expand Up @@ -521,6 +521,11 @@ public ServerStatus startServer(String serverName, ModelNode domainModel) {
return serverInventory.startServer(serverName, domainModel);
}

@Override
public ServerStatus startServer(String serverName, ModelNode domainModel, boolean blocking) {
return serverInventory.startServer(serverName, domainModel, blocking);
}

public void reconnectServer(String serverName, ModelNode domainModel, boolean running) {
serverInventory.reconnectServer(serverName, domainModel, running);
}
Expand All @@ -529,10 +534,20 @@ public ServerStatus restartServer(String serverName, int gracefulTimeout, ModelN
return serverInventory.restartServer(serverName, gracefulTimeout, domainModel);
}

@Override
public ServerStatus restartServer(String serverName, int gracefulTimeout, ModelNode domainModel, boolean blocking) {
return serverInventory.restartServer(serverName, gracefulTimeout, domainModel, blocking);
}

public ServerStatus stopServer(String serverName, int gracefulTimeout) {
return serverInventory.stopServer(serverName, gracefulTimeout);
}

@Override
public ServerStatus stopServer(String serverName, int gracefulTimeout, boolean blocking) {
return serverInventory.stopServer(serverName, gracefulTimeout, blocking);
}

public CallbackHandler getServerCallbackHandler() {
return serverInventory.getServerCallbackHandler();
}
Expand Down
Expand Up @@ -86,10 +86,20 @@ public interface ServerInventory {
*
* @param serverName the name of the server
* @param domainModel the configuration model for the domain
* @return the status of the server followin the attempt to start
* @return the status of the server following the attempt to start
*/
ServerStatus startServer(final String serverName, final ModelNode domainModel);

/**
* Start the server with the given name.
*
* @param serverName the name of the server
* @param domainModel the configuration model for the domain
* @param blocking whether to block until the server is started
* @return the status of the server following the attempt to start
*/
ServerStatus startServer(String serverName, ModelNode domainModel, boolean blocking);

/**
* Restart the server with the given name. Note that returning from this method does not mean the server
* is completely started; it usually will only be in the process of starting, having received all startup instructions.
Expand All @@ -98,10 +108,21 @@ public interface ServerInventory {
* @param gracefulTimeout time in ms the server should allow for graceful shutdown (if supported) before terminating all services
* @param domainModel the configuration model for the domain
*
* @return the status of the server followin the attempt to restart
* @return the status of the server following the attempt to restart
*/
ServerStatus restartServer(String serverName, final int gracefulTimeout, final ModelNode domainModel);

/**
* Restart the server with the given name.
*
* @param serverName the name of the server
* @param gracefulTimeout time in ms the server should allow for graceful shutdown (if supported) before terminating all services
* @param domainModel the configuration model for the domain
* @param blocking whether to block until the server is restarted
* @return the status of the server following the attempt to restart
*/
ServerStatus restartServer(String serverName, int gracefulTimeout, ModelNode domainModel, boolean blocking);

/**
* Stop the server with the given name. Note that returning from this method does not mean the server
* is completely stopped; it may only be in the process of stopping.
Expand All @@ -113,6 +134,16 @@ public interface ServerInventory {
*/
ServerStatus stopServer(final String serverName, final int gracefulTimeout);

/**
* Stop the server with the given name.
*
* @param serverName the name of the server
* @param gracefulTimeout time in ms the server should allow for graceful shutdown (if supported) before terminating all services
* @param blocking whether to block until the server is stopped
* @return the status of the server following the attempt to stop
*/
ServerStatus stopServer(String serverName, int gracefulTimeout, boolean blocking);

/**
* Stop all servers. Note that returning from this method does not mean the servers
* are completely stopped; they may only be in the process of stopping.
Expand Down
Expand Up @@ -147,6 +147,11 @@ public ServerStatus determineServerStatus(final String serverName) {

@Override
public ServerStatus startServer(final String serverName, final ModelNode domainModel) {
return startServer(serverName, domainModel, false);
}

@Override
public ServerStatus startServer(final String serverName, final ModelNode domainModel, final boolean blocking) {
if(shutdown || connectionFinished) {
throw HostControllerMessages.MESSAGES.hostAlreadyShutdown();
}
Expand All @@ -163,11 +168,19 @@ public ServerStatus startServer(final String serverName, final ModelNode domainM
synchronized (shutdownCondition) {
shutdownCondition.notifyAll();
}
if(blocking) {
server.awaitState(ManagedServer.InternalState.SERVER_STARTED);
}
return server.getState();
}

@Override
public ServerStatus restartServer(final String serverName, final int gracefulTimeout, final ModelNode domainModel) {
return restartServer(serverName, gracefulTimeout, domainModel, false);
}

@Override
public ServerStatus restartServer(final String serverName, final int gracefulTimeout, final ModelNode domainModel, final boolean blocking) {
stopServer(serverName, gracefulTimeout);
synchronized (shutdownCondition) {
for(;;) {
Expand All @@ -185,17 +198,25 @@ public ServerStatus restartServer(final String serverName, final int gracefulTim
}
}
}
startServer(serverName, domainModel);
startServer(serverName, domainModel, blocking);
return determineServerStatus(serverName);
}

@Override
public ServerStatus stopServer(final String serverName, final int gracefulTimeout) {
return stopServer(serverName, gracefulTimeout, false);
}

@Override
public ServerStatus stopServer(final String serverName, final int gracefulTimeout, final boolean blocking) {
final ManagedServer server = servers.get(serverName);
if(server == null) {
return ServerStatus.STOPPED;
}
server.stop();
if(blocking) {
server.awaitState(ManagedServer.InternalState.STOPPED);
}
return server.getState();
}

Expand Down
Expand Up @@ -92,6 +92,9 @@
* @author Brian Stansberry
*/
public class HostRootDescription {

private static final String BLOCKING = "blocking";

public static final SimpleAttributeDefinition DIRECTORY_GROUPING = SimpleAttributeDefinitionBuilder.create(ModelDescriptionConstants.DIRECTORY_GROUPING, ModelType.STRING, true).
addFlag(Flag.RESTART_ALL_SERVICES).
setDefaultValue(DirectoryGrouping.defaultValue().toModelNode()).
Expand Down Expand Up @@ -240,6 +243,12 @@ public static ModelNode getStartServerOperation(final Locale locale) {
root.get(REQUEST_PROPERTIES, SERVER, REQUIRED).set(true);
root.get(REQUEST_PROPERTIES, SERVER, MIN_LENGTH).set(1);
root.get(REQUEST_PROPERTIES, SERVER, NILLABLE).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, TYPE).set(ModelType.BOOLEAN);
root.get(REQUEST_PROPERTIES, BLOCKING, DEFAULT).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, DESCRIPTION).set(bundle.getString("host.start-server.blocking"));
root.get(REQUEST_PROPERTIES, BLOCKING, REQUIRED).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, NILLABLE).set(true);
root.get(REPLY_PROPERTIES, TYPE).set(ModelType.STRING);
root.get(REPLY_PROPERTIES, TYPE).set(ModelType.STRING);
root.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString("host.start-server.reply"));
return root;
Expand All @@ -256,6 +265,11 @@ public static ModelNode getRestartServerOperation(final Locale locale) {
root.get(REQUEST_PROPERTIES, SERVER, REQUIRED).set(true);
root.get(REQUEST_PROPERTIES, SERVER, MIN_LENGTH).set(1);
root.get(REQUEST_PROPERTIES, SERVER, NILLABLE).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, TYPE).set(ModelType.BOOLEAN);
root.get(REQUEST_PROPERTIES, BLOCKING, DEFAULT).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, DESCRIPTION).set(bundle.getString("host.restart-server.blocking"));
root.get(REQUEST_PROPERTIES, BLOCKING, REQUIRED).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, NILLABLE).set(true);
root.get(REPLY_PROPERTIES, TYPE).set(ModelType.STRING);
root.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString("host.restart-server.reply"));
return root;
Expand All @@ -272,6 +286,11 @@ public static ModelNode getStopServerOperation(final Locale locale) {
root.get(REQUEST_PROPERTIES, SERVER, REQUIRED).set(true);
root.get(REQUEST_PROPERTIES, SERVER, MIN_LENGTH).set(1);
root.get(REQUEST_PROPERTIES, SERVER, NILLABLE).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, TYPE).set(ModelType.BOOLEAN);
root.get(REQUEST_PROPERTIES, BLOCKING, DEFAULT).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, DESCRIPTION).set(bundle.getString("host.stop-server.blocking"));
root.get(REQUEST_PROPERTIES, BLOCKING, REQUIRED).set(false);
root.get(REQUEST_PROPERTIES, BLOCKING, NILLABLE).set(true);
root.get(REPLY_PROPERTIES, TYPE).set(ModelType.STRING);
root.get(REPLY_PROPERTIES, DESCRIPTION).set(bundle.getString("host.stop-server.reply"));
return root;
Expand Down
Expand Up @@ -68,6 +68,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final PathElement element = address.getLastElement();
final String serverName = element.getValue();
final boolean blocking = operation.get("blocking").asBoolean(false);

final ModelNode model = Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
context.addStep(new OperationStepHandler() {
Expand All @@ -77,7 +78,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
if (origStatus != ServerStatus.STARTED) {
throw new OperationFailedException(new ModelNode(MESSAGES.cannotRestartServer(serverName, origStatus)));
}
final ServerStatus status = serverInventory.restartServer(serverName, -1, model);
final ServerStatus status = serverInventory.restartServer(serverName, -1, model, blocking);
context.getResult().set(status.toString());
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Expand Down
Expand Up @@ -69,14 +69,15 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final PathElement element = address.getLastElement();
final String serverName = element.getValue();
final boolean blocking = operation.get("blocking").asBoolean(false);

final ModelNode model = Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServerStatus origStatus = serverInventory.determineServerStatus(serverName);
if (origStatus != ServerStatus.STARTED && origStatus != ServerStatus.STARTING) {
final ServerStatus status = serverInventory.startServer(serverName, model);
final ServerStatus status = serverInventory.startServer(serverName, model, blocking);
context.getResult().set(status.toString());
} else {
context.getResult().set(origStatus.toString());
Expand Down
Expand Up @@ -70,11 +70,11 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
final PathElement element = address.getLastElement();
final String serverName = element.getValue();

final boolean blocking = operation.get("blocking").asBoolean(false);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServerStatus status = serverInventory.stopServer(serverName, -1);
final ServerStatus status = serverInventory.stopServer(serverName, -1, blocking);
context.getResult().set(status.toString());
context.completeStep();
}
Expand Down
Expand Up @@ -32,13 +32,16 @@ host.shutdown=Shuts down the host and its servers
host.shutdown.restart=If true, once shutdown the host controller will be restarted again
host.start-server=Start a server.
host.start-server.server=The name of the server.
host.start-server.blocking=Whether the operation should block and wait until the server is started.
host.start-server.reply=The status of the server following execution of this operation.
host.state=The current state of the host controller; either STARTING, RUNNING or RESTART_REQUIRED
host.restart-server=Restart a currently running server.
host.restart-server.server=The name of the server.
host.restart-server.blocking=Whether the operation should block and wait until the server is restarted.
host.restart-server.reply=The status of the server following execution of this operation.
host.stop-server=Stop a currently running server.
host.stop-server.server=The name of the server.
host.stop-server.blocking=Whether the operation should block and wait until the server is stopped.
host.stop-server.reply=The status of the server following execution of this operation.
host.master=Whether this host is master host for the domain; i.e. whether this process is acting as the Domain Controller.
host.resolve-expression-on-domain=Operation that accepts an expression as input (or a string that can be parsed into an expression) and resolves it against the local system properties and environment variables on all servers managed by this host controller.
Expand Down
Expand Up @@ -25,6 +25,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.AUTO_START;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILD_TYPE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.COMPOSITE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP;
Expand All @@ -44,6 +45,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_PORT_OFFSET;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.START;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.START_SERVERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STEPS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STOP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STOP_SERVERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
Expand Down Expand Up @@ -164,6 +166,7 @@ public void testAddAndRemoveServer() throws Exception {
final ModelNode stopServer = new ModelNode();
stopServer.get(OP).set("stop");
stopServer.get(OP_ADDR).set(newServerConfigAddress);
stopServer.get("blocking").set(true);
result = client.execute(stopServer);
validateResponse(result);
waitUntilState(client, newServerConfigAddress, "DISABLED");
Expand Down Expand Up @@ -269,32 +272,32 @@ public void testDomainLifecycleMethods() throws Throwable {
@Test
@Ignore("AS7-3764")
public void testAdminOnlyMode() throws Exception {

// restart master HC in admin only mode
final DomainClient masterClient = domainMasterLifecycleUtil.getDomainClient();
ModelNode op = new ModelNode();
op.get(OP_ADDR).add(HOST, "master");
op.get(OP).set("reload");
op.get("admin-only").set(true);
executeForResult(masterClient, op);

// check that the servers are stopped
waitUntilState(masterClient, "master", "main-one", "STOPPED");
waitUntilState(masterClient, "master", "main-one", "STOPPED");

// restart back to normal mode
op = new ModelNode();
op.get(OP_ADDR).add(HOST, "master");
op.get(OP).set("reload");
op.get("admin-only").set(false);
executeForResult(masterClient, op);
executeForResult(masterClient, op);

// check that the servers are up
waitUntilState(masterClient, "master", "main-one", "STARTED");
waitUntilState(masterClient, "master", "main-one", "STARTED");

}

private void executeLifecycleOperation(final ModelControllerClient client, String opName) throws IOException {
executeLifecycleOperation(client, null, opName);
}
Expand Down

0 comments on commit d7da1e5

Please sign in to comment.