Skip to content
Merged
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
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ public class EventTypes {

// DISASTER RECOVERY
public static final String EVENT_DISASTER_RECOVERY_CLUSTER = "DISASTER.RECOVERY.CLUSTER";

// Resource Limit
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/storage/VolumeApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc
Volume cloneVolumeFromSnapshot(Volume volume, long snapshotId, Long vmId) throws StorageUnavailableException;

Volume updateCompressDedupVolume(UpdateCompressDedupCmd cmd);

Long getVolumePhysicalSize(Storage.ImageFormat format, String path, String chainInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.cloudstack.api.BaseCmd;
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 All @@ -51,13 +52,15 @@ public class DeleteBackupScheduleCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "ID of the VM")
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType = UserVmResponse.class,
description = "ID of the VM from which all backup schedules will be deleted.")
private Long vmId;

@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupScheduleResponse.class,
since = "4.20.1", description = "ID of the backup schedule to be deleted. It has precedence over the 'virtualmachineid' parameter, " +
"i.e., when the 'id' parameter is specified, the 'virtualmachineid' parameter will be ignored.")
private Long id;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -66,14 +69,17 @@ 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 @@ -23,6 +23,7 @@
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 @@ -159,12 +160,12 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
*/
List<BackupSchedule> listBackupSchedule(Long vmId);

/**
/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.cloudstack.backup;

import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -42,6 +43,9 @@ public class BackupScheduleVO implements BackupSchedule {
@Column(name = "vm_id")
private Long vmId;

@Column(name = "uuid", nullable = false)
private String uuid = UUID.randomUUID().toString();

@Column(name = "schedule_type")
private Short scheduleType;

Expand Down Expand Up @@ -84,6 +88,11 @@ public long getId() {
return id;
}

@Override
public String getUuid() {
return uuid;
}

public Long getVmId() {
return vmId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.lang3.StringUtils;

import java.beans.Transient;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2445,4 +2445,12 @@ private Optional<AttributeConverter<Object, Object>> getConverter(Field field) {
}
}

public static class SumCount {
public long sum;
public long count;

public SumCount() {
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
}

@Override
public boolean takeBackup(VirtualMachine vm) {
public Pair<Boolean, Backup> takeBackup(VirtualMachine vm) {
String hostName = null;
try {
String commvaultServer = getUrlDomain(CommvaultUrl.value());
Expand Down Expand Up @@ -821,7 +821,7 @@ public boolean takeBackup(VirtualMachine vm) {
}
}
LOG.error("Failed to request createSnapshot Mold-API.");
return false;
return new Pair<>(false, null);
} else {
JSONObject jsonObject = new JSONObject(createSnapResult);
String jobId = jsonObject.get("jobid").toString();
Expand All @@ -843,7 +843,7 @@ public boolean takeBackup(VirtualMachine vm) {
}
}
LOG.error("createSnapshot Mold-API async job resulted in failure.");
return false;
return new Pair<>(false, null);
}
checkResult.put(vol.getId(), snapId);
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findLatestSnapshotForVolume(vol.getId(), DataStoreRole.Primary);
Expand Down Expand Up @@ -1001,7 +1001,7 @@ public boolean takeBackup(VirtualMachine vm) {
command = String.format(RM_COMMAND, storagePath + "/" + vm.getInstanceName());
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
}
return true;
return new Pair<>(true, backup);
} else {
// 백업 실패
if (!checkResult.isEmpty()) {
Expand All @@ -1018,7 +1018,7 @@ public boolean takeBackup(VirtualMachine vm) {
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
}
LOG.error("createBackup commvault api resulted in " + jobStatus);
return false;
return new Pair<>(false, null);
}
} else {
// 백업 실패
Expand All @@ -1036,7 +1036,7 @@ public boolean takeBackup(VirtualMachine vm) {
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
}
LOG.error("createBackup commvault api resulted in " + jobStatus);
return false;
return new Pair<>(false, null);
}
} else {
// 백업 실패
Expand All @@ -1054,7 +1054,7 @@ public boolean takeBackup(VirtualMachine vm) {
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
}
LOG.error("failed request createBackup commvault api");
return false;
return new Pair<>(false, null);
}
} else {
// 백업 경로 업데이트 실패
Expand All @@ -1072,7 +1072,7 @@ public boolean takeBackup(VirtualMachine vm) {
executeDeleteXmlCommand(hostVO, credentials.first(), credentials.second(), sshPort, command);
}
LOG.error("updateBackupSet commvault api resulted in failure.");
return false;
return new Pair<>(false, null);
}
}

Expand Down Expand Up @@ -1559,4 +1559,16 @@ public static boolean versionCheck(String csVersionInfo) {
}
return true;
}

@Override
public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
return null;
}


@Override
public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoint, VirtualMachine vm, Backup.Metric metric) {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ public String getConfigComponentName() {
return BackupService.class.getSimpleName();
}

@Override
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
}

@Override
public boolean checkBackupAgent(final Long zoneId) { return true; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.VMInstanceDao;

import org.apache.cloudstack.backup.dao.BackupDao;
import org.apache.cloudstack.backup.dao.BackupOfferingDaoImpl;
import org.apache.cloudstack.backup.networker.NetworkerClient;
Expand Down Expand Up @@ -624,4 +625,8 @@ public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {

@Override
public boolean updateBackupPlan(final Long zoneId, final String retentionPeriod, final String externalId) { return true; }

@Override
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ public String getDescription() {
return "Veeam Backup Plugin";
}

@Override
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
}

@Override
public boolean checkBackupAgent(final Long zoneId) { return true; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.Pod;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.ActionEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -33,7 +34,6 @@
import com.cloud.alert.AlertManager;
import com.cloud.configuration.Resource;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.storage.Snapshot;
import com.cloud.storage.VolumeApiService;
import com.cloud.user.DomainManager;
import com.cloud.user.ResourceLimitService;
Expand Down Expand Up @@ -74,7 +74,6 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
Expand All @@ -87,6 +86,7 @@
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import com.cloud.api.ApiDispatcher;
Expand Down Expand Up @@ -589,16 +589,53 @@ public List<BackupSchedule> listBackupSchedule(final Long vmId) {

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_BACKUP_SCHEDULE_DELETE, eventDescription = "deleting VM backup schedule")
public boolean deleteBackupSchedule(Long vmId) {
final VMInstanceVO vm = findVmById(vmId);
public boolean deleteBackupSchedule(DeleteBackupScheduleCmd cmd) {
Long vmId = cmd.getVmId();
Long id = cmd.getId();
if (ObjectUtils.allNull(vmId, id)) {
throw new InvalidParameterValueException("Either instance ID or ID of backup schedule needs to be specified.");
}

if (Objects.nonNull(id)) {
BackupSchedule schedule = backupScheduleDao.findById(id);
if (schedule == null) {
throw new InvalidParameterValueException("Could not find the requested backup schedule.");
}
checkCallerAccessToBackupScheduleVm(schedule.getVmId());
return backupScheduleDao.remove(schedule.getId());
}

checkCallerAccessToBackupScheduleVm(vmId);
return deleteAllVmBackupSchedules(vmId);
}

/**
* Checks if the backup framework is enabled for the zone in which the VM with specified ID is allocated and
* if the caller has access to the VM.
*
* @param vmId The ID of the virtual machine to check access for
* @throws PermissionDeniedException if the caller doesn't have access to the VM
* @throws CloudRuntimeException if the backup framework is disabled
*/
protected void checkCallerAccessToBackupScheduleVm(long vmId) {
VMInstanceVO vm = findVmById(vmId);
validateForZone(vm.getDataCenterId());
accountManager.checkAccess(CallContext.current().getCallingAccount(), null, true, vm);
}

final BackupSchedule schedule = backupScheduleDao.findByVM(vmId);
if (schedule == null) {
throw new CloudRuntimeException("VM has no backup schedule defined, no need to delete anything.");
/**
* Deletes all backup schedules associated with a specific VM.
*
* @param vmId The ID of the virtual machine whose backup schedules should be deleted
* @return true if all backup schedules were successfully deleted, false if any deletion failed
*/
protected boolean deleteAllVmBackupSchedules(long vmId) {
List<BackupScheduleVO> vmBackupSchedules = backupScheduleDao.listByVM(vmId);
boolean success = true;
for (BackupScheduleVO vmBackupSchedule : vmBackupSchedules) {
success = success && backupScheduleDao.remove(vmBackupSchedule.getId());
}
return backupScheduleDao.remove(schedule.getId());
return success;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.cloudstack.api.ServerApiException;
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.backup.dao.BackupDao;
import org.apache.cloudstack.backup.dao.BackupOfferingDao;
import org.apache.cloudstack.backup.dao.BackupScheduleDao;
Expand Down
Loading
Loading