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 a221ecb
Date Sun, 05 May 2013 06:10:14 GMT
Updated Branches:
  refs/heads/object_store bb7a72b7d -> a221ecb48


Workaround an issue of null url when ListTemplateCommand is received on
SSVM side, also fix a bug in listTemplates with id passed.

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

Branch: refs/heads/object_store
Commit: a221ecb48444b7ec53682a1db9baf5c73e14d35f
Parents: bb7a72b
Author: Min Chen <min.chen@citrix.com>
Authored: Sat May 4 23:09:23 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Sat May 4 23:09:23 2013 -0700

----------------------------------------------------------------------
 .../agent/api/storage/ListTemplateCommand.java     |   11 ++-
 .../cloud/agent/api/storage/ListVolumeCommand.java |    9 +++-
 .../resource/NfsSecondaryStorageResource.java      |   45 +++++++++++++--
 .../storage/image/TemplateServiceImpl.java         |    2 +-
 .../storage/volume/VolumeServiceImpl.java          |    4 +-
 .../src/com/cloud/api/query/QueryManagerImpl.java  |    5 +-
 6 files changed, 62 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a221ecb4/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java b/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java
index 4a15887..390f09b 100644
--- a/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java
+++ b/api/src/com/cloud/agent/api/storage/ListTemplateCommand.java
@@ -16,19 +16,18 @@
 // under the License.
 package com.cloud.agent.api.storage;
 
-import com.cloud.agent.api.LogLevel;
-import com.cloud.agent.api.LogLevel.Log4jLevel;
 import com.cloud.agent.api.to.DataStoreTO;
 
 public class ListTemplateCommand extends StorageCommand {
-    @LogLevel(Log4jLevel.Off)
     private DataStoreTO store;
+    private String secUrl;
 
     public ListTemplateCommand() {
     }
 
-	public ListTemplateCommand(DataStoreTO store) {
+	public ListTemplateCommand(DataStoreTO store, String url) {
         this.store = store;
+        this.secUrl = url;
 	}
 
     @Override
@@ -41,4 +40,8 @@ public class ListTemplateCommand extends StorageCommand {
         return store;
     }
 
+    public String getSecUrl() {
+        return secUrl;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a221ecb4/api/src/com/cloud/agent/api/storage/ListVolumeCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/storage/ListVolumeCommand.java b/api/src/com/cloud/agent/api/storage/ListVolumeCommand.java
index 63c5b62..0de44de 100755
--- a/api/src/com/cloud/agent/api/storage/ListVolumeCommand.java
+++ b/api/src/com/cloud/agent/api/storage/ListVolumeCommand.java
@@ -16,15 +16,19 @@
 // under the License.
 package com.cloud.agent.api.storage;
 
+import com.cloud.agent.api.to.DataStoreTO;
+
 
 public class ListVolumeCommand extends StorageCommand {
 
+    private DataStoreTO store;
     private String secUrl;
 
     public ListVolumeCommand() {
     }
 
-	public ListVolumeCommand(String secUrl) {
+	public ListVolumeCommand(DataStoreTO store, String secUrl) {
+	    this.store = store;
 	    this.secUrl = secUrl;
 	}
 
@@ -37,4 +41,7 @@ public class ListVolumeCommand extends StorageCommand {
         return secUrl;
     }
 
+    public DataStoreTO getDataStore() {
+        return store;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a221ecb4/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 0345f6b..9c09faa 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -328,6 +328,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
     }
 
     @SuppressWarnings("unchecked")
+    protected Long determineS3VolumeIdFromKey(String key) {
+        return Long.parseLong(StringUtils.substringAfterLast(StringUtils.substringBeforeLast(key,
S3Utils.SEPARATOR), S3Utils.SEPARATOR));
+    }
+
+    @SuppressWarnings("unchecked")
     private String determineStorageTemplatePath(final String storagePath, String dataPath)
{
         return join(asList(getRootDir(storagePath), dataPath), File.separator);
     }
@@ -1121,6 +1126,25 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
 
     }
 
+    Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
+        String bucket = s3.getBucketName();
+        // List the objects in the source directory on S3
+        final List<S3ObjectSummary> objectSummaries = S3Utils.getDirectory(s3, bucket,
this.VOLUME_ROOT_DIR);
+        if (objectSummaries == null)
+            return null;
+        Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>();
+        for (S3ObjectSummary objectSummary : objectSummaries) {
+            String key = objectSummary.getKey();
+            String installPath = StringUtils.substringBeforeLast(key, S3Utils.SEPARATOR);
+            Long id = this.determineS3VolumeIdFromKey(key);
+            // TODO: how to get volume template name
+            TemplateProp tInfo = new TemplateProp(id.toString(), installPath, objectSummary.getSize(),
objectSummary.getSize(), true, false);
+            tmpltInfos.put(id, tInfo);
+        }
+        return tmpltInfos;
+
+    }
+
     private Answer execute(ListTemplateCommand cmd) {
         if (!_inSystemVM) {
             return new Answer(cmd, true, null);
@@ -1129,9 +1153,10 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         DataStoreTO store = cmd.getDataStore();
         if (store instanceof NfsTO) {
             NfsTO nfs = (NfsTO) store;
-            String root = getRootDir(nfs.getUrl());
+            String secUrl = cmd.getSecUrl();
+            String root = getRootDir(secUrl);
             Map<String, TemplateProp> templateInfos = _dlMgr.gatherTemplateInfo(root);
-            return new ListTemplateAnswer(nfs.getUrl(), templateInfos);
+            return new ListTemplateAnswer(secUrl, templateInfos);
         } else if (store instanceof SwiftTO) {
             SwiftTO swift = (SwiftTO) store;
             Map<String, TemplateProp> templateInfos = swiftListTemplate(swift);
@@ -1150,9 +1175,19 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
             return new Answer(cmd, true, null);
         }
 
-        String root = getRootDir(cmd.getSecUrl());
-        Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
-        return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
+        DataStoreTO store = cmd.getDataStore();
+        if (store instanceof NfsTO) {
+            NfsTO nfs = (NfsTO)store;
+            String root = getRootDir(cmd.getSecUrl());
+            Map<Long, TemplateProp> templateInfos = _dlMgr.gatherVolumeInfo(root);
+            return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
+        } else if (store instanceof S3TO ){
+            S3TO s3 = (S3TO)store;
+            Map<Long, TemplateProp> templateInfos = s3ListVolume(s3);
+            return new ListVolumeAnswer(s3.getBucketName(), templateInfos);
+        } else {
+            return new Answer(cmd, false, "Unsupported image data store: " + store);
+        }
 
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a221ecb4/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 60b3f53..b7b42e5 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
@@ -417,7 +417,7 @@ public class TemplateServiceImpl implements TemplateService {
 
 
     private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
-        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO());
+        ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), ssStore.getUri());
         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/a221ecb4/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 1f049cd..ec38a21 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -428,7 +428,7 @@ public class VolumeServiceImpl implements VolumeService {
     protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore,
PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
         DataObject volumeOnPrimaryStorage = pd.create(volume);
         volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
-        
+
         CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null,
volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
         AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller =  AsyncCallbackDispatcher.create(this);
         caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
@@ -828,7 +828,7 @@ public class VolumeServiceImpl implements VolumeService {
     }
 
     private Map<Long, TemplateProp> listVolume(DataStore store) {
-        ListVolumeCommand cmd = new ListVolumeCommand(store.getUri());
+        ListVolumeCommand cmd = new ListVolumeCommand(store.getTO(), store.getUri());
         EndPoint ep = _epSelector.select(store);
         Answer answer = ep.sendMessage(cmd);
         if (answer != null && answer.getResult()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a221ecb4/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 234d410..a79a2b2 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -2643,7 +2643,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
             }
 
             // other criteria
-            if (keyword != null) {
+            if (templateId != null){
+                sc.addAnd("id", SearchCriteria.Op.EQ, templateId);
+            }
+            else if (keyword != null) {
                 sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
             } else if (name != null) {
                 sc.addAnd("name", SearchCriteria.Op.EQ, name);


Mime
View raw message