diff --git a/engine/components-api/src/com/cloud/capacity/CapacityManager.java b/engine/components-api/src/com/cloud/capacity/CapacityManager.java index 51f73326d53..3db6e578152 100644 --- a/engine/components-api/src/com/cloud/capacity/CapacityManager.java +++ b/engine/components-api/src/com/cloud/capacity/CapacityManager.java @@ -53,6 +53,16 @@ public interface CapacityManager { "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the pool for low allocated storage available.", true, ConfigKey.Scope.Zone); + static final ConfigKey StorageOperationsExcludeCluster = + new ConfigKey( + Boolean.class, + "cluster.storage.operations.exclude", + "Advanced", + "false", + "Exclude cluster from storage operations", + true, + ConfigKey.Scope.Cluster, + null); public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, boolean moveToReservered, Long hostId); diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java index d38aaed80ed..012d6b3fc3d 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java +++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java @@ -44,6 +44,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.storage.LocalHostEndpoint; import org.apache.cloudstack.storage.RemoteHostEndPoint; +import com.cloud.capacity.CapacityManager; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; @@ -64,9 +65,13 @@ public class DefaultEndPointSelector implements EndPointSelector { private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class); @Inject HostDao hostDao; - private final String findOneHostOnPrimaryStorage = - "select h.id from host h, storage_pool_host_ref s where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and" - + " h.id = s.host_id and s.pool_id = ? "; + private final String findOneHostOnPrimaryStorage = "select t.id from " + + "(select h.id, cd.value " + + "from host h join storage_pool_host_ref s on h.id = s.host_id " + + "join cluster c on c.id=h.cluster_id " + + "left join cluster_details cd on c.id=cd.cluster_id and cd.name='" + CapacityManager.StorageOperationsExcludeCluster.key() + "' " + + "where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and s.pool_id = ? "; + private String findOneHypervisorHostInScope = "select h.id from host h where h.status = 'Up' and h.hypervisor_type is not null "; protected boolean moveBetweenPrimaryImage(DataStore srcStore, DataStore destStore) { @@ -115,6 +120,7 @@ public class DefaultEndPointSelector implements EndPointSelector { sbuilder.append(scope.getScopeId()); } // TODO: order by rand() is slow if there are lot of hosts + sbuilder.append(") t where t.value<>'true' or t.value is null"); //Added for exclude cluster's subquery sbuilder.append(" ORDER by rand() limit 1"); String sql = sbuilder.toString(); HostVO host = null; diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index 55ed9171c98..ac97bc96abf 100644 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -1082,6 +1082,6 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, @Override public ConfigKey[] getConfigKeys() { return new ConfigKey[] {CpuOverprovisioningFactor, MemOverprovisioningFactor, StorageCapacityDisableThreshold, StorageOverprovisioningFactor, - StorageAllocatedCapacityDisableThreshold}; + StorageAllocatedCapacityDisableThreshold, StorageOperationsExcludeCluster}; } } diff --git a/setup/db/db/schema-481to490.sql b/setup/db/db/schema-481to490.sql index 75df7d0eb25..b9a8b2fb934 100644 --- a/setup/db/db/schema-481to490.sql +++ b/setup/db/db/schema-481to490.sql @@ -410,3 +410,6 @@ VIEW `user_vm_view` AS AND (`custom_speed`.`name` = 'CpuSpeed')))) LEFT JOIN `user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `vm_instance`.`id`) AND (`custom_ram_size`.`name` = 'memory')))); + +-- Add cluster.storage.operations.exclude property +INSERT INTO `cloud`.`configuration` (`category`, `instance`, `component`, `name`, `description`, `default_value`, `updated`, `scope`, `is_dynamic`) VALUES ('Advanced', 'DEFAULT', 'CapacityManager', 'cluster.storage.operations.exclude', 'Exclude cluster from storage operations', 'false', now(), 'Cluster', '1');