Search in sources :

Example 6 with LbConfigs

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

the class EnableHTTPLBServerCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    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 (tgt.isCluster(target)) {
        // enable all servers in cluster
        updateLBForCluster(report, target, "true", null);
    } else {
        boolean foundTarget = false;
        List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
        for (LbConfig lc : lbConfigs) {
            // ServerRef  sRef = lc.getServerRefByRef(target);
            ServerRef sRef = lc.getRefByRef(ServerRef.class, target);
            if (sRef == null) {
                // log a warning and continue search
                logger.warning(localStrings.getLocalString("InvalidInstance", "Server {0} does not exist in {1}", target, lc.getName()));
            } else {
                boolean enabled = sRef.getLbEnabled().equals("true");
                if (enabled == true) {
                    String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
                    report.setMessage(msg);
                    return;
                }
                try {
                    updateLbEnabled(sRef, "true", null);
                } catch (TransactionFailure ex) {
                    String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
                    report.setMessage(msg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(ex);
                    return;
                }
                foundTarget = true;
            }
        }
        // did not find server target
        if (!foundTarget) {
            ServerRef sRef = getServerRefFromCluster(report, target);
            if (sRef == null) {
                String msg = localStrings.getLocalString("InvalidServer", "Server {0} does not exist", target);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setMessage(msg);
                return;
            } else {
                boolean enabled = sRef.getLbEnabled().equals("true");
                if (enabled == true) {
                    String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setMessage(msg);
                    return;
                }
                try {
                    updateLbEnabled(sRef, "true", null);
                } catch (TransactionFailure ex) {
                    String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
                    report.setMessage(msg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(ex);
                    return;
                }
            }
        }
    }
}
Also used : LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 7 with LbConfigs

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

the class ListLBConfigsCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    boolean isCluster = tgt.isCluster(list_target);
    LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
    if (lbconfigs == null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
        }
        return;
    }
    List<LbConfig> lbconfigsList = lbconfigs.getLbConfig();
    if (lbconfigsList.size() == 0) {
        logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
        return;
    }
    if (list_target == null) {
        for (LbConfig lbc : lbconfigsList) {
            ActionReport.MessagePart childPart = part.addChild();
            childPart.setMessage(lbc.getName());
        }
    } else {
        // target is a cluster
        if (isCluster) {
            for (LbConfig lbc : lbconfigsList) {
                List<ClusterRef> refs = lbc.getRefs(ClusterRef.class);
                for (ClusterRef cRef : refs) {
                    if (cRef.getRef().equals(list_target)) {
                        ActionReport.MessagePart childPart = part.addChild();
                        childPart.setMessage(lbc.getName());
                    }
                }
            }
        // target is a server
        } else if (domain.isServer(list_target)) {
            for (LbConfig lbc : lbconfigsList) {
                List<ServerRef> refs = lbc.getRefs(ServerRef.class);
                for (ServerRef sRef : refs) {
                    if (sRef.getRef().equals(list_target)) {
                        ActionReport.MessagePart childPart = part.addChild();
                        childPart.setMessage(lbc.getName());
                    }
                }
            }
        } else {
            // target is a lb config
            LbConfig lbConfig = lbconfigs.getLbConfig(list_target);
            if (lbConfig != null) {
                List<ClusterRef> cRefs = lbConfig.getRefs(ClusterRef.class);
                for (ClusterRef ref : cRefs) {
                    String s = localStrings.getLocalString("ClusterPrefix", "Cluster:");
                    ActionReport.MessagePart childPart = part.addChild();
                    childPart.setMessage(s + ref.getRef());
                }
                List<ServerRef> sRefs = lbConfig.getRefs(ServerRef.class);
                for (ServerRef ref : sRefs) {
                    String s = localStrings.getLocalString("ServerPrefix", "Server:");
                    ActionReport.MessagePart childPart = part.addChild();
                    childPart.setMessage(s + ref.getRef());
                }
            }
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LbConfig(org.glassfish.loadbalancer.config.LbConfig) List(java.util.List) ActionReport(org.glassfish.api.ActionReport) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 8 with LbConfigs

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

Aggregations

LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)8 LbConfig (org.glassfish.loadbalancer.config.LbConfig)6 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)3 ActionReport (org.glassfish.api.ActionReport)3 Logger (java.util.logging.Logger)2 LoadBalancer (org.glassfish.loadbalancer.config.LoadBalancer)2 LoadBalancers (org.glassfish.loadbalancer.config.LoadBalancers)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)1 Server (com.sun.enterprise.config.serverbeans.Server)1 List (java.util.List)1 LoadbalancerReaderImpl (org.glassfish.loadbalancer.admin.cli.reader.impl.LoadbalancerReaderImpl)1