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