Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source.
  * Copyright 2011, Red Hat Middleware LLC, 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.host.controller.operations;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
 
Writes the group and socket-binding-group attributes of a server group and validates the new value. ServerOperationResolver is responsible for putting the affected server in the restart-required state.

Author(s):
Kabir Khan
 
 
 
     private final AttributeDefinition attributeDefinition;
 
         super(attributeDefinition);
         this. = attributeDefinition;
     }
 
         return new GroupHandler(hostControllerInfo);
     }
 
         return new SocketBindingGroupHandler(hostControllerInfo);
     }
 
 
     @Override
     protected void finishModelStage(OperationContext contextModelNode operationString attributeNameModelNode newValue,
             ModelNode currentValueResource resourcethrows OperationFailedException {
         if (newValue.equals(currentValue)) {
             //Set an attachment to avoid propagation to the servers, we don't want them to go into restart-required if nothing changed
             ServerOperationResolver.addToDontPropagateToServersAttachment(contextoperation);
         }
 
         // Validate the model reference.
 
         // Issue: We resolve in Stage.MODEL even though system properties may not be available yet. Not ideal,
         // but the attributes involved do not support expressions because they are model references
         ModelNode resolvedValue = .resolveModelAttribute(contextresource.getModel());
         validateReferencedNewValueExists(contextoperationcurrentValueresolvedValue);
     }
 
     protected abstract void validateReferencedNewValueExists(OperationContext contextModelNode operationModelNode currentValueModelNode valuethrows OperationFailedException;
 
     private static class GroupHandler extends ServerRestartRequiredServerConfigWriteAttributeHandler {
 
 
         public GroupHandler(LocalHostControllerInfo hostControllerInfo) {
             super(.);
             this. = hostControllerInfo;
         }
 
         @Override
         protected void validateReferencedNewValueExists(final OperationContext contextfinal ModelNode operationfinal ModelNode currentValuefinal ModelNode resolvedValuethrows OperationFailedException{
            final Resource root = context.readResourceFromRoot(.false);
            //Don't do this on boot since the domain model is not populated yet
            if (!context.isBooting() && root.getChild(PathElement.pathElement(resolvedValue.asString())) == null) {
                        throw ..noServerGroupCalled(resolvedValue.asString());
                } else {
                    //We are a slave HC set up to ignore unaffected resources and we don't have the server-group required, so pull it down
                    final String serverName = PathAddress.pathAddress(operation.require()).getLastElement().getValue();
                    final ModelNode model = context.readResource(.).getModel();
                    String socketBindingGroupName = model.hasDefined() ? model.get().asString() : null;
                    pullDownMissingDataFromDc(contextserverNameresolvedValue.asString(), socketBindingGroupName);
                }
            }
        }
    }
        public SocketBindingGroupHandler(LocalHostControllerInfo hostControllerInfo) {
            this. = hostControllerInfo;
        }
        @Override
        protected void validateReferencedNewValueExists(final OperationContext contextfinal ModelNode operationfinal ModelNode currentValuefinal ModelNode resolvedValuethrows OperationFailedException{
            final Resource root = context.readResourceFromRoot(.false);
            if (resolvedValue.isDefined()) {
                //Don't do this on boot since the domain model is not populated yet
                if (!context.isBooting() && resolvedValue.isDefined() && root.getChild(PathElement.pathElement(resolvedValue.asString())) == null) {
                        throw ..noSocketBindingGroupCalled(resolvedValue.asString());
                    } else {
                        //We are a slave HC set up to ignore unaffected resources and we don't have the socket-binding-group required, so pull it down
                        final String serverName = PathAddress.pathAddress(operation.require()).getLastElement().getValue();
                        final ModelNode model = context.readResource(.).getModel();
                        String serverGroupName = model.require().asString();
                        pullDownMissingDataFromDc(contextserverNameserverGroupNameresolvedValue.asString());
                    }
                }
            }
        }
    }
        public SocketBindingPortOffsetHandler() {
        }
        @Override
        protected void validateReferencedNewValueExists(OperationContext contextModelNode operationModelNode currentValueModelNode resolvedValuethrows OperationFailedException {
            // our attribute is not a model reference
        }
    }
    private static void pullDownMissingDataFromDc(final OperationContext contextfinal String serverNamefinal String serverGroupNamefinal String socketBindingGroupName) {
        context.addStep(new OperationStepHandler() {
            public void execute(OperationContext contextModelNode operationthrows OperationFailedException {
                //Get the missing data
                final MasterDomainControllerClient masterDomainControllerClient = (MasterDomainControllerClient)context.getServiceRegistry(false).getRequiredService(.).getValue();
                masterDomainControllerClient.pullDownDataForUpdatedServerConfigAndApplyToModel(contextserverNameserverGroupNamesocketBindingGroupName);
                context.addStep(new OperationStepHandler() {
                    public void execute(OperationContext contextModelNode operationthrows OperationFailedException {
                        //An extra sanity check, is this necessary?
                        final Resource root = context.readResourceFromRoot(.false);
                        if (!root.hasChild(PathElement.pathElement(serverGroupName))) {
                            throw ..noServerGroupCalled(serverGroupName);
                        }
                        if (socketBindingGroupName != null) {
                            if (!root.hasChild(PathElement.pathElement(socketBindingGroupName))) {
                                throw ..noSocketBindingGroupCalled(socketBindingGroupName);
                            }
                        }
                        context.stepCompleted();
                    }
                }, .);
                context.stepCompleted();
            }
        }, .);
    }
New to GrepCode? Check out our FAQ X