Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/main/java/com/cloud/configuration/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ enum ResourceType { // Primary and Secondary storage are allocated_storage and n
cpu("cpu", 8),
memory("memory", 9),
primary_storage("primary_storage", 10),
secondary_storage("secondary_storage", 11);
secondary_storage("secondary_storage", 11),
backup("backup", 12);

private String name;
private int ordinal;
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public class ApiConstants {
public static final String MAC_ADDRESS = "macaddress";
public static final String MAX = "max";
public static final String MAX_SNAPS = "maxsnaps";
public static final String MAX_BACKUPS = "maxbackups";
public static final String MAX_CPU_NUMBER = "maxcpunumber";
public static final String MAX_MEMORY = "maxmemory";
public static final String MIN_CPU_NUMBER = "mincpunumber";
Expand Down Expand Up @@ -426,6 +427,7 @@ public class ApiConstants {
public static final String QUALIFIERS = "qualifiers";
public static final String QUERY_FILTER = "queryfilter";
public static final String SCHEDULE = "schedule";
public static final String SCHEDULE_ID = "scheduleid";
public static final String SCOPE = "scope";
public static final String SEARCH_BASE = "searchbase";
public static final String SECONDARY_IP = "secondaryip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import javax.inject.Inject;

import com.cloud.storage.Snapshot;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
Expand All @@ -27,6 +28,7 @@
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.BackupScheduleResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.backup.BackupManager;
Expand Down Expand Up @@ -60,6 +62,13 @@ public class CreateBackupCmd extends BaseAsyncCreateCmd {
description = "ID of the VM")
private Long vmId;

@Parameter(name = ApiConstants.SCHEDULE_ID,
type = CommandType.UUID,
entityType = BackupScheduleResponse.class,
description = "backup schedule ID of the VM, if this is null, it indicates that it is a manual backup.",
since = "4.20.1")
private Long scheduleId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -68,14 +77,22 @@ public Long getVmId() {
return vmId;
}

public Long getScheduleId() {
if (scheduleId != null) {
return scheduleId;
} else {
return Snapshot.MANUAL_POLICY_ID;
}
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.createBackup(getVmId());
boolean result = backupManager.createBackup(getVmId(), getScheduleId());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.cloud.utils.DateUtil;
import com.cloud.utils.exception.CloudRuntimeException;

import java.util.Objects;

@APICommand(name = "createBackupSchedule",
description = "Creates a user-defined VM backup schedule",
responseObject = BackupResponse.class, since = "4.14.0",
Expand Down Expand Up @@ -75,6 +77,9 @@ public class CreateBackupScheduleCmd extends BaseCmd {
description = "Specifies a timezone for this command. For more information on the timezone parameter, see TimeZone Format.")
private String timezone;

@Parameter(name = ApiConstants.MAX_BACKUPS, type = CommandType.INTEGER, required = true, description = "maximum number of backups to retain", since = "4.20.1")
private Integer maxBackups;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -95,6 +100,8 @@ public String getTimezone() {
return timezone;
}

public Integer getMaxBackups() { return Objects.nonNull(maxBackups) ? maxBackups : 0; }

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.backup.BackupSchedule;
import org.apache.cloudstack.context.CallContext;

import com.cloud.exception.ConcurrentOperationException;
Expand Down Expand Up @@ -58,6 +59,14 @@ public class DeleteBackupScheduleCmd extends BaseCmd {
description = "ID of the VM")
private Long vmId;

@Parameter(name = ApiConstants.ID,
type = CommandType.UUID,
entityType = BackupSchedule.class,
required = true,
description = "ID of the schedule",
since = "4.20.1")
private Long id;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -66,14 +75,16 @@ public Long getVmId() {
return vmId;
}

public Long getId() { return id; }

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.deleteBackupSchedule(getVmId());
boolean result = backupManager.deleteBackupSchedule(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
List<BackupSchedule> schedules = backupManager.listBackupSchedule(getVmId());
ListResponse<BackupScheduleResponse> response = new ListResponse<>();
List<BackupScheduleResponse> scheduleResponses = new ArrayList<>();
if (CollectionUtils.isNullOrEmpty(schedules)) {
if (!CollectionUtils.isNullOrEmpty(schedules)) {
for (BackupSchedule schedule : schedules) {
scheduleResponses.add(_responseGenerator.createBackupScheduleResponse(schedule));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou
@Param(description = "the total number of snapshots available for this account")
private String snapshotAvailable;

@SerializedName("backuplimit")
@Param(description = "the total number of backups which can be stored by this account")
private String backupLimit;

@SerializedName("backuptotal")
@Param(description = "the total number of backups stored by this account")
private Long backupTotal;

@SerializedName("backupvailable")
@Param(description = "the total number of backups available for this account")
private String backupAvailable;

@SerializedName("templatelimit")
@Param(description = "the total number of templates which can be created by this account")
private String templateLimit;
Expand Down Expand Up @@ -382,6 +394,21 @@ public void setSnapshotAvailable(String snapshotAvailable) {
this.snapshotAvailable = snapshotAvailable;
}

@Override
public void setBackupLimit(String backupLimit) {
this.backupLimit = backupLimit;
}

@Override
public void setBackupTotal(Long backupTotal) {
this.backupTotal = backupTotal;
}

@Override
public void setBackupAvailable(String backupAvailable) {
this.backupAvailable = backupAvailable;
}

@Override
public void setTemplateLimit(String templateLimit) {
this.templateLimit = templateLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ public class BackupRepositoryResponse extends BaseResponse {
@Param(description = "backup type")
private String type;

@SerializedName(ApiConstants.MOUNT_OPTIONS)
@Param(description = "mount options for the backup repository")
private String mountOptions;

@SerializedName(ApiConstants.CAPACITY_BYTES)
@Param(description = "capacity of the backup repository")
private Long capacityBytes;
Expand Down Expand Up @@ -112,14 +108,6 @@ public void setAddress(String address) {
this.address = address;
}

public String getMountOptions() {
return mountOptions;
}

public void setMountOptions(String mountOptions) {
this.mountOptions = mountOptions;
}

public String getProviderName() {
return providerName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou
@SerializedName("snapshotavailable") @Param(description="the total number of snapshots available for this domain")
private String snapshotAvailable;

@SerializedName("backuplimit") @Param(description="the total number of backups which can be stored by this domain")
private String backupLimit;

@SerializedName("backuptotal") @Param(description="the total number of backups stored by this domain")
private Long backupTotal;

@SerializedName("backupavailable") @Param(description="the total number of backups available for this domain")
private String backupAvailable;

@SerializedName("templatelimit") @Param(description="the total number of templates which can be created by this domain")
private String templateLimit;

Expand Down Expand Up @@ -313,6 +322,21 @@ public void setSnapshotAvailable(String snapshotAvailable) {
this.snapshotAvailable = snapshotAvailable;
}

@Override
public void setBackupLimit(String backupLimit) {
this.backupLimit = backupLimit;
}

@Override
public void setBackupTotal(Long backupTotal) {
this.backupTotal = backupTotal;
}

@Override
public void setBackupAvailable(String backupAvailable) {
this.backupAvailable = backupAvailable;
}

@Override
public void setTemplateLimit(String templateLimit) {
this.templateLimit = templateLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou
@Param(description = "the total number of snapshots available for this project", since = "4.2.0")
private String snapshotAvailable;

@SerializedName("backuplimit")
@Param(description = "the total number of backups which can be stored by this project", since = "4.20.1")
private String backupLimit;

@SerializedName("backuptotal")
@Param(description = "the total number of backups stored by this project", since = "4.20.1")
private Long backupTotal;

@SerializedName("backupavailable")
@Param(description = "the total number of backups available for this project", since = "4.20.1")
private String backupAvailable;

@SerializedName("templatelimit")
@Param(description = "the total number of templates which can be created by this project", since = "4.2.0")
private String templateLimit;
Expand Down Expand Up @@ -320,6 +332,21 @@ public void setSnapshotAvailable(String snapshotAvailable) {
this.snapshotAvailable = snapshotAvailable;
}

@Override
public void setBackupLimit(String backupLimit) {
this.backupLimit = backupLimit;
}

@Override
public void setBackupTotal(Long backupTotal) {
this.backupTotal = backupTotal;
}

@Override
public void setBackupAvailable(String backupAvailable) {
this.backupAvailable = backupAvailable;
}

@Override
public void setTemplateLimit(String templateLimit) {
this.templateLimit = templateLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public interface ResourceLimitAndCountResponse {

public void setSnapshotAvailable(String snapshotAvailable);

public void setBackupLimit(String backupLimit);

public void setBackupTotal(Long backupTotal);

public void setBackupAvailable(String backupAvailable);

public void setTemplateLimit(String templateLimit);

public void setTemplateTotal(Long templateTotal);
Expand Down
22 changes: 22 additions & 0 deletions api/src/main/java/org/apache/cloudstack/backup/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ enum Status {
Allocated, Queued, BackingUp, BackedUp, Error, Failed, Restoring, Removed, Expunged
}

public enum Type {
MANUAL, HOURLY, DAILY, WEEKLY, MONTHLY;
private int max = 8;

public void setMax(int max) {
this.max = max;
}

public int getMax() {
return max;
}

@Override
public String toString() {
return this.name();
}

public boolean equals(String snapshotType) {
return this.toString().equalsIgnoreCase(snapshotType);
}
}

class Metric {
private Long backupSize = 0L;
private Long dataSize = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

import java.util.List;

import com.cloud.exception.ResourceAllocationException;
import org.apache.cloudstack.api.command.admin.backup.ImportBackupOfferingCmd;
import org.apache.cloudstack.api.command.admin.backup.UpdateBackupOfferingCmd;
import org.apache.cloudstack.api.command.user.backup.CreateBackupScheduleCmd;
import org.apache.cloudstack.api.command.user.backup.DeleteBackupScheduleCmd;
import org.apache.cloudstack.api.command.user.backup.ListBackupOfferingsCmd;
import org.apache.cloudstack.api.command.user.backup.ListBackupsCmd;
import org.apache.cloudstack.framework.config.ConfigKey;
Expand Down Expand Up @@ -111,17 +113,18 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer

/**
* Deletes VM backup schedule for a VM
* @param vmId
* @param cmd
* @return
*/
boolean deleteBackupSchedule(Long vmId);
boolean deleteBackupSchedule(DeleteBackupScheduleCmd cmd);

/**
* Creates backup of a VM
* @param vmId Virtual Machine ID
* @param scheduleId Virtual Machine Backup Schedule ID
* @return returns operation success
*/
boolean createBackup(final Long vmId);
boolean createBackup(final Long vmId, final Long scheduleId) throws ResourceAllocationException;

/**
* List existing backups for a VM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface BackupProvider {
* @param backup
* @return
*/
boolean takeBackup(VirtualMachine vm);
Backup takeBackup(VirtualMachine vm);

/**
* Delete an existing backup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public interface BackupSchedule extends InternalIdentity {
String getTimezone();
Date getScheduledTimestamp();
Long getAsyncJobId();
int getMaxBackups();
}
Loading