DaanHoogland commented on a change in pull request #5866:
URL: https://github.com/apache/cloudstack/pull/5866#discussion_r794412183



##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -166,46 +168,27 @@ public boolean 
generateUsageRecords(GenerateUsageRecordsCmd cmd) {
         Long accountId = cmd.getAccountId();
         Long domainId = cmd.getDomainId();
         String accountName = cmd.getAccountName();
-        Account userAccount = null;
         Account caller = CallContext.current().getCallingAccount();
         Long usageType = cmd.getUsageType();
         Long projectId = cmd.getProjectId();
         String usageId = cmd.getUsageId();
+        boolean projectRequested = false;
 
         if (projectId != null) {
             if (accountId != null) {
                 throw new InvalidParameterValueException("Projectid and 
accountId can't be specified together");
             }
-            Project project = _projectMgr.getProject(projectId);
-            if (project == null) {
-                throw new InvalidParameterValueException("Unable to find 
project by id " + projectId);
-            }
-            accountId = project.getProjectAccountId();
-        }
-
-        //if accountId is not specified, use accountName and domainId
-        if ((accountId == null) && (accountName != null) && (domainId != 
null)) {
-            if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
-                Filter filter = new Filter(AccountVO.class, "id", 
Boolean.FALSE, null, null);
-                List<AccountVO> accounts = 
_accountDao.listAccounts(accountName, domainId, filter);
-                if (accounts.size() > 0) {
-                    userAccount = accounts.get(0);
-                }
-                if (userAccount != null) {
-                    accountId = userAccount.getId();
-                } else {
-                    throw new InvalidParameterValueException("Unable to find 
account " + accountName + " in domain " + domainId);
-                }
-            } else {
-                throw new PermissionDeniedException("Invalid Domain Id or 
Account");
-            }
+            accountId = GetAccountIdFromProject(projectId);

Review comment:
       ```suggestion
               accountId = getAccountIdFromProject(projectId);
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to