use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class CreateHTTPHealthCheckerCommand method execute.
@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
if (lbconfigs == null) {
String msg = localStrings.getLocalString("NoLbConfigsElement", "Empty lb-configs");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (config != null) {
LbConfig lbConfig = lbconfigs.getLbConfig(config);
createHealthCheckerInternal(url, interval, timeout, lbConfig, config, target);
} else {
List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
if (lbConfigs.size() == 0) {
String msg = localStrings.getLocalString("NoLbConfigsElement", "No LB configs defined");
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
List<LbConfig> match = null;
match = matchLbConfigToTarget(lbConfigs, target);
if ((match == null) || (match.size() == 0)) {
String msg = localStrings.getLocalString("UnassociatedTarget", "No LB config references target {0}", target);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
for (LbConfig lc : match) {
createHealthCheckerInternal(url, interval, timeout, lc, lc.getName(), target);
}
}
}
use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class CreateHTTPHealthCheckerCommand method matchLbConfigToTarget.
/**
* Returns an array of LbConfigs that has a reference to the target
* server or cluster. If there are no references found for the
* target or the arguments are null, this method returns null.
*
* @param lbConfigs array of existing LbConfigs in the system
* @param target name of server or cluster
*
* @return array of LbConfigs that has a ref to the target server
*/
private List<LbConfig> matchLbConfigToTarget(List<LbConfig> lbConfigs, String target) {
List<LbConfig> list = null;
// bad target
if (target == null) {
String msg = localStrings.getLocalString("Nulltarget", "Null target");
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return null;
}
// system has lb configs defined
if (!lbConfigs.isEmpty()) {
list = new ArrayList<LbConfig>();
for (int i = 0; i < lbConfigs.size(); i++) {
// target is a cluster
if (tgt.isCluster(target)) {
ClusterRef cRef = lbConfigs.get(i).getRefByRef(ClusterRef.class, target);
// this lb config has a reference to the target cluster
if (cRef != null) {
list.add(lbConfigs.get(i));
}
// target is a server
} else if (domain.isServer(target)) {
ServerRef sRef = lbConfigs.get(i).getRefByRef(ServerRef.class, target);
// this lb config has a reference to the target server
if (sRef != null) {
list.add(lbConfigs.get(i));
}
}
}
}
return list;
}
Aggregations