Search in sources :

Example 1 with ClusterRef

use of com.sun.enterprise.config.serverbeans.ClusterRef in project Payara by payara.

the class CreateHTTPHealthCheckerCommand method createHealthCheckerInternal.

/**
 * This is to create a health checker for a cluster configuration. By
 * default the healh checker will be configured.  This applies only
 * to our native load balancer.
 *
 * @param   url   the URL to ping so as to determine the health state
 *   of a listener.
 *
 * @param   interval   specifies the interval in seconds at which health
 *   checks of unhealthy instances carried out to check if the instances
 *   has turned healthy. Default value is 30 seconds. A value of 0 would
 *   imply that health check is disabled.
 *
 * @param   timeout    timeout interval in seconds within which response
 *   should be obtained for a health check request; else the instance would
 *   be considered unhealthy.Default value is 10 seconds.
 *
 * @param   lbConfig    the load balancer configuration bean
 * @param   lbConfigName    the load balancer configuration's name
 *
 * @param   target      name of the target - cluster or stand alone
 *  server instance
 *
 * @throws CommandException   If the operation is failed
 */
private void createHealthCheckerInternal(String url, String interval, String timeout, LbConfig lbConfig, String lbConfigName, String target) {
    // invalid lb config name
    if (lbConfigName == null) {
        String msg = localStrings.getLocalString("InvalidLbConfigName", "Invalid LB configuration.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    lbConfigName = lbConfig.getName();
    // print diagnostics msg
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("[LB-ADMIN] createHealthChecker called - URL " + url + ", Interval " + interval + ", Time out " + timeout + ", LB Config  " + lbConfigName + ", Target " + target);
    }
    // null target
    if (target == null) {
        String msg = localStrings.getLocalString("Nulltarget", "Null target");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    // target is a cluster
    if (tgt.isCluster(target)) {
        ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, target);
        // cluster is not associated to this lb config
        if (cRef == null) {
            String msg = localStrings.getLocalString("UnassociatedCluster", "Load balancer configuration [{0}] does not have a reference to the given cluster [{1}].", lbConfigName, target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        if (cRef.getHealthChecker() == null) {
            try {
                addHealthChecker(cRef);
            } catch (TransactionFailure ex) {
                String msg = localStrings.getLocalString("FailedToAddHC", "Failed to add health checker");
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setMessage(msg);
                report.setFailureCause(ex);
                return;
            }
            logger.info(localStrings.getLocalString("http_lb_admin.HealthCheckerCreated", "Health checker created for target {0}", target));
        } else {
            String msg = localStrings.getLocalString("HealthCheckerExists", "Health checker server/cluster [{0}] already exists.", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    // target is a server
    } else if (domain.isServer(target)) {
        ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, target);
        // server is not associated to this lb config
        if (sRef == null) {
            String msg = localStrings.getLocalString("UnassociatedServer", "Load balancer configuration [{0}] does not have a reference to the given server [{1}].", lbConfigName, target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        if (sRef.getHealthChecker() == null) {
            try {
                addHealthChecker(sRef);
            } catch (TransactionFailure ex) {
                String msg = localStrings.getLocalString("FailedToAddHC", "Failed to add health checker");
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setMessage(msg);
                report.setFailureCause(ex);
                return;
            }
            logger.info(localStrings.getLocalString("http_lb_admin.HealthCheckerCreated", "Health checker created for target {0}", target));
        } else {
            String msg = localStrings.getLocalString("HealthCheckerExists", "Health checker server/cluster [{0}] already exists.", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    // unknown target
    } else {
        String msg = localStrings.getLocalString("InvalidTarget", "Invalid target", target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
}
Also used : ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 2 with ClusterRef

use of com.sun.enterprise.config.serverbeans.ClusterRef in project Payara by payara.

the class DeleteHTTPHealthCheckerCommand method deleteHealthCheckerInternal.

/**
 * Deletes a health checker from a load balancer configuration.
 *
 * @param   lbConfig        Http load balancer configuration bean
 * @param   target          Name of a cluster or stand alone server instance
 * @param   ignoreFailure   if ignoreError is true, exceptions are not
 *                          thrown in the following cases
 *                          1). The specified server instance or cluster
 *                          does not exist in the LB config.
 *                          2).The target already contains the health checker
 */
private void deleteHealthCheckerInternal(LbConfig lbConfig, String target, boolean ignoreFailure) {
    // invalid lb config name
    if (lbConfig == null) {
        String msg = localStrings.getLocalString("InvalidLbConfigName", "Invalid LB configuration.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    String lbConfigName = lbConfig.getName();
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("[LB-ADMIN] deleteHealthChecker called - LB Config Name: " + lbConfigName + ", Target: " + target);
    }
    // null target
    if (target == null) {
        String msg = localStrings.getLocalString("Nulltarget", "Null target");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    // target is a cluster
    if (tgt.isCluster(target)) {
        ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, target);
        // cluster is not associated to this lb config
        if ((cRef == null) && (ignoreFailure == false)) {
            String msg = localStrings.getLocalString("UnassociatedCluster", "Load balancer configuration [{0}] does not have a reference to the given cluster [{1}].", lbConfigName, target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        if (cRef != null) {
            HealthChecker hc = cRef.getHealthChecker();
            if (hc != null) {
                removeHealthCheckerFromClusterRef(cRef);
                String msg = localStrings.getLocalString("http_lb_admin.HealthCheckerDeleted", "Health checker deleted for target {0}", target);
                logger.info(msg);
            } else {
                if (ignoreFailure == false) {
                    String msg = localStrings.getLocalString("HealthCheckerDoesNotExist", "Health checker does not exist for target {0} in LB {1}", target, lbConfigName);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setMessage(msg);
                    return;
                }
            }
        }
    // target is a server
    } else if (domain.isServer(target)) {
        ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, target);
        // server is not associated to this lb config
        if ((sRef == null) && (ignoreFailure == false)) {
            String msg = localStrings.getLocalString("UnassociatedServer", "Load balancer configuration [{0}] does not have a reference to the given server [{1}].", lbConfigName, target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        if (sRef != null) {
            HealthChecker hc = sRef.getHealthChecker();
            if (hc != null) {
                removeHealthCheckerFromServerRef(sRef);
                String msg = localStrings.getLocalString("http_lb_admin.HealthCheckerDeleted", "Health checker deleted for target {0}", target);
                logger.info(msg);
            } else {
                if (ignoreFailure == false) {
                    String msg = localStrings.getLocalString("HealthCheckerDoesNotExist", "Health checker does not exist for target {0} in LB {1}", target, lbConfigName);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setMessage(msg);
                    return;
                }
            }
        }
    } else {
        String msg = localStrings.getLocalString("InvalidTarget", "Invalid target", target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
}
Also used : ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) HealthChecker(com.sun.enterprise.config.serverbeans.HealthChecker)

Example 3 with ClusterRef

use of com.sun.enterprise.config.serverbeans.ClusterRef in project Payara by payara.

the class CreateHTTPLBRefCommand method addClusterToLbConfig.

private void addClusterToLbConfig(final LbConfigs lbconfigs, final String configName, final String clusterName) {
    LbConfig lbConfig = lbconfigs.getLbConfig(configName);
    ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, clusterName);
    if (cRef != null) {
        String msg = localStrings.getLocalString("LBClusterRefExists", "LB config already contains a cluster-ref for target {0}", target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<LbConfig>() {

            @Override
            public Object run(LbConfig param) throws PropertyVetoException, TransactionFailure {
                ClusterRef ref = param.createChild(ClusterRef.class);
                ref.setRef(clusterName);
                if (lbpolicy != null) {
                    ref.setLbPolicy(lbpolicy);
                }
                if (lbpolicymodule != null) {
                    ref.setLbPolicyModule(lbpolicymodule);
                }
                param.getClusterRefOrServerRef().add(ref);
                return Boolean.TRUE;
            }
        }, lbConfig);
    } catch (TransactionFailure ex) {
        String msg = localStrings.getLocalString("FailedToAddClusterRef", "Failed to add cluster-ref");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        report.setFailureCause(ex);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef)

Example 4 with ClusterRef

use of com.sun.enterprise.config.serverbeans.ClusterRef in project Payara by payara.

the class DeleteHTTPLBRefCommand method deleteClusterFromLBConfig.

private void deleteClusterFromLBConfig(LbConfigs lbconfigs, String configName, String clusterName) {
    LbConfig lbConfig = lbconfigs.getLbConfig(configName);
    ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, clusterName);
    if (cRef == null) {
        // does not exist, just return from here
        String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Cluster " + clusterName + " does not exist.");
        }
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (!Boolean.parseBoolean(force)) {
        Cluster c = domain.getClusterNamed(clusterName);
        if (c == null) {
            String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        List<ServerRef> sRefs = c.getServerRef();
        boolean refLbEnabled = false;
        for (ServerRef ref : sRefs) {
            if (Boolean.parseBoolean(ref.getLbEnabled())) {
                refLbEnabled = true;
            }
        }
        if (refLbEnabled) {
            String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    removeClusterRef(lbConfig, cRef);
}
Also used : LbConfig(org.glassfish.loadbalancer.config.LbConfig) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 5 with ClusterRef

use of com.sun.enterprise.config.serverbeans.ClusterRef 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)

Aggregations

ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)7 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)6 LbConfig (org.glassfish.loadbalancer.config.LbConfig)4 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 HealthChecker (com.sun.enterprise.config.serverbeans.HealthChecker)1 Ref (com.sun.enterprise.config.serverbeans.Ref)1 PropertyVetoException (java.beans.PropertyVetoException)1 List (java.util.List)1 ActionReport (org.glassfish.api.ActionReport)1 ClusterReader (org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader)1 LbReaderException (org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)1 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)1