Search in sources :

Example 1 with ConfigBeanProxy

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

the class CreateNetworkListener 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();
    NetworkConfig networkConfig = config.getNetworkConfig();
    NetworkListeners nls = networkConfig.getNetworkListeners();
    // ensure we don't have one of this name already
    for (NetworkListener networkListener : nls.getNetworkListener()) {
        if (networkListener.getName().equals(listenerName)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_DUPLICATE), listenerName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (!verifyUniquePort(networkConfig)) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.PORT_IN_USE), port, address));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    Protocol prot = networkConfig.findProtocol(protocol);
    if (prot == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocol));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (prot.getHttp() == null && prot.getPortUnification() == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_BAD_PROTOCOL), protocol));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new ConfigCode() {

            public Object run(ConfigBeanProxy... params) throws TransactionFailure, PropertyVetoException {
                NetworkListeners listeners = (NetworkListeners) params[0];
                NetworkListener newNetworkListener = listeners.createChild(NetworkListener.class);
                newNetworkListener.setProtocol(protocol);
                newNetworkListener.setTransport(transport);
                newNetworkListener.setEnabled(enabled.toString());
                newNetworkListener.setJkEnabled(jkEnabled.toString());
                newNetworkListener.setPort(port);
                newNetworkListener.setThreadPool(threadPool);
                newNetworkListener.setName(listenerName);
                newNetworkListener.setAddress(address);
                listeners.getNetworkListener().add(newNetworkListener);
                ((VirtualServer) params[1]).addNetworkListener(listenerName);
                return newNetworkListener;
            }
        }, nls, findVirtualServer(prot));
    } catch (TransactionFailure e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with ConfigBeanProxy

use of org.jvnet.hk2.config.ConfigBeanProxy 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 3 with ConfigBeanProxy

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

the class RestMonitoringLoader method createAndRegisterApplication.

/**
 * Create the system application entry and register the application
 * @throws Exception
 */
private void createAndRegisterApplication() throws Exception {
    LOGGER.log(Level.FINE, "Registering the Rest Monitoring Application...");
    // Create the system application entry and application-ref in the config
    ConfigCode code = new ConfigCode() {

        @Override
        public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
            // Create the system application
            SystemApplications systemApplications = (SystemApplications) proxies[0];
            Application application = systemApplications.createChild(Application.class);
            // Check if the application name is valid, generating a new one if it isn't
            checkAndResolveApplicationName(systemApplications);
            systemApplications.getModules().add(application);
            application.setName(applicationName);
            application.setEnabled(Boolean.TRUE.toString());
            application.setObjectType("system-admin");
            application.setDirectoryDeployed("true");
            application.setContextRoot(contextRoot);
            try {
                application.setLocation("${com.sun.aas.installRootURI}/lib/install/applications/" + RestMonitoringService.DEFAULT_REST_MONITORING_APP_NAME);
            } catch (Exception me) {
                throw new RuntimeException(me);
            }
            // Set the engine types
            Module singleModule = application.createChild(Module.class);
            application.getModule().add(singleModule);
            singleModule.setName(applicationName);
            Engine webEngine = singleModule.createChild(Engine.class);
            webEngine.setSniffer("web");
            Engine weldEngine = singleModule.createChild(Engine.class);
            weldEngine.setSniffer("weld");
            Engine securityEngine = singleModule.createChild(Engine.class);
            securityEngine.setSniffer("security");
            singleModule.getEngines().add(webEngine);
            singleModule.getEngines().add(weldEngine);
            singleModule.getEngines().add(securityEngine);
            // Create the application-ref
            Server s = (Server) proxies[1];
            List<ApplicationRef> arefs = s.getApplicationRef();
            ApplicationRef aref = s.createChild(ApplicationRef.class);
            aref.setRef(application.getName());
            aref.setEnabled(Boolean.TRUE.toString());
            aref.setVirtualServers(getVirtualServerListAsString());
            arefs.add(aref);
            return true;
        }
    };
    Server server = domain.getServerNamed(serverEnv.getInstanceName());
    ConfigSupport.apply(code, domain.getSystemApplications(), server);
    LOGGER.log(Level.FINE, "Rest Monitoring Application Registered.");
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Server(com.sun.enterprise.config.serverbeans.Server) ConfigCode(org.jvnet.hk2.config.ConfigCode) SystemApplications(com.sun.enterprise.config.serverbeans.SystemApplications) Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef) PropertyVetoException(java.beans.PropertyVetoException) Engine(com.sun.enterprise.config.serverbeans.Engine)

Example 4 with ConfigBeanProxy

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

the class RestMonitoringLoader method registerApplication.

private void registerApplication() throws Exception {
    LOGGER.log(Level.FINE, "Registering the Rest Monitoring Application...");
    // Create the application-ref entry in the domain.xml
    ConfigCode code = new ConfigCode() {

        @Override
        public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
            // Get the system application config
            SystemApplications systemApplications = (SystemApplications) proxies[0];
            Application application = null;
            for (Application systemApplication : systemApplications.getApplications()) {
                if (systemApplication.getName().equals(applicationName)) {
                    application = systemApplication;
                    break;
                }
            }
            if (application == null) {
                throw new IllegalStateException("The Rest Monitoring application has no system app entry!");
            }
            // Create the application-ref
            Server s = (Server) proxies[1];
            List<ApplicationRef> arefs = s.getApplicationRef();
            ApplicationRef aref = s.createChild(ApplicationRef.class);
            aref.setRef(application.getName());
            aref.setEnabled(Boolean.TRUE.toString());
            aref.setVirtualServers(getVirtualServerListAsString());
            arefs.add(aref);
            return true;
        }
    };
    Server server = domain.getServerNamed(serverEnv.getInstanceName());
    ConfigSupport.apply(code, domain.getSystemApplications(), server);
    // Update the adapter state
    LOGGER.log(Level.FINE, "Rest Monitoring Application Registered.");
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Server(com.sun.enterprise.config.serverbeans.Server) ConfigCode(org.jvnet.hk2.config.ConfigCode) SystemApplications(com.sun.enterprise.config.serverbeans.SystemApplications) Application(com.sun.enterprise.config.serverbeans.Application) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 5 with ConfigBeanProxy

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

the class RestMonitoringLoader method reconfigureSystemApplication.

private void reconfigureSystemApplication() throws Exception {
    Application systemApplication = restMonitoringAdapter.getSystemApplicationConfig();
    LOGGER.log(Level.FINE, "Reconfiguring the Rest Monitoring Application...");
    // Reconfigure the system-application entry in the domain.xml
    ConfigCode code = new ConfigCode() {

        @Override
        public Object run(ConfigBeanProxy... proxies) throws PropertyVetoException, TransactionFailure {
            Application systemApplication = (Application) proxies[0];
            systemApplication.setContextRoot(contextRoot);
            return true;
        }
    };
    ConfigSupport.apply(code, systemApplication);
    LOGGER.log(Level.FINE, "Rest Monitoring Application Reconfigured.");
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCode(org.jvnet.hk2.config.ConfigCode) Application(com.sun.enterprise.config.serverbeans.Application)

Aggregations

ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)41 PropertyVetoException (java.beans.PropertyVetoException)21 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)14 Method (java.lang.reflect.Method)11 ArrayList (java.util.ArrayList)11 ConfigCode (org.jvnet.hk2.config.ConfigCode)10 Config (com.sun.enterprise.config.serverbeans.Config)8 Server (com.sun.enterprise.config.serverbeans.Server)6 IOException (java.io.IOException)6 List (java.util.List)6 ActionReport (org.glassfish.api.ActionReport)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocol (org.glassfish.grizzly.config.dom.Protocol)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigModel (org.jvnet.hk2.config.ConfigModel)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 ConfigBean (org.jvnet.hk2.config.ConfigBean)5 Property (org.jvnet.hk2.config.types.Property)5