Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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 static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONCURRENT_GROUPS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GRACEFUL_SHUTDOWN_TIMEOUT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.IN_SERIES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MAX_FAILED_SERVERS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MAX_FAILURE_PERCENTAGE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ACROSS_GROUPS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLING_TO_SERVERS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
Coordinates rolling out a series of operations to the servers specified in a rollout plan.

Author(s):
Brian Stansberry (c) 2011 Red Hat Inc.
 
 public class RolloutPlanController {
 
     public static enum Result {
         SUCCESS,
         PARTIAL,
         FAILED
     }
 
     private final boolean rollbackAcrossGroups;
     private final RollingUpdateTask rootTask;
     private final Map<StringServerUpdatePolicyupdatePolicies = new HashMap<StringServerUpdatePolicy>();
     private final boolean shutdown;
     private final long gracefulShutdownPeriod;
 
     public RolloutPlanController(final Map<StringMap<ServerIdentityModelNode>> opsByGroup,
                                  final ModelNode rolloutPlan,
                                  final DomainOperationContext domainOperationContext,
                                  final ServerTaskExecutor taskExecutor,
                                  final ExecutorService executor) {
         this. = domainOperationContext;
 
         this. = !rolloutPlan.hasDefined() || rolloutPlan.get().asBoolean();
         this. = rolloutPlan.hasDefined() && rolloutPlan.get().asBoolean();
         this. = rolloutPlan.hasDefined() ? rolloutPlan.get().asInt() : -1;
 
         final List<RunnablerollingTasks = new ArrayList<Runnable>();
         this. = new RollingUpdateTask(rollingTasks);
 
         if (rolloutPlan.hasDefined()) {
 
             ConcurrentGroupServerUpdatePolicy predecessor = null;
             Subject subject = SecurityActions.getCurrentSubject();
             for (ModelNode series : rolloutPlan.get().asList()) {
 
                 final List<RunnableseriesTasks = new ArrayList<Runnable>();
                 rollingTasks.add(new ConcurrentUpdateTask(seriesTasksexecutor));
 
                 Set<StringgroupNames = new HashSet<String>();
                 List<PropertygroupPolicies = new ArrayList<Property>();
                 if (series.hasDefined()) {
                     for (Property pol : series.get().asPropertyList()) {
                        groupNames.add(pol.getName());
                        groupPolicies.add(pol);
                    }
                }
                else {
                    Property pol = series.require().asProperty();
                    groupNames.add(pol.getName());
                    groupPolicies.add(pol);
                }
                ConcurrentGroupServerUpdatePolicy parent = new ConcurrentGroupServerUpdatePolicy(predecessorgroupNames);
                for (Property prop : groupPolicies) {
                    final String serverGroupName = prop.getName();
                    final Map<ServerIdentityModelNodegroupEntry = opsByGroup.get(serverGroupName);
                    if (groupEntry == null) {
                        continue;
                    }
                    final List<ServerUpdateTaskgroupTasks = new ArrayList<ServerUpdateTask>();
                    final ModelNode policyNode = prop.getValue();
                    final boolean rollingGroup = policyNode.hasDefined() && policyNode.get().asBoolean();
                    final Set<ServerIdentityservers = groupEntry.keySet();
                    int maxFailures = 0;
                    if (policyNode.hasDefined()) {
                        int pct = policyNode.get().asInt();
                        maxFailures = ((servers.size() * pct) / 100);
                    }
                    else if (policyNode.hasDefined()) {
                        maxFailures = policyNode.get().asInt();
                    }
                    ServerUpdatePolicy policy = new ServerUpdatePolicy(parentserverGroupNameserversmaxFailures);
                    seriesTasks.add(rollingGroup ? new RollingServerGroupUpdateTask(groupTaskspolicytaskExecutorsubject)
                        : new ConcurrentServerGroupUpdateTask(groupTaskspolicytaskExecutorsubject));
                    .put(serverGroupNamepolicy);
                    for (Map.Entry<ServerIdentityModelNodeentry : groupEntry.entrySet()) {
                        groupTasks.add(createServerTask(entry.getKey(), entry.getValue(), policy));
                    }
                }
            }
        }
    }
    public Result execute() {
        this..run();
        Result result = null;
        for (ServerUpdatePolicy policy : .values()) {
            if (policy.isFailed()) {
                .setServerGroupRollback(policy.getServerGroupName(), true);
                if () {
                    .setCompleteRollback(true);
                }
                result = (result == null || result == .) ? . : .;
            }
            else {
                .setServerGroupRollback(policy.getServerGroupName(), false);
                result = (result == null || result == .) ? . : .;
            }
        }
        return result;
    }
    private ServerUpdateTask createServerTask(final ServerIdentity serverIdentityfinal ModelNode serverOp,
                                              final ServerUpdatePolicy policy) {
        ServerUpdateTask result;
        if () {
            result = new ServerRestartTask(serverIdentitypolicy);
        }
        else {
            result = new RunningServerUpdateTask(serverIdentityserverOppolicy);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X