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 public SnapshotDescription(String name) { 042 this(name, null); 043 } 044 045 public SnapshotDescription(String name, TableName table) { 046 this(name, table, SnapshotType.DISABLED, null, -1, -1, null); 047 } 048 049 public SnapshotDescription(String name, TableName table, SnapshotType type) { 050 this(name, table, type, null, -1, -1, null); 051 } 052 053 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner) { 054 this(name, table, type, owner, -1, -1, null); 055 } 056 057 /** 058 * SnapshotDescription Parameterized Constructor 059 * 060 * @param name Name of the snapshot 061 * @param table TableName associated with the snapshot 062 * @param type Type of the snapshot - enum SnapshotType 063 * @param owner Snapshot Owner 064 * @param creationTime Creation time for Snapshot 065 * @param version Snapshot Version 066 * @deprecated since 2.3.0 and will be removed in 4.0.0. Use 067 * {@link #SnapshotDescription(String, TableName, SnapshotType, String, long, int, Map)} 068 */ 069 @Deprecated 070 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner, 071 long creationTime, int version) { 072 this(name, table, type, owner, creationTime, version, null); 073 } 074 075 /** 076 * SnapshotDescription Parameterized Constructor 077 * 078 * @param name Name of the snapshot 079 * @param table TableName associated with the snapshot 080 * @param type Type of the snapshot - enum SnapshotType 081 * @param owner Snapshot Owner 082 * @param creationTime Creation time for Snapshot 083 * @param version Snapshot Version 084 * @param snapshotProps Additional properties for snapshot e.g. TTL 085 */ 086 public SnapshotDescription(String name, TableName table, SnapshotType type, String owner, 087 long creationTime, int version, Map<String, Object> snapshotProps) { 088 this.name = name; 089 this.table = table; 090 this.snapShotType = type; 091 this.owner = owner; 092 this.creationTime = creationTime; 093 this.ttl = getTtlFromSnapshotProps(snapshotProps); 094 this.version = version; 095 } 096 097 private long getTtlFromSnapshotProps(Map<String, Object> snapshotProps) { 098 return MapUtils.getLongValue(snapshotProps, "TTL", -1); 099 } 100 101 /** 102 * SnapshotDescription Parameterized Constructor 103 * 104 * @param snapshotName Name of the snapshot 105 * @param tableName TableName associated with the snapshot 106 * @param type Type of the snapshot - enum SnapshotType 107 * @param snapshotProps Additional properties for snapshot e.g. TTL 108 */ 109 public SnapshotDescription(String snapshotName, TableName tableName, SnapshotType type, 110 Map<String, Object> snapshotProps) { 111 this(snapshotName, tableName, type, null, -1, -1, snapshotProps); 112 } 113 114 public String getName() { 115 return this.name; 116 } 117 118 public String getTableNameAsString() { 119 return this.table.getNameAsString(); 120 } 121 122 public TableName getTableName() { 123 return this.table; 124 } 125 126 public SnapshotType getType() { 127 return this.snapShotType; 128 } 129 130 public String getOwner() { 131 return this.owner; 132 } 133 134 public long getCreationTime() { 135 return this.creationTime; 136 } 137 138 // get snapshot ttl in sec 139 public long getTtl() { 140 return ttl; 141 } 142 143 public int getVersion() { 144 return this.version; 145 } 146 147 @Override 148 public String toString() { 149 return new ToStringBuilder(this) 150 .append("name", name) 151 .append("table", table) 152 .append("snapShotType", snapShotType) 153 .append("owner", owner) 154 .append("creationTime", creationTime) 155 .append("ttl", ttl) 156 .append("version", version) 157 .toString(); 158 } 159}