SnapshotVO prevSnapshot = null;
String prevSnapshotUuid = null;
String prevBackupUuid = null;
SwiftTO swift = _swiftMgr.getSwiftTO();
long prevSnapshotId = snapshot.getPrevSnapshotId();
if (prevSnapshotId > 0) {
prevSnapshot = _snapshotDao.findByIdIncludingRemoved(prevSnapshotId);
if ( prevSnapshot.getBackupSnapshotId() != null && swift == null) {
if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2")) {
prevBackupUuid = prevSnapshot.getBackupSnapshotId();
prevSnapshotUuid = prevSnapshot.getPath();
}
} else if ( prevSnapshot.getSwiftId() != null && swift != null ) {
prevBackupUuid = prevSnapshot.getBackupSnapshotId();
prevSnapshotUuid = prevSnapshot.getPath();
}
}
boolean isVolumeInactive = _storageMgr.volumeInactive(volume);
String vmName = _storageMgr.getVmNameOnVolume(volume);
StoragePoolVO srcPool = _storagePoolDao.findById(volume.getPoolId());
BackupSnapshotCommand backupSnapshotCommand = new BackupSnapshotCommand(primaryStoragePoolNameLabel, secondaryStoragePoolUrl, dcId, accountId, volumeId, snapshot.getId(), volume.getPath(), srcPool, snapshotUuid,
snapshot.getName(), prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, _backupsnapshotwait);
if ( swift != null ) {
backupSnapshotCommand.setSwift(swift);
}
String backedUpSnapshotUuid = null;
// By default, assume failed.
boolean backedUp = false;
BackupSnapshotAnswer answer = (BackupSnapshotAnswer) sendToPool(volume, backupSnapshotCommand);
if (answer != null && answer.getResult()) {
backedUpSnapshotUuid = answer.getBackupSnapshotName();
if (backedUpSnapshotUuid != null) {
backedUp = true;
}
} else if (answer != null) {
s_logger.error(answer.getDetails());
}
// Update the status in all cases.
Transaction txn = Transaction.currentTxn();
txn.start();
if (backedUp) {
if (backupSnapshotCommand.getSwift() != null ) {
snapshot.setSwiftId(swift.getId());
snapshot.setBackupSnapshotId(backedUpSnapshotUuid);
} else {
snapshot.setSecHostId(secHost.getId());
snapshot.setBackupSnapshotId(backedUpSnapshotUuid);
}