Search in sources :

Example 11 with ConfigCode

use of org.jvnet.hk2.config.ConfigCode in project Payara by payara.

the class InstallerThread method install.

/**
 * <p> Install the admingui.war file.</p>
 */
private void install() throws Exception {
    if (domain.getSystemApplicationReferencedFrom(env.getInstanceName(), AdminConsoleAdapter.ADMIN_APP_NAME) != null) {
        // Application is already installed
        adapter.setStateMsg(AdapterState.APPLICATION_INSTALLED_BUT_NOT_LOADED);
        return;
    }
    // Set the adapter state
    adapter.setStateMsg(AdapterState.INSTALLING);
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Installing the Admin Console Application...");
    }
    // create the application entry in domain.xml
    ConfigCode code = new ConfigCode() {

        @Override
        public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
            SystemApplications sa = (SystemApplications) proxies[0];
            Application app = sa.createChild(Application.class);
            sa.getModules().add(app);
            app.setName(AdminConsoleAdapter.ADMIN_APP_NAME);
            app.setEnabled(Boolean.TRUE.toString());
            // TODO
            app.setObjectType("system-admin");
            app.setDirectoryDeployed("true");
            app.setContextRoot(contextRoot);
            try {
                app.setLocation("${com.sun.aas.installRootURI}/lib/install/applications/" + AdminConsoleAdapter.ADMIN_APP_NAME);
            } catch (Exception me) {
                // can't do anything
                throw new RuntimeException(me);
            }
            Module singleModule = app.createChild(Module.class);
            app.getModule().add(singleModule);
            singleModule.setName(app.getName());
            Engine webe = singleModule.createChild(Engine.class);
            webe.setSniffer("web");
            Engine sece = singleModule.createChild(Engine.class);
            sece.setSniffer("security");
            singleModule.getEngines().add(webe);
            singleModule.getEngines().add(sece);
            Server s = (Server) proxies[1];
            List<ApplicationRef> arefs = s.getApplicationRef();
            ApplicationRef aref = s.createChild(ApplicationRef.class);
            aref.setRef(app.getName());
            aref.setEnabled(Boolean.TRUE.toString());
            // TODO
            aref.setVirtualServers(getVirtualServerList());
            arefs.add(aref);
            return true;
        }
    };
    Server server = domain.getServerNamed(env.getInstanceName());
    ConfigSupport.apply(code, domain.getSystemApplications(), server);
    // Set the adapter state
    adapter.setStateMsg(AdapterState.APPLICATION_INSTALLED_BUT_NOT_LOADED);
    if (log.isLoggable(Level.FINE)) {
        log.log(Level.FINE, "Admin Console Application Installed.");
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) PropertyVetoException(java.beans.PropertyVetoException)

Example 12 with ConfigCode

use of org.jvnet.hk2.config.ConfigCode in project Payara by payara.

the class WebContainerImpl method removeListener.

private void removeListener(String name) {
    try {
        NetworkListeners networkListeners = networkConfig.getNetworkListeners();
        final NetworkListener listenerToBeRemoved = networkConfig.getNetworkListener(name);
        final Protocols protocols = networkConfig.getProtocols();
        final Protocol protocol = networkConfig.findProtocol(name);
        if (listenerToBeRemoved == null) {
            log.severe("Network Listener " + name + " doesn't exist");
        } else {
            final com.sun.enterprise.config.serverbeans.VirtualServer virtualServer = httpService.getVirtualServerByName(listenerToBeRemoved.findHttpProtocol().getHttp().getDefaultVirtualServer());
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final NetworkListeners listeners = (NetworkListeners) params[0];
                    final com.sun.enterprise.config.serverbeans.VirtualServer server = (com.sun.enterprise.config.serverbeans.VirtualServer) params[1];
                    listeners.getNetworkListener().remove(listenerToBeRemoved);
                    server.removeNetworkListener(listenerToBeRemoved.getName());
                    return listenerToBeRemoved;
                }
            }, networkListeners, virtualServer);
            ConfigSupport.apply(new ConfigCode() {

                public Object run(ConfigBeanProxy... params) throws PropertyVetoException {
                    final Protocols protocols = (Protocols) params[0];
                    final Protocol protocol = (Protocol) params[1];
                    protocols.getProtocol().remove(protocol);
                    return protocol;
                }
            }, protocols, protocol);
        }
    } catch (TransactionFailure e) {
        log.severe("Remove listener " + name + " failed " + e.getMessage());
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Protocol(org.glassfish.grizzly.config.dom.Protocol) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)10 ConfigCode (org.jvnet.hk2.config.ConfigCode)10 PropertyVetoException (java.beans.PropertyVetoException)9 ActionReport (org.glassfish.api.ActionReport)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 Config (com.sun.enterprise.config.serverbeans.Config)4 Server (com.sun.enterprise.config.serverbeans.Server)4 ArrayList (java.util.ArrayList)4 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)4 Application (com.sun.enterprise.config.serverbeans.Application)3 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 CommandTarget (org.glassfish.config.support.CommandTarget)3 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)3 Protocols (org.glassfish.grizzly.config.dom.Protocols)3 Target (org.glassfish.internal.api.Target)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)2 SystemApplications (com.sun.enterprise.config.serverbeans.SystemApplications)2 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)2 Logger (java.util.logging.Logger)2