use of org.glassfish.loadbalancer.config.LoadBalancers in project Payara by payara.
the class CreateHTTPLoadBalancerCommand method execute.
@Override
public void execute(AdminCommandContext context) {
// final Logger logger = context.getLogger();
report = context.getActionReport();
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
if (load_balancer_name == null) {
String msg = localStrings.getLocalString("NullLBName", "Load balancer name cannot be null");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (!Pattern.matches(NAME_REGEX, load_balancer_name)) {
String msg = localStrings.getLocalString("loadbalancer.invalid.name", "Invalid load-balancer name");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
if (loadBalancers != null && loadBalancers.getLoadBalancer(load_balancer_name) != null) {
String msg = localStrings.getLocalString("LBExists", "Load balancer {0} already exists", load_balancer_name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (target != null && !tgt.isValid(target)) {
String msg = localStrings.getLocalString("InvalidTarget", "Invalid target", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
boolean isCluster = tgt.isCluster(target);
String lbConfigName = load_balancer_name + "_LB_CONFIG";
if (!isCluster) {
if ((lbpolicy != null) || (lbpolicymodule != null)) {
String msg = localStrings.getLocalString("NotCluster", "{0} not a cluster", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
try {
createLBConfig(lbConfigName, context.getSubject());
if (target != null) {
final CreateHTTPLBRefCommand command = (CreateHTTPLBRefCommand) runner.getCommand("create-http-lb-ref", report, context.getLogger());
command.target = target;
// command.lbname = load_balancer_name;
command.config = lbConfigName;
command.lbpolicy = lbpolicy;
command.lbpolicymodule = lbpolicymodule;
command.healthcheckerurl = healthcheckerurl;
command.healthcheckerinterval = healthcheckerinterval;
command.healthcheckertimeout = healthcheckertimeout;
command.lbenableallinstances = lbenableallinstances;
command.lbenableallapplications = lbenableallapplications;
command.lbweight = lbweight;
command.execute(context);
checkCommandStatus(context);
}
} catch (CommandException e) {
String msg = e.getLocalizedMessage();
logger.warning(msg);
// report.setActionExitCode(ExitCode.FAILURE);
// report.setMessage(msg);
// return;
}
addLoadBalancer(lbConfigName);
if (isCluster && lbweight != null) {
try {
final ConfigureLBWeightCommand command = (ConfigureLBWeightCommand) runner.getCommand("configure-lb-weight", report, context.getLogger());
command.weights = lbweight;
command.cluster = target;
command.execute(context);
checkCommandStatus(context);
} catch (CommandException e) {
String msg = e.getLocalizedMessage();
logger.warning(msg);
// report.setActionExitCode(ExitCode.FAILURE);
// report.setMessage(msg);
// return;
}
}
}
use of org.glassfish.loadbalancer.config.LoadBalancers 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.LoadBalancers 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.LoadBalancers in project Payara by payara.
the class LbConfigHelper method getLoadBalancer.
public static LoadBalancer getLoadBalancer(Domain domain, String lbName) throws Exception {
LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
if (loadBalancers == null) {
throw new Exception(LbLogUtil.getStringManager().getString("UnableToGetLoadbalancer", lbName));
}
LoadBalancer loadBalancer = loadBalancers.getLoadBalancer(lbName);
if (loadBalancer == null) {
throw new Exception(LbLogUtil.getStringManager().getString("UnableToGetLoadbalancer", lbName));
}
return loadBalancer;
}
use of org.glassfish.loadbalancer.config.LoadBalancers in project Payara by payara.
the class LoadBalancerConfigUpgrade method updateLoadBalancerElements.
private void updateLoadBalancerElements() {
LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
if (loadBalancers == null) {
return;
}
List<LoadBalancer> loadBalancerList = loadBalancers.getLoadBalancer();
for (LoadBalancer loadBalancer : loadBalancerList) {
try {
ConfigSupport.apply(new LoadBalancerConfigCode(), loadBalancer);
} catch (TransactionFailure ex) {
String msg = LbLogUtil.getStringManager().getString("ErrorDuringUpgrade", loadBalancer.getName(), ex.getMessage());
Logger.getAnonymousLogger().log(Level.SEVERE, msg);
if (Logger.getAnonymousLogger().isLoggable(Level.FINE)) {
Logger.getAnonymousLogger().log(Level.FINE, "Exception during upgrade operation", ex);
}
}
}
}
Aggregations