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.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.HTableDescriptor;
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      // FIXME these method names is really bad - trunk will probably change
42      // .META. and -ROOT- snapshots are not allowed
43      if (HTableDescriptor.isMetaTable(Bytes.toBytes(snapshot.getTable()))) {
44        throw new IllegalArgumentException(".META. and -ROOT- snapshots are not allowed");
45      }
46      // make sure the snapshot name is valid
47      HTableDescriptor.isLegalTableName(Bytes.toBytes(snapshot.getName()));
48      // make sure the table name is valid
49      HTableDescriptor.isLegalTableName(Bytes.toBytes(snapshot.getTable()));
50    }
51  
52    /**
53     * Returns a single line (no \n) representation of snapshot metadata.  Use this instead of
54     * {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription#toString()}.  We don't replace SnapshotDescrpition's toString
55     * because it is auto-generated by protoc.
56     * @param ssd
57     * @return Single line string with a summary of the snapshot parameters
58     */
59    public static String toString(HBaseProtos.SnapshotDescription ssd) {
60      if (ssd == null) {
61        return null;
62      }
63      return "{ ss=" + ssd.getName() + " table=" + ssd.getTable()
64          + " type=" + ssd.getType() + " }";
65    }
66  }