Updated Branches:
  refs/heads/object_store 5b76e4914 -> 79151f5f5

Fix DeleteSnapshotBackupCommand to pass dataStore information.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4c174a68
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4c174a68
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4c174a68

Branch: refs/heads/object_store
Commit: 4c174a6867f353654ec2d7178b76bfc0c66c232a
Parents: 5b76e49
Author: Min Chen <[email protected]>
Authored: Wed Apr 24 17:30:38 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Wed Apr 24 17:30:38 2013 -0700

----------------------------------------------------------------------
 .../agent/api/DeleteSnapshotBackupCommand.java     |   22 +---
 .../resource/NfsSecondaryStorageResource.java      |   88 +++++++--------
 .../storage/snapshot/SnapshotObject.java           |   24 +++--
 .../storage/snapshot/SnapshotServiceImpl.java      |   13 ++-
 .../driver/CloudStackImageStoreDriverImpl.java     |   28 +++--
 .../datastore/driver/S3ImageStoreDriverImpl.java   |   83 +++++++-------
 .../driver/SwiftImageStoreDriverImpl.java          |   82 +++++++-------
 .../storage/snapshot/SnapshotManagerImpl.java      |   47 ++------
 8 files changed, 182 insertions(+), 205 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/api/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java 
b/api/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java
index 6114148..89145d3 100644
--- a/api/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java
+++ b/api/src/com/cloud/agent/api/DeleteSnapshotBackupCommand.java
@@ -17,6 +17,7 @@
 package com.cloud.agent.api;
 
 import com.cloud.agent.api.LogLevel.Log4jLevel;
+import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.S3TO;
 import com.cloud.agent.api.to.SwiftTO;
 
@@ -26,14 +27,9 @@ import com.cloud.agent.api.to.SwiftTO;
  */
 public class DeleteSnapshotBackupCommand extends SnapshotCommand {
     @LogLevel(Log4jLevel.Off)
-    private SwiftTO swift;
-    private S3TO s3;
+    private DataStoreTO store;
     private Boolean all;
 
-    public SwiftTO getSwift() {
-        return swift;
-    }
-
     public Boolean isAll() {
         return all;
     }
@@ -42,12 +38,8 @@ public class DeleteSnapshotBackupCommand extends 
SnapshotCommand {
         this.all = all;
     }
 
-    public void setSwift(SwiftTO swift) {
-        this.swift = swift;
-    }
-
-    public S3TO getS3() {
-        return s3;
+    public DataStoreTO getDataStore(){
+        return store;
     }
 
     protected DeleteSnapshotBackupCommand() {
@@ -78,8 +70,7 @@ public class DeleteSnapshotBackupCommand extends 
SnapshotCommand {
      * @param backupUUID                  The VHD which has to be deleted
      * @param childUUID                   The child VHD file of the backup 
whose parent is reset to its grandparent.
      */
-    public DeleteSnapshotBackupCommand(SwiftTO swift,
-                                       S3TO s3,
+    public DeleteSnapshotBackupCommand(DataStoreTO store,
                                        String secondaryStoragePoolURL,
                                        Long   dcId,
                                        Long   accountId,
@@ -87,8 +78,7 @@ public class DeleteSnapshotBackupCommand extends 
SnapshotCommand {
  String backupUUID, Boolean all)
     {
         super(null, secondaryStoragePoolURL, backupUUID, null, dcId, 
accountId, volumeId);
-        setSwift(swift);
-        this.s3 = s3;
+        this.store = store;
         setAll(all);
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git 
a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java 
b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
index b474210..6003fac 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -265,22 +265,22 @@ SecondaryStorageResource {
                       break;
                   }
               }
-              
+
               if (destFile == null) {
-                  return new CopyCmdAnswer("Can't find template"); 
+                  return new CopyCmdAnswer("Can't find template");
               }
-              
+
               DataTO newDestTO = null;
-              
+
               if (destData.getObjectType() == DataObjectType.TEMPLATE) {
                   TemplateObjectTO newTemplTO = new TemplateObjectTO();
                   newTemplTO.setPath(destPath + File.separator + 
destFile.getName());
                   newTemplTO.setName(destFile.getName());
                   newDestTO = newTemplTO;
               } else {
-                  return new CopyCmdAnswer("not implemented yet"); 
+                  return new CopyCmdAnswer("not implemented yet");
               }
-              
+
               return new CopyCmdAnswer(newDestTO);
           } catch (Exception e) {
 
@@ -1145,45 +1145,40 @@ SecondaryStorageResource {
         Long accountId = cmd.getAccountId();
         Long volumeId = cmd.getVolumeId();
         String name = cmd.getSnapshotUuid();
-        try {
-            SwiftTO swift = cmd.getSwift();
-            S3TO s3 = cmd.getS3();
-            if (swift == null) {
-                final String result = deleteSnapshotBackupFromLocalFileSystem(
-                        secondaryStorageUrl, accountId, volumeId, name,
-                        cmd.isAll());
-                if (result != null) {
-                    s_logger.warn(result);
-                    return new Answer(cmd, false, result);
-                }
-            } else if (s3 != null) {
-                final String result = deleteSnapshotBackupfromS3(s3,
-                        secondaryStorageUrl, accountId, volumeId, name,
-                        cmd.isAll());
-                if (result != null) {
-                    s_logger.warn(result);
-                    return new Answer(cmd, false, result);
-                }
+        DataStoreTO dstore = cmd.getDataStore();
+        if ( dstore instanceof NfsTO ){
+            final String result = deleteSnapshotBackupFromLocalFileSystem(
+                    secondaryStorageUrl, accountId, volumeId, name,
+                    cmd.isAll());
+            if (result != null) {
+                s_logger.warn(result);
+                return new Answer(cmd, false, result);
+            }
+        } else if (dstore instanceof S3TO ){
+            final String result = deleteSnapshotBackupfromS3((S3TO)dstore,
+                    secondaryStorageUrl, accountId, volumeId, name,
+                    cmd.isAll());
+            if (result != null) {
+                s_logger.warn(result);
+                return new Answer(cmd, false, result);
+            }
+        } else if (dstore instanceof SwiftTO ){
+            String filename;
+            if (cmd.isAll()) {
+                filename = "";
             } else {
-                String filename;
-                if (cmd.isAll()) {
-                    filename = "";
-                } else {
-                    filename = name;
-                }
-                String result = swiftDelete(swift, "V-" + volumeId.toString(), 
filename);
-                if (result != null) {
-                    String errMsg = "failed to delete snapshot " + filename + 
" , err=" + result;
-                    s_logger.warn(errMsg);
-                    return new Answer(cmd, false, errMsg);
-                }
+                filename = name;
             }
-            return new Answer(cmd, true, "success");
-        } catch (Exception e) {
-            String errMsg = cmd + " Command failed due to " + e.toString();
-            s_logger.warn(errMsg, e);
-            return new Answer(cmd, false, errMsg);
+            String result = swiftDelete((SwiftTO)dstore, "V-" + 
volumeId.toString(), filename);
+            if (result != null) {
+                String errMsg = "failed to delete snapshot " + filename + " , 
err=" + result;
+                s_logger.warn(errMsg);
+                return new Answer(cmd, false, errMsg);
+            }
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + 
dstore);
         }
+        return new Answer(cmd, true, "success");
     }
 
     Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
@@ -1425,8 +1420,7 @@ SecondaryStorageResource {
                 return new Answer(cmd, false, details);
             }
             return new Answer(cmd, true, null);
-        }
-        else if (dstore instanceof S3TO ){
+        } else if (dstore instanceof S3TO ){
             final S3TO s3 = (S3TO)dstore;
             final Long accountId = cmd.getAccountId();
             final Long templateId = cmd.getTemplateId();
@@ -1458,8 +1452,7 @@ SecondaryStorageResource {
                 s_logger.error(errorMessage, e);
                 return new Answer(cmd, false, errorMessage);
             }
-        }
-        else if (dstore instanceof SwiftTO){
+        } else if (dstore instanceof SwiftTO){
             SwiftTO swift = (SwiftTO)dstore;
             String container = "T-" + cmd.getTemplateId();
             String object = "";
@@ -1477,8 +1470,7 @@ SecondaryStorageResource {
                 s_logger.warn(errMsg, e);
                 return new Answer(cmd, false, errMsg);
             }
-        }
-        else{
+        } else{
             return new Answer(cmd, false, "Unsupported image data store: " + 
dstore);
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
index b8a7760..e22cfb9 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
@@ -48,7 +48,7 @@ public class SnapshotObject implements SnapshotInfo {
     private SnapshotVO snapshot;
     private DataStore store;
     @Inject
-    protected SnapshotDao snapshotDao; 
+    protected SnapshotDao snapshotDao;
     @Inject
     protected VolumeDao volumeDao;
     @Inject protected VolumeDataFactory volFactory;
@@ -56,14 +56,14 @@ public class SnapshotObject implements SnapshotInfo {
     @Inject
     ObjectInDataStoreManager ojbectInStoreMgr;
     public SnapshotObject() {
-      
+
     }
-    
+
     protected void configure(SnapshotVO snapshot, DataStore store) {
        this.snapshot = snapshot;
        this.store = store;
     }
-    
+
     public static SnapshotObject getSnapshotObject(SnapshotVO snapshot, 
DataStore store) {
        SnapshotObject snapObj = ComponentContext.inject(SnapshotObject.class);
        snapObj.configure(snapshot, store);
@@ -151,7 +151,7 @@ public class SnapshotObject implements SnapshotInfo {
        public String getPath() {
                return this.snapshot.getPath();
        }
-       
+
        public void setPath(String path) {
                this.snapshot.setPath(path);
        }
@@ -195,7 +195,7 @@ public class SnapshotObject implements SnapshotInfo {
        public long getDomainId() {
                return this.snapshot.getDomainId();
        }
-       
+
        public void setPrevSnapshotId(Long id) {
                this.snapshot.setPrevSnapshotId(id);
        }
@@ -204,7 +204,7 @@ public class SnapshotObject implements SnapshotInfo {
        public Long getDataCenterId() {
                return this.snapshot.getDataCenterId();
        }
-       
+
        public void processEvent(Snapshot.Event event)
                        throws NoTransitionException {
                stateMachineMgr.processEvent(this.snapshot, event);
@@ -214,15 +214,19 @@ public class SnapshotObject implements SnapshotInfo {
        public Long getPrevSnapshotId() {
                return this.snapshot.getPrevSnapshotId();
        }
-       
+
        public void setBackupSnapshotId(String id) {
                this.snapshot.setBackupSnapshotId(id);
        }
-       
+
        public String getBackupSnapshotId() {
                return this.snapshot.getBackupSnapshotId();
        }
 
+       public SnapshotVO getSnapshotVO(){
+           return this.snapshot;
+       }
+
     @Override
     public DataTO getTO() {
         // TODO Auto-generated method stub
@@ -232,6 +236,6 @@ public class SnapshotObject implements SnapshotInfo {
     @Override
     public void 
processEvent(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event
 event, Answer answer) {
         // TODO Auto-generated method stub
-        
+
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
index 633e193..6674880 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
@@ -44,6 +44,8 @@ import 
org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcConext;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -89,6 +91,8 @@ public class SnapshotServiceImpl implements SnapshotService {
        @Inject
        protected SnapshotDao _snapshotDao;
        @Inject
+       protected SnapshotDataStoreDao _snapshotStoreDao;
+       @Inject
        private ResourceManager _resourceMgr;
        @Inject
        protected SnapshotManager snapshotMgr;
@@ -461,9 +465,14 @@ public class SnapshotServiceImpl implements 
SnapshotService {
 
        @DB
        protected boolean destroySnapshotBackUp(SnapshotVO snapshot) {
-               DataStore store = objInStoreMgr.findStore(snapshot.getId(), 
DataObjectType.SNAPSHOT, DataStoreRole.Image);
+           SnapshotDataStoreVO snapshotStore = 
this._snapshotStoreDao.findBySnapshot(snapshot.getId());
+           if ( snapshotStore == null ){
+            s_logger.debug("Can't find snapshot" + snapshot.getId() + " backed 
up into image store");
+            return false;
+           }
+               DataStore store = 
this.dataStoreMgr.getDataStore(snapshotStore.getDataStoreId(), 
DataStoreRole.Image);
                if (store == null) {
-                       s_logger.debug("Can't find snapshot" + snapshot.getId() 
+ " backed up into image store");
+                       s_logger.debug("Can't find mage store " + 
snapshotStore.getDataStoreId());
                        return false;
                }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
 
b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index 4f8096c..20ddd90 100644
--- 
a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ 
b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@ -44,6 +44,7 @@ import 
org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
 import org.apache.cloudstack.storage.image.store.TemplateObject;
+import org.apache.cloudstack.storage.snapshot.SnapshotObject;
 import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 
@@ -320,43 +321,44 @@ public class CloudStackImageStoreDriverImpl implements 
ImageStoreDriver {
     }
 
     private void deleteSnapshot(DataObject data, 
AsyncCompletionCallback<CommandResult> callback) {
-       Long snapshotId = data.getId();
-       SnapshotVO snapshot = 
this.snapshotDao.findByIdIncludingRemoved(snapshotId);
-       CommandResult result = new CommandResult();
+        SnapshotObject snapshotObj = (SnapshotObject)data;
+        DataStore secStore = snapshotObj.getDataStore();
+        CommandResult result = new CommandResult();
+       SnapshotVO snapshot = snapshotObj.getSnapshotVO();
+
        if (snapshot == null) {
-               s_logger.debug("Destroying snapshot " + snapshotId + " backup 
failed due to unable to find snapshot ");
-               result.setResult("Unable to find snapshot: " + snapshotId);
+               s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " 
backup failed due to unable to find snapshot ");
+               result.setResult("Unable to find snapshot: " + 
snapshotObj.getId());
                callback.complete(result);
                return;
        }
 
        try {
-               String secondaryStoragePoolUrl = 
this.snapshotMgr.getSecondaryStorageURL(snapshot);
+               String secondaryStoragePoolUrl = secStore.getUri();
                Long dcId = snapshot.getDataCenterId();
                Long accountId = snapshot.getAccountId();
                Long volumeId = snapshot.getVolumeId();
 
-               String backupOfSnapshot = snapshot.getBackupSnapshotId();
+               String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
                if (backupOfSnapshot == null) {
                        callback.complete(result);
                        return;
                }
-               SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
-               S3TO s3 = _s3Mgr.getS3TO();
 
                DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(
-                               swift, s3, secondaryStoragePoolUrl, dcId, 
accountId, volumeId,
+                               secStore.getTO(), secondaryStoragePoolUrl, 
dcId, accountId, volumeId,
                                backupOfSnapshot, false);
-               Answer answer = agentMgr.sendToSSVM(dcId, cmd);
+               EndPoint ep = _epSelector.select(secStore);
+               Answer answer = ep.sendMessage(cmd);
 
                if ((answer != null) && answer.getResult()) {
                        snapshot.setBackupSnapshotId(null);
-                       snapshotDao.update(snapshotId, snapshot);
+                       snapshotDao.update(snapshotObj.getId(), snapshot);
                } else if (answer != null) {
                        result.setResult(answer.getDetails());
                }
        } catch (Exception e) {
-               s_logger.debug("failed to delete snapshot: " + snapshotId + ": 
" + e.toString());
+               s_logger.debug("failed to delete snapshot: " + 
snapshotObj.getId() + ": " + e.toString());
                result.setResult(e.toString());
        }
        callback.complete(result);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
 
b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
index 3bbbb70..740dcdc 100644
--- 
a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
+++ 
b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
@@ -45,6 +45,7 @@ import 
org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
 import org.apache.cloudstack.storage.image.store.TemplateObject;
+import org.apache.cloudstack.storage.snapshot.SnapshotObject;
 import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 
@@ -279,48 +280,50 @@ public class S3ImageStoreDriverImpl implements 
ImageStoreDriver {
     }
 
     private void deleteSnapshot(DataObject data, 
AsyncCompletionCallback<CommandResult> callback) {
-       Long snapshotId = data.getId();
-       SnapshotVO snapshot = 
this.snapshotDao.findByIdIncludingRemoved(snapshotId);
-       CommandResult result = new CommandResult();
-       if (snapshot == null) {
-               s_logger.debug("Destroying snapshot " + snapshotId + " backup 
failed due to unable to find snapshot ");
-               result.setResult("Unable to find snapshot: " + snapshotId);
-               callback.complete(result);
-               return;
-       }
-
-       try {
-               String secondaryStoragePoolUrl = 
this.snapshotMgr.getSecondaryStorageURL(snapshot);
-               Long dcId = snapshot.getDataCenterId();
-               Long accountId = snapshot.getAccountId();
-               Long volumeId = snapshot.getVolumeId();
-
-               String backupOfSnapshot = snapshot.getBackupSnapshotId();
-               if (backupOfSnapshot == null) {
-                       callback.complete(result);
-                       return;
-               }
-               SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
-               S3TO s3 = _s3Mgr.getS3TO();
-
-               DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(
-                               swift, s3, secondaryStoragePoolUrl, dcId, 
accountId, volumeId,
-                               backupOfSnapshot, false);
-               Answer answer = agentMgr.sendToSSVM(dcId, cmd);
-
-               if ((answer != null) && answer.getResult()) {
-                       snapshot.setBackupSnapshotId(null);
-                       snapshotDao.update(snapshotId, snapshot);
-               } else if (answer != null) {
-                       result.setResult(answer.getDetails());
-               }
-       } catch (Exception e) {
-               s_logger.debug("failed to delete snapshot: " + snapshotId + ": 
" + e.toString());
-               result.setResult(e.toString());
-       }
-       callback.complete(result);
+        SnapshotObject snapshotObj = (SnapshotObject)data;
+        DataStore secStore = snapshotObj.getDataStore();
+        CommandResult result = new CommandResult();
+        SnapshotVO snapshot = snapshotObj.getSnapshotVO();
+
+        if (snapshot == null) {
+            s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " 
backup failed due to unable to find snapshot ");
+            result.setResult("Unable to find snapshot: " + 
snapshotObj.getId());
+            callback.complete(result);
+            return;
+        }
+
+        try {
+            String secondaryStoragePoolUrl = secStore.getUri();
+            Long dcId = snapshot.getDataCenterId();
+            Long accountId = snapshot.getAccountId();
+            Long volumeId = snapshot.getVolumeId();
+
+            String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
+            if (backupOfSnapshot == null) {
+                callback.complete(result);
+                return;
+            }
+
+            DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
+                    secStore.getTO(), secondaryStoragePoolUrl, dcId, 
accountId, volumeId,
+                    backupOfSnapshot, false);
+            EndPoint ep = _epSelector.select(secStore);
+            Answer answer = ep.sendMessage(cmd);
+
+            if ((answer != null) && answer.getResult()) {
+                snapshot.setBackupSnapshotId(null);
+                snapshotDao.update(snapshotObj.getId(), snapshot);
+            } else if (answer != null) {
+                result.setResult(answer.getDetails());
+            }
+        } catch (Exception e) {
+            s_logger.debug("failed to delete snapshot: " + snapshotObj.getId() 
+ ": " + e.toString());
+            result.setResult(e.toString());
+        }
+        callback.complete(result);
     }
 
+
     @Override
     public void deleteAsync(DataObject data,
             AsyncCompletionCallback<CommandResult> callback) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
 
b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
index 9ec73e6..00ed2c5 100644
--- 
a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
+++ 
b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
@@ -45,6 +45,7 @@ import 
org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
 import org.apache.cloudstack.storage.image.store.TemplateObject;
+import org.apache.cloudstack.storage.snapshot.SnapshotObject;
 import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 
@@ -273,46 +274,47 @@ public class SwiftImageStoreDriverImpl implements 
ImageStoreDriver {
     }
 
     private void deleteSnapshot(DataObject data, 
AsyncCompletionCallback<CommandResult> callback) {
-       Long snapshotId = data.getId();
-       SnapshotVO snapshot = 
this.snapshotDao.findByIdIncludingRemoved(snapshotId);
-       CommandResult result = new CommandResult();
-       if (snapshot == null) {
-               s_logger.debug("Destroying snapshot " + snapshotId + " backup 
failed due to unable to find snapshot ");
-               result.setResult("Unable to find snapshot: " + snapshotId);
-               callback.complete(result);
-               return;
-       }
-
-       try {
-               String secondaryStoragePoolUrl = 
this.snapshotMgr.getSecondaryStorageURL(snapshot);
-               Long dcId = snapshot.getDataCenterId();
-               Long accountId = snapshot.getAccountId();
-               Long volumeId = snapshot.getVolumeId();
-
-               String backupOfSnapshot = snapshot.getBackupSnapshotId();
-               if (backupOfSnapshot == null) {
-                       callback.complete(result);
-                       return;
-               }
-               SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
-               S3TO s3 = _s3Mgr.getS3TO();
-
-               DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(
-                               swift, s3, secondaryStoragePoolUrl, dcId, 
accountId, volumeId,
-                               backupOfSnapshot, false);
-               Answer answer = agentMgr.sendToSSVM(dcId, cmd);
-
-               if ((answer != null) && answer.getResult()) {
-                       snapshot.setBackupSnapshotId(null);
-                       snapshotDao.update(snapshotId, snapshot);
-               } else if (answer != null) {
-                       result.setResult(answer.getDetails());
-               }
-       } catch (Exception e) {
-               s_logger.debug("failed to delete snapshot: " + snapshotId + ": 
" + e.toString());
-               result.setResult(e.toString());
-       }
-       callback.complete(result);
+        SnapshotObject snapshotObj = (SnapshotObject)data;
+        DataStore secStore = snapshotObj.getDataStore();
+        CommandResult result = new CommandResult();
+        SnapshotVO snapshot = snapshotObj.getSnapshotVO();
+
+        if (snapshot == null) {
+            s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " 
backup failed due to unable to find snapshot ");
+            result.setResult("Unable to find snapshot: " + 
snapshotObj.getId());
+            callback.complete(result);
+            return;
+        }
+
+        try {
+            String secondaryStoragePoolUrl = secStore.getUri();
+            Long dcId = snapshot.getDataCenterId();
+            Long accountId = snapshot.getAccountId();
+            Long volumeId = snapshot.getVolumeId();
+
+            String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
+            if (backupOfSnapshot == null) {
+                callback.complete(result);
+                return;
+            }
+
+            DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
+                    secStore.getTO(), secondaryStoragePoolUrl, dcId, 
accountId, volumeId,
+                    backupOfSnapshot, false);
+            EndPoint ep = _epSelector.select(secStore);
+            Answer answer = ep.sendMessage(cmd);
+
+            if ((answer != null) && answer.getResult()) {
+                snapshot.setBackupSnapshotId(null);
+                snapshotDao.update(snapshotObj.getId(), snapshot);
+            } else if (answer != null) {
+                result.setResult(answer.getDetails());
+            }
+        } catch (Exception e) {
+            s_logger.debug("failed to delete snapshot: " + snapshotObj.getId() 
+ ": " + e.toString());
+            result.setResult(e.toString());
+        }
+        callback.complete(result);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c174a68/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java 
b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 624d1d5..4fa6834 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -33,11 +33,14 @@ import 
org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
 import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
@@ -198,6 +201,7 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
     @Inject SnapshotService snapshotSrv;
     @Inject VolumeDataFactory volFactory;
     @Inject SnapshotDataFactory snapshotFactory;
+    @Inject EndPointSelector _epSelector;
 
 
     private int _totalRetries;
@@ -666,47 +670,18 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
                 // This volume doesn't have any snapshots. Nothing do delete.
                 continue;
             }
-            List<HostVO> ssHosts = 
_ssvmMgr.listSecondaryStorageHostsInOneZone(dcId);
-            SwiftTO swift = _swiftMgr.getSwiftTO();
-            S3TO s3 = _s3Mgr.getS3TO();
-
-            checkObjectStorageConfiguration(swift, s3);
-
-            if (swift == null && s3 == null) {
-                for (HostVO ssHost : ssHosts) {
-                    DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(
-                            null, null, ssHost.getStorageUrl(), dcId,
-                            accountId, volumeId, "", true);
-                    Answer answer = null;
-                    try {
-                        answer = _agentMgr.sendToSSVM(dcId, cmd);
-                    } catch (Exception e) {
-                        s_logger.warn("Failed to delete all snapshot for 
volume " + volumeId + " on secondary storage " + ssHost.getStorageUrl());
-                    }
-                    if ((answer != null) && answer.getResult()) {
-                        s_logger.debug("Deleted all snapshots for volume: " + 
volumeId + " under account: " + accountId);
-                    } else {
-                        success = false;
-                        if (answer != null) {
-                            s_logger.error(answer.getDetails());
-                        }
-                    }
-                }
-            } else {
-                DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(
-                        swift, s3, "", dcId, accountId, volumeId, "", true);
-                Answer answer = null;
-                try {
-                    answer = _agentMgr.sendToSSVM(dcId, cmd);
-                } catch (Exception e) {
-                    final String storeType = s3 != null ? "S3" : "swift";
-                    s_logger.warn("Failed to delete all snapshot for volume " 
+ volumeId + " on " + storeType);
-                }
+            List<DataStore> ssHosts = 
this.dataStoreMgr.getImageStoresByScope(new ZoneScope(dcId));
+            for (DataStore ssHost : ssHosts) {
+                DeleteSnapshotBackupCommand cmd = new 
DeleteSnapshotBackupCommand(ssHost.getTO(), ssHost.getUri(), dcId, accountId, 
volumeId, "",
+                        true);
+                EndPoint ep = _epSelector.select(ssHost);
+                Answer answer = ep.sendMessage(cmd);
                 if ((answer != null) && answer.getResult()) {
                     s_logger.debug("Deleted all snapshots for volume: " + 
volumeId + " under account: " + accountId);
                 } else {
                     success = false;
                     if (answer != null) {
+                        s_logger.warn("Failed to delete all snapshot for 
volume " + volumeId + " on secondary storage " + ssHost.getUri());
                         s_logger.error(answer.getDetails());
                     }
                 }

Reply via email to