From d39408cd0cb86680d2113cb3e14899034cb02df9 Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Sat, 10 Aug 2013 17:43:15 -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 9f720d63d5a..df0832ab6ba 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -81,6 +81,7 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; 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.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; @@ -207,6 +208,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; @@ -778,6 +781,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(); @@ -786,6 +802,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); }