View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.snapshot;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.TableName;
24  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
25  import org.apache.hadoop.hbase.util.Bytes;
26  
27  /**
28   * Class to help with dealing with a snapshot description on the client side.
29   * There is a corresponding class on the server side.
30   */
31  @InterfaceAudience.Private
32  public class ClientSnapshotDescriptionUtils {
33    /**
34     * Check to make sure that the description of the snapshot requested is valid
35     * @param snapshot description of the snapshot
36     * @throws IllegalArgumentException if the name of the snapshot or the name of the table to
37     *           snapshot are not valid names.
38     */
39    public static void assertSnapshotRequestIsValid(HBaseProtos.SnapshotDescription snapshot)
40        throws IllegalArgumentException {
41      // make sure the snapshot name is valid
42      TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName()), true);
43      if(snapshot.hasTable()) {
44        // make sure the table name is valid, this will implicitly check validity
45        TableName tableName = TableName.valueOf(snapshot.getTable());
46  
47        if (tableName.isSystemTable()) {
48          throw new IllegalArgumentException("System table snapshots are not allowed");
49        }
50      }
51    }
52  
53    /**
54     * Returns a single line (no \n) representation of snapshot metadata.  Use this instead of
55     * {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription#toString()}.  We don't replace SnapshotDescrpition's toString
56     * because it is auto-generated by protoc.
57     * @param ssd
58     * @return Single line string with a summary of the snapshot parameters
59     */
60    public static String toString(HBaseProtos.SnapshotDescription ssd) {
61      if (ssd == null) {
62        return null;
63      }
64      return "{ ss=" + ssd.getName() +
65             " table=" + (ssd.hasTable()?TableName.valueOf(ssd.getTable()):"") +
66             " type=" + ssd.getType() + " }";
67    }
68  }