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;
}
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;
}
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));
}
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());
}
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();
}
}
Aggregations