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.CALLER_TYPE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DOMAIN_RESULTS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.IGNORED;
 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.RESULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_OPERATIONS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.USER;
 import static org.jboss.as.domain.controller.DomainControllerLogger.HOST_CONTROLLER_LOGGER;
 
 import java.util.Map;
 import java.util.Set;
 
Adds to the localResponse the server-level operations needed to effect the given domain/host operation on the servers controlled by this host.

Author(s):
Brian Stansberry (c) 2011 Red Hat Inc.
 
 
     public static final String DOMAIN_PUSH_TO_SERVERS = "push-to-servers";
     public static final String OPERATION_NAME = "server-operation-resolver";
 
             @Override
             public Map<Set<ServerIdentity>, ModelNodegetServerOperations(ModelNode domainOpPathAddress address) {
 
                 return Collections.emptyMap();
             }
         };
 
     private final ServerOperationResolver resolver;
     private final PathAddress originalAddress;
     private final ModelNode localResponse;
 
                                     final HostControllerExecutionSupport hostControllerExecutionSupport,
                                     final PathAddress originalAddress,
                                     final ImmutableManagementResourceRegistration originalRegistration,
                                     final ModelNode response) {
         this. = resolver;
         this. = hostControllerExecutionSupport;
         this. = originalAddress;
         this. = originalRegistration;
         this. = response;
     }
 
     @Override
     public void execute(final OperationContext contextfinal ModelNode operationthrows OperationFailedException {
 
         if (context.hasFailureDescription()) {
             .get().set(context.getFailureDescription());
             // We do not allow failures on the host controllers
             context.setRollbackOnly();
         } else {
             boolean nullDomainOp = .getDomainOperation() == null;
 
            // Transformed operations might need to simulate certain behavior, so allow read-only operations to be pushed as well
            final boolean pushToServers;
            if(operation.hasDefined()) {
                pushToServers = operation.get().asBoolean(false);
            } else {
                pushToServers = false;
            }
            HostControllerExecutionSupport.ServerOperationProvider provider = nullDomainOp
                ? 
                : new HostControllerExecutionSupport.ServerOperationProvider() {
                    @Override
                    public Map<Set<ServerIdentity>, ModelNodegetServerOperations(ModelNode domainOpPathAddress address) {
                        Map<Set<ServerIdentity>, ModelNodeops = ServerOperationsResolverHandler.this.getServerOperations(contextdomainOpaddresspushToServers);
                        for (Map.Entry<Set<ServerIdentity>, ModelNodeentry : ops.entrySet()) {
                            ModelNode op = entry.getValue();
                            //Remove the caller-type=user header
                            if (op.hasDefined() && op.get().hasDefined() && op.get().asString().equals()) {
                                op.get().remove();
                            }
                        }
                        return ops;
                    }
                };
            Map<ServerIdentityModelNodeserverOps = .getServerOps(provider);
            ModelNode domainOpResult = nullDomainOp ? new ModelNode() : (context.hasResult() ? context.getResult() : new ModelNode());
            ModelNode overallResult =  == null ? context.getResult() : .get();
            createOverallResult(serverOpsdomainOpResultoverallResult);
            if (.isTraceEnabled()) {
                .tracef("%s responseNode is %s"getClass().getSimpleName(), overallResult);
            }
        }
        context.stepCompleted();
    }
    private Map<Set<ServerIdentity>, ModelNodegetServerOperations(OperationContext contextModelNode domainOpPathAddress domainOpAddressboolean pushToServers) {
        Map<Set<ServerIdentity>, ModelNoderesult = null;
        final PathAddress relativeAddress = domainOpAddress.subAddress(.size());
        if(! pushToServers) {
            Set<OperationEntry.Flagflags = .getOperationFlags(relativeAddressdomainOp.require().asString());
            if (flags.contains(..) && !flags.contains(..)) {
                result = Collections.emptyMap();
            }
        }
        if (result == null) {
            result = .getServerOperations(contextdomainOpdomainOpAddress);
        }
        return result;
    }
    private void createOverallResult(final Map<ServerIdentityModelNodeserverOps,
                                     final ModelNode localResultfinal ModelNode overallResult) {
        ModelNode domainResult = .getFormattedDomainResult(localResult);
        overallResult.setEmptyObject();
        overallResult.get().set(domainResult);
        ModelNode serverOpsNode = overallResult.get();
        // Group servers with the same ops together to save bandwidth
        final Map<ModelNodeSet<ServerIdentity>> bundled = new HashMap<ModelNodeSet<ServerIdentity>>();
        for (Map.Entry<ServerIdentityModelNodeentry : serverOps.entrySet()) {
            Set<ServerIdentityidSet = bundled.get(entry.getValue());
            if (idSet == null) {
                idSet = new HashSet<ServerIdentity>();
                bundled.put(entry.getValue(), idSet);
            }
            idSet.add(entry.getKey());
        }
        for (Map.Entry<ModelNodeSet<ServerIdentity>> entry : bundled.entrySet()) {
            ModelNode setNode = serverOpsNode.add();
            ModelNode serverNode = setNode.get("servers");
            serverNode.setEmptyList();
            for (ServerIdentity server : entry.getValue()) {
                serverNode.add(server.getServerName(), server.getServerGroupName());
            }
            setNode.get().set(entry.getKey());
        }
    }
New to GrepCode? Check out our FAQ X