use of org.glassfish.loadbalancer.config.LoadBalancers in project Payara by payara.
the class CreateHTTPLoadBalancerCommand method addLoadBalancer.
private void addLoadBalancer(final String lbConfigName) {
LoadBalancers loadBalancers = domain.getExtensionByType(LoadBalancers.class);
// create load-balancers parent element if it does not exist
if (loadBalancers == null) {
Transaction transaction = new Transaction();
try {
ConfigBeanProxy domainProxy = transaction.enroll(domain);
loadBalancers = domainProxy.createChild(LoadBalancers.class);
((Domain) domainProxy).getExtensions().add(loadBalancers);
transaction.commit();
} catch (TransactionFailure ex) {
transaction.rollback();
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
} catch (RetryableException ex) {
transaction.rollback();
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<LoadBalancers>() {
@Override
public Object run(LoadBalancers param) throws PropertyVetoException, TransactionFailure {
LoadBalancer lb = param.createChild(LoadBalancer.class);
lb.setDeviceHost(devicehost);
lb.setDevicePort(deviceport);
lb.setLbConfigName(lbConfigName);
lb.setName(load_balancer_name);
// add properties
if (properties != null) {
for (Object propname : properties.keySet()) {
Property newprop = lb.createChild(Property.class);
newprop.setName((String) propname);
newprop.setValue(properties.getProperty((String) propname));
lb.getProperty().add(newprop);
}
}
if (sslproxyhost != null) {
Property newprop = lb.createChild(Property.class);
newprop.setName("ssl-proxy-host");
newprop.setValue(sslproxyhost);
lb.getProperty().add(newprop);
}
if (sslproxyport != null) {
Property newprop = lb.createChild(Property.class);
newprop.setName("ssl-proxy-port");
newprop.setValue(sslproxyport);
lb.getProperty().add(newprop);
}
param.getLoadBalancer().add(lb);
return Boolean.TRUE;
}
}, loadBalancers);
} catch (TransactionFailure ex) {
String msg = localStrings.getLocalString("FailedToUpdateLB", "Failed to update load-balancers");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
Aggregations