use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class LBCommandsBase method updateLBForCluster.
void updateLBForCluster(ActionReport report, String clusterName, String value, String timeout) {
Cluster c = domain.getClusterNamed(clusterName);
if (c == null) {
report.setMessage("Cluster not defined");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
for (ServerRef sRef : c.getServerRef()) {
try {
updateLbEnabled(sRef, value, timeout);
} catch (TransactionFailure ex) {
report.setMessage("Failed to update lb-enabled");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class GMSAdapterImpl method generateDiscoveryUriList.
/*
* Get existing nodes based on cluster element in domain.
* Then check for DAS address in das.properties. When the
* list is set to 'generate' then the gms listener port
* must also be specified. So the same port is used for
* each cluster member.
*/
private String generateDiscoveryUriList() {
String clusterPort = null;
Property gmsPortProp = cluster.getProperty("GMS_LISTENER_PORT");
if (gmsPortProp == null || gmsPortProp.getValue() == null || gmsPortProp.getValue().trim().charAt(0) == '$') {
clusterPort = "9090";
GMS_LOGGER.log(LogLevel.WARNING, GMS_LISTENER_PORT_REQUIRED, new Object[] { cluster.getName(), clusterPort });
} else {
clusterPort = gmsPortProp.getValue();
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, "will use gms listener port: " + clusterPort);
}
}
// get cluster member server refs
Set<String> instanceNames = new HashSet<String>();
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("checking cluster.getServerRef() for '%s'", cluster.getName()));
}
for (ServerRef sRef : cluster.getServerRef()) {
/*
* When an instance (not DAS) starts up, it will add
* its own address to the discovery list. This is ok
* now. If we want to skip it, here's the place to
* check.
*/
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("adding server ref %s to set of instance names", sRef.getRef()));
}
instanceNames.add(sRef.getRef());
}
StringBuilder sb = new StringBuilder();
final String SEP = ",";
final String scheme = "tcp://";
// use server refs to find matching nodes
for (String name : instanceNames) {
Server server = servers.getServer(name);
if (server != null) {
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("found server for name %s", name));
}
Node node = nodes.getNode(server.getNodeRef());
if (node != null) {
String host = scheme + node.getNodeHost() + ":" + clusterPort;
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("Adding host '%s' to discovery list", host));
}
sb.append(host).append(SEP);
}
}
}
// add das location from das.properties if needed
if (server.isInstance()) {
try {
ServerDirs sDirs = new ServerDirs(env.getInstanceRoot());
File dasPropsFile = sDirs.getDasPropertiesFile();
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("found das.props file at %s", dasPropsFile.getAbsolutePath()));
}
Properties dasProps = getProperties(dasPropsFile);
String host = scheme + dasProps.getProperty("agent.das.host") + ":" + clusterPort;
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("adding '%s' from das.props file", host));
}
sb.append(host).append(SEP);
} catch (IOException ioe) {
GMS_LOGGER.log(LogLevel.WARNING, ioe.toString());
}
}
// trim list if needed and return
int lastCommaIndex = sb.lastIndexOf(SEP);
if (lastCommaIndex != -1) {
sb.deleteCharAt(lastCommaIndex);
}
if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
GMS_LOGGER.log(LogLevel.FINE, String.format("returning discovery list '%s'", sb.toString()));
}
return sb.toString();
}
use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class ReferenceConstrainClusterTest method clusterServerRefInvalid.
@Test
public void clusterServerRefInvalid() throws TransactionFailure {
Cluster cluster = habitat.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("ref", "server-nonexist");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
assertNotNull(cv);
}
}
use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class ReferenceConstrainClusterTest method clusterServerRefValid.
@Test
public void clusterServerRefValid() throws TransactionFailure {
Cluster cluster = habitat.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("ref", "server");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
} catch (TransactionFailure tf) {
fail("Can not reach this point");
}
}
use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class HealthHistory method changed.
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
Object oldVal;
Object newVal;
for (PropertyChangeEvent event : events) {
oldVal = event.getOldValue();
newVal = event.getNewValue();
if (oldVal instanceof ServerRef && newVal == null) {
ServerRef instance = (ServerRef) oldVal;
deleteInstance(instance.getRef());
} else if (newVal instanceof ServerRef && oldVal == null) {
ServerRef instance = (ServerRef) newVal;
addInstance(instance.getRef());
}
}
return null;
}
Aggregations