Bug 11126 - Give ability to define tags post storage addition

Changes:
- Enabled updating storage tags
- All existing tags are wiped out and new ones provided are stored.
- Note that, if tags are updated on the storage, no changes are done to the deployment of already running VMs that were deployed prior to tag addition.
- Also added some validation to host tags update API.
This commit is contained in:
prachi 2011-11-23 14:12:53 -08:00
parent a3d221b842
commit f56c3d7bc5
4 changed files with 15 additions and 10 deletions

View File

@ -18,6 +18,8 @@
package com.cloud.api.commands; package com.cloud.api.commands;
import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants; import com.cloud.api.ApiConstants;
@ -44,8 +46,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the Id of the storage pool") @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the Id of the storage pool")
private Long id; private Long id;
@Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the storage pool") @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma-separated list of tags for the storage pool")
private String tags; private List<String> tags;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// /////////////////// Accessors ///////////////////////
@ -55,7 +58,7 @@ public class UpdateStoragePoolCmd extends BaseCmd {
return id; return id;
} }
public String getTags() { public List<String> getTags() {
return tags; return tags;
} }

View File

@ -213,7 +213,7 @@ listAsyncJobs=com.cloud.api.commands.ListAsyncJobsCmd;15
#### storage pools commands #### storage pools commands
listStoragePools=com.cloud.api.commands.ListStoragePoolsCmd;3 listStoragePools=com.cloud.api.commands.ListStoragePoolsCmd;3
createStoragePool=com.cloud.api.commands.CreateStoragePoolCmd;1 createStoragePool=com.cloud.api.commands.CreateStoragePoolCmd;1
#### updateStoragePool=com.cloud.api.commands.UpdateStoragePoolCmd;1 updateStoragePool=com.cloud.api.commands.UpdateStoragePoolCmd;1
deleteStoragePool=com.cloud.api.commands.DeletePoolCmd;1 deleteStoragePool=com.cloud.api.commands.DeletePoolCmd;1
listClusters=com.cloud.api.commands.ListClustersCmd;3 listClusters=com.cloud.api.commands.ListClustersCmd;3
enableStorageMaintenance=com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;1 enableStorageMaintenance=com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;1

View File

@ -63,8 +63,11 @@ public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements
expunge(sc); expunge(sc);
for (String tag : hostTags) { for (String tag : hostTags) {
HostTagVO vo = new HostTagVO(hostId, tag); tag.trim();
persist(vo); if(tag.length() > 0) {
HostTagVO vo = new HostTagVO(hostId, tag);
persist(vo);
}
} }
txn.commit(); txn.commit();
} }

View File

@ -1341,7 +1341,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
public StoragePoolVO updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException { public StoragePoolVO updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
// Input validation // Input validation
Long id = cmd.getId(); Long id = cmd.getId();
String tags = cmd.getTags(); List<String> tags = cmd.getTags();
StoragePoolVO pool = _storagePoolDao.findById(id); StoragePoolVO pool = _storagePoolDao.findById(id);
if (pool == null) { if (pool == null) {
@ -1349,9 +1349,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
} }
if (tags != null) { if (tags != null) {
Map<String, String> details = _storagePoolDao.getDetails(id); Map<String, String> details = new HashMap<String, String>();
String[] tagsList = tags.split(","); for (String tag : tags) {
for (String tag : tagsList) {
tag = tag.trim(); tag = tag.trim();
if (tag.length() > 0 && !details.containsKey(tag)) { if (tag.length() > 0 && !details.containsKey(tag)) {
details.put(tag, "true"); details.put(tag, "true");