HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / StartTestingClusterOption.java
blobafd74bb9314ff8dc6ec7a19bd7a7f5f89b0e7452
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.
19 package org.apache.hadoop.hbase;
21 import java.util.Arrays;
22 import java.util.List;
23 import org.apache.commons.lang3.StringUtils;
24 import org.apache.hadoop.hbase.master.HMaster;
25 import org.apache.yetus.audience.InterfaceAudience;
26 import org.apache.yetus.audience.InterfaceStability;
28 /**
29 * Options for starting up a testing cluster (including an hbase, dfs and zookeeper clusters) in
30 * test. The options include HDFS options to build mini dfs cluster, Zookeeper options to build mini
31 * zk cluster, and mostly HBase options to build mini hbase cluster.
32 * <p/>
33 * To create an object, use a {@link Builder}.
34 * <p/>
35 * Example usage:
37 * <pre>
38 * StartTestingClusterOption option = StartTestingClusterOption.builder().
39 * .numMasters(3).rsClass(MyRegionServer.class).createWALDir(true).build();
40 * </pre>
42 * Default values can be found in {@link Builder}.
44 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.PHOENIX)
45 @InterfaceStability.Evolving
46 public final class StartTestingClusterOption {
47 /**
48 * Number of masters to start up. We'll start this many hbase masters. If numMasters > 1, you can
49 * find the active/primary master with {@link SingleProcessHBaseCluster#getMaster()}.
51 private final int numMasters;
53 /**
54 * Number of masters that always remain standby. These set of masters never transition to active
55 * even if an active master does not exist. These are needed for testing scenarios where there are
56 * no active masters in the cluster but the cluster connection (backed by master registry) should
57 * still work.
59 private final int numAlwaysStandByMasters;
60 /**
61 * The class to use as HMaster, or null for default.
63 private final Class<? extends HMaster> masterClass;
65 /**
66 * Number of region servers to start up. If this value is > 1, then make sure config
67 * "hbase.regionserver.info.port" is -1 (i.e. no ui per regionserver) otherwise bind errors.
69 private final int numRegionServers;
70 /**
71 * Ports that RegionServer should use. Pass ports if you want to test cluster restart where for
72 * sure the regionservers come up on same address+port (but just with different startcode); by
73 * default mini hbase clusters choose new arbitrary ports on each cluster start.
75 private final List<Integer> rsPorts;
76 /**
77 * The class to use as HRegionServer, or null for default.
79 private Class<? extends SingleProcessHBaseCluster.MiniHBaseClusterRegionServer> rsClass;
81 /**
82 * Number of datanodes. Used to create mini DSF cluster. Surpassed by {@link #dataNodeHosts} size.
84 private final int numDataNodes;
85 /**
86 * The hostnames of DataNodes to run on. This is useful if you want to run datanode on distinct
87 * hosts for things like HDFS block location verification. If you start MiniDFSCluster without
88 * host names, all instances of the datanodes will have the same host name.
90 private final String[] dataNodeHosts;
92 /**
93 * Number of Zookeeper servers.
95 private final int numZkServers;
97 /**
98 * Whether to create a new root or data directory path. If true, the newly created data directory
99 * will be configured as HBase rootdir. This will overwrite existing root directory config.
101 private final boolean createRootDir;
104 * Whether to create a new WAL directory. If true, the newly created directory will be configured
105 * as HBase wal.dir which is separate from HBase rootdir.
107 private final boolean createWALDir;
110 * Private constructor. Use {@link Builder#build()}.
112 private StartTestingClusterOption(int numMasters, int numAlwaysStandByMasters,
113 Class<? extends HMaster> masterClass, int numRegionServers, List<Integer> rsPorts,
114 Class<? extends SingleProcessHBaseCluster.MiniHBaseClusterRegionServer> rsClass,
115 int numDataNodes, String[] dataNodeHosts, int numZkServers, boolean createRootDir,
116 boolean createWALDir) {
117 this.numMasters = numMasters;
118 this.numAlwaysStandByMasters = numAlwaysStandByMasters;
119 this.masterClass = masterClass;
120 this.numRegionServers = numRegionServers;
121 this.rsPorts = rsPorts;
122 this.rsClass = rsClass;
123 this.numDataNodes = numDataNodes;
124 this.dataNodeHosts = dataNodeHosts;
125 this.numZkServers = numZkServers;
126 this.createRootDir = createRootDir;
127 this.createWALDir = createWALDir;
130 public int getNumMasters() {
131 return numMasters;
134 public int getNumAlwaysStandByMasters() {
135 return numAlwaysStandByMasters;
138 public Class<? extends HMaster> getMasterClass() {
139 return masterClass;
142 public int getNumRegionServers() {
143 return numRegionServers;
146 public List<Integer> getRsPorts() {
147 return rsPorts;
150 public Class<? extends SingleProcessHBaseCluster.MiniHBaseClusterRegionServer> getRsClass() {
151 return rsClass;
154 public int getNumDataNodes() {
155 return numDataNodes;
158 public String[] getDataNodeHosts() {
159 return dataNodeHosts;
162 public int getNumZkServers() {
163 return numZkServers;
166 public boolean isCreateRootDir() {
167 return createRootDir;
170 public boolean isCreateWALDir() {
171 return createWALDir;
174 @Override
175 public String toString() {
176 return "StartMiniClusterOption{" + "numMasters=" + numMasters + ", masterClass=" + masterClass +
177 ", numRegionServers=" + numRegionServers + ", rsPorts=" + StringUtils.join(rsPorts) +
178 ", rsClass=" + rsClass + ", numDataNodes=" + numDataNodes + ", dataNodeHosts=" +
179 Arrays.toString(dataNodeHosts) + ", numZkServers=" + numZkServers + ", createRootDir=" +
180 createRootDir + ", createWALDir=" + createWALDir + '}';
184 * Returns a new builder.
186 public static Builder builder() {
187 return new Builder();
191 * Builder pattern for creating an {@link StartTestingClusterOption}.
192 * <p/>
193 * The default values of its fields should be considered public and constant. Changing the default
194 * values may cause other tests fail.
196 public static final class Builder {
197 private int numMasters = 1;
198 private int numAlwaysStandByMasters = 0;
199 private Class<? extends HMaster> masterClass = null;
200 private int numRegionServers = 1;
201 private List<Integer> rsPorts = null;
202 private Class<? extends SingleProcessHBaseCluster.MiniHBaseClusterRegionServer> rsClass = null;
203 private int numDataNodes = 1;
204 private String[] dataNodeHosts = null;
205 private int numZkServers = 1;
206 private boolean createRootDir = false;
207 private boolean createWALDir = false;
209 private Builder() {
212 public StartTestingClusterOption build() {
213 if (dataNodeHosts != null && dataNodeHosts.length != 0) {
214 numDataNodes = dataNodeHosts.length;
216 return new StartTestingClusterOption(numMasters, numAlwaysStandByMasters, masterClass,
217 numRegionServers, rsPorts, rsClass, numDataNodes, dataNodeHosts, numZkServers,
218 createRootDir, createWALDir);
221 public Builder numMasters(int numMasters) {
222 this.numMasters = numMasters;
223 return this;
226 public Builder numAlwaysStandByMasters(int numAlwaysStandByMasters) {
227 this.numAlwaysStandByMasters = numAlwaysStandByMasters;
228 return this;
231 public Builder masterClass(Class<? extends HMaster> masterClass) {
232 this.masterClass = masterClass;
233 return this;
236 public Builder numRegionServers(int numRegionServers) {
237 this.numRegionServers = numRegionServers;
238 return this;
241 public Builder rsPorts(List<Integer> rsPorts) {
242 this.rsPorts = rsPorts;
243 return this;
246 public Builder
247 rsClass(Class<? extends SingleProcessHBaseCluster.MiniHBaseClusterRegionServer> rsClass) {
248 this.rsClass = rsClass;
249 return this;
252 public Builder numDataNodes(int numDataNodes) {
253 this.numDataNodes = numDataNodes;
254 return this;
257 public Builder dataNodeHosts(String[] dataNodeHosts) {
258 this.dataNodeHosts = dataNodeHosts;
259 return this;
262 public Builder numZkServers(int numZkServers) {
263 this.numZkServers = numZkServers;
264 return this;
267 public Builder createRootDir(boolean createRootDir) {
268 this.createRootDir = createRootDir;
269 return this;
272 public Builder createWALDir(boolean createWALDir) {
273 this.createWALDir = createWALDir;
274 return this;