[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-7309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14094205#comment-14094205
 ] 

Simon Godard commented on CLOUDSTACK-7309:
------------------------------------------

I faced the same issue yesterday when trying to listUsageRecords after a 
project was removed.

The bug is in the following code:
{code:title=ApiResponseHelper.java|borderStyle=solid}
        Account account = 
ApiDBUtils.findAccountById(usageRecord.getAccountId());
        if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
            //find the project
            Project project = 
ApiDBUtils.findProjectByProjectAccountId(account.getId());
            usageRecResponse.setProjectId(project.getUuid());
            usageRecResponse.setProjectName(project.getName());
        } else {
            usageRecResponse.setAccountId(account.getUuid());
            usageRecResponse.setAccountName(account.getAccountName());
        }
{code}

The Account lookup by ID is performed including the removed Accounts, but the 
Project lookup by ID doesn't included the removed Projects. There is an 
assumption that the project won't be null since the account isn't.

I will try to create a Pull request to fix this problem. This is a blocker 
issue for us since we rely on the Usage reporting.

> NPE when project was already deleted
> ------------------------------------
>
>                 Key: CLOUDSTACK-7309
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-7309
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: Usage
>    Affects Versions: 4.3.0, 4.4.0, 4.3.1
>            Reporter: Daniel Vega Simoes
>
> When listing usage records for running VMs and project to which this VM 
> belonged was removed, a Null Pointer Exception happens at the time of 
> building an usage response. Steps to reproduce the error:
> 1 - create a new project
> 2 - create a new VM under this project
> 3 - remove the project (which also removes the VM)
> 4 - collect usage data (usually happens overnight automatically)
> 5 - list usage records by issuing following command on Cloudmonkey (make sure 
> the date range comprises the project removal event)
>   list usagerecords startdate=2014-08-05 enddate=2014-08-08 type=1
> Bug happens at the ApiResponseHelper.java file. Whenever account type is 
> ACCOUNT_TYPE_PROJECT, it tries to retrieve the Project object, which returns 
> null when project was removed.



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

Reply via email to