Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9530317A7E for ; Tue, 20 Jan 2015 06:41:46 +0000 (UTC) Received: (qmail 68438 invoked by uid 500); 20 Jan 2015 06:41:48 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 68318 invoked by uid 500); 20 Jan 2015 06:41:48 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 68289 invoked by uid 99); 20 Jan 2015 06:41:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jan 2015 06:41:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EED75E0476; Tue, 20 Jan 2015 06:41:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Tue, 20 Jan 2015 06:41:48 -0000 Message-Id: <0aa2ca8bf07c425aace0ecc87ce12b2e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/8] git commit: updated refs/heads/4.5 to 31a6517 CLOUDSTACK-7909: Change the capacity_state in op_host_Capacity table only on explicit enabling/disabling of the host and remove the logic for changing it when cluster/pod/zone is enabled/disabled. Also add the logic in capacity checker thread so that previous changes finally get consistent with this new model and also its good to have it for sanity reasons. (cherry picked from commit ade305be20021d20a881693625864f46a335ea98) Signed-off-by: Rohit Yadav Conflicts: server/src/com/cloud/capacity/CapacityManagerImpl.java Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/be0882b1 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/be0882b1 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/be0882b1 Branch: refs/heads/4.5 Commit: be0882b19e16b72cacc1a38b6bb72953b9053c5a Parents: 665aa6b Author: Nitin Mehta Authored: Thu Nov 13 13:54:45 2014 -0800 Committer: Rohit Yadav Committed: Tue Jan 20 11:58:04 2015 +0530 ---------------------------------------------------------------------- .../com/cloud/capacity/CapacityManagerImpl.java | 25 ++++++++++++-------- .../configuration/ConfigurationManagerImpl.java | 6 ++--- .../com/cloud/resource/ResourceManagerImpl.java | 15 ++++-------- 3 files changed, 21 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be0882b1/server/src/com/cloud/capacity/CapacityManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java index e5b7d19..5ea7e3e 100755 --- a/server/src/com/cloud/capacity/CapacityManagerImpl.java +++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java @@ -27,6 +27,8 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.resource.ResourceState; + import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; @@ -49,7 +51,6 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; -import com.cloud.api.ApiDBUtils; import com.cloud.capacity.dao.CapacityDao; import com.cloud.configuration.Config; import com.cloud.configuration.ConfigurationManager; @@ -67,7 +68,6 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; import com.cloud.offering.ServiceOffering; -import com.cloud.org.Grouping.AllocationState; import com.cloud.resource.ResourceListener; import com.cloud.resource.ResourceManager; import com.cloud.resource.ServerResource; @@ -597,6 +597,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, long usedMemory = 0; long reservedMemory = 0; long reservedCpu = 0; + final CapacityState capacityState = (host.getResourceState() == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled; List vms = _vmDao.listUpByHostId(host.getId()); if (s_logger.isDebugEnabled()) { @@ -680,6 +681,12 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, cpuCap.setTotalCapacity(hostTotalCpu); } + // Set the capacity state as per the host allocation state. + if(capacityState != cpuCap.getCapacityState()){ + s_logger.debug("Calibrate cpu capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu); + cpuCap.setCapacityState(capacityState); + } + memCap.setCapacityState(capacityState); if (cpuCap.getUsedCapacity() == usedCpu && cpuCap.getReservedCapacity() == reservedCpu) { s_logger.debug("No need to calibrate cpu capacity, host:" + host.getId() + " usedCpu: " + cpuCap.getUsedCapacity() + " reservedCpu: " + @@ -702,6 +709,11 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, memCap.setTotalCapacity(host.getTotalMemory()); } + // Set the capacity state as per the host allocation state. + if(capacityState != memCap.getCapacityState()){ + s_logger.debug("Calibrate memory capacity state for host: " + host.getId() + " old capacity state:" + cpuCap.getTotalCapacity() + " new capacity state:" + hostTotalCpu); + memCap.setCapacityState(capacityState); + } if (memCap.getUsedCapacity() == usedMemory && memCap.getReservedCapacity() == reservedMemory) { s_logger.debug("No need to calibrate memory capacity, host:" + host.getId() + " usedMem: " + memCap.getUsedCapacity() + " reservedMem: " + @@ -741,14 +753,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager, new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemoryFinal, host.getTotalMemory(), Capacity.CAPACITY_TYPE_MEMORY); capacity.setReservedCapacity(reservedMemoryFinal); - CapacityState capacityState = CapacityState.Enabled; - if (host.getClusterId() != null) { - ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId()); - if (cluster != null) { - capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled ? CapacityState.Disabled : CapacityState.Enabled; - capacity.setCapacityState(capacityState); - } - } + capacity.setCapacityState(capacityState); _capacityDao.persist(capacity); capacity = http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be0882b1/server/src/com/cloud/configuration/ConfigurationManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index d9ce3fd..b18e154 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1237,9 +1237,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String ipRange = startIp + "-" + endIp; pod.setDescription(ipRange); Grouping.AllocationState allocationState = null; - if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) { - allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal); - _capacityDao.updateCapacityState(null, pod.getId(), null, null, allocationStateStrFinal); + if (allocationStateStrFinal != null && !allocationStateStrFinal.isEmpty()) { + allocationState = Grouping.AllocationState.valueOf(allocationStateStrFinal); pod.setAllocationState(allocationState); } @@ -1774,7 +1773,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("Cannot enable this Zone since: " + ex.getMessage()); } } - _capacityDao.updateCapacityState(zone.getId(), null, null, null, allocationStateStr); zone.setAllocationState(allocationState); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/be0882b1/server/src/com/cloud/resource/ResourceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 5a1b8ce..5723196 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -30,6 +30,7 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.capacity.CapacityState; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.ApiConstants; @@ -68,7 +69,6 @@ import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.agent.api.to.GPUDeviceTO; import com.cloud.agent.transport.Request; -import com.cloud.api.ApiDBUtils; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityManager; import com.cloud.capacity.CapacityVO; @@ -126,7 +126,6 @@ import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; import com.cloud.org.Cluster; import com.cloud.org.Grouping; -import com.cloud.org.Grouping.AllocationState; import com.cloud.org.Managed; import com.cloud.serializer.GsonHelper; import com.cloud.service.dao.ServiceOfferingDetailsDao; @@ -1041,7 +1040,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, s_logger.error("Unable to resolve " + allocationState + " to a valid supported allocation State"); throw new InvalidParameterValueException("Unable to resolve " + allocationState + " to a supported state"); } else { - _capacityDao.updateCapacityState(null, null, cluster.getId(), null, allocationState); cluster.setAllocationState(newAllocationState); doUpdate = true; } @@ -1163,14 +1161,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, throw new NoTransitionException("No next resource state found for current state =" + currentState + " event =" + event); } - // TO DO - Make it more granular and have better conversion into - // capacity type - - if (host.getType() == Type.Routing && host.getClusterId() != null) { - AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId())); - if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled) { - capacityState = AllocationState.Disabled; - } + // TO DO - Make it more granular and have better conversion into capacity type + if(host.getType() == Type.Routing){ + CapacityState capacityState = (nextState == ResourceState.Enabled) ? CapacityState.Enabled : CapacityState.Disabled; _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString()); } return _hostDao.updateResourceState(currentState, event, nextState, host);