JoaoJandre commented on code in PR #11016:
URL: https://github.com/apache/cloudstack/pull/11016#discussion_r2182778119


##########
engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java:
##########
@@ -75,9 +92,64 @@ public int expungeByVmList(List<Long> vmIds, Long batchSize) 
{
             return 0;
         }
         SearchBuilder<ConsoleSessionVO> sb = createSearchBuilder();
-        sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN);
+        sb.and(VM_IDS, sb.entity().getInstanceId(), SearchCriteria.Op.IN);
         SearchCriteria<ConsoleSessionVO> sc = sb.create();
-        sc.setParameters("vmIds", vmIds.toArray());
+        sc.setParameters(VM_IDS, vmIds.toArray());
         return batchExpunge(sc, batchSize);
     }
+
+    @Override
+    public Pair<List<ConsoleSessionVO>, Integer> listConsoleSessions(Long id, 
List<Long> domainIds, Long accountId, Long userId, Long hostId,
+                                                                     Date 
startDate, Date endDate, Long instanceId,
+                                                                     String 
consoleEndpointCreatorAddress, String clientAddress,
+                                                                     boolean 
activeOnly, Long pageSizeVal, Long startIndex) {
+        Filter filter = new Filter(ConsoleSessionVO.class, CREATED, false, 
startIndex, pageSizeVal);
+        SearchCriteria<ConsoleSessionVO> searchCriteria = 
createListConsoleSessionsSearchCriteria(id, domainIds, accountId, userId, 
hostId,
+                startDate, endDate, instanceId, consoleEndpointCreatorAddress, 
clientAddress, activeOnly);
+
+        return searchAndCount(searchCriteria, filter, true);
+    }
+
+    private SearchCriteria<ConsoleSessionVO> 
createListConsoleSessionsSearchCriteria(Long id, List<Long> domainIds, Long 
accountId, Long userId, Long hostId,
+                                                                               
      Date startDate, Date endDate, Long instanceId,
+                                                                               
      String consoleEndpointCreatorAddress, String clientAddress,
+                                                                               
      boolean activeOnly) {
+        SearchCriteria<ConsoleSessionVO> searchCriteria = 
createListConsoleSessionsSearchBuilder(activeOnly).create();
+
+        searchCriteria.setParametersIfNotNull(ID, id);
+        searchCriteria.setParametersIfNotNull(DOMAIN_IDS, domainIds.toArray());
+        searchCriteria.setParametersIfNotNull(ACCOUNT_ID, accountId);
+        searchCriteria.setParametersIfNotNull(USER_ID, userId);
+        searchCriteria.setParametersIfNotNull(HOST_ID, hostId);
+        searchCriteria.setParametersIfNotNull(INSTANCE_ID, instanceId);
+        searchCriteria.setParametersIfNotNull(START_DATE, startDate);
+        searchCriteria.setParametersIfNotNull(END_DATE, endDate);
+        searchCriteria.setParametersIfNotNull(CREATOR_ADDRESS, 
consoleEndpointCreatorAddress);
+        searchCriteria.setParametersIfNotNull(CLIENT_ADDRESS, clientAddress);
+
+        return searchCriteria;
+    }
+
+    private SearchBuilder<ConsoleSessionVO> 
createListConsoleSessionsSearchBuilder(boolean activeOnly) {
+        SearchBuilder<ConsoleSessionVO> searchBuilder = createSearchBuilder();
+
+        searchBuilder.and(ID, searchBuilder.entity().getId(), 
SearchCriteria.Op.EQ);
+        searchBuilder.and(DOMAIN_IDS, searchBuilder.entity().getDomainId(), 
SearchCriteria.Op.IN);
+        searchBuilder.and(ACCOUNT_ID, searchBuilder.entity().getAccountId(), 
SearchCriteria.Op.EQ);
+        searchBuilder.and(USER_ID, searchBuilder.entity().getUserId(), 
SearchCriteria.Op.EQ);
+        searchBuilder.and(HOST_ID, searchBuilder.entity().getHostId(), 
SearchCriteria.Op.EQ);
+        searchBuilder.and(INSTANCE_ID, searchBuilder.entity().getInstanceId(), 
SearchCriteria.Op.EQ);
+        searchBuilder.and(START_DATE, searchBuilder.entity().getAcquired(), 
SearchCriteria.Op.GTEQ);
+        searchBuilder.and(END_DATE, searchBuilder.entity().getAcquired(), 
SearchCriteria.Op.LTEQ);

Review Comment:
   I was testing this and found that when listing using the start and end date, 
sessions which were never acquired were not being listed. I believe that it 
would be more interesting to search using the created date and not the acquired 
date. 
   Maybe we could add a parameter to filter for acquired sessions specifically.



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to