mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-2571 Zone Wide Primary Storage blocker issues while Enabling in Maintenance State
Signed-off-by: Edison Su <sudison@gmail.com>
This commit is contained in:
parent
db5d526269
commit
2bc4cbf9fb
@ -30,24 +30,19 @@ import com.cloud.utils.db.GenericDao;
|
||||
public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
|
||||
|
||||
/**
|
||||
* @param datacenterId
|
||||
* -- the id of the datacenter (availability zone)
|
||||
* @param datacenterId -- the id of the datacenter (availability zone)
|
||||
*/
|
||||
List<StoragePoolVO> listByDataCenterId(long datacenterId);
|
||||
|
||||
/**
|
||||
* @param datacenterId
|
||||
* -- the id of the datacenter (availability zone)
|
||||
* @param datacenterId -- the id of the datacenter (availability zone)
|
||||
*/
|
||||
List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope);
|
||||
List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope);
|
||||
|
||||
/**
|
||||
* Set capacity of storage pool in bytes
|
||||
*
|
||||
* @param id
|
||||
* pool id.
|
||||
* @param capacity
|
||||
* capacity in bytes
|
||||
* @param id pool id.
|
||||
* @param capacity capacity in bytes
|
||||
*/
|
||||
void updateCapacity(long id, long capacity);
|
||||
|
||||
@ -82,7 +77,7 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
|
||||
* @return List of StoragePoolVO
|
||||
*/
|
||||
List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details,
|
||||
ScopeType scope);
|
||||
ScopeType scope);
|
||||
|
||||
List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags);
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope) {
|
||||
public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope) {
|
||||
if (clusterId != null) {
|
||||
SearchCriteria<StoragePoolVO> sc = DcPodSearch.create();
|
||||
sc.setParameters("datacenterId", datacenterId);
|
||||
@ -249,7 +249,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
|
||||
@DB
|
||||
@Override
|
||||
public List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details,
|
||||
ScopeType scope) {
|
||||
ScopeType scope) {
|
||||
StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
|
||||
if (clusterId != null) {
|
||||
sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
|
||||
|
||||
@ -400,7 +400,7 @@ 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) {
|
||||
final Set<StoragePool> avoid) {
|
||||
|
||||
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
|
||||
@ -637,7 +637,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException,
|
||||
ResourceUnavailableException {
|
||||
ResourceUnavailableException {
|
||||
String providerName = cmd.getStorageProviderName();
|
||||
DataStoreProvider storeProvider = dataStoreProviderMgr.getDataStoreProvider(providerName);
|
||||
|
||||
@ -1181,14 +1181,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
@Override
|
||||
@DB
|
||||
public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException,
|
||||
InsufficientCapacityException {
|
||||
InsufficientCapacityException {
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
User user = _userDao.findById(userId);
|
||||
Account account = UserContext.current().getCaller();
|
||||
|
||||
boolean restart = true;
|
||||
StoragePoolVO primaryStorage = null;
|
||||
|
||||
primaryStorage = _storagePoolDao.findById(primaryStorageId);
|
||||
|
||||
if (primaryStorage == null) {
|
||||
@ -1197,15 +1196,6 @@ 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);
|
||||
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 ");
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
@ -1285,8 +1275,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
// 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))) {
|
||||
|| pool.getStatus().equals(StoragePoolStatus.PrepareForMaintenance) || pool.getStatus().equals(
|
||||
StoragePoolStatus.CancelMaintenance))) {
|
||||
_storagePoolWorkDao.removePendingJobsOnMsRestart(vo.getMsid(), poolId);
|
||||
pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
|
||||
_storagePoolDao.update(poolId, pool);
|
||||
@ -1496,7 +1486,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
|
||||
@Override
|
||||
public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes,
|
||||
StoragePool pool) {
|
||||
StoragePool pool) {
|
||||
if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
|
||||
return false;
|
||||
}
|
||||
@ -1530,7 +1520,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
|
||||
@Override
|
||||
public boolean storagePoolHasEnoughSpace(List<Volume> volumes,
|
||||
StoragePool pool) {
|
||||
StoragePool pool) {
|
||||
if (volumes == null || volumes.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -27,6 +28,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -36,8 +38,10 @@ import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
@ -101,7 +105,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
@Inject
|
||||
ManagementServer server;
|
||||
@Inject DataStoreProviderManager providerMgr;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean maintain(DataStore store) {
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
@ -109,9 +113,37 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
Account account = UserContext.current().getCaller();
|
||||
StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
|
||||
try {
|
||||
List<StoragePoolVO> spes = null;
|
||||
// Handling Zone and Cluster wide storage scopes.
|
||||
// if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS
|
||||
if (pool.getScope() == ScopeType.ZONE) {
|
||||
spes = primaryDataStoreDao.listBy(
|
||||
pool.getDataCenterId(), null,
|
||||
null, ScopeType.ZONE);
|
||||
}
|
||||
else {
|
||||
spes = primaryDataStoreDao.listBy(
|
||||
pool.getDataCenterId(), pool.getPodId(),
|
||||
pool.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 ");
|
||||
}
|
||||
}
|
||||
StoragePool storagePool = (StoragePool) store;
|
||||
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
|
||||
pool.getClusterId(), Status.Up);
|
||||
|
||||
//Handeling the Zone wide and cluster wide primay storage
|
||||
List<HostVO> hosts = new ArrayList<HostVO>();
|
||||
// if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
|
||||
if (pool.getScope().equals(ScopeType.ZONE)) {
|
||||
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor() , pool.getDataCenterId());
|
||||
} else {
|
||||
hosts = _resourceMgr.listHostsInClusterByStatus(
|
||||
pool.getClusterId(), Status.Up);
|
||||
}
|
||||
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
pool.setStatus(StoragePoolStatus.Maintenance);
|
||||
primaryDataStoreDao.update(pool.getId(), pool);
|
||||
@ -130,11 +162,11 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("ModifyStoragePool false failed due to "
|
||||
+ ((answer == null) ? "answer null" : answer
|
||||
.getDetails()));
|
||||
.getDetails()));
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("ModifyStoragePool false secceeded");
|
||||
s_logger.debug("ModifyStoragePool false succeeded");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -314,7 +346,6 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
s_logger.error(
|
||||
"Exception in enabling primary storage maintenance:", e);
|
||||
@ -334,7 +365,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
StoragePoolVO poolVO = this.primaryDataStoreDao
|
||||
.findById(store.getId());
|
||||
StoragePool pool = (StoragePool)store;
|
||||
|
||||
|
||||
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
|
||||
pool.getClusterId(), Status.Up);
|
||||
if (hosts == null || hosts.size() == 0) {
|
||||
@ -349,7 +380,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("ModifyStoragePool add failed due to "
|
||||
+ ((answer == null) ? "answer null" : answer
|
||||
.getDetails()));
|
||||
.getDetails()));
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user