1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.rest.model;
21
22 import java.io.Serializable;
23
24 import javax.xml.bind.annotation.XmlAttribute;
25 import javax.xml.bind.annotation.XmlRootElement;
26
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.HRegionInfo;
30 import org.apache.hadoop.hbase.util.Bytes;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 @XmlRootElement(name="Region")
47 @InterfaceAudience.Private
48 public class TableRegionModel implements Serializable {
49
50 private static final long serialVersionUID = 1L;
51
52 private String table;
53 private long id;
54 private byte[] startKey;
55 private byte[] endKey;
56 private String location;
57
58
59
60
61 public TableRegionModel() {}
62
63
64
65
66
67
68
69
70 public TableRegionModel(String table, long id, byte[] startKey,
71 byte[] endKey) {
72 this(table, id, startKey, endKey, null);
73 }
74
75
76
77
78
79
80
81
82
83 public TableRegionModel(String table, long id, byte[] startKey,
84 byte[] endKey, String location) {
85 this.table = table;
86 this.id = id;
87 this.startKey = startKey;
88 this.endKey = endKey;
89 this.location = location;
90 }
91
92
93
94
95 @XmlAttribute
96 public String getName() {
97 byte [] tableNameAsBytes = Bytes.toBytes(this.table);
98 TableName tableName = TableName.valueOf(tableNameAsBytes);
99 byte [] nameAsBytes = HRegionInfo.createRegionName(
100 tableName, this.startKey, this.id, !tableName.isSystemTable());
101 return Bytes.toString(nameAsBytes);
102 }
103
104
105
106
107 @XmlAttribute
108 public long getId() {
109 return id;
110 }
111
112
113
114
115 @XmlAttribute
116 public byte[] getStartKey() {
117 return startKey;
118 }
119
120
121
122
123 @XmlAttribute
124 public byte[] getEndKey() {
125 return endKey;
126 }
127
128
129
130
131 @XmlAttribute
132 public String getLocation() {
133 return location;
134 }
135
136
137
138
139 public void setName(String name) {
140 String split[] = name.split(",");
141 this.table = split[0];
142 this.startKey = Bytes.toBytes(split[1]);
143 String tail = split[2];
144 split = tail.split("\\.");
145 id = Long.parseLong(split[0]);
146 }
147
148
149
150
151 public void setId(long id) {
152 this.id = id;
153 }
154
155
156
157
158 public void setStartKey(byte[] startKey) {
159 this.startKey = startKey;
160 }
161
162
163
164
165 public void setEndKey(byte[] endKey) {
166 this.endKey = endKey;
167 }
168
169
170
171
172 public void setLocation(String location) {
173 this.location = location;
174 }
175
176
177
178
179 @Override
180 public String toString() {
181 StringBuilder sb = new StringBuilder();
182 sb.append(getName());
183 sb.append(" [\n id=");
184 sb.append(id);
185 sb.append("\n startKey='");
186 sb.append(Bytes.toString(startKey));
187 sb.append("'\n endKey='");
188 sb.append(Bytes.toString(endKey));
189 if (location != null) {
190 sb.append("'\n location='");
191 sb.append(location);
192 }
193 sb.append("'\n]\n");
194 return sb.toString();
195 }
196 }