Skip to content

Commit 2969780

Browse files
Subhash Yedugundlasubhash_y
authored andcommitted
BUG-ID: CLOUDSTACK-8922: Unable to delete IP tag
1 parent c9e14c9 commit 2969780

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

server/src/com/cloud/tags/TaggedResourceManagerImpl.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,46 @@ public String getUuid(String resourceId, ResourceObjectType resourceType) {
297297
@ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = "deleting resource tags")
298298
public boolean deleteTags(List<String> resourceIds, ResourceObjectType resourceType, Map<String, String> tags) {
299299
Account caller = CallContext.current().getCallingAccount();
300+
List<String> uuids = new ArrayList<String>();
301+
List<String> internalIds = new ArrayList<String>();
302+
for(String resourceId : resourceIds){
303+
if(resourceId.matches("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")){
304+
uuids.add(resourceId);
305+
}else{
306+
Long internalId = null;
307+
try {
308+
internalId = Long.parseLong(resourceId);
309+
} catch (final NumberFormatException e) {
310+
internalId = null;
311+
}
312+
if (internalId != null) {
313+
internalIds.add(resourceId);
314+
}else{
315+
throw new InvalidParameterValueException("Invalid resourceId");
316+
}
317+
}
318+
}
300319

301320
SearchBuilder<ResourceTagVO> sb = _resourceTagDao.createSearchBuilder();
302-
sb.and().op("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN);
303-
sb.or("resourceUuid", sb.entity().getResourceUuid(), SearchCriteria.Op.IN);
304-
sb.cp();
321+
322+
if(!uuids.isEmpty() && !internalIds.isEmpty()){
323+
throw new InvalidParameterValueException("Expecting only uuids or Ids");
324+
}else if (!uuids.isEmpty()){
325+
sb.and("resourceUuid", sb.entity().getResourceUuid(), SearchCriteria.Op.IN);
326+
}else if (!internalIds.isEmpty()){
327+
sb.and("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN);
328+
}
329+
305330
sb.and("resourceType", sb.entity().getResourceType(), SearchCriteria.Op.EQ);
306331

307332
SearchCriteria<ResourceTagVO> sc = sb.create();
308-
sc.setParameters("resourceId", resourceIds.toArray());
309-
sc.setParameters("resourceUuid", resourceIds.toArray());
333+
334+
if (!uuids.isEmpty()){
335+
sc.setParameters("resourceUuid", resourceIds.toArray());
336+
}else if (!internalIds.isEmpty()){
337+
sc.setParameters("resourceId", resourceIds.toArray());
338+
}
339+
310340
sc.setParameters("resourceType", resourceType);
311341

312342
List<? extends ResourceTag> resourceTags = _resourceTagDao.search(sc, null);

0 commit comments

Comments
 (0)