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