|
34 | 34 | import org.apache.cloudstack.api.command.user.account.ListAccountsCmd; |
35 | 35 | import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd; |
36 | 36 | import org.apache.cloudstack.api.command.user.event.ListEventsCmd; |
| 37 | +import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd; |
37 | 38 | import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd; |
38 | 39 | import org.apache.cloudstack.api.command.user.project.ListProjectsCmd; |
39 | 40 | import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd; |
|
42 | 43 | import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; |
43 | 44 | import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; |
44 | 45 | import org.apache.cloudstack.api.response.AccountResponse; |
| 46 | +import org.apache.cloudstack.api.response.AsyncJobResponse; |
45 | 47 | import org.apache.cloudstack.api.response.DomainRouterResponse; |
46 | 48 | import org.apache.cloudstack.api.response.EventResponse; |
47 | 49 | import org.apache.cloudstack.api.response.HostResponse; |
|
62 | 64 | import com.cloud.api.ApiDBUtils; |
63 | 65 | import com.cloud.api.ApiResponseHelper; |
64 | 66 | import com.cloud.api.query.dao.AccountJoinDao; |
| 67 | +import com.cloud.api.query.dao.AsyncJobJoinDao; |
65 | 68 | import com.cloud.api.query.dao.DomainRouterJoinDao; |
66 | 69 | import com.cloud.api.query.dao.HostJoinDao; |
67 | 70 | import com.cloud.api.query.dao.InstanceGroupJoinDao; |
|
74 | 77 | import com.cloud.api.query.dao.UserVmJoinDao; |
75 | 78 | import com.cloud.api.query.dao.VolumeJoinDao; |
76 | 79 | import com.cloud.api.query.vo.AccountJoinVO; |
| 80 | +import com.cloud.api.query.vo.AsyncJobJoinVO; |
77 | 81 | import com.cloud.api.query.vo.DomainRouterJoinVO; |
78 | 82 | import com.cloud.api.query.vo.EventJoinVO; |
79 | 83 | import com.cloud.api.query.vo.HostJoinVO; |
|
87 | 91 | import com.cloud.api.query.vo.UserVmJoinVO; |
88 | 92 | import com.cloud.api.query.vo.VolumeJoinVO; |
89 | 93 | import com.cloud.async.AsyncJob; |
| 94 | +import com.cloud.async.AsyncJobVO; |
90 | 95 | import com.cloud.domain.Domain; |
91 | 96 | import com.cloud.domain.DomainVO; |
92 | 97 | import com.cloud.domain.dao.DomainDao; |
@@ -216,6 +221,9 @@ public class QueryManagerImpl implements QueryService, Manager { |
216 | 221 | @Inject |
217 | 222 | private AccountJoinDao _accountJoinDao; |
218 | 223 |
|
| 224 | + @Inject |
| 225 | + private AsyncJobJoinDao _jobJoinDao; |
| 226 | + |
219 | 227 | @Inject |
220 | 228 | private HighAvailabilityManager _haMgr; |
221 | 229 |
|
@@ -1727,10 +1735,86 @@ public Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccounts |
1727 | 1735 | } |
1728 | 1736 | } |
1729 | 1737 |
|
1730 | | - Pair<List<AccountJoinVO>, Integer> result = _accountJoinDao.searchAndCount(sc, searchFilter); |
1731 | | - return new Pair<List<AccountJoinVO>, Integer>(result.first(), result.second()); |
| 1738 | + return _accountJoinDao.searchAndCount(sc, searchFilter); |
| 1739 | + } |
| 1740 | + |
| 1741 | + @Override |
| 1742 | + public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd) { |
| 1743 | + Pair<List<AsyncJobJoinVO>, Integer> result = searchForAsyncJobsInternal(cmd); |
| 1744 | + ListResponse<AsyncJobResponse> response = new ListResponse<AsyncJobResponse>(); |
| 1745 | + List<AsyncJobResponse> jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray(new AsyncJobJoinVO[result.first().size()])); |
| 1746 | + response.setResponses(jobResponses, result.second()); |
| 1747 | + return response; |
1732 | 1748 | } |
1733 | 1749 |
|
1734 | 1750 |
|
| 1751 | + public Pair<List<AsyncJobJoinVO>, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) { |
| 1752 | + |
| 1753 | + Account caller = UserContext.current().getCaller(); |
| 1754 | + |
| 1755 | + List<Long> permittedAccounts = new ArrayList<Long>(); |
| 1756 | + |
| 1757 | + Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>( |
| 1758 | + cmd.getDomainId(), cmd.isRecursive(), null); |
| 1759 | + _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, domainIdRecursiveListProject, |
| 1760 | + cmd.listAll(), false); |
| 1761 | + Long domainId = domainIdRecursiveListProject.first(); |
| 1762 | + Boolean isRecursive = domainIdRecursiveListProject.second(); |
| 1763 | + ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); |
| 1764 | + |
| 1765 | + Filter searchFilter = new Filter(AsyncJobJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal()); |
| 1766 | + SearchBuilder<AsyncJobJoinVO> sb = _jobJoinDao.createSearchBuilder(); |
| 1767 | + sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN); |
| 1768 | + SearchBuilder<AccountVO> accountSearch = null; |
| 1769 | + boolean accountJoinIsDone = false; |
| 1770 | + if (permittedAccounts.isEmpty() && domainId != null) { |
| 1771 | + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); |
| 1772 | + sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE); |
| 1773 | + accountJoinIsDone = true; |
| 1774 | + } |
| 1775 | + |
| 1776 | + if (listProjectResourcesCriteria != null) { |
| 1777 | + |
| 1778 | + if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) { |
| 1779 | + sb.and("type", sb.entity().getAccountType(), SearchCriteria.Op.EQ); |
| 1780 | + } else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) { |
| 1781 | + sb.and("type", sb.entity().getAccountType(), SearchCriteria.Op.NEQ); |
| 1782 | + } |
| 1783 | + |
| 1784 | + if (!accountJoinIsDone) { |
| 1785 | + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); |
| 1786 | + sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE); |
| 1787 | + } |
| 1788 | + } |
| 1789 | + |
| 1790 | + Object keyword = cmd.getKeyword(); |
| 1791 | + Object startDate = cmd.getStartDate(); |
| 1792 | + |
| 1793 | + SearchCriteria<AsyncJobJoinVO> sc = sb.create(); |
| 1794 | + if (listProjectResourcesCriteria != null) { |
| 1795 | + sc.setParameters("type", Account.ACCOUNT_TYPE_PROJECT); |
| 1796 | + } |
| 1797 | + |
| 1798 | + if (!permittedAccounts.isEmpty()) { |
| 1799 | + sc.setParameters("accountIdIN", permittedAccounts.toArray()); |
| 1800 | + } else if (domainId != null) { |
| 1801 | + DomainVO domain = _domainDao.findById(domainId); |
| 1802 | + if (isRecursive) { |
| 1803 | + sc.setParameters("path", domain.getPath() + "%"); |
| 1804 | + } else { |
| 1805 | + sc.setParameters("domainId", domainId); |
| 1806 | + } |
| 1807 | + } |
| 1808 | + |
| 1809 | + if (keyword != null) { |
| 1810 | + sc.addAnd("cmd", SearchCriteria.Op.LIKE, "%" + keyword + "%"); |
| 1811 | + } |
| 1812 | + |
| 1813 | + if (startDate != null) { |
| 1814 | + sc.addAnd("created", SearchCriteria.Op.GTEQ, startDate); |
| 1815 | + } |
| 1816 | + |
| 1817 | + return _jobJoinDao.searchAndCount(sc, searchFilter); |
| 1818 | + } |
1735 | 1819 |
|
1736 | 1820 | } |
0 commit comments