Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, 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.operations.coordination;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DOMAIN_UUID;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXECUTE_FOR_COORDINATOR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLOUT_PLAN;
 import static org.jboss.as.domain.controller.DomainControllerLogger.HOST_CONTROLLER_LOGGER;
 import static org.jboss.as.domain.controller.DomainControllerMessages.MESSAGES;
 
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
Coordinates the overall execution of an operation on behalf of the domain.

Author(s):
Brian Stansberry (c) 2011 Red Hat Inc.
 
 
     private final ContentRepository contentRepository;
     private final Map<StringProxyControllerhostProxies;
     private final Map<StringProxyControllerserverProxies;
     private volatile ExecutorService executorService;
 
     OperationCoordinatorStepHandler(final LocalHostControllerInfo localHostControllerInfo,
                                     ContentRepository contentRepository,
                                     final Map<StringProxyControllerhostProxies,
                                     final Map<StringProxyControllerserverProxies,
                                     final OperationSlaveStepHandler localSlaveHandler,
                                     final DomainControllerRuntimeIgnoreTransformationRegistry runtimeIgnoreTransformationRegistry) {
         this. = localHostControllerInfo;
         this. = contentRepository;
         this. = hostProxies;
         this. = serverProxies;
         this. = localSlaveHandler;
         this. = runtimeIgnoreTransformationRegistry;
     }
 
     void execute(OperationContext contextModelNode operationthrows OperationFailedException {
 
         // Determine routing
         OperationRouting routing = OperationRouting.determineRouting(contextoperation);
 
                 && !routing.isLocalOnly(.getLocalHostName())) {
             // We cannot handle this ourselves
             routeToMasterDomainController(contextoperation);
         }
         else if (routing.getSingleHost() != null && !.getLocalHostName().equals(routing.getSingleHost())) {
             if (.isTraceEnabled()) {
                 .trace("Remote single host");
             }
             // This host is the master, but this op is addressed specifically to another host.
             // This is possibly a two step operation, but it's not coordinated by this host.
             // Execute direct (which will proxy the request to the intended HC) and let the remote HC coordinate
             // any two step process (if there is one)
             configureDomainUUID(operation);
            executeDirect(contextoperation);
        }
        else if (!routing.isTwoStep()) {
            // It's a domain or host level op (probably a read) that does not require bringing in other hosts or servers
            executeDirect(contextoperation);
        }
        else {
            // Else we are responsible for coordinating a two-phase op
            // -- domain level op: apply to HostController models across domain and then push to servers
            // -- host level op: apply to our model  and then push to servers
            executeTwoPhaseOperation(contextoperationrouting);
        }
    }
    public void setExecutorService(ExecutorService executorService) {
        this. = executorService;
    }
    private ExecutorService getExecutorService() {
        return  == null ? Executors.newSingleThreadExecutor() : ;
    }
    private void routeToMasterDomainController(OperationContext contextModelNode operation) {
        // Per discussion on 2011/03/07, routing requests from a slave to the
        // master may overly complicate the security infrastructure. Therefore,
        // the ability to do this is being disabled until it's clear that it's
        // not a problem
                PathAddress.pathAddress(operation.get())));
        context.stepCompleted();
    }

    
Directly handles the op in the standard way the default prepare step handler would

Parameters:
context the operation execution context
operation the operation
Throws:
org.jboss.as.controller.OperationFailedException if there is no handler registered for the operation
    private void executeDirect(OperationContext contextModelNode operationthrows OperationFailedException {
        if (.isTraceEnabled()) {
            .tracef("%s executing direct"getClass().getSimpleName());
        }
        PrepareStepHandler.executeDirectOperation(contextoperation);
    }
    private void executeTwoPhaseOperation(OperationContext contextModelNode operationOperationRouting routingthrows OperationFailedException {
        if (.isTraceEnabled()) {
            .trace("Executing two-phase");
        }
        configureDomainUUID(operation);
        // Get a copy of the rollout plan so it doesn't get disrupted by any handlers
        ModelNode rolloutPlan = operation.hasDefined() && operation.get().has()
            ? operation.get().remove() : new ModelNode();
        // A stage that on the way out fixes up the result/failure description. On the way in it does nothing
        context.addStep(new DomainFinalResultHandler(overallContext), ..);
        final ModelNode slaveOp = operation.clone();
        slaveOp.get().set(true);
        slaveOp.protect();
        // If necessary, execute locally first. This gets all of the Stage.MODEL, Stage.RUNTIME, Stage.VERIFY
        // steps registered. A failure in those will prevent the rest of the steps below executing
        String localHostName = .getLocalHostName();
        if (routing.isLocalCallNeeded(localHostName)) {
            ModelNode localResponse = overallContext.getCoordinatorResult();
            .addSteps(contextslaveOp.clone(), localResponsefalse);
        }
            // Add steps to invoke on the HC for each relevant slave
            Set<StringremoteHosts = new HashSet<String>(routing.getHosts());
            boolean global = remoteHosts.size() == 0;
            remoteHosts.remove(localHostName);
            if (remoteHosts.size() > 0 || global) {
                // Lock the controller to ensure there are no topology changes mid-op.
                // This assumes registering/unregistering a remote proxy will involve an op and hence will block
                context.acquireControllerLock();
                if (global) {
                    remoteHosts.addAll(.keySet());
                }
                Map<StringProxyControllerremoteProxies = new HashMap<StringProxyController>();
                for (String host : remoteHosts) {
                    ProxyController proxy = .get(host);
                    if (proxy != null) {
                        remoteProxies.put(hostproxy);
                    } else if (!global) {
                        throw .invalidOperationTargetHost(host);
                    }
                }
                context.addStep(slaveOp.clone(), new DomainSlaveHandler(remoteProxiesoverallContext), ..);
            }
        }
        // Finally, the step to formulate and execute the 2nd phase rollout plan
        context.addStep(new DomainRolloutStepHandler(overallContextrolloutPlangetExecutorService()), ..);
        context.stepCompleted();
    }
    static void configureDomainUUID(ModelNode operation) {
        if (!operation.hasDefined() || !operation.get().hasDefined()) {
            String domainUUID = UUID.randomUUID().toString();
            operation.get().set(domainUUID);
            AccessAuditContext accessContext = SecurityActions.currentAccessAuditContext();
            if (accessContext != null) {
                accessContext.setDomainUuid(domainUUID);
            }
        }
    }
New to GrepCode? Check out our FAQ X