Search in sources :

Example 1 with HealthChecker

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

Aggregations

ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)1 HealthChecker (com.sun.enterprise.config.serverbeans.HealthChecker)1 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)1