Uploaded image for project: 'CloudStack'
  1. CloudStack
  2. CLOUDSTACK-7362

Resource tagging sometimes tags the wrong resource

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.4.1
    • None
    • API
    • Security Level: Public (Anyone can view this level - this is the default.)
    • None

    Description

      This problem occurs when the uuid of the resource you are about to tag begins with a number that actually corresponds to the id field of an entry in the same resource type table.

      Example:

      We want to tag security group with UUID 6cb95038-6b76-4905-bdf5-85bf0e0eda51 which has ID #5. But we also have a security group with ID #6 and UUID d582e52c-f3c1-4e12-8e86-9dad0a5bd725. What happens is the following:

      First it runs this method:

      long id = getResourceId(resourceId, resourceType);
      

      which actually tries to find the entity by its UUID and returns the resource id (numeric). This process goes off without a hitch.

      Next, it actually tries to find the UUID of the resource (because you can also send in the internal (numeric) identifier):

      String resourceUuid = getUuid(resourceId, resourceType)
      

      Now this is when the magic starts happening, this is what's happening inside the method:

      entity = _entityMgr.findById(clazz, resourceId);
              if (entity != null && entity instanceof Identity) {
                  return ((Identity)entity).getUuid();
             }
      

      Because our resourceId starts with a numeric 6 the findById method somehow returns the object that actually has the internal numeric identifier 6. Thus it ends up tagging the wrong object.

      This issue can be resolved by changing the getUUID() method to:

          @Override
          public String getUuid(String resourceId, ResourceObjectType resourceType) {
              Class<?> clazz = s_typeMap.get(resourceType);
      
              Object entity = _entityMgr.findByUuid(clazz, resourceId);
              if (entity != null) {
                  return ((Identity)entity).getUuid();
              }
      
              entity = _entityMgr.findById(clazz, resourceId);
              if (entity != null && entity instanceof Identity) {
                  return ((Identity)entity).getUuid();
              }
      
              return resourceId;
          }
      

      What i would like to know is if this is a known issue or not? I couldn't find a bug report here in Jira. If this is an unknown bug then i will go ahead and submit the patch.

      Attachments

        Activity

          People

            weizhou Wei Zhou
            thecodeassassin Stephen Hoogendijk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: