1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import com.google.protobuf.InvalidProtocolBufferException;
22 import org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.exceptions.DeserializationException;
24 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
25 import org.apache.hadoop.hbase.protobuf.generated.HBase170CompatibilityProtos.TableDescriptor;
26 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.Table;
27 import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.Table.State;
28
29
30
31
32 @InterfaceAudience.Private
33 public final class DeprecatedTableDescriptor {
34
35 private HTableDescriptor hTableDescriptor;
36 private Table tableState;
37
38 private DeprecatedTableDescriptor(HTableDescriptor hTableDescriptor, Table tableState) {
39 this.hTableDescriptor = hTableDescriptor;
40 this.tableState = tableState;
41 }
42
43 public HTableDescriptor getHTableDescriptor() {
44 return hTableDescriptor;
45 }
46
47 public Table getTableState() {
48 return tableState;
49 }
50
51
52
53
54
55 public static DeprecatedTableDescriptor parseFrom(final byte [] bytes)
56 throws DeserializationException {
57 if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
58 throw new DeserializationException("Expected PB encoded TableDescriptor");
59 }
60 int pblen = ProtobufUtil.lengthOfPBMagic();
61 TableDescriptor.Builder builder = TableDescriptor.newBuilder();
62 TableDescriptor ts;
63 try {
64 ts = builder.mergeFrom(bytes, pblen, bytes.length - pblen).build();
65 } catch (InvalidProtocolBufferException e) {
66 throw new DeserializationException(e);
67 }
68 return convert(ts);
69 }
70
71 private static DeprecatedTableDescriptor convert(TableDescriptor proto) {
72 HTableDescriptor hTableDescriptor = HTableDescriptor.convert(proto.getSchema());
73 State state = State.valueOf(proto.getState().getNumber());
74 Table tableState = Table.newBuilder().setState(state).build();
75 return new DeprecatedTableDescriptor(hTableDescriptor, tableState);
76 }
77 }