use of org.glassfish.loadbalancer.config.LbConfigs in project Payara by payara.
the class EnableHTTPLBServerCommand 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;
}
if (tgt.isCluster(target)) {
// enable all servers in cluster
updateLBForCluster(report, target, "true", null);
} else {
boolean foundTarget = false;
List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
for (LbConfig lc : lbConfigs) {
// ServerRef sRef = lc.getServerRefByRef(target);
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 {
boolean enabled = sRef.getLbEnabled().equals("true");
if (enabled == true) {
String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "true", null);
} 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 {
boolean enabled = sRef.getLbEnabled().equals("true");
if (enabled == true) {
String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
try {
updateLbEnabled(sRef, "true", null);
} 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 ListLBConfigsCommand method execute.
@Override
public void execute(AdminCommandContext context) {
report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
boolean isCluster = tgt.isCluster(list_target);
LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
if (lbconfigs == null) {
if (logger.isLoggable(Level.FINE)) {
logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
}
return;
}
List<LbConfig> lbconfigsList = lbconfigs.getLbConfig();
if (lbconfigsList.size() == 0) {
logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
return;
}
if (list_target == null) {
for (LbConfig lbc : lbconfigsList) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(lbc.getName());
}
} else {
// target is a cluster
if (isCluster) {
for (LbConfig lbc : lbconfigsList) {
List<ClusterRef> refs = lbc.getRefs(ClusterRef.class);
for (ClusterRef cRef : refs) {
if (cRef.getRef().equals(list_target)) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(lbc.getName());
}
}
}
// target is a server
} else if (domain.isServer(list_target)) {
for (LbConfig lbc : lbconfigsList) {
List<ServerRef> refs = lbc.getRefs(ServerRef.class);
for (ServerRef sRef : refs) {
if (sRef.getRef().equals(list_target)) {
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(lbc.getName());
}
}
}
} else {
// target is a lb config
LbConfig lbConfig = lbconfigs.getLbConfig(list_target);
if (lbConfig != null) {
List<ClusterRef> cRefs = lbConfig.getRefs(ClusterRef.class);
for (ClusterRef ref : cRefs) {
String s = localStrings.getLocalString("ClusterPrefix", "Cluster:");
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(s + ref.getRef());
}
List<ServerRef> sRefs = lbConfig.getRefs(ServerRef.class);
for (ServerRef ref : sRefs) {
String s = localStrings.getLocalString("ServerPrefix", "Server:");
ActionReport.MessagePart childPart = part.addChild();
childPart.setMessage(s + ref.getRef());
}
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.loadbalancer.config.LbConfigs 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