Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[AS7-4527] rollout plan tasks cleanup

  • Loading branch information...
commit 01514c8215d87196e05466c35c3f38c71b196935 1 parent 69775a4
@emuckenhuber emuckenhuber authored bstansberry committed
Showing with 199 additions and 276 deletions.
  1. +7 −0 controller/src/main/java/org/jboss/as/controller/remote/BlockingQueueOperationListener.java
  2. +4 −2 controller/src/main/java/org/jboss/as/controller/remote/TransactionalProtocolClientImpl.java
  3. +10 −12 ...ntroller/src/main/java/org/jboss/as/domain/controller/operations/coordination/DomainRolloutStepHandler.java
  4. +7 −6 host-controller/src/main/java/org/jboss/as/domain/controller/plan/AbstractServerGroupRolloutTask.java
  5. +5 −5 ...boss/as/domain/controller/plan/{ConcurrentGroupUpdateTask.java → ConcurrentServerGroupUpdateTask.java}
  6. +5 −5 .../org/jboss/as/domain/controller/plan/{RollingGroupUpdateTask.java → RollingServerGroupUpdateTask.java}
  7. +6 −9 host-controller/src/main/java/org/jboss/as/domain/controller/plan/RolloutPlanController.java
  8. +2 −6 host-controller/src/main/java/org/jboss/as/domain/controller/plan/RunningServerUpdateTask.java
  9. +0 −23 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerOperationExecutor.java
  10. +2 −5 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerRestartTask.java
  11. +0 −154 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerRolloutTaskHandler.java
  12. +0 −36 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerTask.java
  13. +145 −8 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerTaskExecutor.java
  14. +6 −5 .../main/java/org/jboss/as/domain/controller/plan/{AbstractServerUpdateTask.java → ServerUpdateTask.java}
View
7 controller/src/main/java/org/jboss/as/controller/remote/BlockingQueueOperationListener.java
@@ -26,6 +26,7 @@
import org.jboss.dmr.ModelNode;
import org.jboss.threads.AsyncFuture;
+import java.util.Collection;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CancellationException;
@@ -84,6 +85,12 @@ public void operationComplete(T operation, ModelNode result) {
return queue.take();
}
+ protected void drainTo(final Collection<TransactionalProtocolClient.PreparedOperation<T>> collection) {
+ if(queue.size() > 0) {
+ queue.drainTo(collection);
+ }
+ }
+
/**
* Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
*
View
6 controller/src/main/java/org/jboss/as/controller/remote/TransactionalProtocolClientImpl.java
@@ -82,7 +82,7 @@ public TransactionalProtocolClientImpl(final ManagementChannelAssociation channe
if (operationType == ModelControllerProtocol.HANDLE_REPORT_REQUEST) {
return new HandleReportRequestHandler();
} else if (operationType == ModelControllerProtocol.GET_INPUTSTREAM_REQUEST) {
- return new ReadAttachmentInputStreamRequestHandler();
+ return ReadAttachmentInputStreamRequestHandler.INSTANCE;
}
return handlers.resolveNext();
}
@@ -243,7 +243,9 @@ public void handleRequest(final DataInput input, final ActiveOperation.ResultHan
* Handles reads on the inputstreams returned by {@link org.jboss.as.controller.client.OperationAttachments#getInputStreams()}
* done in the remote target controller
*/
- private class ReadAttachmentInputStreamRequestHandler implements ManagementRequestHandler<ModelNode, ExecuteRequestContext> {
+ private static class ReadAttachmentInputStreamRequestHandler implements ManagementRequestHandler<ModelNode, ExecuteRequestContext> {
+
+ static final ReadAttachmentInputStreamRequestHandler INSTANCE = new ReadAttachmentInputStreamRequestHandler();
@Override
public void handleRequest(final DataInput input, final ActiveOperation.ResultHandler<ModelNode> resultHandler,
View
22 ...java/org/jboss/as/domain/controller/operations/coordination/DomainRolloutStepHandler.java
@@ -64,7 +64,6 @@
import org.jboss.as.controller.ProxyController;
import org.jboss.as.domain.controller.ServerIdentity;
import org.jboss.as.domain.controller.plan.RolloutPlanController;
-import org.jboss.as.domain.controller.plan.ServerRolloutTaskHandler;
import org.jboss.as.domain.controller.plan.ServerTaskExecutor;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
@@ -136,11 +135,10 @@ public void execute(final OperationContext context, final ModelNode operation) t
// We no longer roll back by default
domainOperationContext.setCompleteRollback(false);
- final Map<ServerIdentity, ServerRolloutTaskHandler.ServerExecutedRequest> submittedTasks = new HashMap<ServerIdentity, ServerRolloutTaskHandler.ServerExecutedRequest>();
- final List<ServerRolloutTaskHandler.ServerPreparedResponse> preparedResults = new ArrayList<ServerRolloutTaskHandler.ServerPreparedResponse>();
- final ServerRolloutTaskHandler rolloutHandler = new ServerRolloutTaskHandler(submittedTasks, preparedResults);
+ final Map<ServerIdentity, ServerTaskExecutor.ExecutedServerRequest> submittedTasks = new HashMap<ServerIdentity, ServerTaskExecutor.ExecutedServerRequest>();
+ final List<ServerTaskExecutor.ServerPreparedResponse> preparedResults = new ArrayList<ServerTaskExecutor.ServerPreparedResponse>();
try {
- pushToServers(context, rolloutHandler);
+ pushToServers(context, submittedTasks, preparedResults);
context.completeStep();
} finally {
@@ -148,7 +146,7 @@ public void execute(final OperationContext context, final ModelNode operation) t
// Do them all before reading results so the commits/rollbacks can be executed in parallel
boolean completeRollback = domainOperationContext.isCompleteRollback();
final String localHostName = domainOperationContext.getLocalHostInfo().getLocalHostName();
- for(final ServerRolloutTaskHandler.ServerPreparedResponse preparedResult : preparedResults) {
+ for(final ServerTaskExecutor.ServerPreparedResponse preparedResult : preparedResults) {
boolean rollback = completeRollback || domainOperationContext.isServerGroupRollback(preparedResult.getServerGroupName());
// Require a server reload, in case the operation failed, but the overall state was commit
if(! preparedResult.finalizeTransaction(! rollback)) {
@@ -171,7 +169,7 @@ public void execute(final OperationContext context, final ModelNode operation) t
}
final Future<ModelNode> future = executorService.submit(new ServerRequireRestartTask(identity, proxy, result));
// replace the existing future
- submittedTasks.put(identity, new ServerRolloutTaskHandler.ServerExecutedRequest(identity, future));
+ submittedTasks.put(identity, new ServerTaskExecutor.ExecutedServerRequest(identity, future));
} catch (Exception ignore) {
// getUncommittedResult() won't fail here
}
@@ -181,7 +179,7 @@ public void execute(final OperationContext context, final ModelNode operation) t
// before we expose the servers to further requests
boolean interrupted = false;
try {
- for (Map.Entry<ServerIdentity, ServerRolloutTaskHandler.ServerExecutedRequest> entry : submittedTasks.entrySet()) {
+ for (Map.Entry<ServerIdentity, ServerTaskExecutor.ExecutedServerRequest> entry : submittedTasks.entrySet()) {
Future<ModelNode> future = entry.getValue().getFinalResult();
try {
ModelNode finalResult = future.isCancelled() ? getCancelledResult() : future.get();
@@ -213,8 +211,8 @@ private ModelNode getCancelledResult() {
return cancelled;
}
- private void pushToServers(final OperationContext context, final ServerRolloutTaskHandler rolloutHandler) throws OperationFailedException {
-
+ private void pushToServers(final OperationContext context, final Map<ServerIdentity,ServerTaskExecutor.ExecutedServerRequest> submittedTasks,
+ final List<ServerTaskExecutor.ServerPreparedResponse> preparedResults) throws OperationFailedException {
final String localHostName = domainOperationContext.getLocalHostInfo().getLocalHostName();
Map<String, ModelNode> hostResults = new HashMap<String, ModelNode>(domainOperationContext.getHostControllerResults());
@@ -229,7 +227,7 @@ private void pushToServers(final OperationContext context, final ServerRolloutTa
HOST_CONTROLLER_LOGGER.tracef("Rollout plan is %s", rolloutPlan);
}
- final ServerTaskExecutor taskExecutor = new ServerTaskExecutor(context, rolloutHandler) {
+ final ServerTaskExecutor taskExecutor = new ServerTaskExecutor(context, submittedTasks, preparedResults) {
@Override
protected boolean execute(TransactionalProtocolClient.TransactionalOperationListener<ServerTaskExecutor.ServerOperation> listener, ServerIdentity server, ModelNode original) {
@@ -252,7 +250,7 @@ protected boolean execute(TransactionalProtocolClient.TransactionalOperationList
return executeOperation(listener, client, server, transformedOperation);
}
};
- RolloutPlanController rolloutPlanController = new RolloutPlanController(opsByGroup, rolloutPlan, domainOperationContext, taskExecutor, rolloutHandler, executorService);
+ RolloutPlanController rolloutPlanController = new RolloutPlanController(opsByGroup, rolloutPlan, domainOperationContext, taskExecutor, executorService);
RolloutPlanController.Result planResult = rolloutPlanController.execute();
if (trace) {
HOST_CONTROLLER_LOGGER.tracef("Rollout plan result is %s", planResult);
View
13 ...ler/src/main/java/org/jboss/as/domain/controller/plan/AbstractServerGroupRolloutTask.java
@@ -31,20 +31,21 @@
import java.util.List;
/**
+ * Task responsible for updating a single server-group.
+ *
* @author Emanuel Muckenhuber
*/
+// TODO cleanup ServerGroupRolloutTask vs. ServerUpdateTask vs. Concurrent/RollingUpdateTask
abstract class AbstractServerGroupRolloutTask implements Runnable {
- protected final List<ServerTask> tasks;
+ protected final List<ServerUpdateTask> tasks;
protected final ServerUpdatePolicy updatePolicy;
- protected final ServerRolloutTaskHandler rolloutHandler;
protected final ServerTaskExecutor executor;
- protected final AbstractServerUpdateTask.ServerUpdateResultHandler resultHandler;
+ protected final ServerUpdateTask.ServerUpdateResultHandler resultHandler;
- public AbstractServerGroupRolloutTask(List<ServerTask> tasks, ServerUpdatePolicy updatePolicy, ServerRolloutTaskHandler rolloutHandler, ServerTaskExecutor executor, final AbstractServerUpdateTask.ServerUpdateResultHandler resultHandler) {
+ public AbstractServerGroupRolloutTask(List<ServerUpdateTask> tasks, ServerUpdatePolicy updatePolicy, ServerTaskExecutor executor, final ServerUpdateTask.ServerUpdateResultHandler resultHandler) {
this.tasks = tasks;
this.updatePolicy = updatePolicy;
- this.rolloutHandler = rolloutHandler;
this.executor = executor;
this.resultHandler = resultHandler;
}
@@ -67,7 +68,7 @@ public void run() {
*/
protected void recordPreparedOperation(final ServerIdentity identity, final TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> prepared) {
updatePolicy.recordServerResult(identity, prepared.getPreparedResult());
- rolloutHandler.recordPreparedOperation(prepared);
+ executor.recordPreparedOperation(prepared);
resultHandler.handleServerUpdateResult(identity, prepared.getPreparedResult());
}
View
10 ...oller/plan/ConcurrentGroupUpdateTask.java → ...plan/ConcurrentServerGroupUpdateTask.java
@@ -32,18 +32,18 @@
/**
* @author Emanuel Muckenhuber
*/
-class ConcurrentGroupUpdateTask extends AbstractServerGroupRolloutTask implements Runnable {
+class ConcurrentServerGroupUpdateTask extends AbstractServerGroupRolloutTask implements Runnable {
- public ConcurrentGroupUpdateTask(List<ServerTask> tasks, ServerUpdatePolicy updatePolicy, ServerRolloutTaskHandler rolloutHandler,
- ServerTaskExecutor executor, AbstractServerUpdateTask.ServerUpdateResultHandler resultHandler) {
- super(tasks, updatePolicy, rolloutHandler, executor, resultHandler);
+ public ConcurrentServerGroupUpdateTask(List<ServerUpdateTask> tasks, ServerUpdatePolicy updatePolicy,
+ ServerTaskExecutor executor, ServerUpdateTask.ServerUpdateResultHandler resultHandler) {
+ super(tasks, updatePolicy, executor, resultHandler);
}
@Override
public void execute() {
final Set<ServerIdentity> outstanding = new HashSet<ServerIdentity>();
final ServerTaskExecutor.ServerOperationListener listener = new ServerTaskExecutor.ServerOperationListener();
- for(final ServerTask task : tasks) {
+ for(final ServerUpdateTask task : tasks) {
final ServerIdentity identity = task.getServerIdentity();
if(updatePolicy.canUpdateServer(identity)) {
// Execute the task
View
10 ...ntroller/plan/RollingGroupUpdateTask.java → ...er/plan/RollingServerGroupUpdateTask.java
@@ -30,18 +30,18 @@
/**
* @author Emanuel Muckenhuber
*/
-class RollingGroupUpdateTask extends AbstractServerGroupRolloutTask implements Runnable {
+class RollingServerGroupUpdateTask extends AbstractServerGroupRolloutTask implements Runnable {
- public RollingGroupUpdateTask(List<ServerTask> tasks, ServerUpdatePolicy updatePolicy, ServerRolloutTaskHandler rolloutHandler,
- ServerTaskExecutor executor, AbstractServerUpdateTask.ServerUpdateResultHandler resultHandler) {
- super(tasks, updatePolicy, rolloutHandler, executor, resultHandler);
+ public RollingServerGroupUpdateTask(List<ServerUpdateTask> tasks, ServerUpdatePolicy updatePolicy,
+ ServerTaskExecutor executor, ServerUpdateTask.ServerUpdateResultHandler resultHandler) {
+ super(tasks, updatePolicy, executor, resultHandler);
}
@Override
public void execute() {
boolean interrupted = false;
final ServerTaskExecutor.ServerOperationListener listener = new ServerTaskExecutor.ServerOperationListener();
- for(final ServerTask task : tasks) {
+ for(final ServerUpdateTask task : tasks) {
final ServerIdentity identity = task.getServerIdentity();
if(interrupted || ! updatePolicy.canUpdateServer(identity)) {
sendCancelledResponse(identity);
View
15 host-controller/src/main/java/org/jboss/as/domain/controller/plan/RolloutPlanController.java
@@ -26,7 +26,7 @@
import org.jboss.as.domain.controller.ServerIdentity;
import org.jboss.as.domain.controller.operations.coordination.DomainOperationContext;
-import org.jboss.as.domain.controller.plan.AbstractServerUpdateTask.ServerUpdateResultHandler;
+import org.jboss.as.domain.controller.plan.ServerUpdateTask.ServerUpdateResultHandler;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
@@ -50,18 +50,15 @@
private final long gracefulShutdownPeriod;
private final ServerTaskExecutor taskExecutor;
private final DomainOperationContext domainOperationContext;
- private final ServerRolloutTaskHandler rolloutHandler;
private final ConcurrentMap<String, Map<ServerIdentity, ModelNode>> serverResults = new ConcurrentHashMap<String, Map<ServerIdentity, ModelNode>>();
public RolloutPlanController(final Map<String, Map<ServerIdentity, ModelNode>> opsByGroup,
final ModelNode rolloutPlan,
final DomainOperationContext domainOperationContext,
final ServerTaskExecutor taskExecutor,
- final ServerRolloutTaskHandler rolloutHandler,
final ExecutorService executor) {
this.domainOperationContext = domainOperationContext;
this.taskExecutor = taskExecutor;
- this.rolloutHandler = rolloutHandler;
this.rollbackAcrossGroups = !rolloutPlan.hasDefined(ROLLBACK_ACROSS_GROUPS) || rolloutPlan.get(ROLLBACK_ACROSS_GROUPS).asBoolean();
this.shutdown = rolloutPlan.hasDefined(SHUTDOWN) && rolloutPlan.get(SHUTDOWN).asBoolean();
@@ -100,7 +97,7 @@ public RolloutPlanController(final Map<String, Map<ServerIdentity, ModelNode>> o
continue;
}
- final List<ServerTask> groupTasks = new ArrayList<ServerTask>();
+ final List<ServerUpdateTask> groupTasks = new ArrayList<ServerUpdateTask>();
final ModelNode policyNode = prop.getValue();
final boolean rollingGroup = policyNode.hasDefined(ROLLING_TO_SERVERS) && policyNode.get(ROLLING_TO_SERVERS).asBoolean();
@@ -115,8 +112,8 @@ else if (policyNode.hasDefined(MAX_FAILED_SERVERS)) {
}
ServerUpdatePolicy policy = new ServerUpdatePolicy(parent, serverGroupName, servers, maxFailures);
- seriesTasks.add(rollingGroup ? new RollingGroupUpdateTask(groupTasks, policy, rolloutHandler, taskExecutor, this)
- : new ConcurrentGroupUpdateTask(groupTasks, policy, rolloutHandler, taskExecutor, this));
+ seriesTasks.add(rollingGroup ? new RollingServerGroupUpdateTask(groupTasks, policy, taskExecutor, this)
+ : new ConcurrentServerGroupUpdateTask(groupTasks, policy, taskExecutor, this));
updatePolicies.put(serverGroupName, policy);
@@ -165,8 +162,8 @@ public void handleServerUpdateResult(ServerIdentity serverId, ModelNode response
groupResults.put(serverId, response);
}
- private ServerTask createServerTask(final ServerIdentity serverIdentity, final ModelNode serverOp, final ServerUpdatePolicy policy) {
- ServerTask result;
+ private ServerUpdateTask createServerTask(final ServerIdentity serverIdentity, final ModelNode serverOp, final ServerUpdatePolicy policy) {
+ ServerUpdateTask result;
if (shutdown) {
result = new ServerRestartTask(serverIdentity, policy, this, gracefulShutdownPeriod);
}
View
8 ...controller/src/main/java/org/jboss/as/domain/controller/plan/RunningServerUpdateTask.java
@@ -24,20 +24,16 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNNING_SERVER;
-import static org.jboss.as.domain.controller.DomainControllerLogger.HOST_CONTROLLER_LOGGER;
import org.jboss.as.domain.controller.ServerIdentity;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
/**
- * {@link org.jboss.as.domain.controller.plan.AbstractServerUpdateTask} that performs the updates by applying them
+ * {@link ServerUpdateTask} that performs the updates by applying them
* to a running server.
- *
- * Thread-Safety: This class is immutable, but is intended to only have its
- * {@link #run()} method executed once.
*/
-class RunningServerUpdateTask extends AbstractServerUpdateTask {
+class RunningServerUpdateTask extends ServerUpdateTask {
private final ModelNode serverUpdate;
View
23 ...controller/src/main/java/org/jboss/as/domain/controller/plan/ServerOperationExecutor.java
@@ -1,23 +0,0 @@
-/**
- *
- */
-package org.jboss.as.domain.controller.plan;
-
-import org.jboss.as.domain.controller.ServerIdentity;
-import org.jboss.dmr.ModelNode;
-
-/**
- * Callback from a task when it wants to execute an operation.
- *
- * @author Brian Stansberry (c) 2011 Red Hat Inc.
- */
-public interface ServerOperationExecutor {
-
- /**
- * Execute an operation against the given server
- * @param server the identity of the server
- * @param operation the operation
- * @return the result, or {@code null} if the server is unknown
- */
- ModelNode executeServerOperation(ServerIdentity server, ModelNode operation);
-}
View
7 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerRestartTask.java
@@ -29,14 +29,11 @@
import org.jboss.dmr.ModelNode;
/**
- * {@link org.jboss.as.domain.controller.plan.AbstractServerUpdateTask} that performs the update by triggering a
+ * {@link ServerUpdateTask} that performs the update by triggering a
* restart of the server. The restart results in the server getting the current
* model state.
- *
- * Thread-Safety: This class is immutable, but is intended to only have its
- * {@link #run()} method executed once.
*/
-class ServerRestartTask extends AbstractServerUpdateTask {
+class ServerRestartTask extends ServerUpdateTask {
private final long gracefulTimeout;
View
154 ...ontroller/src/main/java/org/jboss/as/domain/controller/plan/ServerRolloutTaskHandler.java
@@ -1,154 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2012, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.as.domain.controller.plan;
-
-import org.jboss.as.controller.Cancellable;
-import org.jboss.as.controller.remote.TransactionalProtocolClient;
-import org.jboss.as.domain.controller.ServerIdentity;
-import org.jboss.dmr.ModelNode;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Future;
-
-/**
- * Task result handler.
- *
- * @author Emanuel Muckenhuber
- */
-public class ServerRolloutTaskHandler {
-
- private final Map<ServerIdentity, ServerExecutedRequest> submittedTasks;
- private final List<ServerPreparedResponse> preparedResults;
-
- public ServerRolloutTaskHandler(final Map<ServerIdentity, ServerExecutedRequest> submittedTasks, List<ServerPreparedResponse> preparedResults) {
- this.submittedTasks = submittedTasks;
- this.preparedResults = preparedResults;
- }
-
- /**
- * Record a executed request.
- *
- * @param task the executed task
- */
- void recordExecutedRequest(final ServerExecutedRequest task) {
- synchronized (submittedTasks) {
- submittedTasks.put(task.getIdentity(), task);
- }
- }
-
- /**
- * Record a prepare operation.
- *
- * @param preparedOperation the prepared operation
- */
- void recordPreparedOperation(final TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> preparedOperation) {
- recordPreparedTask(new ServerPreparedResponse(preparedOperation));
- }
-
- /**
- * Record a prepared operation.
- *
- * @param task the prepared operation
- */
- void recordPreparedTask(ServerPreparedResponse task) {
- synchronized (preparedResults) {
- preparedResults.add(task);
- }
- }
-
- /**
- * The prepared response.
- */
- public static class ServerPreparedResponse {
-
- private TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> preparedOperation;
- ServerPreparedResponse(TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> preparedOperation) {
- this.preparedOperation = preparedOperation;
- }
-
- public TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> getPreparedOperation() {
- return preparedOperation;
- }
-
- public ServerIdentity getServerIdentity() {
- return preparedOperation.getOperation().getIdentity();
- }
-
- public String getServerGroupName() {
- return getServerIdentity().getServerGroupName();
- }
-
- /**
- * Finalize the transaction. This will return {@code false} in case the local operation failed,
- * but the overall state of the operation is commit=true.
- *
- * @param commit {@code true} to commit, {@code false} to rollback
- * @return whether the local proxy operation result is in sync with the overall operation
- */
- public boolean finalizeTransaction(boolean commit) {
- final boolean failed = preparedOperation.isFailed();
- if(commit && failed) {
- return false;
- }
- if(commit) {
- preparedOperation.commit();
- } else {
- if(!failed) {
- preparedOperation.rollback();
- }
- }
- return true;
- }
-
- }
-
- /**
- * The executed request.
- */
- public static class ServerExecutedRequest implements Cancellable {
-
- private final ServerIdentity identity;
- private final Future<ModelNode> finalResult;
-
- public ServerExecutedRequest(ServerIdentity identity, Future<ModelNode> finalResult) {
- this.identity = identity;
- this.finalResult = finalResult;
- }
-
- public ServerIdentity getIdentity() {
- return identity;
- }
-
- public Future<ModelNode> getFinalResult() {
- return finalResult;
- }
-
- @Override
- public boolean cancel() {
- return finalResult.cancel(false);
- }
- }
-
-
-}
View
36 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerTask.java
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2012, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.as.domain.controller.plan;
-
-import org.jboss.as.domain.controller.ServerIdentity;
-import org.jboss.dmr.ModelNode;
-
-/**
- * @author Emanuel Muckenhuber
- */
-public interface ServerTask {
-
- ServerIdentity getServerIdentity();
- ModelNode getOperation();
-
-}
View
153 host-controller/src/main/java/org/jboss/as/domain/controller/plan/ServerTaskExecutor.java
@@ -22,6 +22,7 @@
package org.jboss.as.domain.controller.plan;
+import org.jboss.as.controller.Cancellable;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.client.MessageSeverity;
import org.jboss.as.controller.client.OperationAttachments;
@@ -35,7 +36,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.Future;
/**
@@ -44,19 +47,45 @@
public abstract class ServerTaskExecutor {
private final OperationContext context;
- private final ServerRolloutTaskHandler rolloutHandler;
+ private final Map<ServerIdentity, ExecutedServerRequest> submittedTasks;
+ private final List<ServerTaskExecutor.ServerPreparedResponse> preparedResults;
- protected ServerTaskExecutor(OperationContext context, ServerRolloutTaskHandler rolloutHandler) {
+ protected ServerTaskExecutor(OperationContext context, Map<ServerIdentity, ExecutedServerRequest> submittedTasks, List<ServerPreparedResponse> preparedResults) {
this.context = context;
- this.rolloutHandler = rolloutHandler;
+ this.submittedTasks = submittedTasks;
+ this.preparedResults = preparedResults;
}
- public boolean executeTask(final TransactionalProtocolClient.TransactionalOperationListener<ServerOperation> listener, final ServerTask task) {
+ /**
+ * Execute
+ *
+ * @param listener the transactional operation listener
+ * @param identity the server identity
+ * @param operation the operation
+ * @return whether the operation was executed or not
+ */
+ protected abstract boolean execute(final TransactionalProtocolClient.TransactionalOperationListener<ServerOperation> listener, final ServerIdentity identity, final ModelNode operation);
+
+ /**
+ * Execute a server task.
+ *
+ * @param listener the transactional server listener
+ * @param task the server task
+ * @return whether the task was executed or not
+ */
+ public boolean executeTask(final TransactionalProtocolClient.TransactionalOperationListener<ServerOperation> listener, final ServerUpdateTask task) {
return execute(listener, task.getServerIdentity(), task.getOperation());
}
- protected abstract boolean execute(final TransactionalProtocolClient.TransactionalOperationListener<ServerOperation> listener, final ServerIdentity identity, final ModelNode operation);
-
+ /**
+ * Execute the operation.
+ *
+ * @param listener the transactional operation listener
+ * @param client the transactional protocol client
+ * @param identity the server identity
+ * @param operation the operation
+ * @return whether the operation was executed
+ */
protected boolean executeOperation(final TransactionalProtocolClient.TransactionalOperationListener<ServerOperation> listener, TransactionalProtocolClient client, final ServerIdentity identity, final ModelNode operation) {
if(client == null) {
return false;
@@ -66,17 +95,53 @@ protected boolean executeOperation(final TransactionalProtocolClient.Transaction
final ServerOperation serverOperation = new ServerOperation(identity, operation, messageHandler, operationAttachments);
try {
final Future<ModelNode> result = client.execute(listener, serverOperation);
- rolloutHandler.recordExecutedRequest(new ServerRolloutTaskHandler.ServerExecutedRequest(identity, result));
+ recordExecutedRequest(new ExecutedServerRequest(identity, result));
} catch (IOException e) {
final TransactionalProtocolClient.PreparedOperation<ServerOperation> result = BlockingQueueOperationListener.FailedOperation.create(serverOperation, e);
listener.operationPrepared(result);
- rolloutHandler.recordExecutedRequest(new ServerRolloutTaskHandler.ServerExecutedRequest(identity, result.getFinalResult()));
+ recordExecutedRequest(new ExecutedServerRequest(identity, result.getFinalResult()));
}
return true;
}
+ /**
+ * Record a executed request.
+ *
+ * @param task the executed task
+ */
+ void recordExecutedRequest(final ExecutedServerRequest task) {
+ synchronized (submittedTasks) {
+ submittedTasks.put(task.getIdentity(), task);
+ }
+ }
+
+ /**
+ * Record a prepare operation.
+ *
+ * @param preparedOperation the prepared operation
+ */
+ void recordPreparedOperation(final TransactionalProtocolClient.PreparedOperation<ServerTaskExecutor.ServerOperation> preparedOperation) {
+ recordPreparedTask(new ServerTaskExecutor.ServerPreparedResponse(preparedOperation));
+ }
+
+ /**
+ * Record a prepared operation.
+ *
+ * @param task the prepared operation
+ */
+ void recordPreparedTask(ServerTaskExecutor.ServerPreparedResponse task) {
+ synchronized (preparedResults) {
+ preparedResults.add(task);
+ }
+ }
+
static class ServerOperationListener extends BlockingQueueOperationListener<ServerOperation> {
+ @Override
+ protected void drainTo(Collection<TransactionalProtocolClient.PreparedOperation<ServerOperation>> preparedOperations) {
+ super.drainTo(preparedOperations);
+ }
+
}
public static class ServerOperation extends TransactionalOperationImpl {
@@ -92,6 +157,78 @@ public ServerIdentity getIdentity() {
}
}
+ /**
+ * The prepared response.
+ */
+ public static class ServerPreparedResponse {
+
+ private TransactionalProtocolClient.PreparedOperation<ServerOperation> preparedOperation;
+ ServerPreparedResponse(TransactionalProtocolClient.PreparedOperation<ServerOperation> preparedOperation) {
+ this.preparedOperation = preparedOperation;
+ }
+
+ public TransactionalProtocolClient.PreparedOperation<ServerOperation> getPreparedOperation() {
+ return preparedOperation;
+ }
+
+ public ServerIdentity getServerIdentity() {
+ return preparedOperation.getOperation().getIdentity();
+ }
+
+ public String getServerGroupName() {
+ return getServerIdentity().getServerGroupName();
+ }
+
+ /**
+ * Finalize the transaction. This will return {@code false} in case the local operation failed,
+ * but the overall state of the operation is commit=true.
+ *
+ * @param commit {@code true} to commit, {@code false} to rollback
+ * @return whether the local proxy operation result is in sync with the overall operation
+ */
+ public boolean finalizeTransaction(boolean commit) {
+ final boolean failed = preparedOperation.isFailed();
+ if(commit && failed) {
+ return false;
+ }
+ if(commit) {
+ preparedOperation.commit();
+ } else {
+ if(!failed) {
+ preparedOperation.rollback();
+ }
+ }
+ return true;
+ }
+
+ }
+
+ /**
+ * The executed request.
+ */
+ public static class ExecutedServerRequest implements Cancellable {
+
+ private final ServerIdentity identity;
+ private final Future<ModelNode> finalResult;
+
+ public ExecutedServerRequest(ServerIdentity identity, Future<ModelNode> finalResult) {
+ this.identity = identity;
+ this.finalResult = finalResult;
+ }
+
+ public ServerIdentity getIdentity() {
+ return identity;
+ }
+
+ public Future<ModelNode> getFinalResult() {
+ return finalResult;
+ }
+
+ @Override
+ public boolean cancel() {
+ return finalResult.cancel(false);
+ }
+ }
private static class DelegatingMessageHandler implements OperationMessageHandler {
View
11 ...roller/plan/AbstractServerUpdateTask.java → ...ain/controller/plan/ServerUpdateTask.java
@@ -29,7 +29,7 @@
*
* @author Brian Stansberry
*/
-abstract class AbstractServerUpdateTask implements ServerTask {
+abstract class ServerUpdateTask {
/**
* Callback interface to allow the creator of this task to
@@ -57,9 +57,9 @@
* @param updatePolicy the policy that controls whether the updates should be applied. Cannot be <code>null</code>
* @param resultHandler handler for the result of the update. Cannot be <code>null</code>
*/
- AbstractServerUpdateTask(final ServerIdentity serverId,
- final ServerUpdatePolicy updatePolicy,
- final ServerUpdateResultHandler resultHandler) {
+ ServerUpdateTask(final ServerIdentity serverId,
+ final ServerUpdatePolicy updatePolicy,
+ final ServerUpdateResultHandler resultHandler) {
assert serverId != null : "serverId is null";
assert updatePolicy != null : "updatePolicy is null";
assert resultHandler != null : "resultHandler is null";
@@ -68,7 +68,8 @@
this.resultHandler = resultHandler;
}
- @Override
+ public abstract ModelNode getOperation();
+
public ServerIdentity getServerIdentity() {
return serverId;
}
Please sign in to comment.
Something went wrong with that request. Please try again.