View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.backup;
20  
21  import java.io.Serializable;
22  
23  import org.apache.hadoop.hbase.TableName;
24  import org.apache.hadoop.hbase.backup.util.BackupClientUtil;
25  import org.apache.hadoop.hbase.classification.InterfaceAudience;
26  import org.apache.hadoop.hbase.classification.InterfaceStability;
27  import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
28  import org.apache.hadoop.hbase.protobuf.generated.BackupProtos;
29  
30  /**
31   * Backup status and related information encapsulated for a table.
32   * At this moment only TargetDir and SnapshotName is encapsulated here.
33   */
34  
35  @InterfaceAudience.Private
36  @InterfaceStability.Evolving
37  public class BackupStatus implements Serializable {
38  
39    private static final long serialVersionUID = -5968397963548535982L;
40  
41    // table name for backup
42    private TableName table;
43  
44    // target directory of the backup image for this table
45    private String targetDir;
46  
47    // snapshot name for offline/online snapshot
48    private String snapshotName = null;
49  
50    public BackupStatus() {
51  
52    }
53  
54    public BackupStatus(TableName table, String targetRootDir, String backupId) {
55      this.table = table;
56      this.targetDir = BackupClientUtil.getTableBackupDir(targetRootDir, backupId, table);
57    }
58  
59    public String getSnapshotName() {
60      return snapshotName;
61    }
62  
63    public void setSnapshotName(String snapshotName) {
64      this.snapshotName = snapshotName;
65    }
66  
67    public String getTargetDir() {
68      return targetDir;
69    }
70  
71    public TableName getTable() {
72      return table;
73    }
74  
75    public void setTable(TableName table) {
76      this.table = table;
77    }
78  
79    public void setTargetDir(String targetDir) {
80      this.targetDir = targetDir;
81    }
82  
83    public static BackupStatus convert(BackupProtos.TableBackupStatus proto)
84    {
85      BackupStatus bs = new BackupStatus();
86      bs.setTable(ProtobufUtil.toTableName(proto.getTable()));
87      bs.setTargetDir(proto.getTargetDir());
88      if(proto.hasSnapshot()){
89        bs.setSnapshotName(proto.getSnapshot());
90      }
91      return bs;
92    }
93  
94    public BackupProtos.TableBackupStatus toProto() {
95      BackupProtos.TableBackupStatus.Builder builder =
96          BackupProtos.TableBackupStatus.newBuilder();
97      if(snapshotName != null) {
98        builder.setSnapshot(snapshotName);
99      }
100     builder.setTable(ProtobufUtil.toProtoTableName(table));
101     builder.setTargetDir(targetDir);
102     return builder.build();
103   }
104 }