3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org
.apache
.hadoop
.hbase
.client
;
22 import java
.util
.List
;
24 import org
.apache
.commons
.lang3
.builder
.ToStringBuilder
;
25 import org
.apache
.hadoop
.hbase
.util
.GsonUtil
;
26 import org
.apache
.yetus
.audience
.InterfaceAudience
;
27 import org
.apache
.yetus
.audience
.InterfaceStability
;
29 import org
.apache
.hbase
.thirdparty
.com
.google
.gson
.Gson
;
30 import org
.apache
.hbase
.thirdparty
.com
.google
.gson
.JsonSerializer
;
33 * History of balancer decisions taken for region movements.
35 @InterfaceAudience.Public
36 @InterfaceStability.Evolving
37 final public class BalancerDecision
extends LogEntry
{
39 private final String initialFunctionCosts
;
40 private final String finalFunctionCosts
;
41 private final double initTotalCost
;
42 private final double computedTotalCost
;
43 private final long computedSteps
;
44 private final List
<String
> regionPlans
;
46 // used to convert object to pretty printed format
47 // used by toJsonPrettyPrint()
48 private static final Gson GSON
= GsonUtil
.createGson()
50 .registerTypeAdapter(BalancerDecision
.class, (JsonSerializer
<BalancerDecision
>)
51 (balancerDecision
, type
, jsonSerializationContext
) -> {
52 Gson gson
= new Gson();
53 return gson
.toJsonTree(balancerDecision
);
56 private BalancerDecision(String initialFunctionCosts
, String finalFunctionCosts
,
57 double initTotalCost
, double computedTotalCost
, List
<String
> regionPlans
,
59 this.initialFunctionCosts
= initialFunctionCosts
;
60 this.finalFunctionCosts
= finalFunctionCosts
;
61 this.initTotalCost
= initTotalCost
;
62 this.computedTotalCost
= computedTotalCost
;
63 this.regionPlans
= regionPlans
;
64 this.computedSteps
= computedSteps
;
67 public String
getInitialFunctionCosts() {
68 return initialFunctionCosts
;
71 public String
getFinalFunctionCosts() {
72 return finalFunctionCosts
;
75 public double getInitTotalCost() {
79 public double getComputedTotalCost() {
80 return computedTotalCost
;
83 public List
<String
> getRegionPlans() {
87 public long getComputedSteps() {
92 public String
toString() {
93 return new ToStringBuilder(this)
94 .append("initialFunctionCosts", initialFunctionCosts
)
95 .append("finalFunctionCosts", finalFunctionCosts
)
96 .append("initTotalCost", initTotalCost
)
97 .append("computedTotalCost", computedTotalCost
)
98 .append("computedSteps", computedSteps
)
99 .append("regionPlans", regionPlans
)
104 public String
toJsonPrettyPrint() {
105 return GSON
.toJson(this);
108 public static class Builder
{
109 private String initialFunctionCosts
;
110 private String finalFunctionCosts
;
111 private double initTotalCost
;
112 private double computedTotalCost
;
113 private long computedSteps
;
114 private List
<String
> regionPlans
;
116 public Builder
setInitialFunctionCosts(String initialFunctionCosts
) {
117 this.initialFunctionCosts
= initialFunctionCosts
;
121 public Builder
setFinalFunctionCosts(String finalFunctionCosts
) {
122 this.finalFunctionCosts
= finalFunctionCosts
;
126 public Builder
setInitTotalCost(double initTotalCost
) {
127 this.initTotalCost
= initTotalCost
;
131 public Builder
setComputedTotalCost(double computedTotalCost
) {
132 this.computedTotalCost
= computedTotalCost
;
136 public Builder
setRegionPlans(List
<String
> regionPlans
) {
137 this.regionPlans
= regionPlans
;
141 public Builder
setComputedSteps(long computedSteps
) {
142 this.computedSteps
= computedSteps
;
146 public BalancerDecision
build() {
147 return new BalancerDecision(initialFunctionCosts
, finalFunctionCosts
,
148 initTotalCost
, computedTotalCost
, regionPlans
, computedSteps
);