use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class DeleteHTTPLBRefCommand method deleteServerFromLBConfig.
private void deleteServerFromLBConfig(LbConfigs lbconfigs, String configName, String serverName) {
LbConfig lbConfig = lbconfigs.getLbConfig(configName);
ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, serverName);
if (sRef == null) {
// does not exist, just return from here
String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Server " + serverName + " does not exist in any cluster in the domain");
}
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (!Boolean.parseBoolean(force)) {
if (Boolean.parseBoolean(sRef.getLbEnabled())) {
String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", serverName);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// check if its applications are LB disabled.
Server s = domain.getServerNamed(serverName);
if (s == null) {
String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
List<ApplicationRef> appRefs = domain.getApplicationRefsInTarget(target);
if (appRefs == null) {
String msg = localStrings.getLocalString("AppRefsNotDefined", "Application refs does not exist in server {0}", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
boolean appLbEnabled = false;
for (ApplicationRef aRef : appRefs) {
if (Boolean.parseBoolean(aRef.getLbEnabled())) {
appLbEnabled = true;
break;
}
}
if (appLbEnabled) {
String msg = localStrings.getLocalString("AppsNotDisabled", "All referenced applications must be disabled in LB");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
removeServerRef(lbConfig, sRef);
}
use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class DisableHTTPLBServerCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
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;
}
int t = Integer.parseInt(timeout);
if (t < 0) {
String msg = localStrings.getLocalString("InvalidTimeout", "Invalid timeout {0}", timeout);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (tgt.isCluster(target)) {
// disable all servers in cluster
updateLBForCluster(report, target, "false", timeout);
} else {
boolean foundTarget = false;
List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
for (LbConfig lc : lbConfigs) {
ServerRef sRef = lc.getRefByRef(ServerRef.class, target);
if (sRef == null) {
// log a warning and continue search
logger.warning(localStrings.getLocalString("InvalidInstance", "Server {0} does not exist in {1}", target, lc.getName()));
} else {
int curTout = Integer.parseInt(sRef.getDisableTimeoutInMinutes());
boolean enabled = sRef.getLbEnabled().equals("true");
if ((enabled == false) && (curTout == t)) {
String msg = localStrings.getLocalString("ServerDisabled", "Server [{0}] is already disabled.", sRef.getRef());
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "false", timeout);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
return;
}
foundTarget = true;
}
}
// did not find server target
if (!foundTarget) {
ServerRef sRef = getServerRefFromCluster(report, target);
if (sRef == null) {
String msg = localStrings.getLocalString("InvalidServer", "Server {0} does not exist", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
} else {
int curTout = Integer.parseInt(sRef.getDisableTimeoutInMinutes());
boolean enabled = sRef.getLbEnabled().equals("true");
if ((enabled == false) && (curTout == t)) {
String msg = localStrings.getLocalString("ServerDisabled", "Server [{0}] is already disabled.", sRef.getRef());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "false", timeout);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(ex);
return;
}
}
}
}
}
use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class CreateHTTPLBRefCommand method addServerToLBConfig.
private void addServerToLBConfig(final LbConfigs lbconfigs, final String configName, final String serverName) {
LbConfig lbConfig = lbconfigs.getLbConfig(configName);
ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, serverName);
if (sRef != null) {
String msg = localStrings.getLocalString("LBServerRefExists", "LB config already contains a server-ref for target {0}", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
Server server = domain.getServerNamed(serverName);
boolean isStandAlone = server.getCluster() == null && server.isInstance();
if (!isStandAlone) {
String msg = localStrings.getLocalString("NotStandAloneInstance", "[{0}] is not a stand alone instance. Only stand alone instance can be added to a load balancer.", serverName);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<LbConfig>() {
@Override
public Object run(LbConfig param) throws PropertyVetoException, TransactionFailure {
ServerRef ref = param.createChild(ServerRef.class);
ref.setRef(serverName);
param.getClusterRefOrServerRef().add(ref);
return Boolean.TRUE;
}
}, lbConfig);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToAddServerRef", "Failed to add server-ref");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
report.setFailureCause(ex);
}
}
use of org.glassfish.loadbalancer.config.LbConfig in project Payara by payara.
the class LbConfigHelper method getLbReader.
/**
* exports the loadbalancer.xml from the config to the outputstream provided
* @param ctx ConfigContext
* @param lbConfigName name of lb-config
* @param out OutputStream into which the loadbalancer.xml is written
*/
public static LoadbalancerReader getLbReader(Domain domain, ApplicationRegistry appRegistry, String lbConfigName) throws Exception {
// reads the load balancer related data
LbConfigs lbConfigs = domain.getExtensionByType(LbConfigs.class);
if (lbConfigs == null) {
throw new Exception(LbLogUtil.getStringManager().getString("UnableToGetLbConfig", lbConfigName));
}
LbConfig lbConfig = lbConfigs.getLbConfig(lbConfigName);
if (lbConfig == null) {
throw new Exception(LbLogUtil.getStringManager().getString("UnableToGetLbConfig", lbConfigName));
}
return new LoadbalancerReaderImpl(domain, appRegistry, lbConfig);
}
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);
}
}
}
Aggregations