Search in sources :

Example 56 with Config

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

the class DeleteLogLevel method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    boolean isCluster = false;
    boolean isDas = false;
    boolean isInstance = false;
    StringBuffer successMsg = new StringBuffer();
    boolean isConfig = false;
    boolean success = false;
    String targetConfigName = "";
    Map<String, String> m = new HashMap<String, String>();
    try {
        String[] loggerNames = properties.split("(?<!\\\\):");
        for (final Object key : loggerNames) {
            final String logger_name = (String) key;
            m.put(logger_name + ".level", null);
        }
        Config config = domain.getConfigNamed(target);
        if (config != null) {
            targetConfigName = target;
            isConfig = true;
            Server targetServer = domain.getServerNamed(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME);
            if (targetServer != null && targetServer.getConfigRef().equals(target)) {
                isDas = true;
            }
            targetServer = null;
        } else {
            Server targetServer = domain.getServerNamed(target);
            if (targetServer != null && targetServer.isDas()) {
                isDas = true;
            } else {
                com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
                if (cluster != null) {
                    isCluster = true;
                    targetConfigName = cluster.getConfigRef();
                } else if (targetServer != null) {
                    isInstance = true;
                    targetConfigName = targetServer.getConfigRef();
                }
            }
            if (isInstance) {
                Cluster clusterForInstance = targetServer.getCluster();
                if (clusterForInstance != null) {
                    targetConfigName = clusterForInstance.getConfigRef();
                }
            }
        }
        if (isCluster || isInstance) {
            loggingConfig.deleteLoggingProperties(m, targetConfigName);
            success = true;
        } else if (isDas) {
            loggingConfig.deleteLoggingProperties(m);
            success = true;
        } else if (isConfig) {
            // This loop is for the config which is not part of any target
            loggingConfig.deleteLoggingProperties(m, targetConfigName);
            success = true;
        } else {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            String msg = localStrings.getLocalString("invalid.target.sys.props", "Invalid target: {0}. Valid default target is a server named ''server'' (default) or cluster name.", target);
            report.setMessage(msg);
            return;
        }
        if (success) {
            successMsg.append(localStrings.getLocalString("delete.log.level.success", "These logging levels are deleted for {0}.", target));
            report.setMessage(successMsg.toString());
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (IOException e) {
        report.setMessage(localStrings.getLocalString("delete.log.level.failed", "Could not delete logger levels for {0}.", target));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) Cluster(com.sun.enterprise.config.serverbeans.Cluster) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 57 with Config

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

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

Example 59 with Config

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

the class ConfigConfigSource method deleteValue.

public boolean deleteValue(String propertyName) throws TransactionFailure {
    boolean result = false;
    Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
    if (config != null) {
        for (Property object : config.getProperty()) {
            if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
                ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(config), (ConfigBean) ConfigBean.unwrap(object));
                result = true;
            }
        }
    }
    return result;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) Property(org.jvnet.hk2.config.types.Property)

Example 60 with Config

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

the class ConfigConfigSource method getValue.

@Override
public String getValue(String propertyName) {
    String result = null;
    Config config = domainConfiguration.getConfigs().getConfigByName(configurationName);
    if (config != null) {
        result = config.getPropertyValue(PROPERTY_PREFIX + propertyName);
    }
    return result;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config)

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