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.TableName; 24 import org.apache.hadoop.hbase.HTableDescriptor; 25 import org.apache.hadoop.hbase.protobuf.ProtobufUtil; 26 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; 27 import org.apache.hadoop.hbase.util.Bytes; 28 29 /** 30 * Class to help with dealing with a snapshot description on the client side. 31 * There is a corresponding class on the server side. 32 */ 33 @InterfaceAudience.Private 34 public class ClientSnapshotDescriptionUtils { 35 /** 36 * Check to make sure that the description of the snapshot requested is valid 37 * @param snapshot description of the snapshot 38 * @throws IllegalArgumentException if the name of the snapshot or the name of the table to 39 * snapshot are not valid names. 40 */ 41 public static void assertSnapshotRequestIsValid(HBaseProtos.SnapshotDescription snapshot) 42 throws IllegalArgumentException { 43 // make sure the snapshot name is valid 44 TableName.isLegalTableQualifierName(Bytes.toBytes(snapshot.getName())); 45 if(snapshot.hasTable()) { 46 // make sure the table name is valid, this will implicitly check validity 47 TableName tableName = TableName.valueOf(snapshot.getTable()); 48 49 if (HTableDescriptor.isSystemTable(tableName)) { 50 throw new IllegalArgumentException("System table snapshots are not allowed"); 51 } 52 } 53 } 54 55 /** 56 * Returns a single line (no \n) representation of snapshot metadata. Use this instead of 57 * {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription#toString()}. We don't replace SnapshotDescrpition's toString 58 * because it is auto-generated by protoc. 59 * @param ssd 60 * @return Single line string with a summary of the snapshot parameters 61 */ 62 public static String toString(HBaseProtos.SnapshotDescription ssd) { 63 if (ssd == null) { 64 return null; 65 } 66 return "{ ss=" + ssd.getName() + 67 " table=" + (ssd.hasTable()?TableName.valueOf(ssd.getTable()):"") + 68 " type=" + ssd.getType() + " }"; 69 } 70 }