cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [1/2] Handle ListTemplateCommand in NfsSecondaryStorageResource for various data store provider.
Date Fri, 26 Apr 2013 19:25:26 GMT
Updated Branches:
  refs/heads/object_store de27f0ff5 -> 91bfbdf1c


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index 708bda7..cc9ad43 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -414,7 +414,7 @@ public class TemplateServiceImpl implements TemplateService {
 
 
     private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
-        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getUri());
+        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO());
         EndPoint ep = _epSelector.select(ssStore);
         Answer answer = ep.sendMessage(cmd);
         if (answer != null && answer.getResult()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/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 0ef735c..d3f6916 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
@@ -292,7 +292,7 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
                 EndPoint ep = _epSelector.select(templateObj);
                 Answer answer = ep.sendMessage(cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/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 740dcdc..4844167 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
@@ -249,7 +249,7 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
                 EndPoint ep = _epSelector.select(templateObj);
                 Answer answer = ep.sendMessage(cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/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 00ed2c5..4fc6948 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
@@ -243,7 +243,7 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), installPath,
template.getId(), template.getAccountId());
                 EndPoint ep = _epSelector.select(templateObj);
                 Answer answer = ep.sendMessage(cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
index fc62a56..73dfa80 100644
--- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
+++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
@@ -93,7 +93,7 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
         CreateCmdResult result = null;
         CreateObjectAnswer volAnswer = (CreateObjectAnswer) callback.getResult();
         if (volAnswer.getResult()) {
-            result = new CreateCmdResult(volAnswer.getPath(), volAnswer.getSize());
+            result = new CreateCmdResult(volAnswer.getPath(), volAnswer);
         } else {
             result = new CreateCmdResult("", null);
             result.setResult(volAnswer.getDetails());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/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 37fb376..60ccc2b 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1245,7 +1245,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
 
                         if (installPath != null) {
                             EndPoint ep = _epSelector.select(store);
-                            Command cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
destroyedTemplateStoreVO.getInstallPath(),
+                            Command cmd = new DeleteTemplateCommand(store.getTO(), destroyedTemplateStoreVO.getInstallPath(),
                                     destroyedTemplate.getId(), destroyedTemplate.getAccountId());
                             Answer answer = ep.sendMessage(cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/server/src/com/cloud/storage/s3/S3Manager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3Manager.java b/server/src/com/cloud/storage/s3/S3Manager.java
index 14da1da..058c5ca 100644
--- a/server/src/com/cloud/storage/s3/S3Manager.java
+++ b/server/src/com/cloud/storage/s3/S3Manager.java
@@ -49,7 +49,7 @@ public interface S3Manager extends Manager {
 
     boolean isTemplateInstalled(Long templateId);
 
-    void deleteTemplate(final Long accountId, final Long templateId);
+    //void deleteTemplate(final Long accountId, final Long templateId);
 
     String downloadTemplateFromS3ToSecondaryStorage(final long dcId,
             final long templateId, final int primaryStorageDownloadWait);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/server/src/com/cloud/storage/s3/S3ManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/s3/S3ManagerImpl.java b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
index 06106db..cf236b8 100644
--- a/server/src/com/cloud/storage/s3/S3ManagerImpl.java
+++ b/server/src/com/cloud/storage/s3/S3ManagerImpl.java
@@ -41,7 +41,6 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.Callable;
 
-import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
@@ -54,7 +53,6 @@ import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.DeleteTemplateFromS3Command;
 import com.cloud.agent.api.DownloadTemplateFromS3ToSecondaryStorageCommand;
 import com.cloud.agent.api.UploadTemplateToS3FromSecondaryStorageCommand;
 import com.cloud.agent.api.to.S3TO;
@@ -282,70 +280,7 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager {
                         + "been implemented");
     }
 
-    @Override
-    public void deleteTemplate(final Long templateId, final Long accountId) {
-
-        final S3TO s3 = getS3TO();
 
-        if (s3 == null) {
-            final String errorMessage = "Delete Template Failed: No S3 configuration defined.";
-            LOGGER.error(errorMessage);
-            throw new CloudRuntimeException(errorMessage);
-        }
-
-        final VMTemplateS3VO vmTemplateS3VO = vmTemplateS3Dao
-                .findOneByS3Template(s3.getId(), templateId);
-        if (vmTemplateS3VO == null) {
-            final String errorMessage = format(
-                    "Delete Template Failed: Unable to find Template %1$s in S3.",
-                    templateId);
-            LOGGER.error(errorMessage);
-            throw new CloudRuntimeException(errorMessage);
-        }
-
-        try {
-
-            executeWithNoWaitLock(determineLockId(accountId, templateId),
-                    new Callable<Void>() {
-
-                @Override
-                public Void call() throws Exception {
-
-                    final Answer answer = agentManager.sendToSSVM(null,
-                            new DeleteTemplateFromS3Command(s3,
-                                    accountId, templateId));
-                    if (answer == null || !answer.getResult()) {
-                        final String errorMessage = format(
-                                "Delete Template Failed: Unable to delete template id %1$s
from S3 due to following error: %2$s",
-                                templateId,
-                                ((answer == null) ? "answer is null"
-                                        : answer.getDetails()));
-                        LOGGER.error(errorMessage);
-                        throw new CloudRuntimeException(errorMessage);
-                    }
-
-                    vmTemplateS3Dao.remove(vmTemplateS3VO.getId());
-                    LOGGER.debug(format(
-                            "Deleted template %1$s from S3.",
-                            templateId));
-
-                    return null;
-
-                }
-
-            });
-
-        } catch (Exception e) {
-
-            final String errorMessage = format(
-                    "Delete Template Failed: Unable to delete template id %1$s from S3 due
to the following error: %2$s.",
-                    templateId, e.getMessage());
-            LOGGER.error(errorMessage);
-            throw new CloudRuntimeException(errorMessage, e);
-
-        }
-
-    }
 
     @SuppressWarnings("unchecked")
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/91bfbdf1/utils/src/com/cloud/utils/S3Utils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/S3Utils.java b/utils/src/com/cloud/utils/S3Utils.java
index 423ea71..a0eb7d3 100644
--- a/utils/src/com/cloud/utils/S3Utils.java
+++ b/utils/src/com/cloud/utils/S3Utils.java
@@ -54,6 +54,7 @@ import com.amazonaws.services.s3.AmazonS3Client;
 import com.amazonaws.services.s3.model.Bucket;
 import com.amazonaws.services.s3.model.GetObjectRequest;
 import com.amazonaws.services.s3.model.ObjectMetadata;
+import com.amazonaws.services.s3.model.S3Object;
 import com.amazonaws.services.s3.model.S3ObjectSummary;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -155,6 +156,22 @@ public final class S3Utils {
 
     }
 
+    // Note that whenever S3Object is returned, client code needs to close the internal stream
to avoid resource leak.
+    public static S3Object getObject(final ClientOptions clientOptions,
+            final String bucketName, final String key) {
+
+        assert clientOptions != null;
+        assert !isBlank(bucketName);
+        assert !isBlank(key);
+
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug(format("Get S3 object %1$s in "
+                    + "bucket %2$s", key, bucketName));
+        }
+
+        return acquireClient(clientOptions).getObject(bucketName, key);
+
+    }
 
     @SuppressWarnings("unchecked")
     public static File getFile(final ClientOptions clientOptions,
@@ -243,6 +260,18 @@ public final class S3Utils {
 
     }
 
+    public static List<S3ObjectSummary> getDirectory(final ClientOptions clientOptions,
+            final String bucketName, final String sourcePath){
+        assert clientOptions != null;
+        assert isNotBlank(bucketName);
+        assert isNotBlank(sourcePath);
+
+        final AmazonS3 connection = acquireClient(clientOptions);
+
+        // List the objects in the source directory on S3
+        return listDirectory(bucketName, sourcePath, connection);
+    }
+
     private static List<S3ObjectSummary> listDirectory(final String bucketName,
             final String directory, final AmazonS3 client) {
 


Mime
View raw message