Skip to content

Commit f56c3d7

Browse files
author
prachi
committed
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.
1 parent a3d221b commit f56c3d7

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

api/src/com/cloud/api/commands/UpdateStoragePoolCmd.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package com.cloud.api.commands;
2020

21+
import java.util.List;
22+
2123
import org.apache.log4j.Logger;
2224

2325
import com.cloud.api.ApiConstants;
@@ -44,8 +46,9 @@ public class UpdateStoragePoolCmd extends BaseCmd {
4446
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the Id of the storage pool")
4547
private Long id;
4648

47-
@Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the storage pool")
48-
private String tags;
49+
@Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma-separated list of tags for the storage pool")
50+
private List<String> tags;
51+
4952

5053
/////////////////////////////////////////////////////
5154
/////////////////// Accessors ///////////////////////
@@ -55,7 +58,7 @@ public Long getId() {
5558
return id;
5659
}
5760

58-
public String getTags() {
61+
public List<String> getTags() {
5962
return tags;
6063
}
6164

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ listAsyncJobs=com.cloud.api.commands.ListAsyncJobsCmd;15
213213
#### storage pools commands
214214
listStoragePools=com.cloud.api.commands.ListStoragePoolsCmd;3
215215
createStoragePool=com.cloud.api.commands.CreateStoragePoolCmd;1
216-
#### updateStoragePool=com.cloud.api.commands.UpdateStoragePoolCmd;1
216+
updateStoragePool=com.cloud.api.commands.UpdateStoragePoolCmd;1
217217
deleteStoragePool=com.cloud.api.commands.DeletePoolCmd;1
218218
listClusters=com.cloud.api.commands.ListClustersCmd;3
219219
enableStorageMaintenance=com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;1

server/src/com/cloud/host/dao/HostTagsDaoImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ public void persist(long hostId, List<String> hostTags) {
6363
expunge(sc);
6464

6565
for (String tag : hostTags) {
66-
HostTagVO vo = new HostTagVO(hostId, tag);
67-
persist(vo);
66+
tag.trim();
67+
if(tag.length() > 0) {
68+
HostTagVO vo = new HostTagVO(hostId, tag);
69+
persist(vo);
70+
}
6871
}
6972
txn.commit();
7073
}

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,17 +1341,16 @@ public StoragePoolVO createPool(CreateStoragePoolCmd cmd) throws ResourceInUseEx
13411341
public StoragePoolVO updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
13421342
// Input validation
13431343
Long id = cmd.getId();
1344-
String tags = cmd.getTags();
1344+
List<String> tags = cmd.getTags();
13451345

13461346
StoragePoolVO pool = _storagePoolDao.findById(id);
13471347
if (pool == null) {
13481348
throw new IllegalArgumentException("Unable to find storage pool with ID: " + id);
13491349
}
13501350

13511351
if (tags != null) {
1352-
Map<String, String> details = _storagePoolDao.getDetails(id);
1353-
String[] tagsList = tags.split(",");
1354-
for (String tag : tagsList) {
1352+
Map<String, String> details = new HashMap<String, String>();
1353+
for (String tag : tags) {
13551354
tag = tag.trim();
13561355
if (tag.length() > 0 && !details.containsKey(tag)) {
13571356
details.put(tag, "true");

0 commit comments

Comments
 (0)