rafaelweingartner commented on a change in pull request #2500: Restrict the
number of managed clustered file systems per compute cluster
URL: https://github.com/apache/cloudstack/pull/2500#discussion_r178529734
##########
File path:
engine/components-api/src/main/java/com/cloud/storage/StorageUtil.java
##########
@@ -0,0 +1,112 @@
+package com.cloud.storage;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.dao.VMInstanceDao;
+
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+
+import java.util.List;
+import javax.inject.Inject;
+
+public class StorageUtil {
+ @Inject private ClusterDao clusterDao;
+ @Inject private HostDao hostDao;
+ @Inject private PrimaryDataStoreDao storagePoolDao;
+ @Inject private VMInstanceDao vmInstanceDao;
+ @Inject private VolumeDao volumeDao;
+
+ private Long getClusterId(Long hostId) {
+ if (hostId == null) {
+ return null;
+ }
+
+ HostVO hostVO = hostDao.findById(hostId);
+
+ if (hostVO == null) {
+ return null;
+ }
+
+ return hostVO.getClusterId();
+ }
+
+ public boolean managedStoragePoolCanScale(StoragePool storagePool, Long
clusterId, Long hostId) {
+ if (clusterId == null) {
+ clusterId = getClusterId(hostId);
+
+ if (clusterId == null) {
+ return true;
+ }
+ }
+
+ ClusterVO clusterVO = clusterDao.findById(clusterId);
+
+ if (clusterVO == null) {
+ return true;
+ }
+
+ Hypervisor.HypervisorType hypervisorType =
clusterVO.getHypervisorType();
+
+ if (hypervisorType == null) {
+ return true;
+ }
+
+ if (Hypervisor.HypervisorType.XenServer.equals(hypervisorType) ||
Hypervisor.HypervisorType.VMware.equals(hypervisorType)) {
+ int maxValue =
StorageManager.MaxNumberOfManagedClusteredFileSystems.valueIn(clusterId);
+
+ return
getNumberOfManagedClusteredFileSystemsInComputeCluster(storagePool.getDataCenterId(),
clusterId) < maxValue;
+ }
+
+ return true;
+ }
+
+ private int getNumberOfManagedClusteredFileSystemsInComputeCluster(long
zoneId, long clusterId) {
+ int numberOfManagedClusteredFileSystemsInComputeCluster = 0;
+
+ List<VolumeVO> volumes = volumeDao.findByDc(zoneId);
+
+ if (volumes == null || volumes.size() == 0) {
+ return numberOfManagedClusteredFileSystemsInComputeCluster;
+ }
+
+ for (VolumeVO volume : volumes) {
+ Long instanceId = volume.getInstanceId();
+
+ if (instanceId != null) {
Review comment:
@mike-tutkowski to reduce a bit of these nesting here, what about inverting
the logic and then using the `continue` key word?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services