Search in sources :

Example 1 with Configs

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

the class SystemTasksImpl method getConfigSystemProperties.

private List<SystemProperty> getConfigSystemProperties() {
    try {
        String configName = server.getConfigRef();
        Configs configs = domain.getConfigs();
        List<Config> configsList = configs.getConfig();
        Config config = null;
        for (Config c : configsList) {
            if (c.getName().equals(configName)) {
                config = c;
                break;
            }
        }
        return (List<SystemProperty>) (config != null ? config.getSystemProperty() : Collections.emptyList());
    } catch (Exception e) {
        // possible NPE if domain.xml has issues!
        return Collections.emptyList();
    }
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) Configs(com.sun.enterprise.config.serverbeans.Configs) List(java.util.List)

Example 2 with Configs

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

the class IiopFolbGmsClient method getConfigForServer.

private Config getConfigForServer(Server server) {
    fineLog("getConfigForServer: server {0}", server);
    String configRef = server.getConfigRef();
    fineLog("getConfigForServer: configRef {0}", configRef);
    Configs configs = services.getService(Configs.class);
    fineLog("getConfigForServer: configs {0}", configs);
    Config config = configs.getConfigByName(configRef);
    fineLog("getConfigForServer: config {0}", config);
    return config;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) Configs(com.sun.enterprise.config.serverbeans.Configs)

Example 3 with Configs

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

the class ConfigRefValidator method isValid.

@Override
public boolean isValid(final Named bean, final ConstraintValidatorContext constraintValidatorContext) {
    if (bean == null)
        return true;
    Server server = null;
    Cluster mycluster = null;
    String configRef = null;
    String serverName = null;
    if (bean instanceof Server) {
        server = (Server) bean;
        configRef = server.getConfigRef();
        serverName = server.getName();
    } else if (bean instanceof Cluster) {
        mycluster = (Cluster) bean;
        configRef = mycluster.getConfigRef();
        serverName = mycluster.getName();
    }
    // skip validation @NotNull is already on getConfigRef
    if (configRef == null)
        return true;
    // cannot use default-config
    if (configRef.equals(SystemPropertyConstants.TEMPLATE_CONFIG_NAME)) {
        logger.warning(ConfigApiLoggerInfo.configRefDefaultconfig);
        return false;
    }
    // cannot change config-ref of DAS
    if (server != null) {
        if (server.isDas() && !configRef.equals(SystemPropertyConstants.DAS_SERVER_CONFIG)) {
            logger.warning(ConfigApiLoggerInfo.configRefDASconfig);
            return false;
        }
        // cannot use server-config if not DAS
        if (!server.isDas() && configRef.equals(SystemPropertyConstants.DAS_SERVER_CONFIG)) {
            logger.warning(ConfigApiLoggerInfo.configRefServerconfig);
            return false;
        }
        final Servers servers = server.getParent(Servers.class);
        final Domain domain = servers.getParent(Domain.class);
        final Configs configs = domain.getConfigs();
        if (servers.getServer(serverName) != null) {
            // validate for set, not _register-instance
            // cannot change config ref of a clustered instance
            Cluster cluster = domain.getClusterForInstance(serverName);
            if (cluster != null) {
                // cluster is not null during create-local-instance --cluster c1 i1
                if (!cluster.getConfigRef().equals(configRef)) {
                    // During set when trying to change config-ref of a clustered instance,
                    // the value of desired config-ref will be different than the current config-ref.
                    // During _register-instance, (create-local-instance --cluster c1 i1)
                    // cluster.getConfigRef().equals(configRef) will be true and not come here.
                    logger.warning(ConfigApiLoggerInfo.configRefClusteredInstance);
                    return false;
                }
            }
            // cannot use a non-existent config  (Only used by set.  _register-instance will fail earlier)
            if (configs == null || configs.getConfigByName(configRef) == null) {
                logger.warning(ConfigApiLoggerInfo.configRefNonexistent);
                return false;
            }
        }
    }
    return true;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Configs(com.sun.enterprise.config.serverbeans.Configs) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Servers(com.sun.enterprise.config.serverbeans.Servers) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 4 with Configs

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

the class DeepCopyTest method configCopy.

@Test
public void configCopy() throws Exception {
    final Config config = getHabitat().getService(Config.class);
    Assert.assertNotNull(config);
    String configName = config.getName();
    final Config newConfig = (Config) ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

        @Override
        public Object run(ConfigBeanProxy parent) throws PropertyVetoException, TransactionFailure {
            return config.deepCopy(parent);
        }
    }, config.getParent());
    Assert.assertNotNull(newConfig);
    try {
        newConfig.setName("some-config");
    } catch (Exception e) {
    // I was expecting this...
    }
    ConfigSupport.apply(new SingleConfigCode<Config>() {

        @Override
        public Object run(Config wConfig) throws PropertyVetoException, TransactionFailure {
            wConfig.setName("some-config");
            return null;
        }
    }, newConfig);
    Assert.assertEquals(newConfig.getName(), "some-config");
    Assert.assertEquals(config.getName(), configName);
    // add it the parent
    ConfigSupport.apply(new SingleConfigCode<Configs>() {

        @Override
        public Object run(Configs wConfigs) throws PropertyVetoException, TransactionFailure {
            wConfigs.getConfig().add(newConfig);
            return null;
        }
    }, getHabitat().<Configs>getService(Configs.class));
    String resultingXML = save(document).toString();
    Assert.assertTrue("Expecting some-config, got " + resultingXML, resultingXML.contains("some-config"));
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Config(com.sun.enterprise.config.serverbeans.Config) Configs(com.sun.enterprise.config.serverbeans.Configs) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) Test(org.junit.Test)

Aggregations

Configs (com.sun.enterprise.config.serverbeans.Configs)4 Config (com.sun.enterprise.config.serverbeans.Config)3 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)1 Server (com.sun.enterprise.config.serverbeans.Server)1 Servers (com.sun.enterprise.config.serverbeans.Servers)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 List (java.util.List)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Test (org.junit.Test)1