use of com.sun.enterprise.config.serverbeans.Cluster 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 com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class LBCommandsBase method updateLBForCluster.
void updateLBForCluster(ActionReport report, String clusterName, String value, String timeout) {
Cluster c = domain.getClusterNamed(clusterName);
if (c == null) {
report.setMessage("Cluster not defined");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
for (ServerRef sRef : c.getServerRef()) {
try {
updateLbEnabled(sRef, value, timeout);
} catch (TransactionFailure ex) {
report.setMessage("Failed to update lb-enabled");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class LBCommandsBase method getServerRefFromCluster.
ServerRef getServerRefFromCluster(ActionReport report, String target) {
// check if this server is part of cluster
Cluster c = domain.getClusterForInstance(target);
if (c == null) {
report.setMessage("ServerNotDefined");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return null;
} else {
return c.getServerRefByRef(target);
}
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class LoadbalancerReaderImpl method getClustersData.
public ClusterReader[] getClustersData() throws LbReaderException {
ClusterReader[] cls = new ClusterReader[_clusters.size()];
Iterator<String> iter = _clusters.iterator();
int i = 0;
boolean isFirstServer = false;
while (iter.hasNext()) {
String name = iter.next();
boolean isServer = _domain.isServer(name);
if (i == 0) {
isFirstServer = isServer;
} else {
// Mix of standalone instances and clusters is not allowed
if (isFirstServer ^ isServer) {
String msg = LbLogUtil.getStringManager().getString("MixofServerAndClusterNotSupported");
throw new LbReaderException(msg);
}
}
if (isServer) {
Server server = _domain.getServerNamed(name);
// An instance within cluster is not allowed
if (server.getCluster() != null) {
String msg = LbLogUtil.getStringManager().getString("ServerPartofClusterNotSupported", name);
throw new LbReaderException(msg);
}
cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, server);
} else {
Cluster cluster = _domain.getClusterNamed(name);
if (cluster == null) {
String msg = LbLogUtil.getStringManager().getString("ClusterorInstanceNotFound", name);
throw new LbReaderException(msg);
}
cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, cluster);
}
}
return cls;
}
use of com.sun.enterprise.config.serverbeans.Cluster in project Payara by payara.
the class JMSDestination method getTypeForTarget.
protected CommandTarget getTypeForTarget(String target) {
Domain domain = Globals.get(Domain.class);
Config config = domain.getConfigNamed(target);
if (config != null)
return CommandTarget.CONFIG;
Server targetServer = domain.getServerNamed(target);
if (targetServer != null) {
// return CommandTarget.CLUSTERED_INSTANCE;
if (targetServer.isDas())
return CommandTarget.DAS;
else
return CommandTarget.STANDALONE_INSTANCE;
}
// end if (targetServer!=null)
Cluster cluster = domain.getClusterNamed(target);
if (cluster != null) {
return CommandTarget.CLUSTER;
}
return CommandTarget.DAS;
}
Aggregations