Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public class EventTypes {
public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS";

// 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_DISABLE_PRIMARY_STORAGE = "DISABLE.PS";
public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL";
Expand Down Expand Up @@ -1001,6 +1002,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class);

// Primary storage pool
entityEventDetails.put(EVENT_UPDATE_PRIMARY_STORAGE, StoragePool.class);
entityEventDetails.put(EVENT_ENABLE_PRIMARY_STORAGE, StoragePool.class);
entityEventDetails.put(EVENT_DISABLE_PRIMARY_STORAGE, StoragePool.class);
entityEventDetails.put(EVENT_CHANGE_STORAGE_POOL_SCOPE, StoragePool.class);
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/storage/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public interface StorageService {

StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException;

StoragePool enablePrimaryStoragePool(Long id);

StoragePool disablePrimaryStoragePool(Long id);

StoragePool getStoragePool(long id);

boolean deleteImageStore(DeleteImageStoreCmd cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import com.cloud.storage.StoragePool;
import com.cloud.user.Account;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ObjectUtils;

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

@Override
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) {
StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result);
response.setResponseName(getCommandName());
Expand Down
28 changes: 17 additions & 11 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,13 @@ private Map<String, String> extractApiParamAsMap(Map ds) {
return details;
}

@Override
@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)) {
Comment thread
sureshanaparti marked this conversation as resolved.
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be disabled. Storage pool state : " + primaryStorage.getStatus().toString());
}
Expand All @@ -1137,10 +1142,17 @@ private void disablePrimaryStoragePool(StoragePoolVO primaryStorage) {
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).disableStoragePool(store);

return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
}

@Override
@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)) {
throw new InvalidParameterValueException("Primary storage with id " + primaryStorage.getId() + " cannot be enabled. Storage pool state : " + primaryStorage.getStatus().toString());
}
Expand All @@ -1149,9 +1161,12 @@ private void enablePrimaryStoragePool(StoragePoolVO primaryStorage) {
DataStoreLifeCycle dataStoreLifeCycle = provider.getDataStoreLifeCycle();
DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
((PrimaryDataStoreLifeCycle)dataStoreLifeCycle).enableStoragePool(store);

return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(id, DataStoreRole.Primary);
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_UPDATE_PRIMARY_STORAGE, eventDescription = "update storage pool")
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
// Input validation
Long id = cmd.getId();
Expand Down Expand Up @@ -1236,15 +1251,6 @@ public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws I
}
}

Boolean enabled = cmd.getEnabled();
if (enabled != null) {
if (enabled) {
enablePrimaryStoragePool(pool);
} else {
disablePrimaryStoragePool(pool);
}
}

return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}

Expand Down