|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hbase.snapshot; |
19 | 19 |
|
| 20 | +import static org.apache.hadoop.hbase.HConstants.DEFAULT_SNAPSHOT_TTL; |
| 21 | + |
20 | 22 | import java.io.FileNotFoundException; |
21 | 23 | import java.io.IOException; |
22 | 24 | import java.net.URI; |
|
71 | 73 | public final class SnapshotInfo extends AbstractHBaseTool { |
72 | 74 | private static final Logger LOG = LoggerFactory.getLogger(SnapshotInfo.class); |
73 | 75 |
|
| 76 | + private static final String EXPIRED_LABEL = "Yes"; |
| 77 | + private static final String NOT_EXPIRED_LABEL = "No"; |
| 78 | + private static final String TTL_FOREVER = "FOREVER"; |
| 79 | + |
74 | 80 | static final class Options { |
75 | 81 | static final Option SNAPSHOT = |
76 | 82 | new Option(null, "snapshot", true, "The name of the snapshot to be detailed."); |
@@ -391,11 +397,18 @@ public int doWork() throws IOException, InterruptedException { |
391 | 397 | // List Available Snapshots |
392 | 398 | if (listSnapshots) { |
393 | 399 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
394 | | - System.out.printf("%-20s | %-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME", "TTL IN SEC", |
395 | | - "TABLE NAME"); |
396 | | - for (SnapshotDescription desc : getSnapshotList(conf)) { |
397 | | - System.out.printf("%-20s | %20s | %20s | %s%n", desc.getName(), |
398 | | - df.format(new Date(desc.getCreationTime())), desc.getTtl(), desc.getTableNameAsString()); |
| 400 | + List<SnapshotDescription> snapshotDescriptions = getSnapshotList(conf); |
| 401 | + System.out.printf("%-20s | %-20s | %-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME", |
| 402 | + "TTL(Sec)", "EXPIRED", "TABLE NAME"); |
| 403 | + long currentTime = System.currentTimeMillis(); |
| 404 | + for (SnapshotDescription desc : snapshotDescriptions) { |
| 405 | + String ttlInfo = |
| 406 | + desc.getTtl() == DEFAULT_SNAPSHOT_TTL ? TTL_FOREVER : String.valueOf(desc.getTtl()); |
| 407 | + String expired = SnapshotDescriptionUtils.isExpiredSnapshot(desc.getTtl(), |
| 408 | + desc.getCreationTime(), currentTime) ? EXPIRED_LABEL : NOT_EXPIRED_LABEL; |
| 409 | + System.out.printf("%-20s | %20s | %20s | %20s | %s%n", desc.getName(), |
| 410 | + df.format(new Date(desc.getCreationTime())), ttlInfo, expired, |
| 411 | + desc.getTableNameAsString()); |
399 | 412 | } |
400 | 413 | return 0; |
401 | 414 | } |
@@ -443,15 +456,23 @@ private boolean loadSnapshotInfo(final String snapshotName) throws IOException { |
443 | 456 | private void printInfo() { |
444 | 457 | SnapshotProtos.SnapshotDescription snapshotDesc = snapshotManifest.getSnapshotDescription(); |
445 | 458 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
| 459 | + String ttlInfo = snapshotDesc.getTtl() == DEFAULT_SNAPSHOT_TTL |
| 460 | + ? TTL_FOREVER |
| 461 | + : String.valueOf(snapshotDesc.getTtl()); |
| 462 | + String expired = SnapshotDescriptionUtils.isExpiredSnapshot(snapshotDesc.getTtl(), |
| 463 | + snapshotDesc.getCreationTime(), System.currentTimeMillis()) |
| 464 | + ? EXPIRED_LABEL |
| 465 | + : NOT_EXPIRED_LABEL; |
446 | 466 | System.out.println("Snapshot Info"); |
447 | | - System.out.println("----------------------------------------"); |
448 | | - System.out.println(" Name: " + snapshotDesc.getName()); |
449 | | - System.out.println(" Type: " + snapshotDesc.getType()); |
450 | | - System.out.println(" Table: " + snapshotDesc.getTable()); |
451 | | - System.out.println(" Format: " + snapshotDesc.getVersion()); |
452 | | - System.out.println("Created: " + df.format(new Date(snapshotDesc.getCreationTime()))); |
453 | | - System.out.println(" Ttl: " + snapshotDesc.getTtl()); |
454 | | - System.out.println(" Owner: " + snapshotDesc.getOwner()); |
| 467 | + System.out.println("-----------------------------------------"); |
| 468 | + System.out.println(" Name: " + snapshotDesc.getName()); |
| 469 | + System.out.println(" Type: " + snapshotDesc.getType()); |
| 470 | + System.out.println(" Table: " + snapshotDesc.getTable()); |
| 471 | + System.out.println(" Format: " + snapshotDesc.getVersion()); |
| 472 | + System.out.println(" Created: " + df.format(new Date(snapshotDesc.getCreationTime()))); |
| 473 | + System.out.println("Ttl(Sec): " + ttlInfo); |
| 474 | + System.out.println(" Expired: " + expired); |
| 475 | + System.out.println(" Owner: " + snapshotDesc.getOwner()); |
455 | 476 | System.out.println(); |
456 | 477 | } |
457 | 478 |
|
|
0 commit comments