use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class DeleteHTTPLBRefCommand method deleteClusterFromLBConfig.
private void deleteClusterFromLBConfig(LbConfigs lbconfigs, String configName, String clusterName) {
LbConfig lbConfig = lbconfigs.getLbConfig(configName);
ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, clusterName);
if (cRef == null) {
// does not exist, just return from here
String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Cluster " + clusterName + " does not exist.");
}
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
if (!Boolean.parseBoolean(force)) {
Cluster c = domain.getClusterNamed(clusterName);
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;
}
List<ServerRef> sRefs = c.getServerRef();
boolean refLbEnabled = false;
for (ServerRef ref : sRefs) {
if (Boolean.parseBoolean(ref.getLbEnabled())) {
refLbEnabled = true;
}
}
if (refLbEnabled) {
String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", target);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
removeClusterRef(lbConfig, cRef);
}
use of com.sun.enterprise.config.serverbeans.ServerRef 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 com.sun.enterprise.config.serverbeans.ServerRef 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 com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.
the class LoadbalancerReaderImpl method getClustersDataFromLBConfig.
public ClusterReader[] getClustersDataFromLBConfig() throws LbReaderException {
List<Ref> serverOrClusters = _lbConfig.getClusterRefOrServerRef();
ClusterReader[] cls = new ClusterReader[serverOrClusters.size()];
Iterator<Ref> iter = serverOrClusters.iterator();
int i = 0;
while (iter.hasNext()) {
Ref ref = iter.next();
if (ref instanceof ServerRef) {
cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, (ServerRef) ref);
} else if (ref instanceof ClusterRef) {
cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, (ClusterRef) ref);
} else {
String msg = LbLogUtil.getStringManager().getString("UnableToDetermineType", ref.getRef());
throw new LbReaderException(msg);
}
}
return cls;
}
use of com.sun.enterprise.config.serverbeans.ServerRef 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