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 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;
}
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 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 CreateHTTPHealthCheckerCommand method createHealthCheckerInternal.
/**
* This is to create a health checker for a cluster configuration. By
* default the healh checker will be configured. This applies only
* to our native load balancer.
*
* @param url the URL to ping so as to determine the health state
* of a listener.
*
* @param interval specifies the interval in seconds at which health
* checks of unhealthy instances carried out to check if the instances
* has turned healthy. Default value is 30 seconds. A value of 0 would
* imply that health check is disabled.
*
* @param timeout timeout interval in seconds within which response
* should be obtained for a health check request; else the instance would
* be considered unhealthy.Default value is 10 seconds.
*
* @param lbConfig the load balancer configuration bean
* @param lbConfigName the load balancer configuration's name
*
* @param target name of the target - cluster or stand alone
* server instance
*
* @throws CommandException If the operation is failed
*/
private void createHealthCheckerInternal(String url, String interval, String timeout, LbConfig lbConfig, String lbConfigName, String target) {
// invalid lb config name
if (lbConfigName == null) {
String msg = localStrings.getLocalString("InvalidLbConfigName", "Invalid LB configuration.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
lbConfigName = lbConfig.getName();
// print diagnostics msg
if (logger.isLoggable(Level.FINE)) {
logger.fine("[LB-ADMIN] createHealthChecker called - URL " + url + ", Interval " + interval + ", Time out " + timeout + ", LB Config " + lbConfigName + ", Target " + target);
}
// null target
if (target == null) {
String msg = localStrings.getLocalString("Nulltarget", "Null target");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// target is a cluster
if (tgt.isCluster(target)) {
ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, target);
// cluster is not associated to this lb config
if (cRef == null) {
String msg = localStrings.getLocalString("UnassociatedCluster", "Load balancer configuration [{0}] does not have a reference to the given cluster [{1}].", lbConfigName, target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (cRef.getHealthChecker() == null) {
try {
addHealthChecker(cRef);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToAddHC", "Failed to add health checker");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
report.setFailureCause(ex);
return;
}
logger.info(localStrings.getLocalString("http_lb_admin.HealthCheckerCreated", "Health checker created for target {0}", target));
} else {
String msg = localStrings.getLocalString("HealthCheckerExists", "Health checker server/cluster [{0}] already exists.", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// target is a server
} else if (domain.isServer(target)) {
ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, target);
// server is not associated to this lb config
if (sRef == null) {
String msg = localStrings.getLocalString("UnassociatedServer", "Load balancer configuration [{0}] does not have a reference to the given server [{1}].", lbConfigName, target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (sRef.getHealthChecker() == null) {
try {
addHealthChecker(sRef);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToAddHC", "Failed to add health checker");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
report.setFailureCause(ex);
return;
}
logger.info(localStrings.getLocalString("http_lb_admin.HealthCheckerCreated", "Health checker created for target {0}", target));
} else {
String msg = localStrings.getLocalString("HealthCheckerExists", "Health checker server/cluster [{0}] already exists.", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// unknown target
} else {
String msg = localStrings.getLocalString("InvalidTarget", "Invalid target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
Aggregations