You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/05/21 21:02:56 UTC
[3/3] git commit: updated refs/heads/object_store to cb0659a
CLOUDSTACK-2590: we should only search for active user templates when
deleting an image store.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/cb0659ab
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/cb0659ab
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/cb0659ab
Branch: refs/heads/object_store
Commit: cb0659ab33fcb0b0b0b8daeadd0fd41576d11db4
Parents: 2af36aa
Author: Min Chen <mi...@citrix.com>
Authored: Tue May 21 12:01:53 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Tue May 21 12:01:53 2013 -0700
----------------------------------------------------------------------
.../com/cloud/api/query/dao/TemplateJoinDao.java | 2 +
.../cloud/api/query/dao/TemplateJoinDaoImpl.java | 18 +
.../src/com/cloud/api/query/vo/TemplateJoinVO.java | 15 +
.../src/com/cloud/storage/StorageManagerImpl.java | 710 ++++++---------
setup/db/db/schema-410to420.sql | 3 +-
5 files changed, 314 insertions(+), 434 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb0659ab/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDao.java b/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
index 3897db5..4d1de90 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDao.java
@@ -39,4 +39,6 @@ public interface TemplateJoinDao extends GenericDao<TemplateJoinVO, Long> {
List<TemplateJoinVO> searchByIds(Long... ids);
+ List<TemplateJoinVO> listActiveTemplates(long storeId);
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb0659ab/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index 0e5001b..5a5ac78 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -75,6 +75,8 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
private final SearchBuilder<TemplateJoinVO> tmpltZoneSearch;
+ private final SearchBuilder<TemplateJoinVO> activeTmpltSearch;
+
protected TemplateJoinDaoImpl() {
@@ -92,6 +94,11 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
tmpltZoneSearch.and("downloadState", tmpltZoneSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
tmpltZoneSearch.done();
+ activeTmpltSearch = createSearchBuilder();
+ activeTmpltSearch.and("store_id", activeTmpltSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
+ activeTmpltSearch.and("type", activeTmpltSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
+ activeTmpltSearch.done();
+
// select distinct pair (template_id, zone_id)
this._count = "select count(distinct id) from template_view WHERE ";
}
@@ -438,4 +445,15 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO, Long> im
+
+ @Override
+ public List<TemplateJoinVO> listActiveTemplates(long storeId) {
+ SearchCriteria<TemplateJoinVO> sc = activeTmpltSearch.create();
+ sc.setParameters("store_id", storeId);
+ sc.setParameters("type", TemplateType.USER);
+ return searchIncludingRemoved(sc, null, null, false);
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb0659ab/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
index 77ce14a..d47141d 100644
--- a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
@@ -179,6 +179,9 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="data_center_name")
private String dataCenterName;
+ @Column(name="store_id")
+ private Long dataStoreId; // this can be null for baremetal templates
+
@Column (name="download_state")
@Enumerated(EnumType.STRING)
private Status downloadState;
@@ -1003,4 +1006,16 @@ public class TemplateJoinVO extends BaseViewVO implements ControlledViewEntity {
+ public Long getDataStoreId() {
+ return dataStoreId;
+ }
+
+
+
+ public void setDataStoreId(Long dataStoreId) {
+ this.dataStoreId = dataStoreId;
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb0659ab/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index ba6b343..3d92052 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -94,6 +94,8 @@ import com.cloud.agent.api.storage.DeleteVolumeCommand;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiDBUtils;
+import com.cloud.api.query.dao.TemplateJoinDao;
+import com.cloud.api.query.vo.TemplateJoinVO;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityManager;
import com.cloud.capacity.CapacityState;
@@ -251,6 +253,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Inject
protected TemplateDataStoreDao _templateStoreDao = null;
@Inject
+ protected TemplateJoinDao _templateViewDao = null;
+ @Inject
protected VolumeDataStoreDao _volumeStoreDao = null;
@Inject
protected CapacityDao _capacityDao;
@@ -305,7 +309,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Inject
ConfigurationServer _configServer;
- @Inject protected ResourceTagDao _resourceTagDao;
+ @Inject
+ protected ResourceTagDao _resourceTagDao;
@Inject
DataStoreManager _dataStoreMgr;
@@ -313,26 +318,30 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
DataStoreProviderManager _dataStoreProviderMgr;
@Inject
private TemplateService _imageSrv;
- @Inject EndPointSelector _epSelector;
+ @Inject
+ EndPointSelector _epSelector;
protected List<StoragePoolAllocator> _storagePoolAllocators;
+
public List<StoragePoolAllocator> getStoragePoolAllocators() {
- return _storagePoolAllocators;
- }
- public void setStoragePoolAllocators(
- List<StoragePoolAllocator> _storagePoolAllocators) {
- this._storagePoolAllocators = _storagePoolAllocators;
- }
+ return _storagePoolAllocators;
+ }
+
+ public void setStoragePoolAllocators(List<StoragePoolAllocator> _storagePoolAllocators) {
+ this._storagePoolAllocators = _storagePoolAllocators;
+ }
protected List<StoragePoolDiscoverer> _discoverers;
+
public List<StoragePoolDiscoverer> getDiscoverers() {
- return _discoverers;
- }
- public void setDiscoverers(List<StoragePoolDiscoverer> _discoverers) {
- this._discoverers = _discoverers;
- }
+ return _discoverers;
+ }
+
+ public void setDiscoverers(List<StoragePoolDiscoverer> _discoverers) {
+ this._discoverers = _discoverers;
+ }
- protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
+ protected SearchBuilder<VMTemplateHostVO> HostTemplateStatesSearch;
protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch;
protected SearchBuilder<VMInstanceVO> StoragePoolSearch;
protected SearchBuilder<StoragePoolVO> LocalStorageSearch;
@@ -347,7 +356,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
protected int _retry = 2;
protected int _pingInterval = 60; // seconds
protected int _hostRetry;
- //protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
+ // protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
private long _maxVolumeSizeInGb;
private long _serverId;
@@ -357,18 +366,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
private boolean _recreateSystemVmEnabled;
- public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host,
- boolean cancelPreviousShare) throws StorageUnavailableException {
+ public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException {
// if pool is in maintenance and it is the ONLY pool available; reject
- List<VolumeVO> rootVolForGivenVm = _volsDao.findByInstanceAndType(
- vm.getId(), Type.ROOT);
+ List<VolumeVO> rootVolForGivenVm = _volsDao.findByInstanceAndType(vm.getId(), Type.ROOT);
if (rootVolForGivenVm != null && rootVolForGivenVm.size() > 0) {
- boolean isPoolAvailable = isPoolAvailable(rootVolForGivenVm.get(0)
- .getPoolId());
+ boolean isPoolAvailable = isPoolAvailable(rootVolForGivenVm.get(0).getPoolId());
if (!isPoolAvailable) {
- throw new StorageUnavailableException("Can not share " + vm,
- rootVolForGivenVm.get(0).getPoolId());
+ throw new StorageUnavailableException("Can not share " + vm, rootVolForGivenVm.get(0).getPoolId());
}
}
@@ -378,8 +383,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// available
for (VolumeVO vol : vols) {
if (vol.getRemoved() != null) {
- s_logger.warn("Volume id:" + vol.getId()
- + " is removed, cannot share on this instance");
+ s_logger.warn("Volume id:" + vol.getId() + " is removed, cannot share on this instance");
// not ok to share
return false;
}
@@ -394,10 +398,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
List<StoragePoolVO> pools = _storagePoolDao.listAll();
// if no pools or 1 pool which is in maintenance
- if (pools == null
- || pools.size() == 0
- || (pools.size() == 1 && pools.get(0).getStatus()
- .equals(StoragePoolStatus.Maintenance))) {
+ if (pools == null || pools.size() == 0 || (pools.size() == 1 && pools.get(0).getStatus().equals(StoragePoolStatus.Maintenance))) {
return false;
} else {
return true;
@@ -405,10 +406,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public List<StoragePoolVO> ListByDataCenterHypervisor(
- long datacenterId, HypervisorType type) {
- List<StoragePoolVO> pools = _storagePoolDao
- .listByDataCenterId(datacenterId);
+ public List<StoragePoolVO> ListByDataCenterHypervisor(long datacenterId, HypervisorType type) {
+ List<StoragePoolVO> pools = _storagePoolDao.listByDataCenterId(datacenterId);
List<StoragePoolVO> retPools = new ArrayList<StoragePoolVO>();
for (StoragePoolVO pool : pools) {
if (pool.getStatus() != StoragePoolStatus.Up) {
@@ -425,35 +424,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Override
public boolean isLocalStorageActiveOnHost(Long hostId) {
- List<StoragePoolHostVO> storagePoolHostRefs = _storagePoolHostDao
- .listByHostId(hostId);
+ List<StoragePoolHostVO> storagePoolHostRefs = _storagePoolHostDao.listByHostId(hostId);
for (StoragePoolHostVO storagePoolHostRef : storagePoolHostRefs) {
- StoragePoolVO PrimaryDataStoreVO = _storagePoolDao
- .findById(storagePoolHostRef.getPoolId());
- if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM
- || PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) {
- SearchBuilder<VolumeVO> volumeSB = _volsDao
- .createSearchBuilder();
- volumeSB.and("poolId", volumeSB.entity().getPoolId(),
- SearchCriteria.Op.EQ);
- volumeSB.and("removed", volumeSB.entity().getRemoved(),
- SearchCriteria.Op.NULL);
+ StoragePoolVO PrimaryDataStoreVO = _storagePoolDao.findById(storagePoolHostRef.getPoolId());
+ if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM || PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) {
+ SearchBuilder<VolumeVO> volumeSB = _volsDao.createSearchBuilder();
+ volumeSB.and("poolId", volumeSB.entity().getPoolId(), SearchCriteria.Op.EQ);
+ volumeSB.and("removed", volumeSB.entity().getRemoved(), SearchCriteria.Op.NULL);
volumeSB.and("state", volumeSB.entity().getState(), SearchCriteria.Op.NIN);
- SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao
- .createSearchBuilder();
- activeVmSB.and("state", activeVmSB.entity().getState(),
- SearchCriteria.Op.IN);
- volumeSB.join("activeVmSB", activeVmSB, volumeSB.entity()
- .getInstanceId(), activeVmSB.entity().getId(),
- JoinBuilder.JoinType.INNER);
+ SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao.createSearchBuilder();
+ activeVmSB.and("state", activeVmSB.entity().getState(), SearchCriteria.Op.IN);
+ volumeSB.join("activeVmSB", activeVmSB, volumeSB.entity().getInstanceId(), activeVmSB.entity().getId(), JoinBuilder.JoinType.INNER);
SearchCriteria<VolumeVO> volumeSC = volumeSB.create();
volumeSC.setParameters("poolId", PrimaryDataStoreVO.getId());
volumeSC.setParameters("state", Volume.State.Expunging, Volume.State.Destroy);
- volumeSC.setJoinParameters("activeVmSB", "state",
- State.Starting, State.Running, State.Stopping,
- State.Migrating);
+ volumeSC.setJoinParameters("activeVmSB", "state", State.Starting, State.Running, State.Stopping, State.Migrating);
List<VolumeVO> volumes = _volsDao.search(volumeSC, null);
if (volumes.size() > 0) {
@@ -466,39 +453,34 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public StoragePool findStoragePool(DiskProfile dskCh,
- final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId,
- VMInstanceVO vm, final Set<StoragePool> avoid) {
+ public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm,
+ final Set<StoragePool> avoid) {
- VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(
- vm);
+ VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
- ExcludeList avoidList = new ExcludeList();
- for(StoragePool pool : avoid){
- avoidList.addPool(pool.getId());
- }
- DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), pod.getId(), clusterId, hostId, null, null);
+ ExcludeList avoidList = new ExcludeList();
+ for (StoragePool pool : avoid) {
+ avoidList.addPool(pool.getId());
+ }
+ DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), pod.getId(), clusterId, hostId, null, null);
- final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
- if (poolList != null && !poolList.isEmpty()) {
- return (StoragePool)this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
- }
+ final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
+ if (poolList != null && !poolList.isEmpty()) {
+ return (StoragePool) this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
+ }
}
return null;
}
@Override
- public Answer[] sendToPool(StoragePool pool, Commands cmds)
- throws StorageUnavailableException {
+ public Answer[] sendToPool(StoragePool pool, Commands cmds) throws StorageUnavailableException {
return sendToPool(pool, null, null, cmds).second();
}
@Override
- public Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst,
- Command cmd) throws StorageUnavailableException {
- Answer[] answers = sendToPool(pool, hostIdsToTryFirst, null,
- new Commands(cmd)).second();
+ public Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst, Command cmd) throws StorageUnavailableException {
+ Answer[] answers = sendToPool(pool, hostIdsToTryFirst, null, new Commands(cmd)).second();
if (answers == null) {
return null;
}
@@ -506,8 +488,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public Answer sendToPool(StoragePool pool, Command cmd)
- throws StorageUnavailableException {
+ public Answer sendToPool(StoragePool pool, Command cmd) throws StorageUnavailableException {
Answer[] answers = sendToPool(pool, new Commands(cmd));
if (answers == null) {
return null;
@@ -515,15 +496,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
return answers[0];
}
- public Long chooseHostForStoragePool(StoragePoolVO poolVO,
- List<Long> avoidHosts, boolean sendToVmResidesOn, Long vmId) {
+ public Long chooseHostForStoragePool(StoragePoolVO poolVO, List<Long> avoidHosts, boolean sendToVmResidesOn, Long vmId) {
if (sendToVmResidesOn) {
if (vmId != null) {
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
if (vmInstance != null) {
Long hostId = vmInstance.getHostId();
- if (hostId != null
- && !avoidHosts.contains(vmInstance.getHostId())) {
+ if (hostId != null && !avoidHosts.contains(vmInstance.getHostId())) {
return hostId;
}
}
@@ -534,8 +513,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
* cmd
*/
}
- List<StoragePoolHostVO> poolHosts = _poolHostDao.listByHostStatus(
- poolVO.getId(), Status.Up);
+ List<StoragePoolHostVO> poolHosts = _poolHostDao.listByHostStatus(poolVO.getId(), Status.Up);
Collections.shuffle(poolHosts);
if (poolHosts != null && poolHosts.size() > 0) {
for (StoragePoolHostVO sphvo : poolHosts) {
@@ -550,130 +528,91 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-
- Map<String, String> configs = _configDao.getConfiguration(
- "management-server", params);
+ Map<String, String> configs = _configDao.getConfiguration("management-server", params);
_retry = NumbersUtil.parseInt(configs.get(Config.StartRetry.key()), 10);
_pingInterval = NumbersUtil.parseInt(configs.get("ping.interval"), 60);
_hostRetry = NumbersUtil.parseInt(configs.get("host.retry"), 2);
- _storagePoolAcquisitionWaitSeconds = NumbersUtil.parseInt(
- configs.get("pool.acquisition.wait.seconds"), 1800);
- s_logger.info("pool.acquisition.wait.seconds is configured as "
- + _storagePoolAcquisitionWaitSeconds + " seconds");
+ _storagePoolAcquisitionWaitSeconds = NumbersUtil.parseInt(configs.get("pool.acquisition.wait.seconds"), 1800);
+ s_logger.info("pool.acquisition.wait.seconds is configured as " + _storagePoolAcquisitionWaitSeconds + " seconds");
- _agentMgr.registerForHostEvents(new StoragePoolMonitor(this,
- _storagePoolDao), true, false, true);
+ _agentMgr.registerForHostEvents(new StoragePoolMonitor(this, _storagePoolDao), true, false, true);
String storageCleanupEnabled = configs.get("storage.cleanup.enabled");
- _storageCleanupEnabled = (storageCleanupEnabled == null) ? true
- : Boolean.parseBoolean(storageCleanupEnabled);
+ _storageCleanupEnabled = (storageCleanupEnabled == null) ? true : Boolean.parseBoolean(storageCleanupEnabled);
- String value = _configDao.getValue(Config.CreateVolumeFromSnapshotWait
- .toString());
- _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value,
- Integer.parseInt(Config.CreateVolumeFromSnapshotWait
- .getDefaultValue()));
+ String value = _configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
+ _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
value = _configDao.getValue(Config.CopyVolumeWait.toString());
- _copyvolumewait = NumbersUtil.parseInt(value,
- Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
+ _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
value = _configDao.getValue(Config.RecreateSystemVmEnabled.key());
_recreateSystemVmEnabled = Boolean.parseBoolean(value);
value = _configDao.getValue(Config.StorageTemplateCleanupEnabled.key());
- _templateCleanupEnabled = (value == null ? true : Boolean
- .parseBoolean(value));
+ _templateCleanupEnabled = (value == null ? true : Boolean.parseBoolean(value));
String time = configs.get("storage.cleanup.interval");
_storageCleanupInterval = NumbersUtil.parseInt(time, 86400);
- s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled
- + ", interval: " + _storageCleanupInterval
+ s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled + ", interval: " + _storageCleanupInterval
+ ", template cleanup enabled: " + _templateCleanupEnabled);
String workers = configs.get("expunge.workers");
int wrks = NumbersUtil.parseInt(workers, 10);
- _executor = Executors.newScheduledThreadPool(wrks,
- new NamedThreadFactory("StorageManager-Scavenger"));
+ _executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("StorageManager-Scavenger"));
- _agentMgr.registerForHostEvents(
- ComponentContext.inject(LocalStoragePoolListener.class), true,
- false, false);
+ _agentMgr.registerForHostEvents(ComponentContext.inject(LocalStoragePoolListener.class), true, false, false);
- String maxVolumeSizeInGbString = _configDao
- .getValue("storage.max.volume.size");
- _maxVolumeSizeInGb = NumbersUtil.parseLong(maxVolumeSizeInGbString,
- 2000);
+ String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size");
+ _maxVolumeSizeInGb = NumbersUtil.parseLong(maxVolumeSizeInGbString, 2000);
- String _customDiskOfferingMinSizeStr = _configDao
- .getValue(Config.CustomDiskOfferingMinSize.toString());
- _customDiskOfferingMinSize = NumbersUtil.parseInt(
- _customDiskOfferingMinSizeStr, Integer
- .parseInt(Config.CustomDiskOfferingMinSize
- .getDefaultValue()));
-
- String _customDiskOfferingMaxSizeStr = _configDao
- .getValue(Config.CustomDiskOfferingMaxSize.toString());
- _customDiskOfferingMaxSize = NumbersUtil.parseInt(
- _customDiskOfferingMaxSizeStr, Integer
- .parseInt(Config.CustomDiskOfferingMaxSize
- .getDefaultValue()));
+ String _customDiskOfferingMinSizeStr = _configDao.getValue(Config.CustomDiskOfferingMinSize.toString());
+ _customDiskOfferingMinSize = NumbersUtil.parseInt(_customDiskOfferingMinSizeStr,
+ Integer.parseInt(Config.CustomDiskOfferingMinSize.getDefaultValue()));
+ String _customDiskOfferingMaxSizeStr = _configDao.getValue(Config.CustomDiskOfferingMaxSize.toString());
+ _customDiskOfferingMaxSize = NumbersUtil.parseInt(_customDiskOfferingMaxSizeStr,
+ Integer.parseInt(Config.CustomDiskOfferingMaxSize.getDefaultValue()));
_serverId = _msServer.getId();
- UpHostsInPoolSearch = _storagePoolHostDao
- .createSearchBuilder(Long.class);
- UpHostsInPoolSearch.selectField(UpHostsInPoolSearch.entity()
- .getHostId());
+ UpHostsInPoolSearch = _storagePoolHostDao.createSearchBuilder(Long.class);
+ UpHostsInPoolSearch.selectField(UpHostsInPoolSearch.entity().getHostId());
SearchBuilder<HostVO> hostSearch = _hostDao.createSearchBuilder();
hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ);
- hostSearch.and("resourceState", hostSearch.entity().getResourceState(),
- Op.EQ);
- UpHostsInPoolSearch.join("hosts", hostSearch, hostSearch.entity()
- .getId(), UpHostsInPoolSearch.entity().getHostId(),
- JoinType.INNER);
- UpHostsInPoolSearch.and("pool", UpHostsInPoolSearch.entity()
- .getPoolId(), Op.EQ);
+ hostSearch.and("resourceState", hostSearch.entity().getResourceState(), Op.EQ);
+ UpHostsInPoolSearch.join("hosts", hostSearch, hostSearch.entity().getId(), UpHostsInPoolSearch.entity().getHostId(), JoinType.INNER);
+ UpHostsInPoolSearch.and("pool", UpHostsInPoolSearch.entity().getPoolId(), Op.EQ);
UpHostsInPoolSearch.done();
StoragePoolSearch = _vmInstanceDao.createSearchBuilder();
SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder();
- volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(),
- SearchCriteria.Op.EQ);
- volumeSearch.and("poolId", volumeSearch.entity().getPoolId(),
- SearchCriteria.Op.EQ);
+ volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(), SearchCriteria.Op.EQ);
+ volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ);
- StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity()
- .getInstanceId(), StoragePoolSearch.entity().getId(),
+ StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity().getInstanceId(), StoragePoolSearch.entity().getId(),
JoinBuilder.JoinType.INNER);
StoragePoolSearch.done();
LocalStorageSearch = _storagePoolDao.createSearchBuilder();
- SearchBuilder<StoragePoolHostVO> storageHostSearch = _storagePoolHostDao
- .createSearchBuilder();
- storageHostSearch.and("hostId", storageHostSearch.entity().getHostId(),
- SearchCriteria.Op.EQ);
- LocalStorageSearch.join("poolHost", storageHostSearch,
- storageHostSearch.entity().getPoolId(), LocalStorageSearch
- .entity().getId(), JoinBuilder.JoinType.INNER);
- LocalStorageSearch.and("type", LocalStorageSearch.entity()
- .getPoolType(), SearchCriteria.Op.IN);
+ SearchBuilder<StoragePoolHostVO> storageHostSearch = _storagePoolHostDao.createSearchBuilder();
+ storageHostSearch.and("hostId", storageHostSearch.entity().getHostId(), SearchCriteria.Op.EQ);
+ LocalStorageSearch.join("poolHost", storageHostSearch, storageHostSearch.entity().getPoolId(), LocalStorageSearch.entity().getId(),
+ JoinBuilder.JoinType.INNER);
+ LocalStorageSearch.and("type", LocalStorageSearch.entity().getPoolType(), SearchCriteria.Op.IN);
LocalStorageSearch.done();
- Volume.State.getStateMachine().registerListener( new VolumeStateListener());
+ Volume.State.getStateMachine().registerListener(new VolumeStateListener());
return true;
}
-
@Override
public String getStoragePoolTags(long poolId) {
- return _configMgr.listToCsvTags(_storagePoolDao
- .searchForStoragePoolDetails(poolId, "true"));
+ return _configMgr.listToCsvTags(_storagePoolDao.searchForStoragePoolDetails(poolId, "true"));
}
@Override
@@ -681,8 +620,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
if (_storageCleanupEnabled) {
Random generator = new Random();
int initialDelay = generator.nextInt(_storageCleanupInterval);
- _executor.scheduleWithFixedDelay(new StorageGarbageCollector(),
- initialDelay, _storageCleanupInterval, TimeUnit.SECONDS);
+ _executor.scheduleWithFixedDelay(new StorageGarbageCollector(), initialDelay, _storageCleanupInterval, TimeUnit.SECONDS);
} else {
s_logger.debug("Storage cleanup is not enabled, so the storage cleanup thread is not being scheduled.");
}
@@ -709,12 +647,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
DataStore store = null;
try {
- StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(), pInfo.getUuid());
- if(pool == null && host.getHypervisorType() == HypervisorType.VMware) {
- // perform run-time upgrade. In versions prior to 2.2.12, there is a bug that we don't save local datastore info (host path is empty), this will cause us
- // not able to distinguish multiple local datastores that may be available on the host, to support smooth migration, we
+ StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(),
+ pInfo.getUuid());
+ if (pool == null && host.getHypervisorType() == HypervisorType.VMware) {
+ // perform run-time upgrade. In versions prior to 2.2.12, there
+ // is a bug that we don't save local datastore info (host path
+ // is empty), this will cause us
+ // not able to distinguish multiple local datastores that may be
+ // available on the host, to support smooth migration, we
// need to perform runtime upgrade here
- if(pInfo.getHostPath().length() > 0) {
+ if (pInfo.getHostPath().length() > 0) {
pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), "", pInfo.getUuid());
}
}
@@ -735,8 +677,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
store = lifeCycle.initialize(params);
} else {
- store = (DataStore) dataStoreMgr.getDataStore(pool.getId(),
- DataStoreRole.Primary);
+ store = (DataStore) dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
HostScope scope = new HostScope(host.getId(), host.getDataCenterId());
@@ -746,24 +687,20 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
}
- return (DataStore) dataStoreMgr.getDataStore(store.getId(),
- DataStoreRole.Primary);
+ return (DataStore) dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
@Override
@SuppressWarnings("rawtypes")
- public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd)
- throws ResourceInUseException, IllegalArgumentException,
- UnknownHostException, ResourceUnavailableException {
+ public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException,
+ ResourceUnavailableException {
String providerName = cmd.getStorageProviderName();
- DataStoreProvider storeProvider = dataStoreProviderMgr
- .getDataStoreProvider(providerName);
+ DataStoreProvider storeProvider = dataStoreProviderMgr.getDataStoreProvider(providerName);
if (storeProvider == null) {
storeProvider = dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
if (storeProvider == null) {
- throw new InvalidParameterValueException(
- "can't find storage provider: " + providerName);
+ throw new InvalidParameterValueException("can't find storage provider: " + providerName);
}
}
@@ -777,17 +714,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
try {
scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
} catch (Exception e) {
- throw new InvalidParameterValueException("invalid scope"
- + scope);
+ throw new InvalidParameterValueException("invalid scope" + scope);
}
}
if (scopeType == ScopeType.CLUSTER && clusterId == null) {
- throw new InvalidParameterValueException(
- "cluster id can't be null, if scope is cluster");
+ throw new InvalidParameterValueException("cluster id can't be null, if scope is cluster");
} else if (scopeType == ScopeType.ZONE && zoneId == null) {
- throw new InvalidParameterValueException(
- "zone id can't be null, if scope is zone");
+ throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
}
Map ds = cmd.getDetails();
@@ -800,24 +734,19 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
Iterator it2 = d.entrySet().iterator();
while (it2.hasNext()) {
Map.Entry entry = (Map.Entry) it2.next();
- details.put((String) entry.getKey(),
- (String) entry.getValue());
+ details.put((String) entry.getKey(), (String) entry.getValue());
}
}
}
DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
if (zone == null) {
- throw new InvalidParameterValueException(
- "unable to find zone by id " + zoneId);
+ throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
}
// Check if zone is disabled
Account account = UserContext.current().getCaller();
- if (Grouping.AllocationState.Disabled == zone.getAllocationState()
- && !_accountMgr.isRootAdmin(account.getType())) {
- throw new PermissionDeniedException(
- "Cannot perform this operation, Zone is currently disabled: "
- + zoneId);
+ if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
+ throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
}
Map<String, Object> params = new HashMap<String, Object>();
@@ -836,8 +765,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
store = lifeCycle.initialize(params);
if (scopeType == ScopeType.CLUSTER) {
- ClusterScope clusterScope = new ClusterScope(clusterId, podId,
- zoneId);
+ ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
lifeCycle.attachCluster(store, clusterScope);
} else if (scopeType == ScopeType.ZONE) {
ZoneScope zoneScope = new ZoneScope(zoneId);
@@ -848,21 +776,18 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new CloudRuntimeException("Failed to add data store", e);
}
- return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(store.getId(),
- DataStoreRole.Primary);
+ return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
@Override
- public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd)
- throws IllegalArgumentException {
+ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
// Input validation
Long id = cmd.getId();
List<String> tags = cmd.getTags();
StoragePoolVO pool = _storagePoolDao.findById(id);
if (pool == null) {
- throw new IllegalArgumentException(
- "Unable to find storage pool with ID: " + id);
+ throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
}
if (tags != null) {
@@ -877,8 +802,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
_storagePoolDao.updateDetails(id, details);
}
- return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(pool.getId(),
- DataStoreRole.Primary);
+ return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
@Override
@@ -890,30 +814,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
StoragePoolVO sPool = _storagePoolDao.findById(id);
if (sPool == null) {
s_logger.warn("Unable to find pool:" + id);
- throw new InvalidParameterValueException(
- "Unable to find pool by id " + id);
+ throw new InvalidParameterValueException("Unable to find pool by id " + id);
}
if (sPool.getStatus() != StoragePoolStatus.Maintenance) {
- s_logger.warn("Unable to delete storage id: " + id
- + " due to it is not in Maintenance state");
- throw new InvalidParameterValueException(
- "Unable to delete storage due to it is not in Maintenance state, id: "
- + id);
+ s_logger.warn("Unable to delete storage id: " + id + " due to it is not in Maintenance state");
+ throw new InvalidParameterValueException("Unable to delete storage due to it is not in Maintenance state, id: " + id);
}
if (sPool.isLocal()) {
s_logger.warn("Unable to delete local storage id:" + id);
- throw new InvalidParameterValueException(
- "Unable to delete local storage id: " + id);
+ throw new InvalidParameterValueException("Unable to delete local storage id: " + id);
}
Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(id);
if (forced) {
if (vlms.first() > 0) {
- Pair<Long, Long> nonDstrdVlms = _volsDao
- .getNonDestroyedCountAndTotalByPool(id);
+ Pair<Long, Long> nonDstrdVlms = _volsDao.getNonDestroyedCountAndTotalByPool(id);
if (nonDstrdVlms.first() > 0) {
- throw new CloudRuntimeException("Cannot delete pool "
- + sPool.getName() + " as there are associated "
+ throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated "
+ "non-destroyed vols for this pool");
}
// force expunge non-destroyed volumes
@@ -933,20 +850,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// Check if the pool has associated volumes in the volumes table
// If it does , then you cannot delete the pool
if (vlms.first() > 0) {
- throw new CloudRuntimeException("Cannot delete pool "
- + sPool.getName() + " as there are associated vols"
- + " for this pool");
+ throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated vols" + " for this pool");
}
}
// First get the host_id from storage_pool_host_ref for given pool id
- StoragePoolVO lock = _storagePoolDao.acquireInLockTable(sPool
- .getId());
+ StoragePoolVO lock = _storagePoolDao.acquireInLockTable(sPool.getId());
if (lock == null) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Failed to acquire lock when deleting PrimaryDataStoreVO with ID: "
- + sPool.getId());
+ s_logger.debug("Failed to acquire lock when deleting PrimaryDataStoreVO with ID: " + sPool.getId());
}
return false;
}
@@ -954,30 +867,27 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
_storagePoolDao.releaseFromLockTable(lock.getId());
s_logger.trace("Released lock for storage pool " + id);
- DataStoreProvider storeProvider = dataStoreProviderMgr
- .getDataStoreProvider(sPool.getStorageProviderName());
+ DataStoreProvider storeProvider = dataStoreProviderMgr.getDataStoreProvider(sPool.getStorageProviderName());
DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
- DataStore store = dataStoreMgr.getDataStore(
- sPool.getId(), DataStoreRole.Primary);
+ DataStore store = dataStoreMgr.getDataStore(sPool.getId(), DataStoreRole.Primary);
return lifeCycle.deleteDataStore(store);
}
@Override
- public void connectHostToSharedPool(long hostId, long poolId)
- throws StorageUnavailableException {
- StoragePool pool = (StoragePool)this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
+ public void connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException {
+ StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
assert (pool.isShared()) : "Now, did you actually read the name of this method?";
s_logger.debug("Adding pool " + pool.getName() + " to host " + hostId);
- DataStoreProvider provider = dataStoreProviderMgr
- .getDataStoreProvider(pool.getStorageProviderName());
+ DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
HypervisorHostListener listener = hostListeners.get(provider.getName());
listener.hostConnect(hostId, pool.getId());
}
@Override
- public BigDecimal getStorageOverProvisioningFactor(Long dcId){
- return new BigDecimal(_configServer.getConfigValue(Config.StorageOverprovisioningFactor.key(), Config.ConfigurationParameterScope.zone.toString(), dcId));
+ public BigDecimal getStorageOverProvisioningFactor(Long dcId) {
+ return new BigDecimal(_configServer.getConfigValue(Config.StorageOverprovisioningFactor.key(),
+ Config.ConfigurationParameterScope.zone.toString(), dcId));
}
@Override
@@ -992,13 +902,24 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
long totalOverProvCapacity;
if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
BigDecimal overProvFactor = getStorageOverProvisioningFactor(storagePool.getDataCenterId());
- totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All this for the inaccuracy of floats for big number multiplication.
+ totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All
+ // this
+ // for
+ // the
+ // inaccuracy
+ // of
+ // floats
+ // for
+ // big
+ // number
+ // multiplication.
} else {
totalOverProvCapacity = storagePool.getCapacityBytes();
}
if (capacities.size() == 0) {
- CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
+ CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(),
+ storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
AllocationState allocationState = null;
if (storagePool.getScope() == ScopeType.ZONE) {
DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
@@ -1006,8 +927,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
} else {
allocationState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(storagePool.getClusterId()));
}
- CapacityState capacityState = (allocationState == AllocationState.Disabled) ?
- CapacityState.Disabled : CapacityState.Enabled;
+ CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
capacity.setCapacityState(capacityState);
_capacityDao.persist(capacity);
@@ -1040,7 +960,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public Pair<Long, Answer[]> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Commands cmds) throws StorageUnavailableException {
+ public Pair<Long, Answer[]> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Commands cmds)
+ throws StorageUnavailableException {
List<Long> hostIds = getUpHostsInPool(pool.getId());
Collections.shuffle(hostIds);
if (hostIdsToTryFirst != null) {
@@ -1055,7 +976,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
hostIds.removeAll(hostIdsToAvoid);
}
if (hostIds == null || hostIds.isEmpty()) {
- throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId());
+ throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId()
+ + " due to there is no enabled hosts up in this cluster", pool.getId());
}
for (Long hostId : hostIds) {
try {
@@ -1078,7 +1000,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public Pair<Long, Answer> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Command cmd) throws StorageUnavailableException {
+ public Pair<Long, Answer> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Command cmd)
+ throws StorageUnavailableException {
Commands cmds = new Commands(cmd);
Pair<Long, Answer[]> result = sendToPool(pool, hostIdsToTryFirst, hostIdsToAvoid, cmds);
return new Pair<Long, Answer>(result.first(), result.second()[0]);
@@ -1098,17 +1021,20 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
try {
List<VMTemplateStoragePoolVO> unusedTemplatesInPool = _tmpltMgr.getUnusedTemplatesInPool(pool);
- s_logger.debug("Storage pool garbage collector found " + unusedTemplatesInPool.size() + " templates to clean up in storage pool: " + pool.getName());
+ s_logger.debug("Storage pool garbage collector found " + unusedTemplatesInPool.size()
+ + " templates to clean up in storage pool: " + pool.getName());
for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) {
if (templatePoolVO.getDownloadState() != VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
- s_logger.debug("Storage pool garbage collector is skipping templatePoolVO with ID: " + templatePoolVO.getId() + " because it is not completely downloaded.");
+ s_logger.debug("Storage pool garbage collector is skipping templatePoolVO with ID: " + templatePoolVO.getId()
+ + " because it is not completely downloaded.");
continue;
}
if (!templatePoolVO.getMarkedForGC()) {
templatePoolVO.setMarkedForGC(true);
_vmTemplatePoolDao.update(templatePoolVO.getId(), templatePoolVO);
- s_logger.debug("Storage pool garbage collector has marked templatePoolVO with ID: " + templatePoolVO.getId() + " for garbage collection.");
+ s_logger.debug("Storage pool garbage collector has marked templatePoolVO with ID: " + templatePoolVO.getId()
+ + " for garbage collection.");
continue;
}
@@ -1120,7 +1046,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
}
-
cleanupSecondaryStorage(recurring);
List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
@@ -1134,22 +1059,21 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
}
-
// remove snapshots in Error state
List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.State.Error);
for (SnapshotVO snapshotVO : snapshots) {
- try{
+ try {
_snapshotDao.expunge(snapshotVO.getId());
- }catch (Exception e) {
+ } catch (Exception e) {
s_logger.warn("Unable to destroy " + snapshotVO.getId(), e);
}
}
- }finally {
+ } finally {
scanLock.unlock();
}
}
- }finally {
+ } finally {
scanLock.releaseRef();
}
}
@@ -1170,8 +1094,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
return list;
} catch (Exception e) {
- s_logger.debug("failed to get all volumes who has snapshots in secondary storage "
- + storeId + " due to " + e.getMessage());
+ s_logger.debug("failed to get all volumes who has snapshots in secondary storage " + storeId + " due to " + e.getMessage());
return null;
}
@@ -1192,8 +1115,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
return list;
} catch (Exception e) {
- s_logger.debug("failed to get all snapshots for a volume "
- + volumeId + " due to " + e.getMessage());
+ s_logger.debug("failed to get all snapshots for a volume " + volumeId + " due to " + e.getMessage());
return null;
}
}
@@ -1312,7 +1234,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
if (installPath != null) {
EndPoint ep = _epSelector.select(store);
- DeleteVolumeCommand cmd = new DeleteVolumeCommand(store.getTO(), destroyedStoreVO.getVolumeId(), destroyedStoreVO.getInstallPath());
+ DeleteVolumeCommand cmd = new DeleteVolumeCommand(store.getTO(), destroyedStoreVO.getVolumeId(),
+ destroyedStoreVO.getInstallPath());
Answer answer = ep.sendMessage(cmd);
if (answer == null || !answer.getResult()) {
s_logger.debug("Failed to delete " + destroyedStoreVO + " due to "
@@ -1342,16 +1265,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// poolId is null only if volume is destroyed, which has been checked
// before.
assert poolId != null;
- StoragePoolVO PrimaryDataStoreVO = _storagePoolDao
- .findById(poolId);
+ StoragePoolVO PrimaryDataStoreVO = _storagePoolDao.findById(poolId);
assert PrimaryDataStoreVO != null;
return PrimaryDataStoreVO.getUuid();
}
@Override
@DB
- public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(
- Long primaryStorageId) throws ResourceUnavailableException,
+ public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException,
InsufficientCapacityException {
Long userId = UserContext.current().getCallerUserId();
User user = _userDao.findById(userId);
@@ -1368,43 +1289,31 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException(msg);
}
- List<StoragePoolVO> spes = _storagePoolDao.listBy(
- primaryStorage.getDataCenterId(), primaryStorage.getPodId(),
- primaryStorage.getClusterId(), ScopeType.CLUSTER);
+ List<StoragePoolVO> spes = _storagePoolDao.listBy(primaryStorage.getDataCenterId(), primaryStorage.getPodId(), primaryStorage.getClusterId(),
+ ScopeType.CLUSTER);
for (StoragePoolVO sp : spes) {
if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
- throw new CloudRuntimeException(
- "Only one storage pool in a cluster can be in PrepareForMaintenance mode, "
- + sp.getId()
- + " is already in PrepareForMaintenance mode ");
+ throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId()
+ + " is already in PrepareForMaintenance mode ");
}
}
- if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)
- && !primaryStorage.getStatus().equals(
- StoragePoolStatus.ErrorInMaintenance)) {
- throw new InvalidParameterValueException("Primary storage with id "
- + primaryStorageId
- + " is not ready for migration, as the status is:"
+ if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up) && !primaryStorage.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)) {
+ throw new InvalidParameterValueException("Primary storage with id " + primaryStorageId + " is not ready for migration, as the status is:"
+ primaryStorage.getStatus().toString());
}
- DataStoreProvider provider = dataStoreProviderMgr
- .getDataStoreProvider(primaryStorage.getStorageProviderName());
+ DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
- DataStore store = dataStoreMgr.getDataStore(
- primaryStorage.getId(), DataStoreRole.Primary);
+ DataStore store = dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
lifeCycle.maintain(store);
- return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(
- primaryStorage.getId(), DataStoreRole.Primary);
+ return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
@Override
@DB
- public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(
- CancelPrimaryStorageMaintenanceCmd cmd)
- throws ResourceUnavailableException {
+ public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
Long primaryStorageId = cmd.getId();
Long userId = UserContext.current().getCallerUserId();
User user = _userDao.findById(userId);
@@ -1419,24 +1328,17 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException(msg);
}
- if (primaryStorage.getStatus().equals(StoragePoolStatus.Up)
- || primaryStorage.getStatus().equals(
- StoragePoolStatus.PrepareForMaintenance)) {
- throw new StorageUnavailableException("Primary storage with id "
- + primaryStorageId
- + " is not ready to complete migration, as the status is:"
- + primaryStorage.getStatus().toString(), primaryStorageId);
+ if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
+ throw new StorageUnavailableException("Primary storage with id " + primaryStorageId
+ + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
}
- DataStoreProvider provider = dataStoreProviderMgr
- .getDataStoreProvider(primaryStorage.getStorageProviderName());
+ DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
- DataStore store = dataStoreMgr.getDataStore(
- primaryStorage.getId(), DataStoreRole.Primary);
+ DataStore store = dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
lifeCycle.cancelMaintain(store);
- return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(
- primaryStorage.getId(), DataStoreRole.Primary);
+ return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
protected class StorageGarbageCollector implements Runnable {
@@ -1458,35 +1360,26 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList,
- long selfNodeId) {
+ public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
// TODO Auto-generated method stub
}
@Override
- public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList,
- long selfNodeId) {
+ public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
for (ManagementServerHostVO vo : nodeList) {
if (vo.getMsid() == _serverId) {
- s_logger.info("Cleaning up storage maintenance jobs associated with Management server"
- + vo.getMsid());
- List<Long> poolIds = _storagePoolWorkDao
- .searchForPoolIdsForPendingWorkJobs(vo.getMsid());
+ s_logger.info("Cleaning up storage maintenance jobs associated with Management server" + vo.getMsid());
+ List<Long> poolIds = _storagePoolWorkDao.searchForPoolIdsForPendingWorkJobs(vo.getMsid());
if (poolIds.size() > 0) {
for (Long poolId : poolIds) {
- StoragePoolVO pool = _storagePoolDao
- .findById(poolId);
+ StoragePoolVO pool = _storagePoolDao.findById(poolId);
// check if pool is in an inconsistent state
if (pool != null
- && (pool.getStatus().equals(
- StoragePoolStatus.ErrorInMaintenance)
- || pool.getStatus()
- .equals(StoragePoolStatus.PrepareForMaintenance) || pool
- .getStatus()
- .equals(StoragePoolStatus.CancelMaintenance))) {
- _storagePoolWorkDao.removePendingJobsOnMsRestart(
- vo.getMsid(), poolId);
+ && (pool.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)
+ || pool.getStatus().equals(StoragePoolStatus.PrepareForMaintenance) || pool.getStatus().equals(
+ StoragePoolStatus.CancelMaintenance))) {
+ _storagePoolWorkDao.removePendingJobsOnMsRestart(vo.getMsid(), poolId);
pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
_storagePoolDao.update(poolId, pool);
}
@@ -1513,34 +1406,29 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
hosts.add(hostId);
} else {
List<DataStore> stores = this._dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
- if (stores != null){
- for (DataStore store : stores){
+ if (stores != null) {
+ for (DataStore store : stores) {
hosts.add(store.getId());
}
}
- }
+ }
- CapacityVO capacity = new CapacityVO(hostId, zoneId, null, null, 0, 0,
- CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE);
+ CapacityVO capacity = new CapacityVO(hostId, zoneId, null, null, 0, 0, CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE);
for (Long id : hosts) {
StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(id);
if (stats == null) {
continue;
}
- capacity.setUsedCapacity(stats.getByteUsed()
- + capacity.getUsedCapacity());
- capacity.setTotalCapacity(stats.getCapacityBytes()
- + capacity.getTotalCapacity());
+ capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
+ capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
}
return capacity;
}
@Override
- public CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId,
- Long podId, Long zoneId) {
- SearchCriteria<StoragePoolVO> sc = _storagePoolDao
- .createSearchCriteria();
+ public CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId) {
+ SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
if (zoneId != null) {
@@ -1564,30 +1452,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
pools = _storagePoolDao.search(sc, null);
}
- CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId,
- 0, 0, CapacityVO.CAPACITY_TYPE_STORAGE);
+ CapacityVO capacity = new CapacityVO(poolId, zoneId, podId, clusterId, 0, 0, CapacityVO.CAPACITY_TYPE_STORAGE);
for (StoragePoolVO PrimaryDataStoreVO : pools) {
- StorageStats stats = ApiDBUtils
- .getStoragePoolStatistics(PrimaryDataStoreVO.getId());
+ StorageStats stats = ApiDBUtils.getStoragePoolStatistics(PrimaryDataStoreVO.getId());
if (stats == null) {
continue;
}
- capacity.setUsedCapacity(stats.getByteUsed()
- + capacity.getUsedCapacity());
- capacity.setTotalCapacity(stats.getCapacityBytes()
- + capacity.getTotalCapacity());
+ capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
+ capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
}
return capacity;
}
@Override
public PrimaryDataStoreInfo getStoragePool(long id) {
- return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(id,
- DataStoreRole.Primary);
+ return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
}
-
-
@Override
@DB
public List<VMInstanceVO> listByStoragePool(long storagePoolId) {
@@ -1602,11 +1483,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@DB
public StoragePoolVO findLocalStorageOnHost(long hostId) {
SearchCriteria<StoragePoolVO> sc = LocalStorageSearch.create();
- sc.setParameters("type", new Object[] { StoragePoolType.Filesystem,
- StoragePoolType.LVM });
+ sc.setParameters("type", new Object[] { StoragePoolType.Filesystem, StoragePoolType.LVM });
sc.setJoinParameters("poolHost", "hostId", hostId);
- List<StoragePoolVO> storagePools = _storagePoolDao
- .search(sc, null);
+ List<StoragePoolVO> storagePools = _storagePoolDao.search(sc, null);
if (!storagePools.isEmpty()) {
return storagePools.get(0);
} else {
@@ -1618,33 +1497,25 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
public Host updateSecondaryStorage(long secStorageId, String newUrl) {
HostVO secHost = _hostDao.findById(secStorageId);
if (secHost == null) {
- throw new InvalidParameterValueException(
- "Can not find out the secondary storage id: "
- + secStorageId);
+ throw new InvalidParameterValueException("Can not find out the secondary storage id: " + secStorageId);
}
if (secHost.getType() != Host.Type.SecondaryStorage) {
- throw new InvalidParameterValueException("host: " + secStorageId
- + " is not a secondary storage");
+ throw new InvalidParameterValueException("host: " + secStorageId + " is not a secondary storage");
}
URI uri = null;
try {
uri = new URI(UriUtils.encodeURIComponent(newUrl));
if (uri.getScheme() == null) {
- throw new InvalidParameterValueException("uri.scheme is null "
- + newUrl + ", add nfs:// as a prefix");
+ throw new InvalidParameterValueException("uri.scheme is null " + newUrl + ", add nfs:// as a prefix");
} else if (uri.getScheme().equalsIgnoreCase("nfs")) {
- if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("")
- || uri.getPath() == null
- || uri.getPath().equalsIgnoreCase("")) {
- throw new InvalidParameterValueException(
- "Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
+ if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
+ throw new InvalidParameterValueException("Your host and/or path is wrong. Make sure it's of the format nfs://hostname/path");
}
}
} catch (URISyntaxException e) {
- throw new InvalidParameterValueException(newUrl
- + " is not a valid uri");
+ throw new InvalidParameterValueException(newUrl + " is not a valid uri");
}
String oldUrl = secHost.getStorageUrl();
@@ -1653,9 +1524,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
try {
oldUri = new URI(UriUtils.encodeURIComponent(oldUrl));
if (!oldUri.getScheme().equalsIgnoreCase(uri.getScheme())) {
- throw new InvalidParameterValueException(
- "can not change old scheme:" + oldUri.getScheme()
- + " to " + uri.getScheme());
+ throw new InvalidParameterValueException("can not change old scheme:" + oldUri.getScheme() + " to " + uri.getScheme());
}
} catch (URISyntaxException e) {
s_logger.debug("Failed to get uri from " + oldUrl);
@@ -1668,8 +1537,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
return secHost;
}
-
-
@Override
public HypervisorType getHypervisorTypeFromFormat(ImageFormat format) {
@@ -1692,7 +1559,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
private boolean checkUsagedSpace(StoragePool pool) {
StatsCollector sc = StatsCollector.getInstance();
- double storageUsedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityDisableThreshold.key(), Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId()));
+ double storageUsedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityDisableThreshold.key(),
+ Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId()));
if (sc != null) {
long totalSize = pool.getCapacityBytes();
StorageStats stats = sc.getStoragePoolStats(pool.getId());
@@ -1702,21 +1570,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
if (stats != null) {
double usedPercentage = ((double) stats.getByteUsed() / (double) totalSize);
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Checking pool " + pool.getId()
- + " for storage, totalSize: "
- + pool.getCapacityBytes() + ", usedBytes: "
- + stats.getByteUsed() + ", usedPct: "
- + usedPercentage + ", disable threshold: "
- + storageUsedThreshold);
+ s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + pool.getCapacityBytes() + ", usedBytes: "
+ + stats.getByteUsed() + ", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold);
}
if (usedPercentage >= storageUsedThreshold) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Insufficient space on pool: "
- + pool.getId()
- + " since its usage percentage: "
- + usedPercentage
- + " has crossed the pool.storage.capacity.disablethreshold: "
- + storageUsedThreshold);
+ s_logger.debug("Insufficient space on pool: " + pool.getId() + " since its usage percentage: " + usedPercentage
+ + " has crossed the pool.storage.capacity.disablethreshold: " + storageUsedThreshold);
}
return false;
}
@@ -1727,8 +1587,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public boolean storagePoolHasEnoughSpace(List<Volume> volumes,
- StoragePool pool) {
+ public boolean storagePoolHasEnoughSpace(List<Volume> volumes, StoragePool pool) {
if (volumes == null || volumes.isEmpty())
return false;
@@ -1737,16 +1596,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// allocated space includes template of specified volume
StoragePoolVO poolVO = _storagePoolDao.findById(pool.getId());
- long allocatedSizeWithtemplate = _capacityMgr.getAllocatedPoolCapacity(
- poolVO, null);
+ long allocatedSizeWithtemplate = _capacityMgr.getAllocatedPoolCapacity(poolVO, null);
long totalAskingSize = 0;
for (Volume volume : volumes) {
if (volume.getTemplateId() != null) {
- VMTemplateVO tmpl = _templateDao.findById(volume
- .getTemplateId());
+ VMTemplateVO tmpl = _templateDao.findById(volume.getTemplateId());
if (tmpl.getFormat() != ImageFormat.ISO) {
- allocatedSizeWithtemplate = _capacityMgr
- .getAllocatedPoolCapacity(poolVO, tmpl);
+ allocatedSizeWithtemplate = _capacityMgr.getAllocatedPoolCapacity(poolVO, tmpl);
}
}
if (volume.getState() != Volume.State.Ready)
@@ -1755,48 +1611,36 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
long totalOverProvCapacity;
if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
- totalOverProvCapacity = getStorageOverProvisioningFactor(pool.getDataCenterId()).multiply(
- new BigDecimal(pool.getCapacityBytes())).longValue();
+ totalOverProvCapacity = getStorageOverProvisioningFactor(pool.getDataCenterId()).multiply(new BigDecimal(pool.getCapacityBytes()))
+ .longValue();
} else {
totalOverProvCapacity = pool.getCapacityBytes();
}
- double storageAllocatedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityDisableThreshold.key(), Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId()));
+ double storageAllocatedThreshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityDisableThreshold.key(),
+ Config.ConfigurationParameterScope.zone.toString(), pool.getDataCenterId()));
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Checking pool: " + pool.getId()
- + " for volume allocation " + volumes.toString()
- + ", maxSize : " + totalOverProvCapacity
- + ", totalAllocatedSize : " + allocatedSizeWithtemplate
- + ", askingSize : " + totalAskingSize
- + ", allocated disable threshold: "
+ s_logger.debug("Checking pool: " + pool.getId() + " for volume allocation " + volumes.toString() + ", maxSize : " + totalOverProvCapacity
+ + ", totalAllocatedSize : " + allocatedSizeWithtemplate + ", askingSize : " + totalAskingSize + ", allocated disable threshold: "
+ storageAllocatedThreshold);
}
- double usedPercentage = (allocatedSizeWithtemplate + totalAskingSize)
- / (double) (totalOverProvCapacity);
+ double usedPercentage = (allocatedSizeWithtemplate + totalAskingSize) / (double) (totalOverProvCapacity);
if (usedPercentage > storageAllocatedThreshold) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Insufficient un-allocated capacity on: "
- + pool.getId()
- + " for volume allocation: "
- + volumes.toString()
- + " since its allocated percentage: "
- + usedPercentage
- + " has crossed the allocated pool.storage.allocated.capacity.disablethreshold: "
- + storageAllocatedThreshold + ", skipping this pool");
+ s_logger.debug("Insufficient un-allocated capacity on: " + pool.getId() + " for volume allocation: " + volumes.toString()
+ + " since its allocated percentage: " + usedPercentage
+ + " has crossed the allocated pool.storage.allocated.capacity.disablethreshold: " + storageAllocatedThreshold
+ + ", skipping this pool");
}
return false;
}
if (totalOverProvCapacity < (allocatedSizeWithtemplate + totalAskingSize)) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Insufficient un-allocated capacity on: "
- + pool.getId() + " for volume allocation: "
- + volumes.toString()
- + ", not enough storage, maxSize : "
- + totalOverProvCapacity + ", totalAllocatedSize : "
- + allocatedSizeWithtemplate + ", askingSize : "
- + totalAskingSize);
+ s_logger.debug("Insufficient un-allocated capacity on: " + pool.getId() + " for volume allocation: " + volumes.toString()
+ + ", not enough storage, maxSize : " + totalOverProvCapacity + ", totalAllocatedSize : " + allocatedSizeWithtemplate
+ + ", askingSize : " + totalAskingSize);
}
return false;
}
@@ -1809,24 +1653,20 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
createCapacityEntry(storage, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, 0);
}
-
@Override
- public synchronized boolean registerHostListener(String providerName,
- HypervisorHostListener listener) {
+ public synchronized boolean registerHostListener(String providerName, HypervisorHostListener listener) {
hostListeners.put(providerName, listener);
return true;
}
@Override
- public Answer sendToPool(long poolId, Command cmd)
- throws StorageUnavailableException {
+ public Answer sendToPool(long poolId, Command cmd) throws StorageUnavailableException {
// TODO Auto-generated method stub
return null;
}
@Override
- public Answer[] sendToPool(long poolId, Commands cmd)
- throws StorageUnavailableException {
+ public Answer[] sendToPool(long poolId, Commands cmd) throws StorageUnavailableException {
// TODO Auto-generated method stub
return null;
}
@@ -1838,8 +1678,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
@Override
- public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException,
- InvalidParameterValueException {
+ public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
String providerName = cmd.getProviderName();
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
@@ -1854,21 +1693,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
String url = cmd.getUrl();
Map details = cmd.getDetails();
ScopeType scopeType = ScopeType.ZONE;
- if ( dcId == null ){
+ if (dcId == null) {
scopeType = ScopeType.REGION;
}
// check if scope is supported by store provider
- if ( !((ImageStoreProvider)storeProvider).isScopeSupported(scopeType)){
+ if (!((ImageStoreProvider) storeProvider).isScopeSupported(scopeType)) {
throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
}
- // check if we have already image stores from other different providers, we currently are not supporting image stores from different
+ // check if we have already image stores from other different providers,
+ // we currently are not supporting image stores from different
// providers co-existing
List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
- for ( ImageStoreVO store : imageStores){
- if (!store.getProviderName().equalsIgnoreCase(providerName)){
- throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName() + " already added");
+ for (ImageStoreVO store : imageStores) {
+ if (!store.getProviderName().equalsIgnoreCase(providerName)) {
+ throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName()
+ + " already added");
}
}
@@ -1888,7 +1729,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
}
-
Map<String, Object> params = new HashMap<String, Object>();
params.put("zoneId", dcId);
params.put("url", cmd.getUrl());
@@ -1915,13 +1755,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
this._imageSrv.addSystemVMTemplatesToSecondary(store);
}
- // associate builtin template with zones associated with this image store
+ // associate builtin template with zones associated with this image
+ // store
this.associateCrosszoneTemplatesToZone(dcId);
return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Image);
}
- private void associateCrosszoneTemplatesToZone(Long zoneId){
+ private void associateCrosszoneTemplatesToZone(Long zoneId) {
VMTemplateZoneVO tmpltZone;
List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
@@ -1961,24 +1802,28 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
_accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), store.getDataCenterId());
- // Verify that there are no live snapshot, template, volume on the image store to be deleted
+ // Verify that there are no live snapshot, template, volume on the image
+ // store to be deleted
List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
- if ( snapshots != null && snapshots.size() > 0 ){
- throw new CloudRuntimeException("Cannot delete image store with active snapshots backup!");
+ if (snapshots != null && snapshots.size() > 0) {
+ throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
}
List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
- if ( volumes != null && volumes.size() > 0 ){
- throw new CloudRuntimeException("Cannot delete image store with active volumes backup!");
+ if (volumes != null && volumes.size() > 0) {
+ throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
}
- List<TemplateDataStoreVO> templates = _templateStoreDao.listByStoreId(storeId);
- if ( templates != null && templates.size() > 0 ){
- throw new CloudRuntimeException("Cannot delete image store with active templates backup!");
+
+ // search if there are user templates stored on this image store, excluding system, builtin templates
+ List<TemplateJoinVO> templates = this._templateViewDao.listActiveTemplates(storeId);
+ if (templates != null && templates.size() > 0) {
+ throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
}
// ready to delete
Transaction txn = Transaction.currentTxn();
txn.start();
- // first delete from image_store_details table, we need to do that since we are not actually deleting record from main
+ // first delete from image_store_details table, we need to do that since
+ // we are not actually deleting record from main
// image_data_store table, so delete cascade will not work
_imageStoreDetailsDao.deleteDetails(storeId);
_snapshotStoreDao.deletePrimaryRecordsForStore(storeId);
@@ -1988,6 +1833,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
txn.commit();
return true;
}
+
@Override
public ImageStore createCacheStore(CreateCacheStoreCmd cmd) {
String providerName = cmd.getProviderName();
@@ -2021,7 +1867,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
}
-
// Check if the zone exists in the system
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
@@ -2057,5 +1902,4 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.ImageCache);
}
-
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cb0659ab/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 556b7f3..134e44d 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -177,7 +177,7 @@ CREATE TABLE `cloud`.`snapshot_store_ref` (
`parent_snapshot_id` bigint unsigned DEFAULT 0,
`install_path` varchar(255),
`state` varchar(255) NOT NULL,
- `removed` datetime COMMENT 'date removed if not null',
+ -- `removed` datetime COMMENT 'date removed if not null',
`update_count` bigint unsigned,
`updated` datetime,
PRIMARY KEY (`id`),
@@ -1752,6 +1752,7 @@ CREATE VIEW `cloud`.`template_view` AS
data_center.uuid data_center_uuid,
data_center.name data_center_name,
launch_permission.account_id lp_account_id,
+ template_store_ref.store_id,
template_store_ref.download_state,
template_store_ref.download_pct,
template_store_ref.error_str,