Search in sources :

Example 46 with Domain

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

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

the class ServerHelper method translateAddressAndPort.

/**
 * @param adminListener
 * @param server
 * @param config
 * @return ret[0] == address, ret[1] == port
 */
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
    NetworkListener adminListenerRaw = null;
    String[] ret = new String[2];
    String portString = null;
    String addressString = null;
    try {
        Dom serverDom = Dom.unwrap(server);
        Domain domain = serverDom.getHabitat().getService(Domain.class);
        adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
        portString = adminListenerRaw.getPort();
        addressString = adminListenerRaw.getAddress();
        PropertyResolver resolver = new PropertyResolver(domain, server.getName());
        if (isToken(portString))
            ret[1] = resolver.getPropertyValue(portString);
        else
            ret[1] = portString;
        if (isToken(addressString))
            ret[0] = resolver.getPropertyValue(addressString);
        else
            ret[0] = addressString;
    } catch (ClassCastException e) {
        // jc: workaround for issue 12354
        // TODO severe error
        ret[0] = translatePortOld(addressString, server, config);
        ret[1] = translatePortOld(portString, server, config);
    }
    return ret;
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) PropertyResolver(org.glassfish.config.support.PropertyResolver) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 48 with Domain

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

the class TraversalTest method traverse.

@Test
public void traverse() {
    ServiceLocator habitat = super.getHabitat();
    Domain domain = Domain.class.cast(habitat.<Domain>getService(Domain.class));
    introspect(0, Dom.unwrap(domain));
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Domain(com.sun.enterprise.config.serverbeans.Domain) Test(org.junit.Test)

Example 49 with Domain

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

the class DuckMethodsTest method getClusterFromServerTest.

@Test
public void getClusterFromServerTest() {
    Domain d = habitat.getService(Domain.class);
    Server server = d.getServerNamed("server");
    assertTrue(server != null);
    Cluster cluster = server.getCluster();
    System.out.println("Cluster name is " + cluster.getName());
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Domain(com.sun.enterprise.config.serverbeans.Domain) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 50 with Domain

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

the class ConcurrentAccessTest method runTest.

private void runTest(final int waitTime) throws TransactionFailure, InterruptedException {
    final Domain domain = getHabitat().getService(Domain.class);
    // my lock.
    final Semaphore lock = new Semaphore(1);
    lock.acquire();
    // end of access
    final Semaphore endOfAccess = new Semaphore(1);
    endOfAccess.acquire();
    final long begin = System.currentTimeMillis();
    // let's start a thread to hold the lock on Domain...
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                ConfigSupport.apply(new SingleConfigCode<Domain>() {

                    @Override
                    public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                        logger.fine("got the lock at " + (System.currentTimeMillis() - begin));
                        lock.release();
                        try {
                            Thread.sleep(waitTime);
                        } catch (InterruptedException e) {
                            // To change body of catch statement use File | Settings | File Templates.
                            e.printStackTrace();
                        }
                        logger.fine("release the lock at " + (System.currentTimeMillis() - begin));
                        return null;
                    }
                }, domain);
            } catch (TransactionFailure e) {
                e.printStackTrace();
            }
            endOfAccess.release();
        }
    });
    t.start();
    // let's change the last modified date...
    lock.acquire();
    logger.fine("looking for second lock at " + (System.currentTimeMillis() - begin));
    try {
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            @Override
            public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                logger.fine("got the second lock at " + (System.currentTimeMillis() - begin));
                lock.release();
                return null;
            }
        }, domain);
    } finally {
        endOfAccess.acquire();
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Semaphore(java.util.concurrent.Semaphore) Domain(com.sun.enterprise.config.serverbeans.Domain)

Aggregations

Domain (com.sun.enterprise.config.serverbeans.Domain)70 Test (org.junit.Test)21 Server (com.sun.enterprise.config.serverbeans.Server)15 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)12 Dom (org.jvnet.hk2.config.Dom)11 PropertyVetoException (java.beans.PropertyVetoException)10 Cluster (com.sun.enterprise.config.serverbeans.Cluster)7 Resources (com.sun.enterprise.config.serverbeans.Resources)7 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)7 ServerContext (org.glassfish.internal.api.ServerContext)7 Config (com.sun.enterprise.config.serverbeans.Config)6 Resource (com.sun.enterprise.config.serverbeans.Resource)6 ParameterMap (org.glassfish.api.admin.ParameterMap)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Before (org.junit.Before)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 PropsFileActionReporter (com.sun.enterprise.admin.report.PropsFileActionReporter)4