Search in sources :

Example 16 with Target

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

the class ListTransports 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();
    List<Transport> list = config.getNetworkConfig().getTransports().getTransport();
    for (Transport transport : list) {
        report.getTopMessagePart().addChild().setMessage(transport.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) Transport(org.glassfish.grizzly.config.dom.Transport)

Example 17 with Target

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

the class ResourceUtil method deleteResourceRef.

public void deleteResourceRef(String jndiName, String target) throws TransactionFailure {
    if (target.equals(DOMAIN)) {
        return;
    }
    Config config = domain.getConfigNamed(target);
    if (config != null) {
        config.deleteResourceRef(jndiName);
    } else {
        Server server = configBeansUtilities.getServerNamed(target);
        if (server != null) {
            if (server.isResourceRefExists(jndiName)) {
                // delete ResourceRef for Server
                server.deleteResourceRef(jndiName);
            }
        } else {
            Cluster cluster = domain.getClusterNamed(target);
            if (cluster != null) {
                if (cluster.isResourceRefExists(jndiName)) {
                    // delete ResourceRef of Cluster
                    cluster.deleteResourceRef(jndiName);
                    // delete ResourceRef for all instances of Cluster
                    Target tgt = targetProvider.get();
                    List<Server> instances = tgt.getInstances(target);
                    for (Server svr : instances) {
                        if (svr.isResourceRefExists(jndiName)) {
                            svr.deleteResourceRef(jndiName);
                        }
                    }
                }
            }
        }
    }
}
Also used : Target(org.glassfish.internal.api.Target)

Example 18 with Target

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

the class DeleteIiopListener 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
 */
@Override
public void execute(AdminCommandContext context) {
    final Target targetUtil = services.getService(Target.class);
    final Config config = targetUtil.getConfig(target);
    ActionReport report = context.getActionReport();
    IiopService iiopService = config.getExtensionByType(IiopService.class);
    if (!isIIOPListenerExists(iiopService)) {
        report.setMessage(localStrings.getLocalString("delete.iiop.listener" + ".notexists", "IIOP Listener {0} does not exist.", listener_id));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopService>() {

            @Override
            public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
                List<IiopListener> listenerList = param.getIiopListener();
                for (IiopListener listener : listenerList) {
                    String currListenerId = listener.getId();
                    if (currListenerId != null && currListenerId.equals(listener_id)) {
                        listenerList.remove(listener);
                        break;
                    }
                }
                return listenerList;
            }
        }, iiopService);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        String actual = e.getMessage();
        report.setMessage(localStrings.getLocalString("delete.iiop.listener.fail", "failed", listener_id, actual));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IiopListener(org.glassfish.orb.admin.config.IiopListener) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) List(java.util.List) ActionReport(org.glassfish.api.ActionReport)

Example 19 with Target

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

the class CreateIiopListener 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
 */
@Override
public void execute(AdminCommandContext context) {
    final Target targetUtil = services.getService(Target.class);
    final Config config = targetUtil.getConfig(target);
    final ActionReport report = context.getActionReport();
    IiopService iiopService = config.getExtensionByType(IiopService.class);
    // check port uniqueness, only for same address
    for (IiopListener listener : iiopService.getIiopListener()) {
        if (listener.getId().equals(listener_id)) {
            String ls = localStrings.getLocalString("create.iiop.listener.duplicate", "IIOP Listener named {0} already exists.", listener_id);
            report.setMessage(ls);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (listener.getAddress().trim().equals(listeneraddress) && listener.getPort().trim().equals((iiopport))) {
            String def = "Port [{0}] is already taken by another listener: " + "[{1}] for address [{2}], choose another port.";
            String ls = localStrings.getLocalString("create.iiop.listener.port.occupied", def, iiopport, listener.getId(), listeneraddress);
            report.setMessage(ls);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopService>() {

            @Override
            public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
                IiopListener newListener = param.createChild(IiopListener.class);
                newListener.setId(listener_id);
                newListener.setAddress(listeneraddress);
                newListener.setPort(iiopport);
                newListener.setSecurityEnabled(securityenabled.toString());
                newListener.setEnabled(enabled.toString());
                newListener.setLazyInit(Boolean.toString(lazyInit));
                // add properties
                if (properties != null) {
                    for (java.util.Map.Entry entry : properties.entrySet()) {
                        Property property = newListener.createChild(Property.class);
                        property.setName((String) entry.getKey());
                        property.setValue((String) entry.getValue());
                        newListener.getProperty().add(property);
                    }
                }
                param.getIiopListener().add(newListener);
                return newListener;
            }
        }, iiopService);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        String actual = e.getMessage();
        String def = "Creation of: " + listener_id + "failed because of: " + actual;
        String msg = localStrings.getLocalString("create.iiop.listener.fail", def, listener_id, actual);
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : IiopListener(org.glassfish.orb.admin.config.IiopListener) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) IiopService(org.glassfish.orb.admin.config.IiopService) Property(org.jvnet.hk2.config.types.Property)

Example 20 with Target

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

the class ListIiopListeners method execute.

/**
 * Executes the command
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Target targetUtil = services.getService(Target.class);
    final Config config = targetUtil.getConfig(target);
    final IiopService iiopService = config.getExtensionByType(IiopService.class);
    try {
        List<IiopListener> listenerList = iiopService.getIiopListener();
        for (IiopListener listener : listenerList) {
            final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
            part.setMessage(listener.getId());
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("list.iiop.listener" + ".fail", "List IIOP listeners failed."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : IiopListener(org.glassfish.orb.admin.config.IiopListener) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) ActionReport(org.glassfish.api.ActionReport)

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