Search in sources :

Example 1 with ServerEnvironment

use of org.jboss.as.server.ServerEnvironment in project wildfly by wildfly.

the class Main method determineEnvironment.

public static ParsedOptions determineEnvironment(String[] args, Properties systemProperties, Map<String, String> systemEnvironment, ServerEnvironment.LaunchType launchType) {
    List<String> clientArguments = new ArrayList<String>();
    ParsedOptions ret = new ParsedOptions();
    ret.clientArguments = clientArguments;
    final int argsLength = args.length;
    String appClientConfig = "appclient.xml";
    boolean clientArgs = false;
    ProductConfig productConfig;
    boolean hostSet = false;
    for (int i = 0; i < argsLength; i++) {
        final String arg = args[i];
        try {
            if (clientArgs) {
                clientArguments.add(arg);
            } else if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg) || CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
                productConfig = new ProductConfig(Module.getBootModuleLoader(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), null);
                STDOUT.println(productConfig.getPrettyVersionString());
                return null;
            } else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
                usage();
                return null;
            } else if (CommandLineConstants.PROPERTIES.equals(arg) || CommandLineConstants.OLD_PROPERTIES.equals(arg) || CommandLineConstants.SHORT_PROPERTIES.equals(arg)) {
                // Set system properties from url/file
                if (!processProperties(arg, args[++i])) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.SHORT_PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.SHORT_PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.startsWith(CommandLineConstants.OLD_PROPERTIES)) {
                String urlSpec = parseValue(arg, CommandLineConstants.OLD_PROPERTIES);
                if (urlSpec == null || !processProperties(arg, urlSpec)) {
                    return null;
                }
            } else if (arg.equals(CommandLineConstants.SHORT_HOST) || arg.equals(CommandLineConstants.HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = args[++i];
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.SHORT_HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = parseValue(arg, CommandLineConstants.SHORT_HOST);
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.HOST)) {
                if (ret.propertiesFile != null) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                hostSet = true;
                String urlSpec = parseValue(arg, CommandLineConstants.HOST);
                ret.hostUrl = urlSpec;
            } else if (arg.startsWith(CommandLineConstants.CONNECTION_PROPERTIES)) {
                if (hostSet) {
                    throw AppClientLogger.ROOT_LOGGER.cannotSpecifyBothHostAndPropertiesFile();
                }
                String fileUrl = parseValue(arg, CommandLineConstants.CONNECTION_PROPERTIES);
                ret.propertiesFile = fileUrl;
            } else if (arg.startsWith(CommandLineConstants.SYS_PROP)) {
                // set a system property
                String name, value;
                int idx = arg.indexOf("=");
                if (idx == -1) {
                    name = arg.substring(2);
                    value = "true";
                } else {
                    name = arg.substring(2, idx);
                    value = arg.substring(idx + 1, arg.length());
                }
                systemProperties.setProperty(name, value);
                WildFlySecurityManager.setPropertyPrivileged(name, value);
            } else if (arg.startsWith(CommandLineConstants.APPCLIENT_CONFIG)) {
                appClientConfig = parseValue(arg, CommandLineConstants.APPCLIENT_CONFIG);
            } else if (CommandLineConstants.SECMGR.equals(arg)) {
            // ignore the argument as it's allowed, but passed to jboss-modules and not used here
            } else {
                if (arg.startsWith("-")) {
                    STDOUT.println(AppClientLogger.ROOT_LOGGER.unknownOption(arg));
                    usage();
                    return null;
                }
                clientArgs = true;
                clientArguments.add(arg);
            }
        } catch (IndexOutOfBoundsException e) {
            STDERR.println(AppClientLogger.ROOT_LOGGER.argumentExpected(arg));
            usage();
            return null;
        }
    }
    // No host controller unless in domain mode.
    String hostControllerName = null;
    productConfig = new ProductConfig(Module.getBootModuleLoader(), WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.HOME_DIR, null), systemProperties);
    ret.environment = new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, appClientConfig, null, launchType, null, productConfig);
    return ret;
}
Also used : ServerEnvironment(org.jboss.as.server.ServerEnvironment) ArrayList(java.util.ArrayList) ProductConfig(org.jboss.as.version.ProductConfig)

Example 2 with ServerEnvironment

use of org.jboss.as.server.ServerEnvironment in project wildfly by wildfly.

the class Main method main.

/**
     * The main method.
     *
     * @param args the command-line arguments
     */
public static void main(String[] args) {
    if (java.util.logging.LogManager.getLogManager().getClass().getName().equals("org.jboss.logmanager.LogManager")) {
        // Make sure our original stdio is properly captured.
        try {
            Class.forName(org.jboss.logmanager.handlers.ConsoleHandler.class.getName(), true, org.jboss.logmanager.handlers.ConsoleHandler.class.getClassLoader());
        } catch (Throwable ignored) {
        }
        // Install JBoss Stdio to avoid any nasty crosstalk, after command line arguments are processed.
        StdioContext.install();
        final StdioContext context = StdioContext.create(new NullInputStream(), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stdout"), org.jboss.logmanager.Level.INFO), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stderr"), org.jboss.logmanager.Level.ERROR));
        StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));
    }
    try {
        Module.registerURLStreamHandlerFactoryModule(Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.vfs")));
        final ParsedOptions options = determineEnvironment(args, new Properties(WildFlySecurityManager.getSystemPropertiesPrivileged()), WildFlySecurityManager.getSystemEnvironmentPrivileged(), ServerEnvironment.LaunchType.APPCLIENT);
        if (options == null) {
            //this happens if --version was specified
            return;
        }
        ServerEnvironment serverEnvironment = options.environment;
        final List<String> clientArgs = options.clientArguments;
        if (clientArgs.isEmpty()) {
            STDERR.println(AppClientLogger.ROOT_LOGGER.appClientNotSpecified());
            usage();
            abort(null);
        } else {
            final QName rootElement = new QName(Namespace.CURRENT.getUriString(), "server");
            final String file = clientArgs.get(0);
            final List<String> params = clientArgs.subList(1, clientArgs.size());
            final String deploymentName;
            final String earPath;
            int pos = file.lastIndexOf("#");
            if (pos == -1) {
                earPath = file;
                deploymentName = null;
            } else {
                deploymentName = file.substring(pos + 1);
                earPath = file.substring(0, pos);
            }
            File realFile = new File(earPath);
            if (!realFile.exists()) {
                throw AppClientLogger.ROOT_LOGGER.cannotFindAppClientFile(realFile.getAbsoluteFile());
            }
            final Bootstrap bootstrap = Bootstrap.Factory.newInstance();
            final Bootstrap.Configuration configuration = new Bootstrap.Configuration(serverEnvironment);
            configuration.setModuleLoader(Module.getBootModuleLoader());
            final ExtensionRegistry extensionRegistry = configuration.getExtensionRegistry();
            final AppClientXml parser = new AppClientXml(Module.getBootModuleLoader(), extensionRegistry);
            final Bootstrap.ConfigurationPersisterFactory configurationPersisterFactory = new Bootstrap.ConfigurationPersisterFactory() {

                @Override
                public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
                    ApplicationClientConfigurationPersister persister = new ApplicationClientConfigurationPersister(earPath, deploymentName, options.hostUrl, options.propertiesFile, params, serverEnvironment.getServerConfigurationFile().getBootFile(), rootElement, parser);
                    for (Namespace namespace : Namespace.domainValues()) {
                        if (!namespace.equals(Namespace.CURRENT)) {
                            persister.registerAdditionalRootElement(new QName(namespace.getUriString(), "server"), parser);
                        }
                    }
                    extensionRegistry.setWriterRegistry(persister);
                    return persister;
                }
            };
            configuration.setConfigurationPersisterFactory(configurationPersisterFactory);
            bootstrap.bootstrap(configuration, Collections.<ServiceActivator>emptyList()).get();
        }
    } catch (Throwable t) {
        abort(t);
    }
}
Also used : StdioContext(org.jboss.stdio.StdioContext) Properties(java.util.Properties) ExtensionRegistry(org.jboss.as.controller.extension.ExtensionRegistry) ServerEnvironment(org.jboss.as.server.ServerEnvironment) Bootstrap(org.jboss.as.server.Bootstrap) NullInputStream(org.jboss.stdio.NullInputStream) QName(javax.xml.namespace.QName) LoggingOutputStream(org.jboss.stdio.LoggingOutputStream) ServiceActivator(org.jboss.msc.service.ServiceActivator) Namespace(org.jboss.as.controller.parsing.Namespace) SimpleStdioContextSelector(org.jboss.stdio.SimpleStdioContextSelector) AppClientXml(org.jboss.as.appclient.subsystem.parsing.AppClientXml) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File)

Example 3 with ServerEnvironment

use of org.jboss.as.server.ServerEnvironment in project wildfly by wildfly.

the class InstanceNameBindingProcessor method bindServices.

private void bindServices(DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName contextServiceName) {
    final ServiceName instanceNameServiceName = contextServiceName.append("InstanceName");
    final BinderService instanceNameService = new BinderService("InstanceName");
    serviceTarget.addService(instanceNameServiceName, instanceNameService).addDependency(contextServiceName, ServiceBasedNamingStore.class, instanceNameService.getNamingStoreInjector()).addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, new Injector<ServerEnvironment>() {

        @Override
        public void inject(final ServerEnvironment serverEnvironment) throws InjectionException {
            instanceNameService.getManagedObjectInjector().inject(new ManagedReferenceFactory() {

                @Override
                public ManagedReference getReference() {
                    return new ManagedReference() {

                        @Override
                        public void release() {
                        }

                        @Override
                        public Object getInstance() {
                            final String nodeName = serverEnvironment.getNodeName();
                            return nodeName == null ? "" : nodeName;
                        }
                    };
                }
            });
        }

        @Override
        public void uninject() {
            instanceNameService.getManagedObjectInjector().uninject();
        }
    }).install();
    deploymentUnit.addToAttachmentList(org.jboss.as.server.deployment.Attachments.JNDI_DEPENDENCIES, instanceNameServiceName);
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) ServiceName(org.jboss.msc.service.ServiceName) Injector(org.jboss.msc.inject.Injector) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServerEnvironment(org.jboss.as.server.ServerEnvironment) ManagedReference(org.jboss.as.naming.ManagedReference)

Aggregations

ServerEnvironment (org.jboss.as.server.ServerEnvironment)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 QName (javax.xml.namespace.QName)1 AppClientXml (org.jboss.as.appclient.subsystem.parsing.AppClientXml)1 ExtensionRegistry (org.jboss.as.controller.extension.ExtensionRegistry)1 Namespace (org.jboss.as.controller.parsing.Namespace)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 BinderService (org.jboss.as.naming.service.BinderService)1 Bootstrap (org.jboss.as.server.Bootstrap)1 ProductConfig (org.jboss.as.version.ProductConfig)1 Injector (org.jboss.msc.inject.Injector)1 ServiceActivator (org.jboss.msc.service.ServiceActivator)1 ServiceName (org.jboss.msc.service.ServiceName)1 LoggingOutputStream (org.jboss.stdio.LoggingOutputStream)1 NullInputStream (org.jboss.stdio.NullInputStream)1 SimpleStdioContextSelector (org.jboss.stdio.SimpleStdioContextSelector)1