diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java index 79f7d655624..ebbce5b16a4 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java @@ -189,8 +189,10 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase { if (result) { //snapshot is deleted on backup storage, need to delete it on primary storage SnapshotDataStoreVO snapshotOnPrimary = snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary); - snapshotOnPrimary.setState(State.Destroyed); - snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary); + if (snapshotOnPrimary != null) { + snapshotOnPrimary.setState(State.Destroyed); + snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary); + } } } catch (Exception e) { s_logger.debug("Failed to delete snapshot: ", e); diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 2cab44d5e4d..21fcb0c7c45 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -783,8 +783,13 @@ public class ApiDBUtils { return _clusterDao.findById(clusterId); } - public static ClusterDetailsVO findClusterDetails(long clusterId, String name){ - return _clusterDetailsDao.findDetail(clusterId,name); + public static String findClusterDetails(long clusterId, String name){ + ClusterDetailsVO detailsVO = _clusterDetailsDao.findDetail(clusterId,name); + if (detailsVO != null) { + return detailsVO.getValue(); + } + + return null; } public static DiskOfferingVO findDiskOfferingById(Long diskOfferingId) { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 60d535e9c4f..f7b740bd3f8 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -979,11 +979,12 @@ public class ApiResponseHelper implements ResponseGenerator { clusterResponse.setClusterType(cluster.getClusterType().toString()); clusterResponse.setAllocationState(cluster.getAllocationState().toString()); clusterResponse.setManagedState(cluster.getManagedState().toString()); - String cpuOvercommitRatio=ApiDBUtils.findClusterDetails(cluster.getId(),"cpuOvercommitRatio").getValue(); - String memoryOvercommitRatio=ApiDBUtils.findClusterDetails(cluster.getId(),"memoryOvercommitRatio").getValue(); + String cpuOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(),"cpuOvercommitRatio"); + String memoryOvercommitRatio = ApiDBUtils.findClusterDetails(cluster.getId(),"memoryOvercommitRatio"); clusterResponse.setCpuOvercommitRatio(cpuOvercommitRatio); clusterResponse.setMemoryOvercommitRatio(memoryOvercommitRatio); + if (showCapacities != null && showCapacities) { List capacities = ApiDBUtils.getCapacityByClusterPodZone(null, null, cluster.getId()); Set capacityResponses = new HashSet(); @@ -994,9 +995,13 @@ public class ApiResponseHelper implements ResponseGenerator { capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { - capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(cpuOvercommitRatio)))); + if (cpuOvercommitRatio != null) { + capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(cpuOvercommitRatio)))); + } } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_MEMORY) { - capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(memoryOvercommitRatio)))); + if (memoryOvercommitRatio != null) { + capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * Float.parseFloat(memoryOvercommitRatio)))); + } } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { List c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, null, cluster.getId()); capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 6a9a434e515..cb0e63331c2 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -479,6 +479,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, result.add(cluster); if (clusterType == Cluster.ClusterType.CloudManaged) { + Map details = new HashMap(); + details.put("cpuOvercommitRatio", _configDao.getValue(Config.CPUOverprovisioningFactor.key())); + details.put("memoryOvercommitRatio", _configDao.getValue(Config.MemOverprovisioningFactor.key())); + _clusterDetailsDao.persist(cluster.getId(), details); return result; }