use of org.glassfish.loadbalancer.config.LbConfigs in project Payara by payara.
the class CreateHTTPLBRefCommand method execute.
@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
boolean isCluster = (target != null) ? tgt.isCluster(target) : false;
if (config != null && lbname != null) {
String msg = localStrings.getLocalString("EitherConfigOrLBName", "Either LB name or LB config name, not both");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (config == null && lbname == null) {
String msg = localStrings.getLocalString("SpecifyConfigOrLBName", "Please specify either LB name or LB config name.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
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) {
if (lbconfigs.getLbConfig(config) == null) {
String msg = localStrings.getLocalString("LbConfigDoesNotExist", "Specified LB config {0} does not exist", config);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
} else if (lbname != null) {
LoadBalancers lbs = domain.getExtensionByType(LoadBalancers.class);
if (lbs == null) {
String msg = localStrings.getLocalString("NoLoadBalancersElement", "No Load balancers defined.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
LoadBalancer lb = lbs.getLoadBalancer(lbname);
if (lb == null) {
String msg = localStrings.getLocalString("LoadBalancerNotDefined", "Load balancer [{0}] not found.", lbname);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
config = lb.getLbConfigName();
}
if ((lbpolicy != null) || (lbpolicymodule != null)) {
if (!isCluster) {
String msg = localStrings.getLocalString("NotCluster", "{0} not a cluster", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
Cluster c = null;
Server s = null;
if (isCluster) {
c = domain.getClusterNamed(target);
if (c == null) {
String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
} else {
s = domain.getServerNamed(target);
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;
}
}
// create lb ref
createLBRef(lbconfigs, target, config);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
return;
}
if (healthcheckerurl != null) {
try {
final CreateHTTPHealthCheckerCommand command = (CreateHTTPHealthCheckerCommand) runner.getCommand("create-http-health-checker", report, context.getLogger());
command.url = healthcheckerurl;
command.interval = healthcheckerinterval;
command.timeout = healthcheckertimeout;
command.config = config;
command.target = target;
command.execute(context);
checkCommandStatus(context);
} catch (CommandException e) {
String msg = e.getLocalizedMessage();
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
if (Boolean.parseBoolean(lbenableallinstances)) {
try {
final EnableHTTPLBServerCommand command = (EnableHTTPLBServerCommand) runner.getCommand("enable-http-lb-server", report, context.getLogger());
command.target = target;
command.execute(context);
checkCommandStatus(context);
} catch (CommandException e) {
String msg = e.getLocalizedMessage();
logger.warning(msg);
// report.setActionExitCode(ExitCode.FAILURE);
// report.setMessage(msg);
// return;
}
}
if (Boolean.parseBoolean(lbenableallapplications)) {
List<ApplicationRef> appRefs = domain.getApplicationRefsInTarget(target);
if ((appRefs.size() > 0) && Boolean.parseBoolean(lbenableallapplications)) {
for (ApplicationRef ref : appRefs) {
// enable only user applications
if (isUserApp(ref.getRef())) {
enableApp(context, ref.getRef());
}
}
}
}
}
use of org.glassfish.loadbalancer.config.LbConfigs in project Payara by payara.
the class DeleteHTTPLBRefCommand method execute.
@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
boolean isCluster = tgt.isCluster(target);
if (logger.isLoggable(Level.FINE)) {
logger.fine("[LB-ADMIN] deleteLBRef called for target " + target);
}
if (config != null && lbname != null) {
String msg = localStrings.getLocalString("EitherConfigOrLBName", "Either LB name or LB config name, not both");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (config == null && lbname == null) {
String msg = localStrings.getLocalString("SpecifyConfigOrLBName", "Please specify either LB name or LB config name.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
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) {
if (lbconfigs.getLbConfig(config) == null) {
String msg = localStrings.getLocalString("LbConfigDoesNotExist", "Specified LB config {0} does not exist", config);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
} else if (lbname != null) {
LoadBalancers lbs = domain.getExtensionByType(LoadBalancers.class);
if (lbs == null) {
String msg = localStrings.getLocalString("NoLoadBalancersElement", "No Load balancers defined.");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
LoadBalancer lb = lbs.getLoadBalancer(lbname);
if (lb == null) {
String msg = localStrings.getLocalString("LoadBalancerNotDefined", "Load balancer [{0}] not found.", lbname);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
config = lb.getLbConfigName();
}
// target is a cluster
if (isCluster) {
deleteClusterFromLBConfig(lbconfigs, config, target);
String msg = localStrings.getLocalString("http_lb_admin.DeleteClusterFromConfig", "Deleted cluster {0} from Lb", target, config);
logger.info(msg);
// target is a server
} else if (domain.isServer(target)) {
deleteServerFromLBConfig(lbconfigs, config, target);
String msg = localStrings.getLocalString("http_lb_admin.DeleteServerFromConfig", "Deleted server {0} from Lb", target, config);
logger.info(msg);
} else {
String msg = localStrings.getLocalString("InvalidTarget", "Invalid target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
use of org.glassfish.loadbalancer.config.LbConfigs 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.LbConfigs 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.LbConfigs in project Payara by payara.
the class DeleteHTTPHealthCheckerCommand 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);
deleteHealthCheckerInternal(lbConfig, target, false);
} else {
List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
if (lbConfigs.isEmpty()) {
String msg = localStrings.getLocalString("NoLbConfigsElement", "Empty lb-configs");
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
for (LbConfig lc : lbConfigs) {
deleteHealthCheckerInternal(lc, target, true);
}
}
}
Aggregations