Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *
   *  * JBoss, Home of Professional Open Source.
   *  * Copyright 2013, 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.host.controller;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.IGNORE_UNUSED_CONFIG;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROFILE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_CONFIG;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
 
 import java.util.Map;
 import java.util.Set;
 
Utility to inspect what resources should be ignored on a slave according to its server-configs

Author(s):
Kabir Khan
 
 
     private final ExtensionRegistry extensionRegistry;
 
     private IgnoredNonAffectedServerGroupsUtil(final ExtensionRegistry extensionRegistry) {
         this. = extensionRegistry;
     }

    
Static factory

Parameters:
extensionRegistry the extension registry
Returns:
the created instance
 
     public static IgnoredNonAffectedServerGroupsUtil create(final ExtensionRegistry extensionRegistry) {
         return new IgnoredNonAffectedServerGroupsUtil(extensionRegistry);
     }

    
Used by the slave host when creating the host info dmr sent across to the DC during the registration process

Parameters:
ignoreUnaffectedServerGroups whether the slave host is set up to ignore config for server groups it does not have servers for
hostModel the resource containing the host model
the dmr sent across to theDC
Returns:
the modified dmr
 
     public static ModelNode addCurrentServerGroupsToHostInfoModel(boolean ignoreUnaffectedServerGroupsResource hostModelModelNode model) {
         if (!ignoreUnaffectedServerGroups) {
             return model;
         }
         model.get().set(ignoreUnaffectedServerGroups);
         ModelNode initialServerGroups = new ModelNode();
         initialServerGroups.setEmptyObject();
         for (ResourceEntry entry : hostModel.getChildren()) {
             ModelNode serverNode = new ModelNode();
             serverNode.get().set(entry.getModel().get());
             if (entry.getModel().hasDefined()) {
                 serverNode.get().set(entry.getModel().get().asString());
             }
             initialServerGroups.get(entry.getName()).set(serverNode);
         }
         model.get(.).set(initialServerGroups);
         return model;
     }

    
For the DC to check whether a resource address should be ignored on the slave, if the slave is set up to ignore config not relevant to it

Parameters:
domainResource the domain root resource
serverConfigs the server configs the slave is known to have
pathAddress the address of the resource to check if should be ignored or not
    public boolean ignoreResource(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal PathAddress pathAddress) {
        if (pathAddress.size() != 1) {
            return false;
        }
        boolean ignore = ignoreResourceInternal(domainResourceserverConfigspathAddress);
        return ignore;
    }

    
For the DC to check whether an operation should be ignored on the slave, if the slave is set up to ignore config not relevant to it

Parameters:
domainResource the domain root resource
serverConfigs the server configs the slave is known to have
pathAddress the address of the operation to check if should be ignored or not
    public boolean ignoreOperation(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal PathAddress pathAddress) {
        if (pathAddress.size() == 0) {
            return false;
        }
        boolean ignore = ignoreResourceInternal(domainResourceserverConfigspathAddress);
        return ignore;
    }

    
Gets all the extensions used by a profile's subsystems on the DC

Parameters:
domainResource the root domain resource
profileElement the address of the profile element
    public Set<PathElementgetAllExtensionsForProfile(Resource domainResourcePathElement profileElement) {
        Set<StringextensionModuleNames = .getExtensionModuleNames();
        Set<StringsubsystemNamesForProfile = new HashSet<>();
        for (ResourceEntry entry : domainResource.getChild(profileElement).getChildren()) {
            subsystemNamesForProfile.add(entry.getName());
        }
        Set<PathElementextensionsForProfile = new HashSet<>();
        for (String extensionModule : extensionModuleNames) {
            Map<StringSubsystemInformationinfos = .getAvailableSubsystems(extensionModule);
            for (String subsystemName : infos.keySet()) {
                if (subsystemNamesForProfile.contains(subsystemName)) {
                    extensionsForProfile.add(PathElement.pathElement(extensionModule));
                }
            }
        }
        return extensionsForProfile;
    }
    private boolean ignoreResourceInternal(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal PathAddress pathAddress) {
        String type = pathAddress.getElement(0).getKey();
        switch (type) {
        case :
            return ignoreProfile(domainResourceserverConfigspathAddress.getElement(0).getValue());
        case :
            return ignoreServerGroup(domainResourceserverConfigspathAddress.getElement(0).getValue());
        case :
            return ignoreExtension(domainResourceserverConfigspathAddress.getElement(0).getValue());
        case :
            return ignoreSocketBindingGroups(domainResourceserverConfigspathAddress.getElement(0).getValue());
        default:
            return false;
        }
    }
    private boolean ignoreProfile(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal String name) {
        Set<StringseenGroups = new HashSet<>();
        for (ServerConfigInfo serverConfig : serverConfigs) {
            if (seenGroups.contains(serverConfig.getServerGroup())) {
                continue;
            }
            seenGroups.add(serverConfig.getServerGroup());
            Resource serverGroupResource = domainResource.getChild(PathElement.pathElement(serverConfig.getServerGroup()));
            if (serverGroupResource.getModel().get().asString().equals(name)) {
                return false;
            }
        }
        return true;
    }
    private boolean ignoreServerGroup(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal String name) {
        for (ServerConfigInfo serverConfig : serverConfigs) {
            if (serverConfig.getServerGroup().equals(name)) {
                return false;
            }
        }
        return true;
    }
    private boolean ignoreExtension(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal String name) {
        //Should these be the subsystems on the master, as we have it at present, or the ones from the slave?
        for (String subsystem : subsystems.keySet()) {
            for (ResourceEntry profileEntry : domainResource.getChildren()) {
                if (profileEntry.hasChild(PathElement.pathElement(subsystem))) {
                    if (!ignoreProfile(domainResourceserverConfigsprofileEntry.getName())) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
    private boolean ignoreSocketBindingGroups(final Resource domainResourcefinal Collection<ServerConfigInfoserverConfigsfinal String name) {
        for (ServerConfigInfo serverConfig : serverConfigs) {
            if (serverConfig.getSocketBindingGroup() != null) {
                if (serverConfig.getSocketBindingGroup().equals(name)) {
                    return false;
                }
            } else {
                Resource serverGroupResource = domainResource.getChild(PathElement.pathElement(serverConfig.getServerGroup()));
                if (name.equals(serverGroupResource.getModel().get().asString())) {
                    return false;
                }
            }
        }
        return true;
    }



    
For use on a slave HC to get all the server groups used by the host

Parameters:
hostResource the host resource
Returns:
the server configs on this host
    public Set<ServerConfigInfogetServerConfigsOnSlave(Resource hostResource){
        Set<ServerConfigInfogroups = new HashSet<>();
        for (ResourceEntry entry : hostResource.getChildren()) {
            groups.add(new ServerConfigInfoImpl(entry.getName(), entry.getModel()));
        }
        return groups;
    }

    
Creates a server config info from its name, its server group and its socket binding group

Parameters:
name the name of the server config
serverGroup the name of the server group
socketBindingGroup the name of the socket binding override used by the server config. May be null
Returns:
the server config info
    public static ServerConfigInfo createServerConfigInfo(String nameString serverGroupString socketBindingGroup) {
        return new ServerConfigInfoImpl(nameserverGroupsocketBindingGroup);
    }

    
Creates a server config info from it's model representation as created by IgnoredNonAffectedServerGroupsUtil.ServerConfigInfo.toModelNode()

Parameters:
model the model
Returns:
the server config info
    public static ServerConfigInfo createServerConfigInfo(ModelNode model) {
        String name = model.keys().iterator().next();
        return new ServerConfigInfoImpl(namemodel.get(name));
    }

    
Contains info about a server config
    public interface ServerConfigInfo {
        
Gets the server config name

Returns:
the name
        String getName();

        
Gets the server config's server group name

Returns:
the server group name
        String getServerGroup();

        
Gets the server config's socket binding group override name

Returns:
the socket binding group name. May be null
        String getSocketBindingGroup();

        
Serializes the server config to dmr

Returns:
the dmr representation of this server config
        ModelNode toModelNode();
    }
    private static class ServerConfigInfoImpl implements ServerConfigInfo {
        private final String name;
        private final String serverGroup;
        private final String socketBindingGroup;
        ServerConfigInfoImpl(String nameModelNode model) {
            this. = name;
            this. = model.get().asString();
            this. = model.has() ? model.get().asString() : null;
        }
        ServerConfigInfoImpl(String nameString serverGroupString socketBindingGroup) {
            this. = name;
            this. = serverGroup;
            this. = socketBindingGroup;
        }
        @Override
        public String getName() {
            return ;
        }
        @Override
        public String getServerGroup() {
            return ;
        }
        @Override
        public String getSocketBindingGroup() {
            return ;
        }
        @Override
        public ModelNode toModelNode() {
            ModelNode model = new ModelNode();
            model.get().set();
            if ( != null) {
                model.get().set();
            }
            return model;
        }
    }
New to GrepCode? Check out our FAQ X