Search in sources :

Example 1 with Config

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

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

Example 3 with Config

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

the class DeleteTransport 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();
    NetworkConfig networkConfig = config.getNetworkConfig();
    Transports transports = networkConfig.getTransports();
    try {
        for (Transport transport : transports.getTransport()) {
            if (transportName.equalsIgnoreCase(transport.getName())) {
                transportToBeRemoved = transport;
            }
        }
        if (transportToBeRemoved == null) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_NOT_EXISTS), transportName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        // check if the transport to be deleted is being used by
        // any network listener
        List<NetworkListener> nwlsnrList = transportToBeRemoved.findNetworkListeners();
        for (NetworkListener nwlsnr : nwlsnrList) {
            if (transportToBeRemoved.getName().equals(nwlsnr.getTransport())) {
                report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_BEINGUSED), transportName, nwlsnr.getName()));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
        ConfigSupport.apply(new SingleConfigCode<Transports>() {

            public Object run(Transports param) {
                param.getTransport().remove(transportToBeRemoved);
                return transportToBeRemoved;
            }
        }, transports);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_TRANSPORT_FAIL), transportName) + "  " + e.getLocalizedMessage());
        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) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Transports(org.glassfish.grizzly.config.dom.Transports) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) Transport(org.glassfish.grizzly.config.dom.Transport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 4 with Config

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

the class GetHttpListener method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
    if (!optionalListener.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
        return;
    }
    NetworkListener listener = optionalListener.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", listener.getName()));
    report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
    report.appendMessage(String.format("Port: %s\n", listener.getPort()));
    report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
    report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
    if (verbose) {
        report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
        report.appendMessage(String.format("Type: %s\n", listener.getType()));
        report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
        report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
        report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", listener.getName());
    properties.put("enabled", listener.getEnabled());
    properties.put("port", listener.getPort());
    properties.put("address", listener.getAddress());
    properties.put("protocol", listener.getProtocol());
    properties.put("transport", listener.getTransport());
    properties.put("type", listener.getType());
    properties.put("threadPool", listener.getThreadPool());
    properties.put("jkEnabled", listener.getJkEnabled());
    properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with Config

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

the class ListNetworkListeners 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();
    List<NetworkListener> list = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    for (NetworkListener networkListener : list) {
        report.getTopMessagePart().addChild().setMessage(networkListener.getName());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10