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