Skip to content

Commit

Permalink
BackupStatusMgr refactor (#569)
Browse files Browse the repository at this point in the history
1. Make backup/snapshot status manager store additional details like meta file location.
2. Ensure it can save last 60 snapshot days.
3. Allow bindable values on how to save snapshot status in file/datastore. Default implementation stores in a file on the local instance.
4. Non-backward compatible. The previous backup file gets overwritten with new values(null) during the upgrade process.
  • Loading branch information
arunagrawal-84 authored Jul 14, 2017
1 parent be895ee commit a551b2d
Show file tree
Hide file tree
Showing 16 changed files with 782 additions and 402 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Jun 28 17:25:48 PDT 2017
#Thu Jun 29 13:18:34 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
174 changes: 123 additions & 51 deletions priam/src/main/java/com/netflix/priam/backup/BackupMetadata.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2017 Netflix, Inc.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,91 +15,163 @@
*/
package com.netflix.priam.backup;

import java.util.ArrayList;
import java.util.Collection;
import com.netflix.priam.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
* POJO to encapsulate the metadata for a snapshot
* Created by aagrawal on 1/31/17.
*/

/*
* Encapsulates metadata for a backup for a day.
*/
public class BackupMetadata {
private List<String> backups = new ArrayList<String>();
private String key;
final public class BackupMetadata implements Serializable {
private String snapshotDate;
private String token;
private Date start, completed;
private Status status;
private String snapshotLocation;

/*
Represents a granular (includes hour and secs) backup for the day.
@param key see formatKey() for format
@param backupDate format is yyyymmddhhss
/**
* Enum to describe the status of the snapshot
*/
public BackupMetadata(String key, String backupDate) {
this.key = key;
backups.add(backupDate);
public enum Status {
/**
* Denotes snapshot has started successfully.
*/
STARTED,
/**
* Denotes snapshot has uploaded successfully.
*/
FINISHED,
/**
* Denotes snapshot has failed to upload successfully or there was a failure marking the snapshot as failure.
*/
FAILED
}
/*
Represents a high level(does not includ hour and secs) backup for the day.
@param key see formatKey() for format
@param backupDate format is yyyymmddhhss
*/
public BackupMetadata(String key) {
this.key = key;

public BackupMetadata(String token, Date start) throws Exception {
if (start == null || token == null || StringUtils.isEmpty(token))
throw new Exception(String.format("Invalid Input: Token: {} or start date:{} is null or empty.", token, start));

this.snapshotDate = DateUtil.formatyyyyMMdd(start);
this.token = token;
this.start = start;
this.status = Status.STARTED;
}

/*
* @return a list of all backups for the day, empty list if no backups.
*/
public Collection<String> getBackups() {
return backups;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;

BackupMetadata that = (BackupMetadata) o;

if (!this.snapshotDate.equals(that.snapshotDate)) return false;
if (!this.token.equals(that.token)) return false;
return this.start.equals(that.start);
}

public void setKey(String key) {
this.key = key;
@Override
public int hashCode() {
int result = this.snapshotDate.hashCode();
result = 31 * result + this.token.hashCode();
result = 31 * result + this.start.hashCode();
return result;
}
/*
* @return the date of the backup. Format of date is yyyymmdd.

/**
* Get the snapshot date formatted in yyyyMMdd.
*
* @return snapshot date formatted in yyyyMMdd.
*/
public String getKey() {
return this.key;
public String getSnapshotDate() {
return this.snapshotDate;
}

/**
* Get the token for which snapshot was initiated.
*
* @return snapshot token.
*/
public String getToken() {
return token;
return this.token;
}

public void setToken(String token) {
this.token = token;
/**
* Get the start date on which snapshot was initiated.
*
* @return start date of snapshot.
*/
public Date getStart() {
return this.start;
}

public Date getStartTime() {
return start;
/**
* Get the date on which snapshot was marked as finished/failed etc.
*
* @return completion date of snapshot.
*/

public Date getCompleted() {
return this.completed;
}

public void setStartTime(Date start) {
this.start = start;
/**
* Get the status of the snapshot.
*
* @return snapshot status
*/
public BackupMetadata.Status getStatus() {
return this.status;
}

public void setCompletedTime(Date completed) {
/**
* Set the completion date of snashot status.
*
* @param completed date of completion for a snapshot.
*/
public void setCompleted(Date completed) {
this.completed = completed;
}

public Date getCompletedTime() {
return this.completed;
/**
* Set the status of the snapshot.
*
* @param status of the snapshot.
*/
public void setStatus(Status status) {
this.status = status;
}

/**
* Get the snapshot location where snapshot is uploaded.
*
* @return snapshot upload location for the meta file.
*/
public String getSnapshotLocation() {
return this.snapshotLocation;
}

/**
* Set the snapshot location where snapshot is uploaded.
*
* @param snapshotLocation where snapshot meta file is uploaded.
*/
public void setSnapshotLocation(String snapshotLocation) {
this.snapshotLocation = snapshotLocation;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("BackupMetadata{");
sb.append("backups=").append(backups);
sb.append(", key='").append(key).append('\'');
final StringBuffer sb = new StringBuffer("BackupMetadata{");
sb.append("snapshotDate='").append(snapshotDate).append('\'');
sb.append(", token='").append(token).append('\'');
sb.append(", start=").append(start);
sb.append(", completed=").append(completed);
sb.append(", status=").append(status);
sb.append(", snapshotLocation=").append(snapshotLocation);
sb.append('}');
return sb.toString();
}
Expand Down
Loading

0 comments on commit a551b2d

Please sign in to comment.