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.commons.lang3.builder.ToStringBuilder; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.yetus.audience.InterfaceAudience; 025 026import org.apache.hbase.thirdparty.org.apache.commons.collections4.MapUtils; 027 028/** 029 * The POJO equivalent of HBaseProtos.SnapshotDescription 030 */ 031@InterfaceAudience.Public 032public class SnapshotDescription { 033 private final String name; 034 private final TableName table; 035 private final SnapshotType snapShotType; 036 private final String owner; 037 private final long creationTime; 038 private final long ttl; 039 private final int version; 040 041 private final long maxFileSize; 042 043 public SnapshotDescription(String name) { 044 this(name, (TableName) null); 045 } 046 047 /** 048 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 049 * instance instead. 050 * @see #SnapshotDescription(String, TableName) 051 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 052 */ 053 @Deprecated 054 public SnapshotDescription(String name, String table) { 055 this(name, TableName.valueOf(table)); 056 } 057 058 public SnapshotDescription(String name, TableName table) { 059 this(name, table, SnapshotType.DISABLED, null, -1, -1, null); 060 } 061 062 /** 063 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 064 * instance instead. 065 * @see #SnapshotDescription(String, TableName, SnapshotType) 066 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 067 */ 068 @Deprecated 069 public SnapshotDescription(String name, String table, SnapshotType type) { 070 this(name, TableName.valueOf(table), type); 071 } 072 073 public SnapshotDescription(String name, TableName table, SnapshotType type) { 074 this(name, table, type, null, -1, -1, null); 075 } 076 077 /** 078 * @see #SnapshotDescription(String, TableName, SnapshotType, String) 079 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 080 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 081 * instance instead. 082 */ 083 @Deprecated 084 public SnapshotDescription(String name, String table, SnapshotType type, String owner) { 085 this(name, TableName.valueOf(table), type, owner); 086 } 087 088 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner) { 089 this(name, table, type, owner, -1, -1, null); 090 } 091 092 /** 093 * @see #SnapshotDescription(String, TableName, SnapshotType, String, long, int, Map) 094 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 095 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use the version with the TableName 096 * instance instead. 097 */ 098 @Deprecated 099 public SnapshotDescription(String name, String table, SnapshotType type, String owner, 100 long creationTime, int version) { 101 this(name, TableName.valueOf(table), type, owner, creationTime, version, null); 102 } 103 104 /** 105 * SnapshotDescription Parameterized Constructor 106 * 107 * @param name Name of the snapshot 108 * @param table TableName associated with the snapshot 109 * @param type Type of the snapshot - enum SnapshotType 110 * @param owner Snapshot Owner 111 * @param creationTime Creation time for Snapshot 112 * @param version Snapshot Version 113 * @deprecated since 2.3.0 and will be removed in 4.0.0. Use 114 * {@link #SnapshotDescription(String, TableName, SnapshotType, String, long, int, Map)} 115 */ 116 @Deprecated 117 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner, 118 long creationTime, int version) { 119 this(name, table, type, owner, creationTime, version, null); 120 } 121 122 /** 123 * SnapshotDescription Parameterized Constructor 124 * 125 * @param name Name of the snapshot 126 * @param table TableName associated with the snapshot 127 * @param type Type of the snapshot - enum SnapshotType 128 * @param owner Snapshot Owner 129 * @param creationTime Creation time for Snapshot 130 * @param version Snapshot Version 131 * @param snapshotProps Additional properties for snapshot e.g. TTL 132 */ 133 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner, 134 long creationTime, int version, Map<String, Object> snapshotProps) { 135 this.name = name; 136 this.table = table; 137 this.snapShotType = type; 138 this.owner = owner; 139 this.creationTime = creationTime; 140 this.ttl = getLongFromSnapshotProps(snapshotProps, "TTL"); 141 this.version = version; 142 this.maxFileSize = getLongFromSnapshotProps(snapshotProps, TableDescriptorBuilder.MAX_FILESIZE); 143 } 144 145 private long getLongFromSnapshotProps(Map<String, Object> snapshotProps, String property) { 146 return MapUtils.getLongValue(snapshotProps, property, -1); 147 } 148 149 150 151 /** 152 * SnapshotDescription Parameterized Constructor 153 * 154 * @param snapshotName Name of the snapshot 155 * @param tableName TableName associated with the snapshot 156 * @param type Type of the snapshot - enum SnapshotType 157 * @param snapshotProps Additional properties for snapshot e.g. TTL 158 */ 159 public SnapshotDescription(String snapshotName, TableName tableName, SnapshotType type, 160 Map<String, Object> snapshotProps) { 161 this(snapshotName, tableName, type, null, -1, -1, snapshotProps); 162 } 163 164 public String getName() { 165 return this.name; 166 } 167 168 /** 169 * @deprecated since 2.0.0 and will be removed in 3.0.0. Use {@link #getTableName()} or 170 * {@link #getTableNameAsString()} instead. 171 * @see #getTableName() 172 * @see #getTableNameAsString() 173 * @see <a href="https://issues.apache.org/jira/browse/HBASE-16892">HBASE-16892</a> 174 */ 175 @Deprecated 176 public String getTable() { 177 return getTableNameAsString(); 178 } 179 180 public String getTableNameAsString() { 181 return this.table.getNameAsString(); 182 } 183 184 public TableName getTableName() { 185 return this.table; 186 } 187 188 public SnapshotType getType() { 189 return this.snapShotType; 190 } 191 192 public String getOwner() { 193 return this.owner; 194 } 195 196 public long getCreationTime() { 197 return this.creationTime; 198 } 199 200 // get snapshot ttl in sec 201 public long getTtl() { 202 return ttl; 203 } 204 205 public int getVersion() { 206 return this.version; 207 } 208 209 public long getMaxFileSize() { return maxFileSize; } 210 211 @Override 212 public String toString() { 213 return new ToStringBuilder(this) 214 .append("name", name) 215 .append("table", table) 216 .append("snapShotType", snapShotType) 217 .append("owner", owner) 218 .append("creationTime", creationTime) 219 .append("ttl", ttl) 220 .append("version", version) 221 .append("maxFileSize", maxFileSize) 222 .toString(); 223 } 224}