Search in sources :

Example 1 with SystemProperty

use of com.sun.enterprise.config.serverbeans.SystemProperty 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 2 with SystemProperty

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

the class OSGIConsoleHandlers method getConsoleUrl.

@Handler(id = "getConsoleUrl", input = { @HandlerInput(name = "instanceName", type = String.class, required = true) }, output = { @HandlerOutput(name = "consoleUrl", type = String.class) })
public static void getConsoleUrl(HandlerContext handlerCtx) {
    String instanceName = (String) handlerCtx.getInputValue("instanceName");
    Domain domain = Globals.get(Domain.class);
    Server server = domain.getServerNamed(instanceName);
    String port = null;
    SystemProperty httpPort = server.getSystemProperty(http_port);
    if (httpPort != null) {
        port = httpPort.getValue();
    } else {
        // if port is not set as system property, get it from config
        Config cfg = server.getConfig();
        SystemProperty httpConfigPort = cfg.getSystemProperty(http_port);
        if (httpConfigPort != null) {
            port = httpConfigPort.getValue();
        }
    }
    if (port == null) {
        throw new RuntimeException("Not able to get HTTP_LISTENER_PORT " + "for instance : " + instanceName);
    }
    Node node = domain.getNodeNamed(server.getNodeRef());
    String host = node.getNodeHost();
    String consoleUrl = "http://" + host + ":" + port + consolePath;
    handlerCtx.setOutputValue("consoleUrl", consoleUrl);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) Node(com.sun.enterprise.config.serverbeans.Node) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with SystemProperty

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

the class TypedListenerTest method multipleListeners.

@Test
public void multipleListeners() throws TransactionFailure {
    final Domain domain = getHabitat().getService(Domain.class);
    final ConfigListener configListener1 = new ConfigListener() {

        @Override
        public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
            listenersInvoked.incrementAndGet();
            return null;
        }
    };
    final ConfigListener configListener2 = new ConfigListener() {

        @Override
        public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
            listenersInvoked.incrementAndGet();
            return null;
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addListenerForType(SystemProperty.class, configListener1);
        transactions.addListenerForType(SystemProperty.class, configListener2);
        assertTrue(domain != null);
        // adding
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            @Override
            public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                SystemProperty prop = domain.createChild(SystemProperty.class);
                domain.getSystemProperty().add(prop);
                prop.setName("Jerome");
                prop.setValue("was here");
                return prop;
            }
        }, domain);
        transactions.waitForDrain();
        assertTrue(listenersInvoked.intValue() == 2);
    } finally {
        assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener1));
        assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener2));
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 4 with SystemProperty

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

the class TypedListenerTest method addElementTest.

@Test
public void addElementTest() throws TransactionFailure {
    final Domain domain = getHabitat().getService(Domain.class);
    final ConfigListener configListener = new ConfigListener() {

        @Override
        public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
            events = Arrays.asList(propertyChangeEvents);
            return null;
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addListenerForType(SystemProperty.class, configListener);
        assertTrue(domain != null);
        // adding
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            @Override
            public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                SystemProperty prop = domain.createChild(SystemProperty.class);
                domain.getSystemProperty().add(prop);
                prop.setName("Jerome");
                prop.setValue("was here");
                return prop;
            }
        }, domain);
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.log(Level.FINE, "Number of events {0}", events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            logger.fine(event.toString());
        }
        events = null;
        // modification
        for (SystemProperty prop : domain.getSystemProperty()) {
            if (prop.getName().equals("Jerome")) {
                ConfigSupport.apply(new SingleConfigCode<SystemProperty>() {

                    @Override
                    public Object run(SystemProperty param) throws PropertyVetoException, TransactionFailure {
                        param.setValue("was also here");
                        return null;
                    }
                }, prop);
                break;
            }
        }
        assertTrue(events != null);
        logger.log(Level.FINE, "Number of events {0}", events.size());
        assertTrue(events.size() == 1);
        for (PropertyChangeEvent event : events) {
            logger.fine(event.toString());
        }
        events = null;
        // removal
        assertNotNull(ConfigSupport.apply(new SingleConfigCode<Domain>() {

            @Override
            public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                for (SystemProperty prop : domain.getSystemProperty()) {
                    if (prop.getName().equals("Jerome")) {
                        domain.getSystemProperty().remove(prop);
                        return prop;
                    }
                }
                return null;
            }
        }, domain));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.log(Level.FINE, "Number of events {0}", events.size());
        assertTrue(events.size() == 1);
        for (PropertyChangeEvent event : events) {
            logger.fine(event.toString());
        }
    } finally {
        assertTrue(transactions.removeListenerForType(SystemProperty.class, configListener));
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) PropertyChangeEvent(java.beans.PropertyChangeEvent) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 5 with SystemProperty

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

the class PortBaseHelper method setSystemProperty.

private void setSystemProperty(String name, String value) throws TransactionFailure, PropertyVetoException {
    SystemProperty sp = _server.getSystemProperty(name);
    if (sp == null) {
        SystemProperty newSP = _server.createChild(SystemProperty.class);
        newSP.setName(name);
        newSP.setValue(value);
        _server.getSystemProperty().add(newSP);
    } else {
    // Don't change the system property if it already exists - leave the original port assignment
    // sp.setName(name);
    // sp.setValue(value);
    }
}
Also used : SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Aggregations

SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)18 PropertyVetoException (java.beans.PropertyVetoException)5 Domain (com.sun.enterprise.config.serverbeans.Domain)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 Server (com.sun.enterprise.config.serverbeans.Server)3 ActionReport (org.glassfish.api.ActionReport)3 Config (com.sun.enterprise.config.serverbeans.Config)2 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 Node (com.sun.enterprise.config.serverbeans.Node)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)2 ArrayList (java.util.ArrayList)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Test (org.junit.Test)2 Changed (org.jvnet.hk2.config.Changed)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2 NotProcessed (org.jvnet.hk2.config.NotProcessed)2 Property (org.jvnet.hk2.config.types.Property)2 ConfigCustomizationToken (com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)1