HBASE-26765 Minor refactor of async scanning code (#4121)
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / client / BalancerRejection.java
blobd6e6cee20fc86b1ef8de6273b398b9429b481312
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.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
26 import org.apache.commons.lang3.builder.ToStringBuilder;
27 import org.apache.hadoop.hbase.util.GsonUtil;
28 import org.apache.yetus.audience.InterfaceAudience;
29 import org.apache.yetus.audience.InterfaceStability;
31 import org.apache.hbase.thirdparty.com.google.gson.Gson;
32 import org.apache.hbase.thirdparty.com.google.gson.JsonSerializer;
34 /**
35 * History of detail information that balancer movements was rejected
37 @InterfaceAudience.Public
38 @InterfaceStability.Evolving
39 final public class BalancerRejection extends LogEntry {
40 //The reason why balancer was rejected
41 private final String reason;
42 private final List<String> costFuncInfoList;
44 // used to convert object to pretty printed format
45 // used by toJsonPrettyPrint()
46 private static final Gson GSON = GsonUtil.createGson()
47 .setPrettyPrinting()
48 .disableHtmlEscaping()
49 .registerTypeAdapter(BalancerRejection.class, (JsonSerializer<BalancerRejection>)
50 (balancerRejection, type, jsonSerializationContext) -> {
51 Gson gson = new Gson();
52 return gson.toJsonTree(balancerRejection);
53 }).create();
55 private BalancerRejection(String reason, List<String> costFuncInfoList) {
56 this.reason = reason;
57 if(costFuncInfoList == null){
58 this.costFuncInfoList = Collections.emptyList();
60 else {
61 this.costFuncInfoList = costFuncInfoList;
65 public String getReason() {
66 return reason;
69 public List<String> getCostFuncInfoList() {
70 return costFuncInfoList;
73 @Override
74 public String toString() {
75 return new ToStringBuilder(this)
76 .append("reason", reason)
77 .append("costFuncInfoList", costFuncInfoList.toString())
78 .toString();
81 @Override
82 public String toJsonPrettyPrint() {
83 return GSON.toJson(this);
86 public static class Builder {
87 private String reason;
88 private List<String> costFuncInfoList;
90 public Builder setReason(String reason) {
91 this.reason = reason;
92 return this;
95 public void addCostFuncInfo(String funcName, double cost, float multiplier){
96 if(costFuncInfoList == null){
97 costFuncInfoList = new ArrayList<>();
99 costFuncInfoList.add(
100 new StringBuilder()
101 .append(funcName)
102 .append(" cost:").append(cost)
103 .append(" multiplier:").append(multiplier)
104 .toString());
107 public Builder setCostFuncInfoList(List<String> costFuncInfoList){
108 this.costFuncInfoList = costFuncInfoList;
109 return this;
112 public BalancerRejection build() {
113 return new BalancerRejection(reason, costFuncInfoList);