3838import org .apache .cloudstack .engine .subsystem .api .storage .StrategyPriority ;
3939import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
4040import org .apache .cloudstack .engine .subsystem .api .storage .VolumeService ;
41- import org .apache .cloudstack .engine .subsystem .api .storage .ObjectInDataStoreStateMachine .Event ;
4241import org .apache .cloudstack .storage .command .SnapshotAndCopyAnswer ;
4342import org .apache .cloudstack .storage .command .SnapshotAndCopyCommand ;
4443import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
4544import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreDao ;
46- import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreVO ;
4745import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
4846
4947import com .cloud .agent .AgentManager ;
6260import com .cloud .storage .Snapshot ;
6361import com .cloud .storage .SnapshotVO ;
6462import com .cloud .storage .Storage .ImageFormat ;
65- import com .cloud .storage .StoragePool ;
66- import com .cloud .storage .StoragePoolStatus ;
6763import com .cloud .storage .Volume ;
6864import com .cloud .storage .VolumeVO ;
6965import com .cloud .storage .dao .SnapshotDao ;
@@ -163,52 +159,7 @@ public boolean deleteSnapshot(Long snapshotId) {
163159
164160 @ Override
165161 public boolean revertSnapshot (SnapshotInfo snapshot ) {
166- if (canHandle (snapshot , SnapshotOperation .REVERT ) == StrategyPriority .CANT_HANDLE ) {
167- throw new UnsupportedOperationException ("Reverting not supported. Create a template or volume based on the snapshot instead." );
168- }
169-
170- SnapshotVO snapshotVO = _snapshotDao .acquireInLockTable (snapshot .getId ());
171-
172- if (snapshotVO == null ) {
173- throw new CloudRuntimeException ("Failed to get lock on snapshot:" + snapshot .getId ());
174- }
175-
176- try {
177- VolumeInfo volumeInfo = snapshot .getBaseVolume ();
178- StoragePool store = (StoragePool )volumeInfo .getDataStore ();
179-
180- if (store != null && store .getStatus () != StoragePoolStatus .Up ) {
181- snapshot .processEvent (Event .OperationFailed );
182-
183- throw new CloudRuntimeException ("store is not in up state" );
184- }
185-
186- volumeInfo .stateTransit (Volume .Event .RevertSnapshotRequested );
187-
188- boolean result = false ;
189-
190- try {
191- result = snapshotSvr .revertSnapshot (snapshot );
192-
193- if (!result ) {
194- s_logger .debug ("Failed to revert snapshot: " + snapshot .getId ());
195-
196- throw new CloudRuntimeException ("Failed to revert snapshot: " + snapshot .getId ());
197- }
198- } finally {
199- if (result ) {
200- volumeInfo .stateTransit (Volume .Event .OperationSucceeded );
201- } else {
202- volumeInfo .stateTransit (Volume .Event .OperationFailed );
203- }
204- }
205-
206- return result ;
207- } finally {
208- if (snapshotVO != null ) {
209- _snapshotDao .releaseFromLockTable (snapshot .getId ());
210- }
211- }
162+ throw new UnsupportedOperationException ("Reverting not supported. Create a template or volume based on the snapshot instead." );
212163 }
213164
214165 @ Override
@@ -422,7 +373,7 @@ private void performSnapshotAndCopyOnHostSide(VolumeInfo volumeInfo, SnapshotInf
422373 }
423374
424375 private Map <String , String > getSourceDetails (VolumeInfo volumeInfo ) {
425- Map <String , String > sourceDetails = new HashMap <String , String >();
376+ Map <String , String > sourceDetails = new HashMap <>();
426377
427378 VolumeVO volumeVO = _volumeDao .findById (volumeInfo .getId ());
428379
@@ -446,7 +397,7 @@ private Map<String, String> getSourceDetails(VolumeInfo volumeInfo) {
446397 }
447398
448399 private Map <String , String > getDestDetails (StoragePoolVO storagePoolVO , SnapshotInfo snapshotInfo ) {
449- Map <String , String > destDetails = new HashMap <String , String >();
400+ Map <String , String > destDetails = new HashMap <>();
450401
451402 destDetails .put (DiskTO .STORAGE_HOST , storagePoolVO .getHostAddress ());
452403 destDetails .put (DiskTO .STORAGE_PORT , String .valueOf (storagePoolVO .getPort ()));
@@ -517,7 +468,7 @@ private HostVO getHost(long zoneId, Long hostId) {
517468 }
518469
519470 private HostVO getHost (long zoneId , boolean computeClusterMustSupportResign ) {
520- List <? extends Cluster > clusters = _mgr .searchForClusters (zoneId , new Long ( 0 ) , Long .MAX_VALUE , HypervisorType .XenServer .toString ());
471+ List <? extends Cluster > clusters = _mgr .searchForClusters (zoneId , 0L , Long .MAX_VALUE , HypervisorType .XenServer .toString ());
521472
522473 if (clusters == null ) {
523474 clusters = new ArrayList <>();
@@ -575,44 +526,28 @@ private void markAsBackedUp(SnapshotObject snapshotObj) {
575526
576527 @ Override
577528 public StrategyPriority canHandle (Snapshot snapshot , SnapshotOperation op ) {
578- long volumeId = snapshot .getVolumeId ();
579- VolumeVO volumeVO = _volumeDao .findById (volumeId );
580-
581529 if (SnapshotOperation .REVERT .equals (op )) {
582- if (volumeVO != null && ImageFormat .QCOW2 .equals (volumeVO .getFormat ())) {
583- return StrategyPriority .DEFAULT ;
584- }
585- else {
586- return StrategyPriority .CANT_HANDLE ;
587- }
530+ return StrategyPriority .CANT_HANDLE ;
588531 }
589532
590- final long storagePoolId ;
533+ long volumeId = snapshot . getVolumeId () ;
591534
592- if (volumeVO == null ) {
593- SnapshotDataStoreVO snapshotStore = _snapshotStoreDao .findBySnapshot (snapshot .getId (), DataStoreRole .Primary );
535+ VolumeVO volumeVO = _volumeDao .findByIdIncludingRemoved (volumeId );
594536
595- if (snapshotStore != null ) {
596- storagePoolId = snapshotStore .getDataStoreId ();
597- }
598- else {
599- throw new CloudRuntimeException ("Unable to determine the storage pool of the snapshot" );
600- }
601- }
602- else {
603- storagePoolId = volumeVO .getPoolId ();
604- }
537+ long storagePoolId = volumeVO .getPoolId ();
605538
606539 DataStore dataStore = _dataStoreMgr .getDataStore (storagePoolId , DataStoreRole .Primary );
607540
608- Map <String , String > mapCapabilities = dataStore .getDriver ().getCapabilities ();
541+ if (dataStore != null ) {
542+ Map <String , String > mapCapabilities = dataStore .getDriver ().getCapabilities ();
609543
610- if (mapCapabilities != null ) {
611- String value = mapCapabilities .get (DataStoreCapabilities .STORAGE_SYSTEM_SNAPSHOT .toString ());
612- Boolean supportsStorageSystemSnapshots = new Boolean (value );
544+ if (mapCapabilities != null ) {
545+ String value = mapCapabilities .get (DataStoreCapabilities .STORAGE_SYSTEM_SNAPSHOT .toString ());
546+ Boolean supportsStorageSystemSnapshots = new Boolean (value );
613547
614- if (supportsStorageSystemSnapshots ) {
615- return StrategyPriority .HIGHEST ;
548+ if (supportsStorageSystemSnapshots ) {
549+ return StrategyPriority .HIGHEST ;
550+ }
616551 }
617552 }
618553
0 commit comments