Search in sources :

Example 11 with LbConfig

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

the class CreateHTTPHealthCheckerCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    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) {
        LbConfig lbConfig = lbconfigs.getLbConfig(config);
        createHealthCheckerInternal(url, interval, timeout, lbConfig, config, target);
    } else {
        List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
        if (lbConfigs.size() == 0) {
            String msg = localStrings.getLocalString("NoLbConfigsElement", "No LB configs defined");
            logger.warning(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        List<LbConfig> match = null;
        match = matchLbConfigToTarget(lbConfigs, target);
        if ((match == null) || (match.size() == 0)) {
            String msg = localStrings.getLocalString("UnassociatedTarget", "No LB config references target {0}", target);
            logger.warning(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        for (LbConfig lc : match) {
            createHealthCheckerInternal(url, interval, timeout, lc, lc.getName(), target);
        }
    }
}
Also used : LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LbConfig(org.glassfish.loadbalancer.config.LbConfig)

Example 12 with LbConfig

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

the class CreateHTTPHealthCheckerCommand method matchLbConfigToTarget.

/**
 * Returns an array of LbConfigs that has a reference to the target
 * server or cluster. If there are no references found for the
 * target or the arguments are null, this method returns null.
 *
 * @param  lbConfigs  array of existing LbConfigs in the system
 * @param  target     name of server or cluster
 *
 * @return array of LbConfigs that has a ref to the target server
 */
private List<LbConfig> matchLbConfigToTarget(List<LbConfig> lbConfigs, String target) {
    List<LbConfig> list = null;
    // bad target
    if (target == null) {
        String msg = localStrings.getLocalString("Nulltarget", "Null target");
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return null;
    }
    // system has lb configs defined
    if (!lbConfigs.isEmpty()) {
        list = new ArrayList<LbConfig>();
        for (int i = 0; i < lbConfigs.size(); i++) {
            // target is a cluster
            if (tgt.isCluster(target)) {
                ClusterRef cRef = lbConfigs.get(i).getRefByRef(ClusterRef.class, target);
                // this lb config has a reference to the target cluster
                if (cRef != null) {
                    list.add(lbConfigs.get(i));
                }
            // target is a server
            } else if (domain.isServer(target)) {
                ServerRef sRef = lbConfigs.get(i).getRefByRef(ServerRef.class, target);
                // this lb config has a reference to the target server
                if (sRef != null) {
                    list.add(lbConfigs.get(i));
                }
            }
        }
    }
    return list;
}
Also used : LbConfig(org.glassfish.loadbalancer.config.LbConfig) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Aggregations

LbConfig (org.glassfish.loadbalancer.config.LbConfig)12 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)7 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)6 ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)4 ActionReport (org.glassfish.api.ActionReport)3 Server (com.sun.enterprise.config.serverbeans.Server)2 PropertyVetoException (java.beans.PropertyVetoException)2 Logger (java.util.logging.Logger)2 LoadbalancerReaderImpl (org.glassfish.loadbalancer.admin.cli.reader.impl.LoadbalancerReaderImpl)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 LoadbalancerReader (org.glassfish.loadbalancer.admin.cli.reader.api.LoadbalancerReader)1 LoadBalancer (org.glassfish.loadbalancer.config.LoadBalancer)1