Skip to content

Commit daeb86c

Browse files
committed
re-remove sync method (and do some warning cleanups)
1 parent f50dbd0 commit daeb86c

File tree

5 files changed

+64
-182
lines changed

5 files changed

+64
-182
lines changed

api/src/main/java/org/apache/cloudstack/backup/BackupProvider.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,38 @@ public interface BackupProvider {
4949

5050
/**
5151
* Assign a VM to a backup offering or policy
52-
* @param vm
53-
* @param backupOffering
54-
* @return
52+
* @param vm the machine to back up
53+
* @param backupOffering the SLA definition for the backup
54+
* @return succeeded?
5555
*/
5656
boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering backupOffering);
5757

5858
/**
5959
* Removes a VM from a backup offering or policy
60-
* @param vm
61-
* @return
60+
* @param vm the machine to stop backing up
61+
* @return succeeded?
6262
*/
6363
boolean removeVMFromBackupOffering(VirtualMachine vm);
6464

6565
/**
66-
* Whether the provide will delete backups on removal of VM from the offfering
66+
* Whether the provider will delete backups on removal of VM from the offering
6767
* @return boolean result
6868
*/
6969
boolean willDeleteBackupsOnOfferingRemoval();
7070

7171
/**
7272
* Starts and creates an adhoc backup process
7373
* for a previously registered VM backup
74-
* @param vm
75-
* @return
74+
* @param vm the machine to make a backup of
75+
* @return the result and {code}Backup{code} {code}Object{code}
7676
*/
7777
Pair<Boolean, Backup> takeBackup(VirtualMachine vm);
7878

7979
/**
8080
* Delete an existing backup
8181
* @param backup The backup to exclude
8282
* @param forced Indicates if backup will be force removed or not
83-
* @return
83+
* @return succeeded?
8484
*/
8585
boolean deleteBackup(Backup backup, boolean forced);
8686

@@ -96,30 +96,23 @@ public interface BackupProvider {
9696

9797
/**
9898
* Returns backup metrics for a list of VMs in a zone
99-
* @param zoneId
100-
* @param vms
101-
* @return
99+
* @param zoneId the zone for which to return metrics
100+
* @param vms a list of machines to get measurements for
101+
* @return a map of machine -> backup metrics
102102
*/
103103
Map<VirtualMachine, Backup.Metric> getBackupMetrics(Long zoneId, List<VirtualMachine> vms);
104104

105105
/**
106106
* This method should TODO
107-
* @param
107+
* @param vm the machine to get restore point for
108108
*/
109-
public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm);
109+
List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm);
110110

111111
/**
112112
* This method should TODO
113-
* @param
114-
* @param
115-
* @param metric
113+
* @param restorePoint the restore point to create a backup for
114+
* @param vm The machine for which to create a backup
115+
* @param metric the metric object to update with the new backup data
116116
*/
117117
Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoint, VirtualMachine vm, Backup.Metric metric);
118-
119-
/**
120-
* This method should reconcile and create backup entries for any backups created out-of-band
121-
* @param vm
122-
* @param metric
123-
*/
124-
void syncBackups(VirtualMachine vm, Backup.Metric metric);
125118
}

plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,4 @@ public Pair<Boolean, Backup> takeBackup(VirtualMachine vm) {
146146
public boolean deleteBackup(Backup backup, boolean forced) {
147147
return true;
148148
}
149-
150-
@Override
151-
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
152-
}
153149
}

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ protected Host getLastVMHypervisorHost(VirtualMachine vm) {
101101
// Try to find any Up host in the same cluster
102102
for (final Host hostInCluster : hostDao.findHypervisorHostInCluster(host.getClusterId())) {
103103
if (hostInCluster.getStatus() == Status.Up) {
104-
LOG.debug("Found Host {}", hostInCluster);
104+
LOG.debug("Found Host {} in cluster {}", hostInCluster, host.getClusterId());
105105
return hostInCluster;
106106
}
107107
}
108108
}
109109
// Try to find any Host in the zone
110110
for (final HostVO hostInZone : hostDao.listByDataCenterIdAndHypervisorType(host.getDataCenterId(), Hypervisor.HypervisorType.KVM)) {
111111
if (hostInZone.getStatus() == Status.Up) {
112-
LOG.debug("Found Host {}", hostInZone);
112+
LOG.debug("Found Host {} in zone {}", hostInZone, host.getDataCenterId());
113113
return hostInZone;
114114
}
115115
}
@@ -407,11 +407,6 @@ public boolean willDeleteBackupsOnOfferingRemoval() {
407407
return false;
408408
}
409409

410-
@Override
411-
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
412-
// TODO: check and sum/return backups metrics on per VM basis
413-
}
414-
415410
@Override
416411
public List<BackupOffering> listBackupOfferings(Long zoneId) {
417412
final List<BackupRepository> repositories = backupRepositoryDao.listByZoneAndProvider(zoneId, getName());

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@
3030
import com.cloud.utils.Pair;
3131
import com.cloud.utils.Ternary;
3232
import com.cloud.utils.component.AdapterBase;
33-
import com.cloud.utils.db.Transaction;
34-
import com.cloud.utils.db.TransactionCallbackNoReturn;
35-
import com.cloud.utils.db.TransactionStatus;
3633
import com.cloud.utils.exception.CloudRuntimeException;
3734
import com.cloud.utils.ssh.SshHelper;
3835
import com.cloud.vm.VMInstanceVO;
3936
import com.cloud.vm.VirtualMachine;
4037
import com.cloud.vm.dao.VMInstanceDao;
4138

42-
import org.apache.cloudstack.api.InternalIdentity;
4339
import org.apache.cloudstack.backup.dao.BackupDao;
4440
import org.apache.cloudstack.backup.dao.BackupOfferingDaoImpl;
4541
import org.apache.cloudstack.backup.networker.NetworkerClient;
@@ -567,86 +563,6 @@ public Map<VirtualMachine, Backup.Metric> getBackupMetrics(Long zoneId, List<Vir
567563
return metrics;
568564
}
569565

570-
@Override
571-
public void syncBackups(VirtualMachine vm, Backup.Metric metric) {
572-
final Long zoneId = vm.getDataCenterId();
573-
Transaction.execute(new TransactionCallbackNoReturn() {
574-
@Override
575-
public void doInTransactionWithoutResult(TransactionStatus status) {
576-
final List<Backup> backupsInDb = backupDao.listByVmId(null, vm.getId());
577-
final ArrayList<String> backupsInNetworker = getClient(zoneId).getBackupsForVm(vm);
578-
final List<Long> removeList = backupsInDb.stream().map(InternalIdentity::getId).collect(Collectors.toList());
579-
for (final String networkerBackupId : backupsInNetworker ) {
580-
long vmBackupSize=0L;
581-
boolean backupExists = false;
582-
for (final Backup backupInDb : backupsInDb) {
583-
LOG.debug(String.format("Checking if Backup %s with external ID %s for VM %s is valid", backupsInDb, backupInDb.getName(), vm));
584-
if ( networkerBackupId.equals(backupInDb.getExternalId()) ) {
585-
LOG.debug(String.format("Found Backup %s in both Database and Networker", backupInDb));
586-
backupExists = true;
587-
removeList.remove(backupInDb.getId());
588-
if (metric != null) {
589-
LOG.debug(String.format("Update backup [%s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].",
590-
backupInDb, backupInDb.getSize(), backupInDb.getProtectedSize(),
591-
metric.getBackupSize(), metric.getDataSize()));
592-
((BackupVO) backupInDb).setSize(metric.getBackupSize());
593-
((BackupVO) backupInDb).setProtectedSize(metric.getDataSize());
594-
backupDao.update(backupInDb.getId(), ((BackupVO) backupInDb));
595-
}
596-
break;
597-
}
598-
}
599-
if (backupExists) {
600-
continue;
601-
}
602-
// Technically an administrator can manually create a backup for a VM by utilizing the KVM scripts
603-
// with the proper parameters. So we will register any backups taken on the Networker side from
604-
// outside Cloudstack. If ever Networker will support KVM out of the box this functionality also will
605-
// ensure that SLA like backups will be found and registered.
606-
NetworkerBackup strayNetworkerBackup = getClient(vm.getDataCenterId()).getNetworkerBackupInfo(networkerBackupId);
607-
// Since running backups are already present in Networker Server but not completed
608-
// make sure the backup is not in progress at this time.
609-
if ( strayNetworkerBackup.getCompletionTime() != null) {
610-
BackupVO strayBackup = new BackupVO();
611-
strayBackup.setVmId(vm.getId());
612-
strayBackup.setExternalId(strayNetworkerBackup.getId());
613-
strayBackup.setType(strayNetworkerBackup.getType());
614-
SimpleDateFormat formatterDateTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
615-
try {
616-
strayBackup.setDate(formatterDateTime.parse(strayNetworkerBackup.getSaveTime()));
617-
} catch (ParseException e) {
618-
String msg = String.format("Unable to parse date [%s].", strayNetworkerBackup.getSaveTime());
619-
LOG.error(msg, e);
620-
throw new CloudRuntimeException(msg, e);
621-
}
622-
strayBackup.setStatus(Backup.Status.BackedUp);
623-
for ( Backup.VolumeInfo thisVMVol : vm.getBackupVolumeList()) {
624-
vmBackupSize += (thisVMVol.getSize() / 1024L /1024L);
625-
}
626-
strayBackup.setSize(vmBackupSize);
627-
strayBackup.setProtectedSize(strayNetworkerBackup.getSize().getValue() / 1024L );
628-
strayBackup.setBackupOfferingId(vm.getBackupOfferingId());
629-
strayBackup.setAccountId(vm.getAccountId());
630-
strayBackup.setDomainId(vm.getDomainId());
631-
strayBackup.setZoneId(vm.getDataCenterId());
632-
LOG.debug(String.format("Creating a new entry in backups: [id: %s, uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, "
633-
+ "domain_id: %s, zone_id: %s].", strayBackup.getId(), strayBackup.getUuid(), strayBackup.getVmId(), strayBackup.getExternalId(),
634-
strayBackup.getType(), strayBackup.getDate(), strayBackup.getBackupOfferingId(), strayBackup.getAccountId(),
635-
strayBackup.getDomainId(), strayBackup.getZoneId()));
636-
backupDao.persist(strayBackup);
637-
LOG.warn("Added backup found in provider [" + strayBackup + "]");
638-
} else {
639-
LOG.debug ("Backup is in progress, skipping addition for this run");
640-
}
641-
}
642-
for (final Long backupIdToRemove : removeList) {
643-
LOG.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove));
644-
backupDao.remove(backupIdToRemove);
645-
}
646-
}
647-
});
648-
}
649-
650566
@Override
651567
public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoint, VirtualMachine vm, Backup.Metric metric) {
652568
// Technically an administrator can manually create a backup for a VM by utilizing the KVM scripts

0 commit comments

Comments
 (0)