Search in sources :

Example 96 with TransactionFailure

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

the class CreateSsl method addSslToJMXConnector.

private void addSslToJMXConnector(Config config, ActionReport report) {
    AdminService adminService = config.getAdminService();
    // ensure we have the specified listener
    JmxConnector jmxConnector = null;
    for (JmxConnector jmxConn : adminService.getJmxConnector()) {
        if (jmxConn.getName().equals(listenerId)) {
            jmxConnector = jmxConn;
        }
    }
    if (jmxConnector == null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.notfound", "JMX Connector named {0} to which this ssl element is " + "being added does not exist.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (jmxConnector.getSsl() != null) {
        report.setMessage(localStrings.getLocalString("create.ssl.jmx.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", listenerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

            @Override
            public Object run(JmxConnector param) throws PropertyVetoException, TransactionFailure {
                Ssl newSsl = param.createChild(Ssl.class);
                populateSslElement(newSsl);
                param.setSsl(newSsl);
                return newSsl;
            }
        }, jmxConnector);
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
    reportSuccess(report);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AdminService(com.sun.enterprise.config.serverbeans.AdminService) JmxConnector(com.sun.enterprise.config.serverbeans.JmxConnector) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Example 97 with TransactionFailure

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

the class DeleteSsl 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) {
    ActionReport report = context.getActionReport();
    Target targetUtil = habitat.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    if (!type.equals("iiop-service")) {
        if (listenerId == null) {
            report.setMessage(localStrings.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        SslConfigHandler sslConfigHandler = habitat.getService(SslConfigHandler.class, type);
        if (sslConfigHandler != null) {
            sslConfigHandler.delete(this, report);
        } else if ("jmx-connector".equals(type)) {
            JmxConnector jmxConnector = null;
            for (JmxConnector listener : config.getAdminService().getJmxConnector()) {
                if (listener.getName().equals(listenerId)) {
                    jmxConnector = listener;
                }
            }
            if (jmxConnector == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.jmx.connector.notfound", "Iiop Listener named {0} not found", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (jmxConnector.getSsl() == null) {
                report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", listenerId));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {

                public Object run(JmxConnector param) throws PropertyVetoException {
                    param.setSsl(null);
                    return null;
                }
            }, jmxConnector);
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (TransactionFailure e) {
        reportError(report, e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport)

Example 98 with TransactionFailure

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

the class ProtocolSslConfigHandler method delete.

@Override
public void delete(final DeleteSsl command, final ActionReport report) {
    try {
        NetworkConfig networkConfig = command.config.getNetworkConfig();
        final Protocol protocol = networkConfig.findProtocol(command.listenerId);
        if (protocol != null) {
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                public Object run(Protocol param) {
                    param.setSecurityEnabled("false");
                    param.setSsl(null);
                    return null;
                }
            }, protocol);
        }
    } catch (TransactionFailure transactionFailure) {
        command.reportError(report, transactionFailure);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 99 with TransactionFailure

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

the class SetConfigOrdinal method execute.

@Override
public void execute(AdminCommandContext context) {
    Config configVal = targetUtil.getConfig(target);
    MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
    if (serviceConfig != null) {
        try {
            // to perform a transaction on the domain.xml you need to use this construct
            // see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
            ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {

                @Override
                public Object run(MicroprofileConfigConfiguration config) {
                    switch(source) {
                        case "domain":
                            {
                                config.setDomainOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "config":
                            {
                                config.setConfigOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "server":
                            {
                                config.setServerOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "application":
                            {
                                config.setApplicationOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "module":
                            {
                                config.setModuleOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "cluster":
                            {
                                config.setClusterOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "jndi":
                            {
                                config.setJNDIOrdinality(Integer.toString(ordinal));
                                break;
                            }
                        case "secrets":
                            {
                                config.setSecretDirOrdinality(Integer.toString(ordinal));
                                break;
                            }
                    }
                    return null;
                }
            }, serviceConfig);
        } catch (TransactionFailure ex) {
            // set failure
            context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "Failed to update message", ex);
        }
    } else {
        context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) MicroprofileConfigConfiguration(fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration) Config(com.sun.enterprise.config.serverbeans.Config)

Example 100 with TransactionFailure

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

the class ConfigConfigSource method setValue.

public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
    boolean success = false;
    Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
    if (config != null) {
        Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
        if (p == null) {
            ConfigSupport.apply(new SingleConfigCode<Config>() {

                @Override
                public Object run(Config config) throws TransactionFailure, PropertyVetoException {
                    Property prop = config.createChild(Property.class);
                    prop.setName(PROPERTY_PREFIX + propertyName);
                    prop.setValue(propertyValue);
                    config.getProperty().add(prop);
                    return null;
                }
            }, config);
        } else {
            ConfigSupport.apply(new SingleConfigCode<Property>() {

                @Override
                public Object run(Property config) throws TransactionFailure, PropertyVetoException {
                    config.setValue(propertyValue);
                    return null;
                }
            }, p);
        }
        success = true;
    }
    return success;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) Config(com.sun.enterprise.config.serverbeans.Config) Property(org.jvnet.hk2.config.types.Property)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)191 PropertyVetoException (java.beans.PropertyVetoException)132 ActionReport (org.glassfish.api.ActionReport)86 Property (org.jvnet.hk2.config.types.Property)61 Config (com.sun.enterprise.config.serverbeans.Config)52 HashMap (java.util.HashMap)30 Test (org.junit.Test)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 Map (java.util.Map)25 List (java.util.List)21 CommandTarget (org.glassfish.config.support.CommandTarget)21 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Target (org.glassfish.internal.api.Target)21 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)20 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 ConfigBean (org.jvnet.hk2.config.ConfigBean)20 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)18 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 ParameterMap (org.glassfish.api.admin.ParameterMap)14