From f56c3d7bc5d40aed37c9979c267c235efdfbf65f Mon Sep 17 00:00:00 2001 From: prachi Date: Wed, 23 Nov 2011 14:12:53 -0800 Subject: [PATCH] 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. --- api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java | 9 ++++++--- client/tomcatconf/commands.properties.in | 2 +- server/src/com/cloud/host/dao/HostTagsDaoImpl.java | 7 +++++-- server/src/com/cloud/storage/StorageManagerImpl.java | 7 +++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java b/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java index 00b0730eb8a..8db855aab80 100644 --- a/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java +++ b/api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands; +import java.util.List; + import org.apache.log4j.Logger; 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") private Long id; - @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the storage pool") - private String tags; + @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma-separated list of tags for the storage pool") + private List tags; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -55,7 +58,7 @@ public class UpdateStoragePoolCmd extends BaseCmd { return id; } - public String getTags() { + public List getTags() { return tags; } diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index ba8b099e52c..8f5341313a0 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -213,7 +213,7 @@ listAsyncJobs=com.cloud.api.commands.ListAsyncJobsCmd;15 #### storage pools commands listStoragePools=com.cloud.api.commands.ListStoragePoolsCmd;3 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 listClusters=com.cloud.api.commands.ListClustersCmd;3 enableStorageMaintenance=com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;1 diff --git a/server/src/com/cloud/host/dao/HostTagsDaoImpl.java b/server/src/com/cloud/host/dao/HostTagsDaoImpl.java index bc0eaceb40f..e620dc62470 100644 --- a/server/src/com/cloud/host/dao/HostTagsDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostTagsDaoImpl.java @@ -63,8 +63,11 @@ public class HostTagsDaoImpl extends GenericDaoBase implements expunge(sc); for (String tag : hostTags) { - HostTagVO vo = new HostTagVO(hostId, tag); - persist(vo); + tag.trim(); + if(tag.length() > 0) { + HostTagVO vo = new HostTagVO(hostId, tag); + persist(vo); + } } txn.commit(); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 860ecad7f8d..449e87278bb 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -1341,7 +1341,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag public StoragePoolVO updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException { // Input validation Long id = cmd.getId(); - String tags = cmd.getTags(); + List tags = cmd.getTags(); StoragePoolVO pool = _storagePoolDao.findById(id); if (pool == null) { @@ -1349,9 +1349,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } if (tags != null) { - Map details = _storagePoolDao.getDetails(id); - String[] tagsList = tags.split(","); - for (String tag : tagsList) { + Map details = new HashMap(); + for (String tag : tags) { tag = tag.trim(); if (tag.length() > 0 && !details.containsKey(tag)) { details.put(tag, "true");