Search in sources :

Example 6 with LoadBalancers

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;
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) LoadBalancers(org.glassfish.loadbalancer.config.LoadBalancers) LoadBalancer(org.glassfish.loadbalancer.config.LoadBalancer) Property(org.jvnet.hk2.config.types.Property)

Aggregations

LoadBalancers (org.glassfish.loadbalancer.config.LoadBalancers)6 LoadBalancer (org.glassfish.loadbalancer.config.LoadBalancer)5 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Server (com.sun.enterprise.config.serverbeans.Server)1 PropertyVetoException (java.beans.PropertyVetoException)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1 Property (org.jvnet.hk2.config.types.Property)1