HBASE-26688 Threads shared EMPTY_RESULT may lead to unexpected client job down. ...
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / BalancerDecision.java
blobe2bf2e28e0e7c950836206d8bcb5da796ebef2c6
1 /*
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;
32 /**
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()
49 .setPrettyPrinting()
50 .registerTypeAdapter(BalancerDecision.class, (JsonSerializer<BalancerDecision>)
51 (balancerDecision, type, jsonSerializationContext) -> {
52 Gson gson = new Gson();
53 return gson.toJsonTree(balancerDecision);
54 }).create();
56 private BalancerDecision(String initialFunctionCosts, String finalFunctionCosts,
57 double initTotalCost, double computedTotalCost, List<String> regionPlans,
58 long computedSteps) {
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() {
76 return initTotalCost;
79 public double getComputedTotalCost() {
80 return computedTotalCost;
83 public List<String> getRegionPlans() {
84 return regionPlans;
87 public long getComputedSteps() {
88 return computedSteps;
91 @Override
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)
100 .toString();
103 @Override
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;
118 return this;
121 public Builder setFinalFunctionCosts(String finalFunctionCosts) {
122 this.finalFunctionCosts = finalFunctionCosts;
123 return this;
126 public Builder setInitTotalCost(double initTotalCost) {
127 this.initTotalCost = initTotalCost;
128 return this;
131 public Builder setComputedTotalCost(double computedTotalCost) {
132 this.computedTotalCost = computedTotalCost;
133 return this;
136 public Builder setRegionPlans(List<String> regionPlans) {
137 this.regionPlans = regionPlans;
138 return this;
141 public Builder setComputedSteps(long computedSteps) {
142 this.computedSteps = computedSteps;
143 return this;
146 public BalancerDecision build() {
147 return new BalancerDecision(initialFunctionCosts, finalFunctionCosts,
148 initTotalCost, computedTotalCost, regionPlans, computedSteps);