4646import org .apache .cloudstack .engine .subsystem .api .storage .SnapshotStrategy ;
4747import org .apache .cloudstack .engine .subsystem .api .storage .StrategyPriority ;
4848import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
49- import org .apache .cloudstack .storage .command .CreateObjectAnswer ;
5049import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
5150import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreDao ;
5251import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreVO ;
@@ -199,8 +198,10 @@ private void cleanUpDestroyedRecords(Long snapshotId) {
199198
200199 private void processResult (List <SnapshotInfo > snapshotInfos , ObjectInDataStoreStateMachine .Event event ) {
201200 for (SnapshotInfo snapshot : snapshotInfos ) {
202- SnapshotObject snapshotObject = (SnapshotObject ) snapshot ;
201+ SnapshotObject snapshotObject = (SnapshotObject ) snapshot ;
202+ if (DataStoreRole .Primary .equals (snapshotObject .getDataStore ().getRole ())) {
203203 snapshotObject .processEvent (event );
204+ }
204205 }
205206 }
206207
@@ -363,7 +364,7 @@ private boolean deleteSnapshotFromDbIfNeeded(SnapshotVO snapshotVO, Long zoneId)
363364 !Snapshot .State .Destroying .equals (snapshotVO .getState ())) {
364365 throw new InvalidParameterValueException (String .format ("Can't delete snapshot %s due to it is in %s Status" , snapshotVO , snapshotVO .getState ()));
365366 }
366- List <SnapshotDataStoreVO > storeRefs = _snapshotStoreDao .listReadyBySnapshot (snapshotId , DataStoreRole .Image );
367+ List <SnapshotDataStoreVO > storeRefs = _snapshotStoreDao .listBySnapshot (snapshotId , DataStoreRole .Image );
367368 if (zoneId != null ) {
368369 storeRefs .removeIf (ref -> !zoneId .equals (dataStoreMgr .getStoreZoneId (ref .getDataStoreId (), ref .getRole ())));
369370 }
@@ -413,17 +414,16 @@ public void copySnapshot(DataObject snapshot, DataObject snapshotDest, AsyncComp
413414 StoragePoolVO storagePoolVO = _primaryDataStoreDao .findById (snapshotDest .getDataStore ().getId ());
414415 String location = StorPoolConfigurationManager .StorPoolClusterLocation .valueIn (snapshotDest .getDataStore ().getId ());
415416 StorPoolUtil .spLog ("StorpoolSnapshotStrategy.copySnapshot: snapshot %s to pool=%s" , snapshot .getUuid (), storagePoolVO .getName ());
416- CreateCmdResult res = null ;
417417 SnapshotInfo srcSnapshot = (SnapshotInfo ) snapshot ;
418418 SnapshotInfo destSnapshot = (SnapshotInfo ) snapshotDest ;
419419 String err = null ;
420420 String snapshotName = StorPoolStorageAdaptor .getVolumeNameFromPath (srcSnapshot .getPath (), false );
421421 if (location != null ) {
422422 SpApiResponse resp = exportSnapshot (snapshot , location , snapshotName );
423423 if (resp .getError () != null ) {
424- StorPoolUtil . spLog ("Failed to export snapshot %s from %s due to %s " , snapshotName , location , resp .getError ());
425- err = String . format ( "Failed to export snapshot %s from %s due to %s" , snapshotName , location , resp . getError () );
426- completeCallback (callback , res , destSnapshot .getPath (), err );
424+ err = String . format ("Failed to export snapshot [{}] from [{}] due to [{}] " , snapshotName , location , resp .getError ());
425+ StorPoolUtil . spLog ( err );
426+ completeCallback (callback , destSnapshot .getPath (), err );
427427 return ;
428428 }
429429 keepExportedSnapshot (snapshot , location , snapshotName );
@@ -433,32 +433,31 @@ public void copySnapshot(DataObject snapshot, DataObject snapshotDest, AsyncComp
433433 SpApiResponse respFromRemote = copySnapshotFromRemote (snapshot , storagePoolVO , snapshotName , connectionRemote );
434434
435435 if (respFromRemote .getError () != null ) {
436- StorPoolUtil . spLog ("Failed to copy snapshot %s to %s due to %s " , snapshotName , location , respFromRemote .getError ());
437- err = String . format ( "Failed to copy snapshot %s to %s due to %s" , snapshotName , location , respFromRemote . getError () );
438- completeCallback (callback , res , destSnapshot .getPath (), err );
436+ err = String . format ("Failed to copy snapshot [{}] to [{}] due to [{}] " , snapshotName , location , respFromRemote .getError ());
437+ StorPoolUtil . spLog ( err );
438+ completeCallback (callback , destSnapshot .getPath (), err );
439439 return ;
440440 }
441441 StorPoolUtil .spLog ("The snapshot [%s] was copied from remote" , snapshotName );
442442
443443 respFromRemote = StorPoolUtil .snapshotReconcile ("~" + snapshotName , connectionRemote );
444444 if (respFromRemote .getError () != null ) {
445- StorPoolUtil . spLog ("Failed to reconcile snapshot %s from %s due to %s " , snapshotName , location , respFromRemote .getError ());
446- err = String . format ( "Failed to reconcile snapshot %s from %s due to %s" , snapshotName , location , respFromRemote . getError () );
447- completeCallback (callback , res , destSnapshot .getPath (), err );
445+ err = String . format ("Failed to reconcile snapshot [{}] from [{}] due to [{}] " , snapshotName , location , respFromRemote .getError ());
446+ StorPoolUtil . spLog ( err );
447+ completeCallback (callback , destSnapshot .getPath (), err );
448448 return ;
449449 }
450450 updateSnapshotPath (snapshotDest , srcSnapshot , destSnapshot );
451451 } else {
452- completeCallback (callback , res , destSnapshot .getPath (), "The snapshot is not in the right location" );
452+ completeCallback (callback , destSnapshot .getPath (), "The snapshot is not in the right location" );
453453 }
454454 SnapshotObjectTO snap = (SnapshotObjectTO ) snapshotDest .getTO ();
455455 snap .setPath (srcSnapshot .getPath ());
456- CreateObjectAnswer answer = new CreateObjectAnswer (snap );
457- completeCallback (callback , res , destSnapshot .getPath (), err );
456+ completeCallback (callback , destSnapshot .getPath (), err );
458457 }
459458
460- private void completeCallback (AsyncCompletionCallback <CreateCmdResult > callback , CreateCmdResult res , String snapshotPath , String err ) {
461- res = new CreateCmdResult (snapshotPath , null );
459+ private void completeCallback (AsyncCompletionCallback <CreateCmdResult > callback , String snapshotPath , String err ) {
460+ CreateCmdResult res = new CreateCmdResult (snapshotPath , null );
462461 res .setResult (err );
463462 callback .complete (res );
464463 }
0 commit comments