Search in sources :

Example 1 with VirtualServer

use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.

the class CreateVirtualServer method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    if (networkListeners != null && httpListeners != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_BOTH_HTTP_NETWORK), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // use the listener parameter provided by the user.
    if (networkListeners == null) {
        networkListeners = httpListeners;
    }
    HttpService httpService = config.getHttpService();
    // ensure we don't already have one of this name
    for (VirtualServer virtualServer : httpService.getVirtualServer()) {
        if (virtualServer.getId().equals(virtualServerId)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_DUPLICATE), virtualServerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                // default
                String docroot = "${com.sun.aas.instanceRoot}/docroot";
                // default
                String accessLog = "${com.sun.aas.instanceRoot}/logs/access";
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setId(virtualServerId);
                newVirtualServer.setHosts(hosts);
                newVirtualServer.setNetworkListeners(networkListeners);
                newVirtualServer.setDefaultWebModule(defaultWebModule);
                newVirtualServer.setState(state);
                newVirtualServer.setLogFile(logFile);
                // values if the properties have not been specified.
                if (properties != null) {
                    for (Map.Entry entry : properties.entrySet()) {
                        String pn = (String) entry.getKey();
                        String pv = (String) entry.getValue();
                        if ("docroot".equals(pn)) {
                            docroot = pv;
                        } else if ("accesslog".equals(pn)) {
                            accessLog = pv;
                        } else {
                            Property property = newVirtualServer.createChild(Property.class);
                            property.setName(pn);
                            property.setValue(pv);
                            newVirtualServer.getProperty().add(property);
                        }
                    }
                }
                newVirtualServer.setDocroot(docroot);
                newVirtualServer.setAccessLog(accessLog);
                param.getVirtualServer().add(newVirtualServer);
                return newVirtualServer;
            }
        }, httpService);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_FAIL), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 2 with VirtualServer

use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.

the class ListVirtualServers method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    List<VirtualServer> list = config.getHttpService().getVirtualServer();
    for (VirtualServer virtualServer : list) {
        report.getTopMessagePart().addChild().setMessage(virtualServer.getId());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 3 with VirtualServer

use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.

the class HttpServiceStatsProviderBootstrap method postConstruct.

public void postConstruct() {
    if (config == null) {
        Object[] params = { VirtualServerInfoStatsProvider.class.getName(), HttpServiceStatsProvider.class.getName(), "http service", "virtual server" };
        logger.log(Level.SEVERE, LogFacade.UNABLE_TO_REGISTER_STATS_PROVIDERS, params);
        throw new ConfigurationException(rb.getString(LogFacade.NULL_CONFIG));
    }
    HttpService httpService = config.getHttpService();
    for (VirtualServer vs : httpService.getVirtualServer()) {
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId(), new VirtualServerInfoStatsProvider(vs));
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId() + "/request", new HttpServiceStatsProvider(vs.getId(), vs.getNetworkListeners(), config.getNetworkConfig()));
    }
}
Also used : ConfigurationException(org.jvnet.hk2.config.ConfigurationException) HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 4 with VirtualServer

use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.

the class WebConfigListener method changed.

/**
 * Handles HttpService change events
 * @param events the PropertyChangeEvent
 */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
            }
            try {
                if (tClass == HttpService.class) {
                    container.updateHttpService((HttpService) t);
                } else if (tClass == NetworkListener.class) {
                    if (type == TYPE.ADD) {
                        container.addConnector((NetworkListener) t, httpService, true);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteConnector((NetworkListener) t);
                    } else if (type == TYPE.CHANGE) {
                        container.updateConnector((NetworkListener) t, httpService);
                    }
                } else if (tClass == VirtualServer.class) {
                    if (type == TYPE.ADD) {
                        container.createHost((VirtualServer) t, httpService, null);
                        container.loadDefaultWebModule((VirtualServer) t);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteHost(httpService);
                    } else if (type == TYPE.CHANGE) {
                        container.updateHost((VirtualServer) t);
                    }
                } else if (tClass == AccessLog.class) {
                    container.updateAccessLog(httpService);
                } else if (tClass == ManagerProperties.class) {
                    return new NotProcessed("ManagerProperties requires restart");
                } else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
                    // container.updateHttpService handles SingleSignOn valve configuration
                    container.updateHttpService(httpService);
                } else if (tClass == NetworkListeners.class) {
                // skip updates
                } else if (tClass == Property.class) {
                    ConfigBeanProxy config = ((Property) t).getParent();
                    if (config instanceof HttpService) {
                        container.updateHttpService((HttpService) config);
                    } else if (config instanceof VirtualServer) {
                        container.updateHost((VirtualServer) config);
                    } else if (config instanceof NetworkListener) {
                        container.updateConnector((NetworkListener) config, httpService);
                    } else {
                        container.updateHttpService(httpService);
                    }
                } else if (tClass == SystemProperty.class) {
                    if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                            if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                                container.updateConnector(listener, httpService);
                            }
                        }
                    }
                } else if (tClass == JavaConfig.class) {
                    JavaConfig jc = (JavaConfig) t;
                    final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
                    for (String jvmOption : jvmOptions) {
                        if (jvmOption.startsWith("-DjvmRoute=")) {
                            container.updateJvmRoute(httpService, jvmOption);
                        }
                    }
                } else {
                // Ignore other unrelated events
                }
            } catch (LifecycleException le) {
                logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
            }
            return null;
        }
    }, logger);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ArrayList(java.util.ArrayList) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ManagerProperties(org.glassfish.web.config.serverbeans.ManagerProperties) WebContainerAvailability(org.glassfish.web.config.serverbeans.WebContainerAvailability) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with VirtualServer

use of com.sun.enterprise.config.serverbeans.VirtualServer in project Payara by payara.

the class ExistingConfigurationTest method setupServer.

@Test
public void setupServer() throws Exception {
    Server server = null;
    System.out.println("setup started with gf installation " + System.getProperty("basedir"));
    File f = new File(System.getProperty("basedir"));
    f = new File(f, "target");
    f = new File(f, "dependency");
    f = new File(f, "glassfish4");
    f = new File(f, "glassfish");
    if (f.exists()) {
        System.out.println("Using gf at " + f.getAbsolutePath());
    } else {
        System.out.println("GlassFish not found at " + f.getAbsolutePath());
        Assert.assertTrue(f.exists());
    }
    try {
        EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
        efsb.installRoot(f, false);
        // find the domain root.
        f = new File(f, "domains");
        f = new File(f, "domain1");
        f = new File(f, "config");
        f = new File(f, "domain.xml");
        Assert.assertTrue(f.exists());
        efsb.configurationFile(f);
        Server.Builder builder = new Server.Builder("inplanted");
        builder.embeddedFileSystem(efsb.build());
        server = builder.build();
        ServiceLocator habitat = server.getHabitat();
        Collection<VirtualServer> vss = habitat.getAllServices(VirtualServer.class);
        Assert.assertTrue(vss.size() > 0);
        for (VirtualServer vs : vss) {
            System.out.println("Virtual Server " + vs.getId());
        }
        Collection<NetworkListener> nls = habitat.getAllServices(NetworkListener.class);
        for (NetworkListener nl : nls) {
            System.out.println("Network listener " + nl.getPort());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) EmbeddedFileSystem(org.glassfish.internal.embedded.EmbeddedFileSystem) Server(org.glassfish.internal.embedded.Server) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) File(java.io.File) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Aggregations

VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)23 HttpService (com.sun.enterprise.config.serverbeans.HttpService)10 Property (org.jvnet.hk2.config.types.Property)8 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 ActionReport (org.glassfish.api.ActionReport)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)5 Target (org.glassfish.internal.api.Target)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 CommandTarget (org.glassfish.config.support.CommandTarget)4 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 HostAndPort (com.sun.enterprise.util.HostAndPort)2 List (java.util.List)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2