cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [44/53] [abbrv] git commit: updated refs/heads/reporter to 5c99784
Date Wed, 15 Apr 2015 08:05:44 GMT
CLOUDSTACK-8386: CS is returning sec. storage even if it is full and there are other sec. storage
with free space.


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

Branch: refs/heads/reporter
Commit: 30604e973afab20bca87346208bf71e8c936ff3b
Parents: 8f4abbc
Author: Sanjay Tripathi <sanjay.tripathi@citrix.com>
Authored: Mon Apr 13 10:56:46 2015 +0530
Committer: Sanjay Tripathi <sanjay.tripathi@citrix.com>
Committed: Tue Apr 14 16:10:40 2015 +0530

----------------------------------------------------------------------
 .../allocator/StorageCacheRandomAllocator.java  | 20 ++++++++----------
 .../manager/ImageStoreProviderManagerImpl.java  | 22 ++++++++++++++++++++
 .../storage/datastore/DataStoreManagerImpl.java |  7 ++-----
 .../datastore/ImageStoreProviderManager.java    |  2 ++
 server/src/com/cloud/server/StatsCollector.java |  9 ++++++++
 .../template/HypervisorTemplateAdapter.java     | 13 +++++++++---
 6 files changed, 54 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
index ba1ee3c..c9832bf 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cloudstack.storage.cache.allocator;
 
-import java.util.Collections;
 import java.util.List;
 
 import javax.inject.Inject;
@@ -33,7 +32,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
+import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
 
+import com.cloud.server.StatsCollector;
 import com.cloud.storage.ScopeType;
 
 @Component
@@ -43,6 +44,10 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator
{
     DataStoreManager dataStoreMgr;
     @Inject
     ObjectInDataStoreManager objectInStoreMgr;
+    @Inject
+    ImageStoreProviderManager imageStoreMgr;
+    @Inject
+    StatsCollector statsCollector;
 
     @Override
     public DataStore getCacheStore(Scope scope) {
@@ -57,8 +62,7 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator
{
             return null;
         }
 
-        Collections.shuffle(cacheStores);
-        return cacheStores.get(0);
+        return imageStoreMgr.getImageStore(cacheStores);
     }
 
     @Override
@@ -78,18 +82,12 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator
{
         if (cacheStores.size() > 1) {
             for (DataStore store : cacheStores) {
                 DataObjectInStore obj = objectInStoreMgr.findObject(data, store);
-                if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready)
{
+                if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready
&& statsCollector.imageStoreHasEnoughCapacity(store)) {
                     s_logger.debug("pick the cache store " + store.getId() + " where data
is already there");
                     return store;
                 }
             }
-
-            // otherwise, just random pick one
-            Collections.shuffle(cacheStores);
         }
-        return cacheStores.get(0);
-
+        return imageStoreMgr.getImageStore(cacheStores);
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
index 882cf18..cb9a97e 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
@@ -19,7 +19,9 @@
 package org.apache.cloudstack.storage.image.manager;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -41,6 +43,7 @@ import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
 
+import com.cloud.server.StatsCollector;
 import com.cloud.storage.ScopeType;
 import com.cloud.storage.dao.VMTemplateDao;
 
@@ -53,6 +56,8 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager
     VMTemplateDao imageDataDao;
     @Inject
     DataStoreProviderManager providerManager;
+    @Inject
+    StatsCollector _statsCollector;
     Map<String, ImageStoreDriver> driverMaps;
 
     @PostConstruct
@@ -137,4 +142,21 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager
         }
         return imageStores;
     }
+
+    @Override
+    public DataStore getImageStore(List<DataStore> imageStores) {
+        if (imageStores.size() > 1) {
+            Collections.shuffle(imageStores); // Randomize image store list.
+            Iterator<DataStore> i = imageStores.iterator();
+            DataStore imageStore = null;
+            while(i.hasNext()) {
+                imageStore = i.next();
+                // Return image store if used percentage is less then threshold value i.e.
90%.
+                if (_statsCollector.imageStoreHasEnoughCapacity(imageStore)) {
+                    return imageStore;
+                }
+            }
+        }
+        return imageStores.get(0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
index d44fb42..aa23a43 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
@@ -18,7 +18,6 @@
  */
 package org.apache.cloudstack.storage.datastore;
 
-import java.util.Collections;
 import java.util.List;
 
 import javax.inject.Inject;
@@ -79,8 +78,7 @@ public class DataStoreManagerImpl implements DataStoreManager {
         if (stores == null || stores.size() == 0) {
             return null;
         }
-        Collections.shuffle(stores);
-        return stores.get(0);
+        return imageDataStoreMgr.getImageStore(stores);
     }
 
     @Override
@@ -112,8 +110,7 @@ public class DataStoreManagerImpl implements DataStoreManager {
         if (stores == null || stores.size() == 0) {
             return null;
         }
-        Collections.shuffle(stores);
-        return stores.get(0);
+        return imageDataStoreMgr.getImageStore(stores);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
index 8afb3d9..70b7a7c 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
@@ -41,4 +41,6 @@ public interface ImageStoreProviderManager {
     List<DataStore> listImageCacheStores(Scope scope);
 
     boolean registerDriver(String uuid, ImageStoreDriver driver);
+
+    DataStore getImageStore(List<DataStore> imageStores);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/server/src/com/cloud/server/StatsCollector.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java
index 60c25f0..9f3c8cb 100644
--- a/server/src/com/cloud/server/StatsCollector.java
+++ b/server/src/com/cloud/server/StatsCollector.java
@@ -212,6 +212,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
     long autoScaleStatsInterval = -1L;
     int vmDiskStatsInterval = 0;
     List<Long> hostIds = null;
+    private double _imageStoreCapacityThreshold = 0.90;
 
     String externalStatsPrefix = "";
     String externalStatsHost = null;
@@ -1045,6 +1046,14 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
         }
     }
 
+    public boolean imageStoreHasEnoughCapacity(DataStore imageStore) {
+        StorageStats imageStoreStats = _storageStats.get(imageStore.getId());
+        if (imageStoreStats != null && (imageStoreStats.getByteUsed()/(imageStoreStats.getCapacityBytes()*1.0))
<= _imageStoreCapacityThreshold) {
+            return true;
+        }
+        return false;
+    }
+
     public StorageStats getStorageStats(long id) {
         return _storageStats.get(id);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/30604e97/server/src/com/cloud/template/HypervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
index 42f4b55..e58edb9 100644
--- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
@@ -60,6 +60,7 @@ import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.org.Grouping;
+import com.cloud.server.StatsCollector;
 import com.cloud.storage.ScopeType;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
@@ -83,8 +84,10 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
     DownloadMonitor _downloadMonitor;
     @Inject
     AgentManager _agentMgr;
-
-    @Inject TemplateDataStoreDao templateDataStoreDao;
+    @Inject
+    StatsCollector _statsCollector;
+    @Inject
+    TemplateDataStoreDao templateDataStoreDao;
     @Inject
     DataStoreManager storeMgr;
     @Inject
@@ -164,13 +167,17 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
                     continue;
                 }
 
+                // Check if image store has enough capacity for template
+                if (!_statsCollector.imageStoreHasEnoughCapacity(imageStore)) {
+                    s_logger.info("Image store doesn't has enough capacity, so skip downloading
template to this image store " + imageStore.getId());
+                    continue;
+                }
                 // We want to download private template to one of the image store in a zone
                 if(isPrivateTemplate(template) && zoneSet.contains(zoneId)){
                     continue;
                 }else {
                     zoneSet.add(zoneId);
                 }
-
             }
 
             TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore);


Mime
View raw message