1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.master;
19
20 import org.apache.hadoop.hbase.HRegionInfo;
21 import org.apache.hadoop.hbase.ServerName;
22
23 /**
24 * Stores the plan for the move of an individual region.
25 *
26 * Contains info for the region being moved, info for the server the region
27 * should be moved from, and info for the server the region should be moved
28 * to.
29 *
30 * The comparable implementation of this class compares only the region
31 * information and not the source/dest server info.
32 */
33 public class RegionPlan implements Comparable<RegionPlan> {
34 private final HRegionInfo hri;
35 private final ServerName source;
36 private ServerName dest;
37
38 /**
39 * Instantiate a plan for a region move, moving the specified region from
40 * the specified source server to the specified destination server.
41 *
42 * Destination server can be instantiated as null and later set
43 * with {@link #setDestination(ServerName)}.
44 *
45 * @param hri region to be moved
46 * @param source regionserver region should be moved from
47 * @param dest regionserver region should be moved to
48 */
49 public RegionPlan(final HRegionInfo hri, ServerName source, ServerName dest) {
50 this.hri = hri;
51 this.source = source;
52 this.dest = dest;
53 }
54
55 /**
56 * Set the destination server for the plan for this region.
57 */
58 public void setDestination(ServerName dest) {
59 this.dest = dest;
60 }
61
62 /**
63 * Get the source server for the plan for this region.
64 * @return server info for source
65 */
66 public ServerName getSource() {
67 return source;
68 }
69
70 /**
71 * Get the destination server for the plan for this region.
72 * @return server info for destination
73 */
74 public ServerName getDestination() {
75 return dest;
76 }
77
78 /**
79 * Get the encoded region name for the region this plan is for.
80 * @return Encoded region name
81 */
82 public String getRegionName() {
83 return this.hri.getEncodedName();
84 }
85
86 public HRegionInfo getRegionInfo() {
87 return this.hri;
88 }
89
90 /**
91 * Compare the region info.
92 * @param o region plan you are comparing against
93 */
94 @Override
95 public int compareTo(RegionPlan o) {
96 return getRegionName().compareTo(o.getRegionName());
97 }
98
99 @Override
100 public String toString() {
101 return "hri=" + this.hri.getRegionNameAsString() + ", src=" +
102 (this.source == null? "": this.source.toString()) +
103 ", dest=" + (this.dest == null? "": this.dest.toString());
104 }
105 }