Search in sources :

Example 26 with org.jvnet.hk2.config

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

the class SetNetworkListenerConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    NetworkListener listener = config.getNetworkConfig().getNetworkListener(listenerName);
    if (!validate(actionReport)) {
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

            @Override
            public Object run(final NetworkListener listenerProxy) throws PropertyVetoException, TransactionFailure {
                if (enabled != null) {
                    listenerProxy.setEnabled(enabled.toString());
                }
                if (address != null) {
                    listenerProxy.setAddress(address);
                }
                if (port != null && !ADMIN_LISTENER.equals(listenerName)) {
                    listenerProxy.setPort(port.toString());
                }
                if (portRange != null) {
                    listenerProxy.setPortRange(portRange);
                }
                if (protocol != null) {
                    listenerProxy.setProtocol(protocol);
                }
                if (threadPool != null) {
                    listenerProxy.setThreadPool(threadPool);
                }
                if (transport != null) {
                    listenerProxy.setTransport(transport);
                }
                if (jkEnabled != null) {
                    listenerProxy.setJkEnabled(jkEnabled.toString());
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return null;
            }
        }, listener);
        String oldPort = listener.getPort();
        if (port != null && ADMIN_LISTENER.equals(listenerName)) {
            UnprocessedChangeEvent unprocessed = new UnprocessedChangeEvent(new PropertyChangeEvent(this, "port", oldPort, port), listener.getName() + " port changed from " + oldPort + " to " + port);
            LOGGER.log(Level.INFO, MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port));
            actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port.toString()));
            List<UnprocessedChangeEvents> unprocessedList = new ArrayList<>();
            unprocessedList.add(new UnprocessedChangeEvents(unprocessed));
            ucl.unprocessedTransactedEvents(unprocessedList);
        }
    } catch (TransactionFailure e) {
        LOGGER.log(Level.SEVERE, null, e);
        actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        actionReport.setFailureCause(e);
        return;
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 27 with org.jvnet.hk2.config

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

the class CreateHttp method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter 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();
    // check for duplicates
    Protocols protocols = config.getNetworkConfig().getProtocols();
    Protocol protocol = null;
    for (Protocol p : protocols.getProtocol()) {
        if (protocolName.equals(p.getName())) {
            protocol = p;
        }
    }
    if (protocol == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (protocol.getHttp() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // Add to the <network-config>
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                Http http = param.createChild(Http.class);
                final FileCache cache = http.createChild(FileCache.class);
                cache.setEnabled("false");
                http.setFileCache(cache);
                http.setDefaultVirtualServer(defaultVirtualServer);
                http.setDnsLookupEnabled(dnsLookupEnabled == null ? null : dnsLookupEnabled.toString());
                http.setMaxConnections(maxConnections);
                http.setRequestTimeoutSeconds(requestTimeoutSeconds);
                http.setTimeoutSeconds(timeoutSeconds);
                http.setXpoweredBy(xPoweredBy == null ? null : xPoweredBy.toString());
                http.setServerHeader(serverHeader == null ? null : serverHeader.toString());
                http.setXframeOptions(xFrameOptions == null ? null : xFrameOptions.toString());
                http.setServerName(serverName);
                // HTTP2 options
                http.setHttp2Enabled(http2Enabled.toString());
                if (http2MaxConcurrentStreams != null) {
                    http.setHttp2MaxConcurrentStreams(http2MaxConcurrentStreams.toString());
                }
                if (http2InitialWindowSizeInBytes != null) {
                    http.setHttp2InitialWindowSizeInBytes(http2InitialWindowSizeInBytes.toString());
                }
                if (http2MaxFramePayloadSizeInBytes != null) {
                    http.setHttp2MaxFramePayloadSizeInBytes(http2MaxFramePayloadSizeInBytes.toString());
                }
                if (http2MaxHeaderListSizeInBytes != null) {
                    http.setHttp2MaxHeaderListSizeInBytes(http2MaxHeaderListSizeInBytes.toString());
                }
                if (http2StreamsHighWaterMark != null) {
                    http.setHttp2StreamsHighWaterMark(http2StreamsHighWaterMark.toString());
                }
                if (http2CleanPercentage != null) {
                    http.setHttp2CleanPercentage(http2CleanPercentage.toString());
                }
                if (http2CleanFrequencyCheck != null) {
                    http.setHttp2CleanFrequencyCheck(http2CleanFrequencyCheck.toString());
                }
                if (http2DisableCipherCheck != null) {
                    http.setHttp2DisableCipherCheck(http2DisableCipherCheck.toString());
                }
                if (http2PushEnabled != null) {
                    http.setHttp2PushEnabled(http2PushEnabled.toString());
                }
                param.setHttp(http);
                return http;
            }
        }, protocol);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName, 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) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) Http(org.glassfish.grizzly.config.dom.Http) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) FileCache(org.glassfish.grizzly.config.dom.FileCache)

Example 28 with org.jvnet.hk2.config

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

the class CreateProtocol 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();
    // check for duplicates
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    for (Protocol protocol : protocols.getProtocol()) {
        if (protocolName != null && protocolName.equalsIgnoreCase(protocol.getName())) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL_DUPLICATE), protocolName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    // Add to the <network-config>
    try {
        create(protocols, protocolName, securityEnabled);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    } catch (Exception e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PROTOCOL_FAIL), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 29 with org.jvnet.hk2.config

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

the class CreateProtocolFinder method execute.

@Override
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    report = context.getActionReport();
    final Protocols protocols = config.getNetworkConfig().getProtocols();
    final Protocol protocol = protocols.findProtocol(protocolName);
    final Protocol target = protocols.findProtocol(targetName);
    try {
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        validate(target, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, targetName);
        final Class<?> finderClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
        if (!org.glassfish.grizzly.portunif.ProtocolFinder.class.isAssignableFrom(finderClass)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFINDER), name, classname));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        PortUnification unif = (PortUnification) ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            @Override
            public Object run(Protocol param) throws PropertyVetoException, TransactionFailure {
                PortUnification pu = param.getPortUnification();
                if (pu == null) {
                    pu = param.createChild(PortUnification.class);
                    param.setPortUnification(pu);
                }
                return pu;
            }
        }, protocol);
        ConfigSupport.apply(new SingleConfigCode<PortUnification>() {

            @Override
            public Object run(PortUnification param) throws PropertyVetoException, TransactionFailure {
                final List<ProtocolFinder> list = param.getProtocolFinder();
                for (ProtocolFinder finder : list) {
                    if (name.equals(finder.getName())) {
                        throw new TransactionFailure(String.format("A protocol finder named %s already exists.", name));
                    }
                }
                final ProtocolFinder finder = param.createChild(ProtocolFinder.class);
                finder.setName(name);
                finder.setProtocol(targetName);
                finder.setClassname(classname);
                list.add(finder);
                return null;
            }
        }, unif);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 30 with org.jvnet.hk2.config

use of org.jvnet.hk2.config 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)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)100 Config (com.sun.enterprise.config.serverbeans.Config)81 ActionReport (org.glassfish.api.ActionReport)79 PropertyVetoException (java.beans.PropertyVetoException)69 Property (org.jvnet.hk2.config.types.Property)53 Properties (java.util.Properties)24 CommandTarget (org.glassfish.config.support.CommandTarget)24 Target (org.glassfish.internal.api.Target)23 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)16 List (java.util.List)16 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)16 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)16 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyChangeEvent (java.beans.PropertyChangeEvent)14 Server (com.sun.enterprise.config.serverbeans.Server)13 IOException (java.io.IOException)12 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 File (java.io.File)10