|
44 | 44 | import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; |
45 | 45 | import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; |
46 | 46 | import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService; |
| 47 | +import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy; |
| 48 | +import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation; |
47 | 49 | import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; |
| 50 | +import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory; |
48 | 51 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; |
49 | 52 | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; |
50 | 53 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; |
@@ -188,6 +191,8 @@ public enum UserVmCloneType { |
188 | 191 | StorageManager storageMgr; |
189 | 192 | @Inject |
190 | 193 | protected UserVmCloneSettingDao _vmCloneSettingDao; |
| 194 | + @Inject |
| 195 | + StorageStrategyFactory _storageStrategyFactory; |
191 | 196 |
|
192 | 197 | private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine; |
193 | 198 | protected List<StoragePoolAllocator> _storagePoolAllocators; |
@@ -393,6 +398,24 @@ public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot, Use |
393 | 398 | DataStoreRole dataStoreRole = getDataStoreRole(snapshot); |
394 | 399 | SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole); |
395 | 400 |
|
| 401 | + |
| 402 | + if(snapInfo == null && dataStoreRole == DataStoreRole.Image) { |
| 403 | + // snapshot is not backed up to secondary, let's do that now. |
| 404 | + snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary); |
| 405 | + |
| 406 | + if (snapInfo == null) { |
| 407 | + throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId()); |
| 408 | + } |
| 409 | + // We need to copy the snapshot onto secondary. |
| 410 | + SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP); |
| 411 | + snapshotStrategy.backupSnapshot(snapInfo); |
| 412 | + |
| 413 | + // Attempt to grab it again. |
| 414 | + snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole); |
| 415 | + if (snapInfo == null) { |
| 416 | + throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup"); |
| 417 | + } |
| 418 | + } |
396 | 419 | // don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary |
397 | 420 | if (!DataStoreRole.Primary.equals(dataStoreRole)) { |
398 | 421 | try { |
|
0 commit comments