001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Response returned from a balancer invocation 024 */ 025@InterfaceAudience.Public 026public final class BalanceResponse { 027 028 /** 029 * Used in HMaster to build a {@link BalanceResponse} for returning results of a balance 030 * invocation to callers 031 */ 032 @InterfaceAudience.Private 033 public final static class Builder { 034 private boolean balancerRan; 035 private int movesCalculated; 036 private int movesExecuted; 037 038 private Builder() { 039 } 040 041 /** 042 * Set true if the balancer ran, otherwise false. The balancer may not run in some 043 * circumstances, such as if a balance is already running or there are regions already in 044 * transition. 045 * @param balancerRan true if balancer ran, false otherwise 046 */ 047 public Builder setBalancerRan(boolean balancerRan) { 048 this.balancerRan = balancerRan; 049 return this; 050 } 051 052 /** 053 * Set how many moves were calculated by the balancer. This will be zero if the cluster is 054 * already balanced. 055 * @param movesCalculated moves calculated by the balance run 056 */ 057 public Builder setMovesCalculated(int movesCalculated) { 058 this.movesCalculated = movesCalculated; 059 return this; 060 } 061 062 /** 063 * Set how many of the calculated moves were actually executed by the balancer. This should be 064 * zero if the balancer is run with {@link BalanceRequest#isDryRun()}. It may also not equal 065 * movesCalculated if the balancer ran out of time while executing the moves. 066 * @param movesExecuted moves executed by the balance run 067 */ 068 public Builder setMovesExecuted(int movesExecuted) { 069 this.movesExecuted = movesExecuted; 070 return this; 071 } 072 073 /** 074 * Build the {@link BalanceResponse} 075 */ 076 public BalanceResponse build() { 077 return new BalanceResponse(balancerRan, movesCalculated, movesExecuted); 078 } 079 } 080 081 /** 082 * Creates a new {@link BalanceResponse.Builder} 083 */ 084 public static Builder newBuilder() { 085 return new Builder(); 086 } 087 088 private final boolean balancerRan; 089 private final int movesCalculated; 090 private final int movesExecuted; 091 092 private BalanceResponse(boolean balancerRan, int movesCalculated, int movesExecuted) { 093 this.balancerRan = balancerRan; 094 this.movesCalculated = movesCalculated; 095 this.movesExecuted = movesExecuted; 096 } 097 098 /** 099 * Returns true if the balancer ran, otherwise false. The balancer may not run for a variety of 100 * reasons, such as: another balance is running, there are regions in transition, the cluster is 101 * in maintenance mode, etc. 102 */ 103 public boolean isBalancerRan() { 104 return balancerRan; 105 } 106 107 /** 108 * The number of moves calculated by the balancer if {@link #isBalancerRan()} is true. This will 109 * be zero if no better balance could be found. 110 */ 111 public int getMovesCalculated() { 112 return movesCalculated; 113 } 114 115 /** 116 * The number of moves actually executed by the balancer if it ran. This will be zero if 117 * {@link #getMovesCalculated()} is zero or if {@link BalanceRequest#isDryRun()} was true. It may 118 * also not be equal to {@link #getMovesCalculated()} if the balancer was interrupted midway 119 * through executing the moves due to max run time. 120 */ 121 public int getMovesExecuted() { 122 return movesExecuted; 123 } 124}