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.host.controller;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ACCESS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADVANCED_FILTER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.APPLICATION_CLASSIFICATION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.AUDIT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.AUDIT_LOG;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.AUTHENTICATION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.AUTHORIZATION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONNECTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONSTRAINT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT_INTERFACE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT_OVERLAY;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ENABLED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXCLUDE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILE_HANDLER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP_SEARCH;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.GROUP_TO_PRINCIPAL;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HASH;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST_SCOPED_ROLE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INTERFACE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.JSON_FORMATTER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LDAP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LDAP_CONNECTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LOGGER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MANAGEMENT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PATH;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PORT_OFFSET;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PRINCIPAL_TO_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROFILE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROFILE_NAME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROPERTIES;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PROVIDER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELATIVE_TO;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLE_MAPPING;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RUNTIME_NAME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SCHEMA_LOCATIONS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SECURITY_REALM;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SENSITIVITY_CLASSIFICATION;
 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.SERVER_GROUP_SCOPED_ROLE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_IDENTITY;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER_LOGGER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_PORT_OFFSET;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSLOG_HANDLER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.USERNAME_FILTER;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.USERNAME_IS_DN;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.USERNAME_TO_DN;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VAULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VAULT_EXPRESSION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VAULT_OPTIONS;
 import static org.jboss.as.host.controller.HostControllerMessages.MESSAGES;
 
 import java.io.File;
Factory creating the boot operations for a ManagedServer.

Author(s):
Kabir Khan
James R. Perkins
Emanuel Muckenhuber
public final class ManagedServerOperationsFactory {
    private static final ModelNode EMPTY = new ModelNode();
    static {
        .setEmptyList();
        .protect();
    }

    
Create a list of operations required to a boot a managed server.

Parameters:
serverName the server name
domainModel the complete domain model
hostModel the local host model
domainController the domain controller
Returns:
the list of boot operations
    public static ModelNode createBootUpdates(final String serverNamefinal ModelNode domainModelfinal ModelNode hostModel,
                                              final DomainController domainControllerfinal ExpressionResolver expressionResolver) {
        final ManagedServerOperationsFactory factory = new ManagedServerOperationsFactory(serverNamedomainModel,
                hostModeldomainControllerexpressionResolver);
        return factory.getBootUpdates();
    }
    private final String serverName;
    private final ModelNode domainModel;
    private final ModelNode hostModel;
    private final ModelNode serverModel;
    private final ModelNode serverGroup;
    private final String serverGroupName;
    private final String profileName;
    private final DomainController domainController;
    private final ExpressionResolver expressionResolver;
    ManagedServerOperationsFactory(final String serverNamefinal ModelNode domainModelfinal ModelNode hostModel,
                                   final DomainController domainControllerfinal ExpressionResolver expressionResolver) {
        this. = serverName;
        this. = domainModel;
        this. = hostModel;
        this. = domainController;
        this. = expressionResolver;
        this. = resolveExpressions(hostModel.require().require(serverName));
        this. = .require().asString();
        this. = .require().asString();
    }

    
Resolve expressions in the given model (if there are any)
    private ModelNode resolveExpressions(final ModelNode unresolved) {
        if (unresolved == null) {
            return null;
        }
        try {
            return .resolveExpressions(unresolved.clone());
        } catch (OperationFailedException e) {
            // Fail
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
        int portOffSet = 0;
        String socketBindingRef = null;
            socketBindingRef = .get().asString();
        }
            socketBindingRef = .get().asString();
        }
            portOffSet = .get().asInt();
        }
            portOffSet = .get().asInt();
        }
        if (socketBindingRef == null) {
            throw .undefinedSocketBinding();
        }
        final ModelNodeList updates = new ModelNodeList();
        setServerGroupHost(updates);
        addNamespaces(updates);
        addProfileName(updates);
        addSchemaLocations(updates);
        addExtensions(updates);
        addPaths(updates);
        addSystemProperties(updates);
        addVault(updates);
        addManagementSecurityRealms(updates);
        addAuditLog(updates);
        addManagementConnections(updates);
        addManagementAuthorization(updates);
        addInterfaces(updates);
        addSocketBindings(updatesportOffSetsocketBindingRef);
        addSubsystems(updates);
        addDeployments(updates);
        addDeploymentOverlays(updates);
        return updates.model;
    }
    private void setServerGroupHost(ModelNodeList updates) {
        op.get().set();
        op.get().set(lhci.getLocalHostName());
        updates.add(op);
    }
    private void addNamespaces(List<ModelNodeupdates) {
        final Map<StringModelNodemap = new LinkedHashMap<StringModelNode>();
        addNamespaces(map.get());
        addNamespaces(map.get());
        updates.addAll(map.values());
    }
    private void addNamespaces(Map<StringModelNodemapModelNode namespaces) {
        if (namespaces.isDefined()) {
            for (Property prop : namespaces.asPropertyList()) {
                map.put(prop.getName(), NamespaceAddHandler.getAddNamespaceOperation(prop.getName(), prop.getValue().asString()));
            }
        }
    }
    private void addProfileName(List<ModelNodeupdates) {
        updates.add(Util.getWriteAttributeOperation());
    }
    private void addSchemaLocations(List<ModelNodeupdates) {
        final Map<StringModelNodemap = new LinkedHashMap<StringModelNode>();
        updates.addAll(map.values());
    }
    private void addSchemaLocations(Map<StringModelNodemapModelNode namespaces) {
        if (namespaces.isDefined()) {
            for (Property prop : namespaces.asPropertyList()) {
                map.put(prop.getName(), SchemaLocationAddHandler.getAddSchemaLocationOperation(prop.getName(), prop.getValue().asString()));
            }
        }
    }
    private void addExtensions(List<ModelNodeupdates) {
        final Set<StringextensionNames = new LinkedHashSet<String>();
        addExtensions(extensionNames.get());
        addExtensions(extensionNames.get());
        for (String name : extensionNames) {
            updates.add(Util.createAddOperation(PathAddress.pathAddress(PathElement.pathElement(name))));
        }
    }
    private void addExtensions(Set<StringextensionNamesModelNode extensions) {
        if (extensions.isDefined()) {
            extensionNames.addAll(extensions.keys());
        }
    }
    private void addPaths(List<ModelNodeupdates) {
        final Map<StringModelNodepaths = new LinkedHashMap<StringModelNode>();
        addPaths(paths.get());
        addPaths(paths.get());
        addPaths(paths.get());
        for (Map.Entry<StringModelNodeentry : paths.entrySet()) {
            updates.add(PathAddHandler.getAddPathOperation(PathAddress.pathAddress(PathElement.pathElement(entry.getKey())), entry.getValue().get(), entry.getValue().get()));
        }
    }
    private void addPaths(Map<StringModelNodemapModelNode path) {
        if (path.isDefined()) {
            for (Property prop : path.asPropertyList()) {
                //TODO merge rather than replace existing?
                map.put(prop.getName(), prop.getValue());
            }
        }
    }
    private void addSystemProperties(List<ModelNodeupdates) {
        Map<StringStringprops = getAllSystemProperties(false);
        for (Map.Entry<StringStringentry : props.entrySet()) {
            ModelNode address = new ModelNode();
            address.add(entry.getKey());
            ModelNode op = Util.getEmptyOperation(.address);
            if (entry.getValue() != null) {
                op.get().set(entry.getValue());
            }
            updates.add(op);
        }
    }
    private Map<StringStringgetAllSystemProperties(boolean boottimeOnly) {
        Map<StringStringprops = new LinkedHashMap<StringString>();
        addSystemProperties(propsboottimeOnly);
        addSystemProperties(propsboottimeOnly);
        addSystemProperties(propsboottimeOnly);
        addSystemProperties(propsboottimeOnly);
        return props;
    }
    private void addSystemProperties(final ModelNode sourcefinal Map<StringStringpropsboolean boottimeOnly) {
        if (source.hasDefined()) {
            for (Property prop : source.get().asPropertyList()) {
                ModelNode propResource = prop.getValue();
                try {
                    if (boottimeOnly && !..resolveModelAttribute(.getExpressionResolver(), propResource).asBoolean()) {
                        continue;
                    }
                } catch (OperationFailedException e) {
                    throw new IllegalStateException(e);
                }
                String val = propResource.hasDefined() ? propResource.get().asString() : null;
                props.put(prop.getName(), val);
            }
        }
    }
    private void addVault(List<ModelNodeupdates) {
        if (.get().isDefined()) {
            addVault(updates.get().get());
        }
    }
    private void addVault(List<ModelNodeupdatesModelNode vaultNode) {
        if (vaultNode.isDefined()) {
            ModelNode vault = new ModelNode();
            ModelNode codeNode = vaultNode.get(..getLocalName());
            if (codeNode.isDefined()) {
                vault.get(..getLocalName()).set(codeNode.asString());
            }
            ModelNode vaultAddress = new ModelNode();
            vaultAddress.add();
            addAddNameAndAddress(vaultvaultAddress);
            ModelNode optionsNode = vaultNode.get();
            if (optionsNode.isDefined()) {
                vault.get().set(optionsNode);
            }
            updates.add(vault);
        }
    }
    private void addManagementSecurityRealms(List<ModelNodeupdates) {
            ModelNode securityRealms = .get();
            Set<Stringkeys = securityRealms.keys();
            for (String current : keys) {
                ModelNode addOp = new ModelNode();
                ModelNode realmAddress = new ModelNode();
                realmAddress.add().add(current);
                addAddNameAndAddress(addOprealmAddress);
                updates.add(addOp);
                ModelNode currentRealm = securityRealms.get(current);
                if (currentRealm.hasDefined()) {
                    addManagementComponentComponent(currentRealmrealmAddressupdates);
                }
                if (currentRealm.hasDefined()) {
                    addManagementComponentComponent(currentRealmrealmAddressupdates);
                }
                if (currentRealm.hasDefined()) {
                    ModelNode authorization = currentRealm.require();
                    if (authorization.hasDefined()) {
                        addManagementComponentComponent(currentRealmrealmAddressupdates);
                    } else if (authorization.hasDefined()) {
                        ModelNode ldap = authorization.require();
                        // Add authorization=ldap
                        ModelNode addLdap = new ModelNode();
                        ModelNode ldapAddr = realmAddress.clone().add();
                        addAddNameAndAddress(addLdapldapAddr);
                        addLdap.get().set(ldap.get());
                        updates.add(addLdap);
                        // Add sub-resources
                        if (ldap.hasDefined()) {
                            ModelNode usernameToDn = ldap.require();
                            if (usernameToDn.hasDefined()) {
                                addLdapChild(usernameToDn.require(), ldapAddrupdates);
                            } else if (usernameToDn.hasDefined()) {
                                addLdapChild(usernameToDn.require(), ldapAddrupdates);
                            } else if (usernameToDn.hasDefined()) {
                                addLdapChild(usernameToDn.require(), ldapAddrupdates);
                            }
                        }
                        if (ldap.hasDefined()) {
                            ModelNode groupSearch = ldap.require();
                            if (groupSearch.hasDefined()) {
                                addLdapChild(groupSearch.require(), ldapAddrupdates);
                            } else if (groupSearch.hasDefined()) {
                                addLdapChild(groupSearch.require(), ldapAddrupdates);
                            }
                        }
                    }
                }
            }
        }
    }
    private void addLdapChild(ModelNode childModelNode parentAddressString keyString valueList<ModelNodeupdates) {
        ModelNode add = new ModelNode();
        convertAttributesToParams(childadd);
        addAddNameAndAddress(addparentAddress.clone().add(keyvalue));
        updates.add(add);
    }
    private void addManagementComponentComponent(ModelNode parentModelNode parentAddressString keyList<ModelNodeupdates) {
        for (String currentComponent : parent.get(key).keys()) {
            ModelNode addComponent = new ModelNode();
            // First take the properties to pass over.
            addComponent.set(parent.get(keycurrentComponent));
            // Now convert it to an operation by adding a name and address.
            ModelNode identityAddress = parentAddress.clone().add(keycurrentComponent);
            addAddNameAndAddress(addComponentidentityAddress);
            updates.add(addComponent);
        }
    }
    private void addAuditLog(ModelNodeList updates) {
        final ModelNode auditLogModel = .get();
        if (auditLogModel.isDefined()){
            final PathAddress auditLogAddr = PathAddress.pathAddress(PathElement.pathElement(), PathElement.pathElement());
            updates.add(Util.createAddOperation(auditLogAddr));
            if (auditLogModel.get().isDefined()) {
                for (Property formatterProp : auditLogModel.get().asPropertyList()) {
                    final PathAddress formatterAddress = auditLogAddr.append(PathElement.pathElement(formatterProp.getName()));
                    updates.add(JsonAuditLogFormatterResourceDefinition.createServerAddOperation(formatterAddressformatterProp.getValue()));
                }
            }
            if (auditLogModel.get().isDefined()){
                for (Property fileProp : auditLogModel.get().asPropertyList()){
                    final PathAddress fileHandlerAddress = auditLogAddr.append(PathElement.pathElement(fileProp.getName()));
                    updates.add(FileAuditLogHandlerResourceDefinition.createServerAddOperation(fileHandlerAddressfileProp.getValue()));
                }
            }
            if (auditLogModel.get().isDefined()){
                for (Property syslogProp : auditLogModel.get().asPropertyList()){
                    final PathAddress syslogHandlerAddress = auditLogAddr.append(syslogProp.getName());
                    SyslogAuditLogHandlerResourceDefinition.createServerAddOperations(updatessyslogHandlerAddresssyslogProp.getValue());
                }
            }
            if (auditLogModel.get().isDefined()){
                //server-logger=audit-log becomes logger=audit-log on the server
                final PathAddress loggerAddress = auditLogAddr.append();
                AuditLogLoggerResourceDefinition.createServerAddOperations(updatesloggerAddressauditLogModel.get());
            }
        }
    }
    private void addManagementConnections(List<ModelNodeupdates) {
            ModelNode baseAddress = new ModelNode();
            baseAddress.add();
            ModelNode connections = .get();
            for (String connectionName : connections.keys()) {
                ModelNode addConnection = new ModelNode();
                // First take the properties to pass over.
                addConnection.set(connections.get(connectionName));
                // Now convert it to an operation by adding a name and address.
                ModelNode identityAddress = baseAddress.clone().add(connectionName);
                addAddNameAndAddress(addConnectionidentityAddress);
                updates.add(addConnection);
            }
        }
    }
    private void addManagementAuthorization(ModelNodeList updates) {
        ModelNode domainConfig = .get();
        if (domainConfig.isDefined()) {
            ModelNode baseAddress = new ModelNode();
            baseAddress.add();
            baseAddress.add();
            if (domainConfig.hasDefined()) {
                ModelNode providerOp = Util.getWriteAttributeOperation(baseAddressdomainConfig.get());
                updates.add(providerOp);
            }
            addRoleMappings(domainConfigbaseAddressupdates);
            convertSimpleResources(domainConfigbaseAddressupdates);
            convertSimpleResources(domainConfigbaseAddressupdates);
            if (domainConfig.hasDefined()) {
                ModelNode constraints = domainConfig.get();
                if (constraints.hasDefined()) {
                    convertSimpleResources(constraints.get(), baseAddressupdates);
                }
                if (constraints.hasDefined()) {
                    convertSimpleResources(constraints.get(), ,
                            baseAddressupdates);
                }
                if (constraints.hasDefined()) {
                    ModelNode address = baseAddress.clone().add();
                    ModelNode ve = constraints.get();
                    // No add for this one; need to write attributes
                    for (AttributeDefinition ad : SensitivityResourceDefinition.getWritableVaultAttributeDefinitions()) {
                        String attr = ad.getName();
                        if (ve.hasDefined(attr)) {
                            updates.add(Util.getWriteAttributeOperation(addressattrve.get(attr)));
                        }
                    }
                }
            }
        }
    }
    private void addRoleMappings(ModelNode accessControlModelNode baseAddressModelNodeList updates) {
        if (accessControl.hasDefined()) {
            for (Property roleProp : accessControl.get().asPropertyList()) {
                ModelNode roleAddress = baseAddress.clone().add(roleProp.getName());
                updates.add(Util.getEmptyOperation(roleAddress));
                ModelNode roleMapping = roleProp.getValue();
                convertSimpleResources(roleMappingroleAddressupdates);
                convertSimpleResources(roleMappingroleAddressupdates);
            }
        }
    }
    private void addInterfaces(List<ModelNodeupdates) {
        final Map<StringModelNodeinterfaces = new LinkedHashMap<StringModelNode>();
        addInterfaces(interfaces.get());
        addInterfaces(interfaces.get());
        addInterfaces(interfaces.get());
        for (Map.Entry<StringModelNodeentry : interfaces.entrySet()) {
            updates.add(getAddInterfaceOperation(PathAddress.pathAddress(PathElement.pathElement(entry.getKey())), entry.getValue()));
        }
    }
    private static ModelNode getAddInterfaceOperation(PathAddress addressModelNode criteria) {
           ModelNode op = Util.createAddOperation(address);
           for (final AttributeDefinition def : .) {
               if(criteria.hasDefined(def.getName())) {
                   op.get(def.getName()).set(criteria.get(def.getName()));
               }
           }
           return op;
       }
    private void addInterfaces(Map<StringModelNodemapModelNode iface) {
        if (iface.isDefined()) {
            for (Property prop : iface.asPropertyList()) {
                map.put(prop.getName(), prop.getValue());
            }
        }
    }
    private void addSocketBindings(List<ModelNodeupdatesint portOffSetString bindingRef) {
        final Set<Stringprocessed = new HashSet<String>();
        final Map<StringModelNodegroups = new LinkedHashMap<StringModelNode>();
            for (Property prop : .get().asPropertyList()) {
                ModelNode node = prop.getValue().clone();
                if (portOffSet > 0) {
                    node.get().set(portOffSet);
                }
                groups.put(prop.getName(), node);
            }
        }
        final ModelNode group = groups.get(bindingRef);
        if (group == null) {
            throw .undefinedSocketBindingGroup(bindingRef);
        }
        final PathAddress groupAddress = PathAddress.pathAddress(PathElement.pathElement(bindingRef));
        final ModelNode groupAdd = BindingGroupAddHandler.getOperation(groupAddressgroup);
        groupAdd.get().set(portOffSet);
        updates.add(groupAdd);
        mergeBindingGroups(updatesgroupsbindingRefgroupprocessed);
    }
    private void mergeBindingGroups(List<ModelNodeupdatesMap<StringModelNodegroupsfinal String groupNameModelNode groupSet<Stringprocessed) {
        addSocketBindings(updatesgroupgroupNamegroup.get());
        if (group.has() && group.get().isDefined()) {
            for (final ModelNode include : group.get().asList()) {
                final String ref = include.asString();
                if (processed.add(ref)) {
                    final ModelNode includedGroup = groups.get(ref);
                    if (includedGroup == null) {
                        throw .undefinedSocketBindingGroup(ref);
                    }
                    mergeBindingGroups(updatesgroupsgroupNameincludedGroupprocessed);
                }
            }
        }
    }
    private void addSocketBindings(List<ModelNodeupdatesModelNode groupfinal String groupNameModelNode defaultInterface) {
        if (group.hasDefined()) {
            for (final Property socketBinding : group.get().asPropertyList()) {
                final String name = socketBinding.getName();
                final ModelNode binding = socketBinding.getValue();
                if (!binding.isDefined()) {
                    continue;
                }
                if (!binding.get().isDefined()) {
                    binding.get().set(defaultInterface);
                }
                updates.add(SocketBindingAddHandler.getOperation(PathAddress.pathAddress(PathElement.pathElement(groupName),
                        PathElement.pathElement(name)), binding));
            }
        }
        // outbound-socket-binding (for local destination)
            for (final Property localDestinationOutboundSocketBindings : group.get().asPropertyList()) {
                final String outboundSocketBindingName = localDestinationOutboundSocketBindings.getName();
                final ModelNode binding = localDestinationOutboundSocketBindings.getValue();
                if (!binding.isDefined()) {
                    continue;
                }
                // add the local destination outbound socket binding add operation
                updates.add(getLocalSocketBindingAddOperation(PathAddress.pathAddress(PathElement.pathElement(groupName),
                        PathElement.pathElement(outboundSocketBindingName)), binding));
            }
        }
        // outbound-socket-binding (for remote destination)
            for (final Property remoteDestinationOutboundSocketBindings : group.get().asPropertyList()) {
                final String outboundSocketBindingName = remoteDestinationOutboundSocketBindings.getName();
                final ModelNode binding = remoteDestinationOutboundSocketBindings.getValue();
                if (!binding.isDefined()) {
                    continue;
                }
                // add the local destination outbound socket binding add operation
                updates.add(getRemoteSocketBindingAddOperation(PathAddress.pathAddress(PathElement.pathElement(groupName),
                        PathElement.pathElement(outboundSocketBindingName)), binding));
            }
        }
    }
    public static ModelNode getLocalSocketBindingAddOperation(final PathAddress addressfinal ModelNode localDestinationOutboundSocketBinding) {
            final ModelNode addOperation = Util.createAddOperation(address);
            // socket binding reference
                if (localDestinationOutboundSocketBinding.get(ad.getName()).isDefined()) {
                    addOperation.get(ad.getName()).set(localDestinationOutboundSocketBinding.get(ad.getName()));
                }
            }
            return addOperation;
        }
        public static ModelNode getRemoteSocketBindingAddOperation(final PathAddress addressfinal ModelNode remoteDestinationOutboundSocketBinding) {
            final ModelNode addOperation = Util.createAddOperation(address);
                if (remoteDestinationOutboundSocketBinding.get(ad.getName()).isDefined()) {
                    addOperation.get(ad.getName()).set(remoteDestinationOutboundSocketBinding.get(ad.getName()));
                }
            }
            return addOperation;
        }
    private void addSubsystems(List<ModelNodeupdates) {
        updates.addAll(node.asList());
    }
    private void addDeployments(List<ModelNodeupdates) {
        if (.hasDefined()) {
            HostFileRepository remoteRepository = null;
            if (!.getLocalHostInfo().isMasterDomainController()) {
                remoteRepository = .getRemoteFileRepository();
            }
            for (Property deployment : .get().asPropertyList()) {
                String name = deployment.getName();
                ModelNode details = deployment.getValue();
                ModelNode domainDeployment = .require().require(name);
                ModelNode deploymentContent = domainDeployment.require().clone();
                if (remoteRepository != null) {
                    // Make sure we have a copy of the deployment in the local repo
                    for (ModelNode content : deploymentContent.asList()) {
                        if ((content.hasDefined())) {
                            byte[] hash = content.require().asBytes();
                            File[] files = .getLocalFileRepository().getDeploymentFiles(hash);
                            if (files == null || files.length == 0) {
                                remoteRepository.getDeploymentFiles(hash);
                            }
                        }
                    }
                }
                PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(name));
                ModelNode addOp = Util.getEmptyOperation(addr.toModelNode());
                addOp.get().set(details.get());
                addOp.get().set(deploymentContent);
                if (!details.hasDefined()) {
                    addOp.get().set(true);  // TODO this seems wrong
                } else {
                    addOp.get().set(details.get());
                }
                updates.add(addOp);
            }
        }
    }
    public void addDeploymentOverlays(final List<ModelNodeupdates) {
        if (.hasDefined()) {
            HostFileRepository remoteRepository = null;
            if (!.getLocalHostInfo().isMasterDomainController()) {
                remoteRepository = .getRemoteFileRepository();
            }
            for (Property deploymentOverlay : .get().asPropertyList()) {
                String name = deploymentOverlay.getName();
                ModelNode details = deploymentOverlay.getValue();
                PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(name));
                ModelNode addOp = Util.getEmptyOperation(addr.toModelNode());
                updates.add(addOp);
                if (details.hasDefined()) {
                    for (Property content : details.get().asPropertyList()) {
                        final String contentName = content.getName();
                        final ModelNode contentDetails = content.getValue();
                        byte[] hash = contentDetails.require().asBytes();
                        File[] files = .getLocalFileRepository().getDeploymentFiles(hash);
                        if (files == null || files.length == 0) {
                            if (remoteRepository != null) {
                                remoteRepository.getDeploymentFiles(hash);
                            }
                        }
                        addr = PathAddress.pathAddress(PathElement.pathElement(name), PathElement.pathElement(contentName));
                        addOp = Util.getEmptyOperation(addr.toModelNode());
                        addOp.get().get().set(contentDetails.get());
                        updates.add(addOp);
                    }
                }
                if (.hasDefined()) {
                    final ModelNode groupOverlay = .get().asObject();
                    if (groupOverlay.has(name)) {
                        ModelNode deploymentsNode = groupOverlay.get(name);
                        if(deploymentsNode.has()) {
                        for (Property content : deploymentsNode.get().asPropertyList()) {
                            final String deploymentName = content.getName();
                            //final ModelNode deploymentDetails = content.getValue();
                            addr = PathAddress.pathAddress(PathElement.pathElement(name), PathElement.pathElement(deploymentName));
                            addOp = Util.getEmptyOperation(addr.toModelNode());
                            updates.add(addOp);
                        }
                        }
                    }
                }
            }
        }
    }
    private ModelNode addAddNameAndAddress(ModelNode opPathAddress address){
        return addAddNameAndAddress(opaddress.toModelNode());
    }
    private ModelNode addAddNameAndAddress(ModelNode opModelNode address){
        op.get().set();
        op.get().set(address);
        return op;
    }
    private static void convertSimpleResources(ModelNode modelString typeModelNode baseAddressModelNodeList updates) {
        if (model.hasDefined(type)) {
            for (Property prop : model.get(type).asPropertyList()) {
                ModelNode address = baseAddress.clone().add(typeprop.getName());
                ModelNode addOp = Util.getEmptyOperation(address);
                convertAttributesToParams(prop.getValue(), addOp);
                updates.add(addOp);
            }
        }
    }
    private static void convertAttributesToParams(ModelNode valueModelNode addOp) {
        if (value.isDefined()) {
            for (Property prop : value.asPropertyList()) {
                ModelNode attrVal = prop.getValue();
                if (attrVal.isDefined()) {
                    addOp.get(prop.getName()).set(attrVal);
                }
            }
        }
    }
    private class ModelNodeList extends AbstractList<ModelNodeimplements List<ModelNode> {
        private final ModelNode model = new ModelNode().setEmptyList();
        @Override
        public boolean add(ModelNode modelNode) {
            .add(modelNode);
            return true;
        }
        @Override
        public ModelNode get(int index) {
            return .get(index);
        }
        @Override
        public int size() {
            return .asInt();
        }
    }