}
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) {