cloudstack-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Hoogendijk (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CLOUDSTACK-7362) Resource tagging sometimes tags the wrong resource
Date Mon, 18 Aug 2014 09:53:18 GMT

     [ https://issues.apache.org/jira/browse/CLOUDSTACK-7362?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Stephen Hoogendijk updated CLOUDSTACK-7362:
-------------------------------------------

    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):

{code:java}
String resourceUuid = getUuid(resourceId, resourceType)
{code}

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:

{code:java}
    @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;
    }
{code}

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.


  was:
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.



> Resource tagging sometimes tags the wrong resource
> --------------------------------------------------
>
>                 Key: CLOUDSTACK-7362
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-7362
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the default.) 
>          Components: API
>    Affects Versions: 4.4.1
>            Reporter: Stephen Hoogendijk
>
> 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):
> {code:java}
> String resourceUuid = getUuid(resourceId, resourceType)
> {code}
> 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:
> {code:java}
>     @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;
>     }
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message