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.GROUP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.JVM;
 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.SUBSYSTEM;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTY;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 
Combines the relevant parts of the domain-level and host-level models to determine the jvm launch command needed to start an application server instance.

Author(s):
Kabir Khan
James R. Perkins
 
 
 
     private static final ModelNode EMPTY = new ModelNode();
     static {
         .setEmptyList();
         .protect();
     }
 
     private final String serverName;
     private final ModelNode domainModel;
     private final ModelNode hostModel;
     private final ModelNode serverModel;
     private final ModelNode serverGroup;
     private final JvmElement jvmElement;
     private final HostControllerEnvironment environment;
     private final boolean managementSubsystemEndpoint;
     private final ModelNode endpointConfig = new ModelNode();
     private final ExpressionResolver expressionResolver;
     private final DirectoryGrouping directoryGrouping;
 
     public ManagedServerBootCmdFactory(final String serverNamefinal ModelNode domainModelfinal ModelNode hostModelfinal HostControllerEnvironment environmentfinal ExpressionResolver expressionResolver) {
         this. = serverName;
         this. = domainModel;
         this. = hostModel;
         this. = environment;
         this. = expressionResolver;
         this. = resolveExpressions(hostModel.require().require(serverName));
         this. = resolveDirectoryGrouping(hostModelexpressionResolver);
         final String serverGroupName = .require().asString();
         this. = resolveExpressions(domainModel.require().require(serverGroupName));
 
         String serverVMName = null;
         ModelNode serverVM = null;
         if(.hasDefined()) {
             for (final String jvm : .get().keys()) {
                 serverVMName = jvm;
                serverVM = .get(jvm);
                break;
            }
        }
        String groupVMName = null;
        ModelNode groupVM = null;
        if(.hasDefined()) {
            for(final String jvm : .get().keys()) {
                groupVMName = jvm;
                groupVM = .get(jvm);
                break;
            }
        }
        // Use the subsystem endpoint
        // TODO by default use the subsystem endpoint
        // Get the endpoint configuration
        if() {
            final String profileName = .get().asString();
            final ModelNode profile = domainModel.get(profileName);
            if(profile.hasDefined() && profile.hasDefined("remoting")) {
                .set(profile.get("remoting"));
            }
        }
        final String jvmName = serverVMName != null ? serverVMName : groupVMName;
        final ModelNode hostVM = jvmName != null ? hostModel.get(jvmName) : null;
        this. = new JvmElement(jvmName,
                resolveExpressions(hostVM),
                resolveExpressions(groupVM),
                resolveExpressions(serverVM));
    }

    
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);
        }
    }

    
Returns the value of found in the model.

Parameters:
model the model that contains the key and value.
expressionResolver the expression resolver to use to resolve expressions
Returns:
the directory grouping found in the model.
Throws:
java.lang.IllegalArgumentException if the directory grouping was not found in the model.
    private static DirectoryGrouping resolveDirectoryGrouping(final ModelNode modelfinal ExpressionResolver expressionResolver) {
        try {
            return DirectoryGrouping.forName(..resolveModelAttribute(expressionResolvermodel).asString());
        } catch (OperationFailedException e) {
            throw new IllegalStateException(e);
        }
    }

    
Create and verify the configuration before trying to start the process.

Returns:
the process boot configuration
        return this;
    }

    
    @Override
        return ;
    }

    
    @Override
    public List<StringgetServerLaunchCommand() {
        final List<Stringcommand = new ArrayList<String>();
        command.add(getJavaCommand());
        command.add("-D[" + ManagedServer.getServerProcessName() + "]");
        JvmOptionsBuilderFactory.getInstance().addOptions(command);
        Map<StringStringbootTimeProperties = getAllSystemProperties(true);
        // Add in properties passed in to the ProcessController command line
        for (Map.Entry<StringStringhostProp : .getHostSystemProperties().entrySet()) {
            if (!bootTimeProperties.containsKey(hostProp.getKey())) {
                bootTimeProperties.put(hostProp.getKey(), hostProp.getValue());
            }
        }
        for (Entry<StringStringentry : bootTimeProperties.entrySet()) {
            String property = entry.getKey();
            String value = entry.getValue();
            if (!"org.jboss.boot.log.file".equals(property) && !"logging.configuration".equals(property)
                    && !.equals(property)) {
                final StringBuilder sb = new StringBuilder("-D");
                sb.append(property);
                if (value != null) {
                    sb.append('=');
                    sb.append(value);
                }
                command.add(sb.toString());
            }
        }
        // Use the directory grouping type to set props controlling the server data/log/tmp dirs
        String serverDirProp = bootTimeProperties.get(.);
        File serverDir = serverDirProp == null ? new File(.getDomainServersDir(), ) : new File(serverDirProp);
        final String logDir = addPathProperty(command"log".bootTimeProperties,
                .getDomainLogDir(), serverDir);
        addPathProperty(command"tmp".bootTimeProperties,
                .getDomainTempDir(), serverDir);
        final String dataDir = addPathProperty(command"data".bootTimeProperties,
                .getDomainDataDir(), serverDir);
        final File loggingConfig = new File(dataDir"logging.properties");
        final String path;
        if (loggingConfig.exists()) {
            path = "file:" + loggingConfig.getAbsolutePath();
        } else {
            // Sets the initial log file to use
            command.add("-Dorg.jboss.boot.log.file=" + getAbsolutePath(new File(logDir), "server.log"));
            // The default host controller and process controller configuration file
            final String domainConfigFile = "file:" + getAbsolutePath(.getDomainConfigurationDir(), "logging.properties");
            // The configuration file from the system property, could the default domain/configuration/logging.properties file
            final String systemPropConfigFile = WildFlySecurityManager.getPropertyPrivileged("logging.configuration"null);
            // The default configuration file to use if nothing is set
            final File defaultConfigFile = getAbsoluteFile(.getDomainConfigurationDir(), "default-server-logging.properties");
            // Ignore the system property value if domain/configuration/logging.properties is used
            if (domainConfigFile.equals(systemPropConfigFile) && defaultConfigFile.exists()) {
                path = "file:" + defaultConfigFile.getAbsolutePath();
            } else if (systemPropConfigFile != null) {
                path = systemPropConfigFile;
            } else {
                // Default to the domain/configuration/logging.properties if nothing else found
                path = domainConfigFile;
            }
        }
        command.add(String.format("-Dlogging.configuration=%s"path));
        command.add("-jar");
        command.add(getAbsolutePath(.getHomeDir(), "jboss-modules.jar"));
        command.add("-mp");
        command.add(.getModulePath());
        command.add("org.jboss.as.server");
        return command;
    }
    @Override
    public boolean isManagementSubsystemEndpoint() {
        return ;
    }
    @Override
        return ;
    }
    private String getJavaCommand() {
        String javaHome = .getJavaHome();
        if (javaHome == null) {
            if(.getDefaultJVM() != null) {
                String defaultJvm = .getDefaultJVM().getAbsolutePath();
                if (!defaultJvm.equals("java") || (defaultJvm.equals("java") && System.getenv("JAVA_HOME") != null)) {
                    return defaultJvm;
                }
            }
            javaHome = DefaultJvmUtils.getCurrentJvmHome();
        }
        return DefaultJvmUtils.findJavaExecutable(javaHome);
    }

    
    @Override
        final Map<StringStringenv = new HashMap<StringString>();
        for(final Entry<StringStringproperty : .getEnvironmentVariables().entrySet()) {
            env.put(property.getKey(), property.getValue());
        }
        return env;
    }
    private Map<StringStringgetAllSystemProperties(boolean boottimeOnly){
        Map<StringStringprops = new TreeMap<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(propResource).asBoolean()) {
                        continue;
                    }
                } catch (OperationFailedException e) {
                    throw new IllegalStateException(e);
                }
                String val = propResource.hasDefined() ? propResource.get().asString() : null;
                props.put(prop.getName(), val);
            }
        }
    }

    
Adds the absolute path to command.

Parameters:
command the command to add the arguments to.
typeName the type of directory.
propertyName the name of the property.
properties the properties where the path may already be defined.
directoryGrouping the directory group type.
typeDir the domain level directory for the given directory type; to be used for by-type grouping
serverDir the root directory for the server, to be used for 'by-server' grouping
Returns:
the absolute path that was added.
    private String addPathProperty(final List<Stringcommandfinal String typeNamefinal String propertyNamefinal Map<StringStringpropertiesfinal DirectoryGrouping directoryGrouping,
                                   final File typeDirFile serverDir) {
        final String result;
        final String value = properties.get(propertyName);
        if (value == null) {
            switch (directoryGrouping) {
                case :
                    result = getAbsolutePath(typeDir"servers");
                    break;
                case :
                default:
                    result = getAbsolutePath(serverDirtypeName);
                    break;
            }
            properties.put(propertyNameresult);
        } else {
            final File dir = new File(value);
            switch (directoryGrouping) {
                case :
                    result = getAbsolutePath(dir"servers");
                    break;
                case :
                default:
                    result = dir.getAbsolutePath();
                    break;
            }
        }
        command.add(String.format("-D%s=%s"propertyNameresult));
        return result;
    }
    static String getAbsolutePath(final File rootfinal String... paths) {
        return getAbsoluteFile(rootpaths).getAbsolutePath();
    }
    static File getAbsoluteFile(final File rootfinal String... paths) {
        File path = root;
        for(String segment : paths) {
            path = new File(pathsegment);
        }
        return path.getAbsoluteFile();
    }
New to GrepCode? Check out our FAQ X