Skip to content

Commit 2bc4cbf

Browse files
rajesh-battalasudison
authored andcommitted
CLOUDSTACK-2571 Zone Wide Primary Storage blocker issues while Enabling in Maintenance State
Signed-off-by: Edison Su <sudison@gmail.com>
1 parent db5d526 commit 2bc4cbf

4 files changed

Lines changed: 54 additions & 38 deletions

File tree

engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,19 @@
3030
public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
3131

3232
/**
33-
* @param datacenterId
34-
* -- the id of the datacenter (availability zone)
33+
* @param datacenterId -- the id of the datacenter (availability zone)
3534
*/
3635
List<StoragePoolVO> listByDataCenterId(long datacenterId);
3736

3837
/**
39-
* @param datacenterId
40-
* -- the id of the datacenter (availability zone)
38+
* @param datacenterId -- the id of the datacenter (availability zone)
4139
*/
42-
List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope);
40+
List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope);
4341

4442
/**
4543
* Set capacity of storage pool in bytes
46-
*
47-
* @param id
48-
* pool id.
49-
* @param capacity
50-
* capacity in bytes
44+
* @param id pool id.
45+
* @param capacity capacity in bytes
5146
*/
5247
void updateCapacity(long id, long capacity);
5348

@@ -82,7 +77,7 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
8277
* @return List of StoragePoolVO
8378
*/
8479
List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details,
85-
ScopeType scope);
80+
ScopeType scope);
8681

8782
List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags);
8883

engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public StoragePoolVO findPoolByHostPath(long datacenterId, Long podId, String ho
194194
}
195195

196196
@Override
197-
public List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope) {
197+
public List<StoragePoolVO> listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope) {
198198
if (clusterId != null) {
199199
SearchCriteria<StoragePoolVO> sc = DcPodSearch.create();
200200
sc.setParameters("datacenterId", datacenterId);
@@ -249,7 +249,7 @@ public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details) {
249249
@DB
250250
@Override
251251
public List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details,
252-
ScopeType scope) {
252+
ScopeType scope) {
253253
StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
254254
if (clusterId != null) {
255255
sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public boolean isLocalStorageActiveOnHost(Long hostId) {
400400

401401
@Override
402402
public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm,
403-
final Set<StoragePool> avoid) {
403+
final Set<StoragePool> avoid) {
404404

405405
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
406406
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
@@ -637,7 +637,7 @@ public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws Con
637637
@Override
638638
@SuppressWarnings("rawtypes")
639639
public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException,
640-
ResourceUnavailableException {
640+
ResourceUnavailableException {
641641
String providerName = cmd.getStorageProviderName();
642642
DataStoreProvider storeProvider = dataStoreProviderMgr.getDataStoreProvider(providerName);
643643

@@ -1181,14 +1181,13 @@ public String getPrimaryStorageNameLabel(VolumeVO volume) {
11811181
@Override
11821182
@DB
11831183
public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(Long primaryStorageId) throws ResourceUnavailableException,
1184-
InsufficientCapacityException {
1184+
InsufficientCapacityException {
11851185
Long userId = UserContext.current().getCallerUserId();
11861186
User user = _userDao.findById(userId);
11871187
Account account = UserContext.current().getCaller();
11881188

11891189
boolean restart = true;
11901190
StoragePoolVO primaryStorage = null;
1191-
11921191
primaryStorage = _storagePoolDao.findById(primaryStorageId);
11931192

11941193
if (primaryStorage == null) {
@@ -1197,15 +1196,6 @@ public PrimaryDataStoreInfo preparePrimaryStorageForMaintenance(Long primaryStor
11971196
throw new InvalidParameterValueException(msg);
11981197
}
11991198

1200-
List<StoragePoolVO> spes = _storagePoolDao.listBy(primaryStorage.getDataCenterId(), primaryStorage.getPodId(), primaryStorage.getClusterId(),
1201-
ScopeType.CLUSTER);
1202-
for (StoragePoolVO sp : spes) {
1203-
if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
1204-
throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId()
1205-
+ " is already in PrepareForMaintenance mode ");
1206-
}
1207-
}
1208-
12091199
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up) && !primaryStorage.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)) {
12101200
throw new InvalidParameterValueException("Primary storage with id " + primaryStorageId + " is not ready for migration, as the status is:"
12111201
+ primaryStorage.getStatus().toString());
@@ -1285,8 +1275,8 @@ public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long sel
12851275
// check if pool is in an inconsistent state
12861276
if (pool != null
12871277
&& (pool.getStatus().equals(StoragePoolStatus.ErrorInMaintenance)
1288-
|| pool.getStatus().equals(StoragePoolStatus.PrepareForMaintenance) || pool.getStatus().equals(
1289-
StoragePoolStatus.CancelMaintenance))) {
1278+
|| pool.getStatus().equals(StoragePoolStatus.PrepareForMaintenance) || pool.getStatus().equals(
1279+
StoragePoolStatus.CancelMaintenance))) {
12901280
_storagePoolWorkDao.removePendingJobsOnMsRestart(vo.getMsid(), poolId);
12911281
pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
12921282
_storagePoolDao.update(poolId, pool);
@@ -1496,7 +1486,7 @@ private boolean checkUsagedSpace(StoragePool pool) {
14961486

14971487
@Override
14981488
public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes,
1499-
StoragePool pool) {
1489+
StoragePool pool) {
15001490
if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
15011491
return false;
15021492
}
@@ -1530,7 +1520,7 @@ public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes,
15301520

15311521
@Override
15321522
public boolean storagePoolHasEnoughSpace(List<Volume> volumes,
1533-
StoragePool pool) {
1523+
StoragePool pool) {
15341524
if (volumes == null || volumes.isEmpty()){
15351525
return false;
15361526
}

server/src/com/cloud/storage/StoragePoolAutomationImpl.java

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package com.cloud.storage;
2020

21+
import java.util.ArrayList;
2122
import java.util.List;
2223

2324
import javax.inject.Inject;
@@ -27,6 +28,7 @@
2728
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
2829
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
2930
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
31+
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
3032
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
3133
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3234
import org.apache.log4j.Logger;
@@ -36,8 +38,10 @@
3638
import com.cloud.agent.api.Answer;
3739
import com.cloud.agent.api.ModifyStoragePoolCommand;
3840
import com.cloud.alert.AlertManager;
41+
import com.cloud.host.Host;
3942
import com.cloud.host.HostVO;
4043
import com.cloud.host.Status;
44+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4145
import com.cloud.resource.ResourceManager;
4246
import com.cloud.server.ManagementServer;
4347
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -101,17 +105,45 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation {
101105
@Inject
102106
ManagementServer server;
103107
@Inject DataStoreProviderManager providerMgr;
104-
108+
105109
@Override
106110
public boolean maintain(DataStore store) {
107111
Long userId = UserContext.current().getCallerUserId();
108112
User user = _userDao.findById(userId);
109113
Account account = UserContext.current().getCaller();
110114
StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId());
111115
try {
116+
List<StoragePoolVO> spes = null;
117+
// Handling Zone and Cluster wide storage scopes.
118+
// if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS
119+
if (pool.getScope() == ScopeType.ZONE) {
120+
spes = primaryDataStoreDao.listBy(
121+
pool.getDataCenterId(), null,
122+
null, ScopeType.ZONE);
123+
}
124+
else {
125+
spes = primaryDataStoreDao.listBy(
126+
pool.getDataCenterId(), pool.getPodId(),
127+
pool.getClusterId(), ScopeType.CLUSTER);
128+
}
129+
for (StoragePoolVO sp : spes) {
130+
if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
131+
throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId()
132+
+ " is already in PrepareForMaintenance mode ");
133+
}
134+
}
112135
StoragePool storagePool = (StoragePool) store;
113-
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
114-
pool.getClusterId(), Status.Up);
136+
137+
//Handeling the Zone wide and cluster wide primay storage
138+
List<HostVO> hosts = new ArrayList<HostVO>();
139+
// if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
140+
if (pool.getScope().equals(ScopeType.ZONE)) {
141+
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor() , pool.getDataCenterId());
142+
} else {
143+
hosts = _resourceMgr.listHostsInClusterByStatus(
144+
pool.getClusterId(), Status.Up);
145+
}
146+
115147
if (hosts == null || hosts.size() == 0) {
116148
pool.setStatus(StoragePoolStatus.Maintenance);
117149
primaryDataStoreDao.update(pool.getId(), pool);
@@ -130,11 +162,11 @@ public boolean maintain(DataStore store) {
130162
if (s_logger.isDebugEnabled()) {
131163
s_logger.debug("ModifyStoragePool false failed due to "
132164
+ ((answer == null) ? "answer null" : answer
133-
.getDetails()));
165+
.getDetails()));
134166
}
135167
} else {
136168
if (s_logger.isDebugEnabled()) {
137-
s_logger.debug("ModifyStoragePool false secceeded");
169+
s_logger.debug("ModifyStoragePool false succeeded");
138170
}
139171
}
140172
}
@@ -314,7 +346,6 @@ public boolean maintain(DataStore store) {
314346
}
315347
}
316348
}
317-
318349
} catch(Exception e) {
319350
s_logger.error(
320351
"Exception in enabling primary storage maintenance:", e);
@@ -334,7 +365,7 @@ public boolean cancelMaintain(DataStore store) {
334365
StoragePoolVO poolVO = this.primaryDataStoreDao
335366
.findById(store.getId());
336367
StoragePool pool = (StoragePool)store;
337-
368+
338369
List<HostVO> hosts = _resourceMgr.listHostsInClusterByStatus(
339370
pool.getClusterId(), Status.Up);
340371
if (hosts == null || hosts.size() == 0) {
@@ -349,7 +380,7 @@ public boolean cancelMaintain(DataStore store) {
349380
if (s_logger.isDebugEnabled()) {
350381
s_logger.debug("ModifyStoragePool add failed due to "
351382
+ ((answer == null) ? "answer null" : answer
352-
.getDetails()));
383+
.getDetails()));
353384
}
354385
} else {
355386
if (s_logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)