mirror of https://github.com/apache/cloudstack.git
Added update, enable, disable events to the updateStoragePool API (#9543)
This commit is contained in:
parent
2245d98598
commit
716ab205ea
|
|
@ -451,6 +451,7 @@ public class EventTypes {
|
||||||
public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS";
|
public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS";
|
||||||
|
|
||||||
// Primary storage pool
|
// Primary storage pool
|
||||||
|
public static final String EVENT_UPDATE_PRIMARY_STORAGE = "UPDATE.PS";
|
||||||
public static final String EVENT_ENABLE_PRIMARY_STORAGE = "ENABLE.PS";
|
public static final String EVENT_ENABLE_PRIMARY_STORAGE = "ENABLE.PS";
|
||||||
public static final String EVENT_DISABLE_PRIMARY_STORAGE = "DISABLE.PS";
|
public static final String EVENT_DISABLE_PRIMARY_STORAGE = "DISABLE.PS";
|
||||||
public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL";
|
public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL";
|
||||||
|
|
@ -1007,6 +1008,7 @@ public class EventTypes {
|
||||||
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class);
|
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class);
|
||||||
|
|
||||||
// Primary storage pool
|
// Primary storage pool
|
||||||
|
entityEventDetails.put(EVENT_UPDATE_PRIMARY_STORAGE, StoragePool.class);
|
||||||
entityEventDetails.put(EVENT_ENABLE_PRIMARY_STORAGE, StoragePool.class);
|
entityEventDetails.put(EVENT_ENABLE_PRIMARY_STORAGE, StoragePool.class);
|
||||||
entityEventDetails.put(EVENT_DISABLE_PRIMARY_STORAGE, StoragePool.class);
|
entityEventDetails.put(EVENT_DISABLE_PRIMARY_STORAGE, StoragePool.class);
|
||||||
entityEventDetails.put(EVENT_CHANGE_STORAGE_POOL_SCOPE, StoragePool.class);
|
entityEventDetails.put(EVENT_CHANGE_STORAGE_POOL_SCOPE, StoragePool.class);
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,10 @@ public interface StorageService {
|
||||||
|
|
||||||
StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException;
|
StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
StoragePool enablePrimaryStoragePool(Long id);
|
||||||
|
|
||||||
|
StoragePool disablePrimaryStoragePool(Long id);
|
||||||
|
|
||||||
StoragePool getStoragePool(long id);
|
StoragePool getStoragePool(long id);
|
||||||
|
|
||||||
boolean deleteImageStore(DeleteImageStoreCmd cmd);
|
boolean deleteImageStore(DeleteImageStoreCmd cmd);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||||
|
|
||||||
import com.cloud.storage.StoragePool;
|
import com.cloud.storage.StoragePool;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
|
import org.apache.commons.collections.MapUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@APICommand(name = "updateStoragePool", description = "Updates a storage pool.", responseObject = StoragePoolResponse.class, since = "3.0.0",
|
@APICommand(name = "updateStoragePool", description = "Updates a storage pool.", responseObject = StoragePoolResponse.class, since = "3.0.0",
|
||||||
|
|
@ -147,7 +149,17 @@ public class UpdateStoragePoolCmd extends BaseCmd {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
StoragePool result = _storageService.updateStoragePool(this);
|
StoragePool result = null;
|
||||||
|
if (ObjectUtils.anyNotNull(name, capacityIops, capacityBytes, url, isTagARule, tags) ||
|
||||||
|
MapUtils.isNotEmpty(details)) {
|
||||||
|
result = _storageService.updateStoragePool(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enabled != null) {
|
||||||
|
result = enabled ? _storageService.enablePrimaryStoragePool(id)
|
||||||
|
: _storageService.disablePrimaryStoragePool(id);
|
||||||
|
}
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
|
StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
|
||||||
response.setResponseName(getCommandName());
|
response.setResponseName(getCommandName());
|
||||||
|
|
|
||||||
|
|
@ -1127,8 +1127,13 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
|
@ActionEvent(eventType = EventTypes.EVENT_DISABLE_PRIMARY_STORAGE, eventDescription = "disable storage pool")
|
||||||
private void disablePrimaryStoragePool(StoragePoolVO primaryStorage) {
|
public StoragePool disablePrimaryStoragePool(Long id) {
|
||||||
|
StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
|
||||||
|
if (primaryStorage == null) {
|
||||||
|
throw new IllegalArgumentException(String.format("Unable to find storage pool with ID: %d", id));
|
||||||
|
}
|
||||||
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)) {
|
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Up)) {
|
||||||
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. Storage pool state : " + primaryStorage.getStatus().toString());
|
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. Storage pool state : " + primaryStorage.getStatus().toString());
|
||||||
}
|
}
|
||||||
|
|
@ -1137,10 +1142,17 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||||
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
|
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
|
||||||
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
|
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
|
||||||
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).disableStoragePool(store);
|
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).disableStoragePool(store);
|
||||||
|
|
||||||
|
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@ActionEvent(eventType = EventTypes.EVENT_ENABLE_PRIMARY_STORAGE, eventDescription = "enable storage pool")
|
@ActionEvent(eventType = EventTypes.EVENT_ENABLE_PRIMARY_STORAGE, eventDescription = "enable storage pool")
|
||||||
private void enablePrimaryStoragePool(StoragePoolVO primaryStorage) {
|
public StoragePool enablePrimaryStoragePool(Long id) {
|
||||||
|
StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
|
||||||
|
if (primaryStorage == null) {
|
||||||
|
throw new IllegalArgumentException(String.format("Unable to find storage pool with ID: %d", id));
|
||||||
|
}
|
||||||
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Disabled)) {
|
if (!primaryStorage.getStatus().equals(StoragePoolStatus.Disabled)) {
|
||||||
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be enabled. Storage pool state : " + primaryStorage.getStatus().toString());
|
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be enabled. Storage pool state : " + primaryStorage.getStatus().toString());
|
||||||
}
|
}
|
||||||
|
|
@ -1149,9 +1161,12 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||||
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
|
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
|
||||||
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
|
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
|
||||||
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).enableStoragePool(store);
|
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).enableStoragePool(store);
|
||||||
|
|
||||||
|
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_PRIMARY_STORAGE, eventDescription = "update storage pool")
|
||||||
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
|
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
|
||||||
// Input validation
|
// Input validation
|
||||||
Long id = cmd.getId();
|
Long id = cmd.getId();
|
||||||
|
|
@ -1236,15 +1251,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean enabled = cmd.getEnabled();
|
|
||||||
if (enabled != null) {
|
|
||||||
if (enabled) {
|
|
||||||
enablePrimaryStoragePool(pool);
|
|
||||||
} else {
|
|
||||||
disablePrimaryStoragePool(pool);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
|
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue