Search in sources :

Example 1 with CustomRebalancer

use of org.apache.helix.controller.rebalancer.CustomRebalancer in project helix by apache.

the class BestPossibleStateCalcStage method getRebalancer.

private Rebalancer getRebalancer(IdealState idealState, String resourceName, boolean isMaintenanceModeEnabled) {
    Rebalancer customizedRebalancer = null;
    String rebalancerClassName = idealState.getRebalancerClassName();
    if (rebalancerClassName != null) {
        logger.debug("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName);
        try {
            customizedRebalancer = Rebalancer.class.cast(HelixUtil.loadClass(getClass(), rebalancerClassName).newInstance());
        } catch (Exception e) {
            logger.error("Exception while invoking custom rebalancer class:" + rebalancerClassName, e);
        }
    }
    Rebalancer rebalancer = null;
    switch(idealState.getRebalanceMode()) {
        case FULL_AUTO:
            if (isMaintenanceModeEnabled) {
                rebalancer = new MaintenanceRebalancer();
            } else {
                if (customizedRebalancer != null) {
                    rebalancer = customizedRebalancer;
                } else {
                    rebalancer = new AutoRebalancer();
                }
            }
            break;
        case SEMI_AUTO:
            rebalancer = new SemiAutoRebalancer();
            break;
        case CUSTOMIZED:
            rebalancer = new CustomRebalancer();
            break;
        case USER_DEFINED:
        case TASK:
            rebalancer = customizedRebalancer;
            break;
        default:
            logger.error("Fail to find the rebalancer, invalid rebalance mode " + idealState.getRebalanceMode());
            break;
    }
    return rebalancer;
}
Also used : AutoRebalancer(org.apache.helix.controller.rebalancer.AutoRebalancer) Rebalancer(org.apache.helix.controller.rebalancer.Rebalancer) SemiAutoRebalancer(org.apache.helix.controller.rebalancer.SemiAutoRebalancer) CustomRebalancer(org.apache.helix.controller.rebalancer.CustomRebalancer) MaintenanceRebalancer(org.apache.helix.controller.rebalancer.MaintenanceRebalancer) SemiAutoRebalancer(org.apache.helix.controller.rebalancer.SemiAutoRebalancer) MaintenanceRebalancer(org.apache.helix.controller.rebalancer.MaintenanceRebalancer) CustomRebalancer(org.apache.helix.controller.rebalancer.CustomRebalancer) StageException(org.apache.helix.controller.pipeline.StageException) AutoRebalancer(org.apache.helix.controller.rebalancer.AutoRebalancer) SemiAutoRebalancer(org.apache.helix.controller.rebalancer.SemiAutoRebalancer)

Aggregations

StageException (org.apache.helix.controller.pipeline.StageException)1 AutoRebalancer (org.apache.helix.controller.rebalancer.AutoRebalancer)1 CustomRebalancer (org.apache.helix.controller.rebalancer.CustomRebalancer)1 MaintenanceRebalancer (org.apache.helix.controller.rebalancer.MaintenanceRebalancer)1 Rebalancer (org.apache.helix.controller.rebalancer.Rebalancer)1 SemiAutoRebalancer (org.apache.helix.controller.rebalancer.SemiAutoRebalancer)1