From 8f503c7ff6efe29ecefac7bed0f3ec7ea74ccc0f Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Sat, 10 Aug 2013 17:03:35 -0600 Subject: [PATCH] CLOUDSTACK-4227 --- .../com/cloud/storage/StorageManagerImpl.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index ad5c71a8bbd..2b94df24c19 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -141,6 +141,7 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; @@ -206,6 +207,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C @Inject protected PrimaryDataStoreDao _storagePoolDao = null; @Inject + protected StoragePoolDetailsDao _storagePoolDetailsDao; + @Inject protected ImageStoreDao _imageStoreDao = null; @Inject protected ImageStoreDetailsDao _imageStoreDetailsDao = null; @@ -789,6 +792,19 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } if (tags != null) { + Map existingDetails = _storagePoolDetailsDao.getDetails(id); + Set existingKeys = existingDetails.keySet(); + + Map existingDetailsToKeep = new HashMap(); + + for (String existingKey : existingKeys) { + String existingValue = existingDetails.get(existingKey); + + if (!Boolean.TRUE.toString().equalsIgnoreCase(existingValue)) { + existingDetailsToKeep.put(existingKey, existingValue); + } + } + Map details = new HashMap(); for (String tag : tags) { tag = tag.trim(); @@ -797,6 +813,18 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } } + Set existingKeysToKeep = existingDetailsToKeep.keySet(); + + for (String existingKeyToKeep : existingKeysToKeep) { + String existingValueToKeep = existingDetailsToKeep.get(existingKeyToKeep); + + if (details.containsKey(existingKeyToKeep)) { + throw new CloudRuntimeException("Storage tag '" + existingKeyToKeep + "' conflicts with a stored property of this primary storage. No changes were made."); + } + + details.put(existingKeyToKeep, existingValueToKeep); + } + _storagePoolDao.updateDetails(id, details); }