001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import java.util.Map; 021 022import org.apache.hadoop.hbase.TableName; 023import org.apache.hbase.thirdparty.org.apache.commons.collections4.MapUtils; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * The POJO equivalent of HBaseProtos.SnapshotDescription 028 */ 029@InterfaceAudience.Public 030public class SnapshotDescription { 031 private final String name; 032 private final TableName table; 033 private final SnapshotType snapShotType; 034 private final String owner; 035 private final long creationTime; 036 private final int version; 037 038 private final long maxFileSize; 039 040 public SnapshotDescription(String name) { 041 this(name, (TableName)null); 042 } 043 044 /** 045 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 046 * instance instead. 047 * @see #SnapshotDescription(String, TableName) 048 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 049 */ 050 @Deprecated 051 public SnapshotDescription(String name, String table) { 052 this(name, TableName.valueOf(table)); 053 } 054 055 public SnapshotDescription(String name, TableName table) { 056 this(name, table, SnapshotType.DISABLED, null, -1, -1, null); 057 } 058 059 /** 060 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 061 * instance instead. 062 * @see #SnapshotDescription(String, TableName, SnapshotType) 063 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 064 */ 065 @Deprecated 066 public SnapshotDescription(String name, String table, SnapshotType type) { 067 this(name, TableName.valueOf(table), type); 068 } 069 070 public SnapshotDescription(String name, TableName table, SnapshotType type) { 071 this(name, table, type, null, -1, -1, null); 072 } 073 074 /** 075 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 076 * instance instead. 077 * @see #SnapshotDescription(String, TableName, SnapshotType, String) 078 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 079 */ 080 @Deprecated 081 public SnapshotDescription(String name, String table, SnapshotType type, String owner) { 082 this(name, TableName.valueOf(table), type, owner); 083 } 084 085 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner) { 086 this(name, table, type, owner, -1, -1, null); 087 } 088 089 /** 090 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 091 * instance instead. 092 * @see #SnapshotDescription(String, String, SnapshotType, String, long, int) 093 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 094 */ 095 @Deprecated 096 public SnapshotDescription(String name, String table, SnapshotType type, String owner, 097 long creationTime, int version) { 098 this(name, TableName.valueOf(table), type, owner, creationTime, version, null); 099 } 100 101 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner, 102 long creationTime, int version, Map<String, Object> snapshotProps) { 103 this.name = name; 104 this.table = table; 105 this.snapShotType = type; 106 this.owner = owner; 107 this.creationTime = creationTime; 108 this.version = version; 109 this.maxFileSize = getLongFromSnapshotProps(snapshotProps, TableDescriptorBuilder.MAX_FILESIZE); 110 } 111 112 private long getLongFromSnapshotProps(Map<String, Object> snapshotProps, String property) { 113 return MapUtils.getLongValue(snapshotProps, property, -1); 114 } 115 116 117 118 /** 119 * SnapshotDescription Parameterized Constructor 120 * 121 * @param snapshotName Name of the snapshot 122 * @param tableName TableName associated with the snapshot 123 * @param type Type of the snapshot - enum SnapshotType 124 * @param snapshotProps Additional properties for snapshot e.g. TTL 125 */ 126 public SnapshotDescription(String snapshotName, TableName tableName, SnapshotType type, 127 Map<String, Object> snapshotProps) { 128 this(snapshotName, tableName, type, null, -1, -1, snapshotProps); 129 } 130 131 public String getName() { 132 return this.name; 133 } 134 135 /** 136 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use {@link #getTableName()} or 137 * {@link #getTableNameAsString()} instead. 138 * @see #getTableName() 139 * @see #getTableNameAsString() 140 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 141 */ 142 @Deprecated 143 public String getTable() { 144 return getTableNameAsString(); 145 } 146 147 public String getTableNameAsString() { 148 return this.table.getNameAsString(); 149 } 150 151 public TableName getTableName() { 152 return this.table; 153 } 154 155 public SnapshotType getType() { 156 return this.snapShotType; 157 } 158 159 public String getOwner() { 160 return this.owner; 161 } 162 163 public long getCreationTime() { 164 return this.creationTime; 165 } 166 167 public int getVersion() { 168 return this.version; 169 } 170 171 public long getMaxFileSize() { 172 return maxFileSize; 173 } 174 175 @Override 176 public String toString() { 177 return "SnapshotDescription: name = " + ((name != null) ? name : null) + "/table = " 178 + ((table != null) ? table : null) + " /owner = " + ((owner != null) ? owner : null) 179 + (creationTime != -1 ? ("/creationtime = " + creationTime) : "") 180 + (version != -1 ? ("/version = " + version) : "") 181 + (maxFileSize != -1 ? ("/maxFileSize = " + maxFileSize) : ""); 182 } 183}