Skip to content

Commit 716ab20

Browse files
Added update, enable, disable events to the updateStoragePool API (#9543)
1 parent 2245d98 commit 716ab20

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ public class EventTypes {
451451
public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS";
452452

453453
// Primary storage pool
454+
public static final String EVENT_UPDATE_PRIMARY_STORAGE = "UPDATE.PS";
454455
public static final String EVENT_ENABLE_PRIMARY_STORAGE = "ENABLE.PS";
455456
public static final String EVENT_DISABLE_PRIMARY_STORAGE = "DISABLE.PS";
456457
public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL";
@@ -1007,6 +1008,7 @@ public class EventTypes {
10071008
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class);
10081009

10091010
// Primary storage pool
1011+
entityEventDetails.put(EVENT_UPDATE_PRIMARY_STORAGE, StoragePool.class);
10101012
entityEventDetails.put(EVENT_ENABLE_PRIMARY_STORAGE, StoragePool.class);
10111013
entityEventDetails.put(EVENT_DISABLE_PRIMARY_STORAGE, StoragePool.class);
10121014
entityEventDetails.put(EVENT_CHANGE_STORAGE_POOL_SCOPE, StoragePool.class);

api/src/main/java/com/cloud/storage/StorageService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public interface StorageService {
9595

9696
StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException;
9797

98+
StoragePool enablePrimaryStoragePool(Long id);
99+
100+
StoragePool disablePrimaryStoragePool(Long id);
101+
98102
StoragePool getStoragePool(long id);
99103

100104
boolean deleteImageStore(DeleteImageStoreCmd cmd);

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import com.cloud.storage.StoragePool;
3333
import com.cloud.user.Account;
34+
import org.apache.commons.collections.MapUtils;
35+
import org.apache.commons.lang3.ObjectUtils;
3436

3537
@SuppressWarnings("rawtypes")
3638
@APICommand(name = "updateStoragePool", description = "Updates a storage pool.", responseObject = StoragePoolResponse.class, since = "3.0.0",
@@ -147,7 +149,17 @@ public void setUrl(String url) {
147149

148150
@Override
149151
public void execute() {
150-
StoragePool result = _storageService.updateStoragePool(this);
152+
StoragePool result = null;
153+
if (ObjectUtils.anyNotNull(name, capacityIops, capacityBytes, url, isTagARule, tags) ||
154+
MapUtils.isNotEmpty(details)) {
155+
result = _storageService.updateStoragePool(this);
156+
}
157+
158+
if (enabled != null) {
159+
result = enabled ? _storageService.enablePrimaryStoragePool(id)
160+
: _storageService.disablePrimaryStoragePool(id);
161+
}
162+
151163
if (result != null) {
152164
StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
153165
response.setResponseName(getCommandName());

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,13 @@ private Map<String, String> extractApiParamAsMap(Map ds) {
11271127
return details;
11281128
}
11291129

1130+
@Override
11301131
@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
1131-
private void disablePrimaryStoragePool(StoragePoolVO primaryStorage) {
1132+
public StoragePool disablePrimaryStoragePool(Long id) {
1133+
StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
1134+
if (primaryStorage == null) {
1135+
throw new IllegalArgumentException(String.format("Unable to find storage pool with ID: %d", id));
1136+
}
11321137
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)) {
11331138
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. Storage pool state : " + primaryStorage.getStatus().toString());
11341139
}
@@ -1137,10 +1142,17 @@ private void disablePrimaryStoragePool(StoragePoolVO primaryStorage) {
11371142
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
11381143
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
11391144
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).disableStoragePool(store);
1145+
1146+
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
11401147
}
11411148

1149+
@Override
11421150
@ActionEvent(eventType = EventTypes.EVENT_ENABLE_PRIMARY_STORAGE, eventDescription = "enable storage pool")
1143-
private void enablePrimaryStoragePool(StoragePoolVO primaryStorage) {
1151+
public StoragePool enablePrimaryStoragePool(Long id) {
1152+
StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
1153+
if (primaryStorage == null) {
1154+
throw new IllegalArgumentException(String.format("Unable to find storage pool with ID: %d", id));
1155+
}
11441156
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Disabled)) {
11451157
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be enabled. Storage pool state : " + primaryStorage.getStatus().toString());
11461158
}
@@ -1149,9 +1161,12 @@ private void enablePrimaryStoragePool(StoragePoolVO primaryStorage) {
11491161
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
11501162
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
11511163
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).enableStoragePool(store);
1164+
1165+
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
11521166
}
11531167

11541168
@Override
1169+
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_PRIMARY_STORAGE, eventDescription = "update storage pool")
11551170
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
11561171
// Input validation
11571172
Long id = cmd.getId();
@@ -1236,15 +1251,6 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
12361251
}
12371252
}
12381253

1239-
Boolean enabled = cmd.getEnabled();
1240-
if (enabled != null) {
1241-
if (enabled) {
1242-
enablePrimaryStoragePool(pool);
1243-
} else {
1244-
disablePrimaryStoragePool(pool);
1245-
}
1246-
}
1247-
12481254
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
12491255
}
12501256

0 commit comments

Comments
 (0)