Search in sources :

Example 26 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteProtocolFilter 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();
    try {
        final Protocols protocols = config.getNetworkConfig().getProtocols();
        final Protocol protocol = protocols.findProtocol(protocolName);
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        ProtocolChainInstanceHandler handler = getHandler(protocol);
        ProtocolChain chain = getChain(handler);
        ConfigSupport.apply(new SingleConfigCode<ProtocolChain>() {

            @Override
            public Object run(ProtocolChain param) throws PropertyVetoException, TransactionFailure {
                final List<ProtocolFilter> list = param.getProtocolFilter();
                List<ProtocolFilter> newList = new ArrayList<ProtocolFilter>();
                for (final ProtocolFilter filter : list) {
                    if (!name.equals(filter.getName())) {
                        newList.add(filter);
                    }
                }
                if (list.size() == newList.size()) {
                    throw new RuntimeException(String.format("No filter named %s found for protocol %s", name, protocolName));
                }
                param.setProtocolFilter(newList);
                return null;
            }
        }, chain);
        cleanChain(chain);
        cleanHandler(handler);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_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) Config(com.sun.enterprise.config.serverbeans.Config) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ProtocolChainInstanceHandler(org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler) ProtocolChain(org.glassfish.grizzly.config.dom.ProtocolChain) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol) ProtocolFilter(org.glassfish.grizzly.config.dom.ProtocolFilter)

Example 27 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class ListHttpListeners 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();
    int size = 0;
    for (NetworkListener networkListener : list) {
        size = Math.max(size, networkListener.getName().length());
    }
    final String format = "%-" + (size + 2) + "s %-6s";
    if (verbose) {
        report.getTopMessagePart().addChild().setMessage(String.format(format, "NAME", "PORT"));
    }
    for (NetworkListener listener : list) {
        if (listener.findHttpProtocol().getHttp() != null) {
            report.getTopMessagePart().addChild().setMessage(String.format(format, listener.getName(), verbose ? listener.getPort() : ""));
        }
    }
    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)

Example 28 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class CreateHttpRedirect method execute.

// ----------------------------------------------- Methods from AdminCommand
@Override
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.getHttpRedirect() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                HttpRedirect httpRedirect = param.createChild(HttpRedirect.class);
                httpRedirect.setPort(port);
                httpRedirect.setSecure(secure);
                param.setHttpRedirect(httpRedirect);
                return httpRedirect;
            }
        }, 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) HttpRedirect(org.glassfish.grizzly.config.dom.HttpRedirect) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 29 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteProtocolFinder 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();
    try {
        final Protocols protocols = config.getNetworkConfig().getProtocols();
        final Protocol protocol = protocols.findProtocol(protocolName);
        validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
        PortUnification pu = getPortUnification(protocol);
        ConfigSupport.apply(new ConfigCode() {

            @Override
            public Object run(ConfigBeanProxy... params) {
                final Protocol prot = (Protocol) params[0];
                final PortUnification portUnification = (PortUnification) params[1];
                final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
                List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
                for (final ProtocolFinder finder : oldList) {
                    if (!name.equals(finder.getName())) {
                        newList.add(finder);
                    }
                }
                if (oldList.size() == newList.size()) {
                    throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
                }
                if (newList.isEmpty()) {
                    prot.setPortUnification(null);
                } else {
                    portUnification.setProtocolFinder(newList);
                }
                return null;
            }
        }, protocol, pu);
        cleanPortUnification(pu);
    } catch (ValidationFailureException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) PortUnification(org.glassfish.grizzly.config.dom.PortUnification) Config(com.sun.enterprise.config.serverbeans.Config) ProtocolFinder(org.glassfish.grizzly.config.dom.ProtocolFinder) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ConfigCode(org.jvnet.hk2.config.ConfigCode) ArrayList(java.util.ArrayList) List(java.util.List) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 30 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class DeleteVirtualServer 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;
    }
    ActionReport report = context.getActionReport();
    httpService = config.getHttpService();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_NOT_EXISTS), vsid));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    // reference check
    String referencedBy = getReferencingListener();
    if (referencedBy != null && referencedBy.length() != 0) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_REFERENCED), vsid, referencedBy));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        // we need to determine which deployed applications reference this virtual-server
        List<ApplicationRef> appRefs = new ArrayList<ApplicationRef>();
        for (ApplicationRef appRef : server.getApplicationRef()) {
            if (appRef.getVirtualServers() != null && appRef.getVirtualServers().contains(vsid)) {
                appRefs.add(appRef);
            }
        }
        // transfer into the array of arguments
        ConfigBeanProxy[] proxies = new ConfigBeanProxy[appRefs.size() + 1];
        proxies[0] = httpService;
        for (int i = 0; i < appRefs.size(); i++) {
            proxies[i + 1] = appRefs.get(i);
        }
        ConfigSupport.apply(new ConfigUpdate(vsid), proxies);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_FAIL), vsid));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Aggregations

Target (org.glassfish.internal.api.Target)39 CommandTarget (org.glassfish.config.support.CommandTarget)35 Config (com.sun.enterprise.config.serverbeans.Config)32 ActionReport (org.glassfish.api.ActionReport)32 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyVetoException (java.beans.PropertyVetoException)11 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)9 List (java.util.List)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 Logger (java.util.logging.Logger)3 Inject (javax.inject.Inject)3 I18n (org.glassfish.api.I18n)3 Param (org.glassfish.api.Param)3