cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/object_store to c2e9be8
Date Fri, 26 Apr 2013 23:45:32 GMT
Updated Branches:
  refs/heads/object_store 471ad5108 -> c2e9be8d3


Handle DeleteVolumeCommand for S3.

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

Branch: refs/heads/object_store
Commit: c2e9be8d311c2ec6534c311df037b8be7e7756d1
Parents: 471ad51
Author: Min Chen <min.chen@citrix.com>
Authored: Fri Apr 26 16:45:11 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Fri Apr 26 16:45:11 2013 -0700

----------------------------------------------------------------------
 .../agent/api/storage/DeleteVolumeCommand.java     |   13 ++-
 .../resource/NfsSecondaryStorageResource.java      |   94 +++++++++------
 .../driver/CloudStackImageStoreDriverImpl.java     |    2 +-
 .../datastore/driver/S3ImageStoreDriverImpl.java   |    2 +-
 .../driver/SwiftImageStoreDriverImpl.java          |    2 +-
 .../src/com/cloud/storage/StorageManagerImpl.java  |    2 +-
 6 files changed, 73 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/api/src/com/cloud/agent/api/storage/DeleteVolumeCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/storage/DeleteVolumeCommand.java b/api/src/com/cloud/agent/api/storage/DeleteVolumeCommand.java
index 949af01..eb17529 100755
--- a/api/src/com/cloud/agent/api/storage/DeleteVolumeCommand.java
+++ b/api/src/com/cloud/agent/api/storage/DeleteVolumeCommand.java
@@ -16,14 +16,17 @@
 // under the License.
 package com.cloud.agent.api.storage;
 
+import com.cloud.agent.api.to.DataStoreTO;
+
 public class DeleteVolumeCommand extends ssCommand {
+    private DataStoreTO store;
 	private String volumePath;
 
 	public DeleteVolumeCommand() {
 	}
 
-	public DeleteVolumeCommand(String secUrl, String volumePath) {
-	    this.setSecUrl(secUrl);
+	public DeleteVolumeCommand(DataStoreTO store, String volumePath) {
+	    this.store = store;
     	this.volumePath = volumePath;
     }
 
@@ -35,4 +38,10 @@ public class DeleteVolumeCommand extends ssCommand {
 	public String getVolumePath() {
 		return volumePath;
 	}
+
+    public DataStoreTO getDataStore() {
+        return store;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/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 5218933..0806dcf 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -1376,7 +1376,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 S3Utils.deleteDirectory(s3, bucket, path);
                 return new Answer(cmd, true, String.format("Deleted template %1%s from bucket
%2$s.", path, bucket));
             } catch (Exception e) {
-                final String errorMessage = String.format("Failed to delete templaet %1$s
from bucket %2$s due to the following error: %3$s",
+                final String errorMessage = String.format("Failed to delete template %1$s
from bucket %2$s due to the following error: %3$s",
                         path, bucket, e.getMessage());
                 s_logger.error(errorMessage, e);
                 return new Answer(cmd, false, errorMessage);
@@ -1405,49 +1405,71 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
     }
 
     protected Answer execute(final DeleteVolumeCommand cmd) {
-        String relativeVolumePath = cmd.getVolumePath();
-        String parent = getRootDir(cmd);
+        DataStoreTO dstore = cmd.getDataStore();
+        if (dstore instanceof NfsTO) {
+            NfsTO nfs = (NfsTO) dstore;
+            String relativeVolumePath = cmd.getVolumePath();
+            String parent = getRootDir(nfs.getUrl());
 
-        if (relativeVolumePath.startsWith(File.separator)) {
-            relativeVolumePath = relativeVolumePath.substring(1);
-        }
+            if (relativeVolumePath.startsWith(File.separator)) {
+                relativeVolumePath = relativeVolumePath.substring(1);
+            }
 
-        if (!parent.endsWith(File.separator)) {
-            parent += File.separator;
-        }
-        String absoluteVolumePath = parent + relativeVolumePath;
-        File tmpltParent = new File(absoluteVolumePath).getParentFile();
-        String details = null;
-        if (!tmpltParent.exists()) {
-            details = "volume parent directory " + tmpltParent.getName() + " doesn't exist";
-            s_logger.debug(details);
-            return new Answer(cmd, true, details);
-        }
-        File[] tmpltFiles = tmpltParent.listFiles();
-        if (tmpltFiles == null || tmpltFiles.length == 0) {
-            details = "No files under volume parent directory " + tmpltParent.getName();
-            s_logger.debug(details);
-        } else {
-            boolean found = false;
-            for (File f : tmpltFiles) {
-                if (!found && f.getName().equals("volume.properties")) {
-                    found = true;
+            if (!parent.endsWith(File.separator)) {
+                parent += File.separator;
+            }
+            String absoluteVolumePath = parent + relativeVolumePath;
+            File tmpltParent = new File(absoluteVolumePath).getParentFile();
+            String details = null;
+            if (!tmpltParent.exists()) {
+                details = "volume parent directory " + tmpltParent.getName() + " doesn't
exist";
+                s_logger.debug(details);
+                return new Answer(cmd, true, details);
+            }
+            File[] tmpltFiles = tmpltParent.listFiles();
+            if (tmpltFiles == null || tmpltFiles.length == 0) {
+                details = "No files under volume parent directory " + tmpltParent.getName();
+                s_logger.debug(details);
+            } else {
+                boolean found = false;
+                for (File f : tmpltFiles) {
+                    if (!found && f.getName().equals("volume.properties")) {
+                        found = true;
+                    }
+                    if (!f.delete()) {
+                        return new Answer(cmd, false, "Unable to delete file " + f.getName()
+ " under Volume path " + relativeVolumePath);
+                    }
                 }
-                if (!f.delete()) {
-                    return new Answer(cmd, false, "Unable to delete file " + f.getName()
+ " under Volume path " + relativeVolumePath);
+                if (!found) {
+                    details = "Can not find volume.properties under " + tmpltParent.getName();
+                    s_logger.debug(details);
                 }
             }
-            if (!found) {
-                details = "Can not find volume.properties under " + tmpltParent.getName();
+            if (!tmpltParent.delete()) {
+                details = "Unable to delete directory " + tmpltParent.getName() + " under
Volume path " + relativeVolumePath;
                 s_logger.debug(details);
+                return new Answer(cmd, false, details);
             }
+            return new Answer(cmd, true, null);
+        } else if (dstore instanceof S3TO) {
+            final S3TO s3 = (S3TO) dstore;
+            final String path = cmd.getVolumePath();
+            final String bucket = s3.getBucketName();
+            try {
+                S3Utils.deleteDirectory(s3, bucket, path);
+                return new Answer(cmd, true, String.format("Deleted volume %1%s from bucket
%2$s.", path, bucket));
+            } catch (Exception e) {
+                final String errorMessage = String.format("Failed to delete volume %1$s from
bucket %2$s due to the following error: %3$s", path,
+                        bucket, e.getMessage());
+                s_logger.error(errorMessage, e);
+                return new Answer(cmd, false, errorMessage);
+            }
+        } else if (dstore instanceof SwiftTO) {
+            return new Answer(cmd, false, "Swift is not currently support DeleteVolumeCommand");
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + dstore);
         }
-        if (!tmpltParent.delete()) {
-            details = "Unable to delete directory " + tmpltParent.getName() + " under Volume
path " + relativeVolumePath;
-            s_logger.debug(details);
-            return new Answer(cmd, false, details);
-        }
-        return new Answer(cmd, true, null);
+
     }
 
     Answer execute(CleanupSnapshotBackupCommand cmd) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/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 d3f6916..1f29dad 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
@@ -237,7 +237,7 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
                 DataStore store = this._dataStoreMgr.getDataStore(volumeStore.getDataStoreId(),
DataStoreRole.Image);
                 EndPoint ep = _epSelector.select(store);
                 DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(
-                        store.getUri(), volumeStore.getInstallPath());
+                        store.getTO(), volumeStore.getInstallPath());
                 Answer answer = ep.sendMessage(dtCommand);
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to delete "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/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 4844167..ecd89c7 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
@@ -195,7 +195,7 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
                 DataStore store = this._dataStoreMgr.getDataStore(volumeStore.getDataStoreId(),
DataStoreRole.Image);
                 EndPoint ep = _epSelector.select(store);
                 DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(
-                        store.getUri(), volumeStore.getInstallPath());
+                        store.getTO(), volumeStore.getInstallPath());
                 Answer answer = ep.sendMessage(dtCommand);
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to delete "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/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 4fc6948..ddc9786 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
@@ -189,7 +189,7 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
                 DataStore store = this._dataStoreMgr.getDataStore(volumeStore.getDataStoreId(),
DataStoreRole.Image);
                 EndPoint ep = _epSelector.select(store);
                 DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(
-                        store.getUri(), volumeStore.getInstallPath());
+                        store.getTO(), volumeStore.getInstallPath());
                 Answer answer = ep.sendMessage(dtCommand);
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to delete "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c2e9be8d/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 60ccc2b..ea737b8 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1325,7 +1325,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
 
                         if (installPath != null) {
                             EndPoint ep = _epSelector.select(store);
-                            DeleteVolumeCommand cmd = new DeleteVolumeCommand(store.getUri(),
destroyedStoreVO.getInstallPath());
+                            DeleteVolumeCommand cmd = new DeleteVolumeCommand(store.getTO(),
destroyedStoreVO.getInstallPath());
                             Answer answer = ep.sendMessage(cmd);
                             if (answer == null || !answer.getResult()) {
                                 s_logger.debug("Failed to delete " + destroyedStoreVO + "
due to "


Mime
View raw message