1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.catalog;
20
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.HRegionInfo;
28 import org.apache.hadoop.hbase.KeyValue;
29 import org.apache.hadoop.hbase.ServerName;
30 import org.apache.hadoop.hbase.client.Result;
31 import org.apache.hadoop.hbase.util.Bytes;
32
33
34
35
36 public class MetaMockingUtil {
37
38
39
40
41
42
43
44
45 public static Result getMetaTableRowResult(final HRegionInfo region)
46 throws IOException {
47 return getMetaTableRowResult(region, null, null, null);
48 }
49
50
51
52
53
54
55
56
57
58 public static Result getMetaTableRowResult(final HRegionInfo region, final ServerName sn)
59 throws IOException {
60 return getMetaTableRowResult(region, sn, null, null);
61 }
62
63
64
65
66
67
68
69
70
71
72
73 public static Result getMetaTableRowResult(HRegionInfo region, final ServerName sn,
74 HRegionInfo splita, HRegionInfo splitb) throws IOException {
75 List<KeyValue> kvs = new ArrayList<KeyValue>();
76 if (region != null) {
77 kvs.add(new KeyValue(
78 region.getRegionName(),
79 HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER,
80 region.toByteArray()));
81 }
82
83 if (sn != null) {
84 kvs.add(new KeyValue(region.getRegionName(),
85 HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER,
86 Bytes.toBytes(sn.getHostAndPort())));
87 kvs.add(new KeyValue(region.getRegionName(),
88 HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER,
89 Bytes.toBytes(sn.getStartcode())));
90 }
91
92 if (splita != null) {
93 kvs.add(new KeyValue(
94 region.getRegionName(),
95 HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER,
96 splita.toByteArray()));
97 }
98
99 if (splitb != null) {
100 kvs.add(new KeyValue(
101 region.getRegionName(),
102 HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER,
103 splitb.toByteArray()));
104 }
105
106
107 Collections.sort(kvs, KeyValue.META_COMPARATOR);
108
109 return new Result(kvs);
110 }
111
112
113
114
115
116
117
118 public static Result getMetaTableRowResultAsSplitRegion(final HRegionInfo hri, final ServerName sn)
119 throws IOException {
120 hri.setOffline(true);
121 hri.setSplit(true);
122 return getMetaTableRowResult(hri, sn);
123 }
124
125 }