Search in sources :

Example 6 with LoadBalancer

use of org.glassfish.loadbalancer.config.LoadBalancer in project Payara by payara.

the class ApplyHttpLbChanges method process.

public void process() throws Exception {
    ConnectionManager _connectionManager = null;
    LoadBalancer lb = LbConfigHelper.getLoadBalancer(domain, lbName);
    String lbHost = lb.getDeviceHost();
    String lbPort = lb.getDevicePort();
    String lbProxyHost = null;
    String lbProxyPort = null;
    Property lbProxyHostProperty = lb.getProperty(SSL_PROXY_HOST_PROPERTY);
    if (lbProxyHostProperty != null) {
        lbProxyHost = lbProxyHostProperty.getValue();
        Property lbProxyPortProperty = lb.getProperty(SSL_PROXY_PORT_PROPERTY);
        if (lbProxyPortProperty != null) {
            lbProxyPort = lbProxyPortProperty.getValue();
        }
    }
    boolean isSec = true;
    Property isSecProperty = lb.getProperty(IS_SECURE_PROPERTY);
    if (isSecProperty != null) {
        isSec = Boolean.getBoolean(isSecProperty.getValue());
    }
    _connectionManager = new ConnectionManager(lbHost, lbPort, lbProxyHost, lbProxyPort, lbName, isSec);
    if (ping != null && Boolean.valueOf(ping).booleanValue()) {
        ping(_connectionManager);
    } else {
        publish(_connectionManager, domain, lb.getLbConfigName());
    }
}
Also used : ConnectionManager(org.glassfish.loadbalancer.admin.cli.connection.ConnectionManager) LoadBalancer(org.glassfish.loadbalancer.config.LoadBalancer) Property(org.jvnet.hk2.config.types.Property)

Example 7 with LoadBalancer

use of org.glassfish.loadbalancer.config.LoadBalancer 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

LoadBalancer (org.glassfish.loadbalancer.config.LoadBalancer)7 LoadBalancers (org.glassfish.loadbalancer.config.LoadBalancers)5 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)2 Property (org.jvnet.hk2.config.types.Property)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 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ConnectionManager (org.glassfish.loadbalancer.admin.cli.connection.ConnectionManager)1 LoadbalancerReader (org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader)1 LoadbalancerReaderImpl (org.glassfish.loadbalancer.admin.cli.reader.impl.LoadbalancerReaderImpl)1 LbConfig (org.glassfish.loadbalancer.config.LbConfig)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1