Skip to content

Commit 6d34e43

Browse files
add acquired param
1 parent 005b6ba commit 6d34e43

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/ListConsoleSessionsCmd.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public class ListConsoleSessionsCmd extends BaseListCmd {
8989
description = "Lists only active console sessions, defaults to true. Active sessions are the ones that have been acquired and have not been removed.")
9090
private boolean activeOnly = true;
9191

92+
@Parameter(name = ApiConstants.ACQUIRED, type = CommandType.BOOLEAN,
93+
description = "Lists acquired console sessions, defaults to false. Acquired console sessions are the ones that have been accessed. " +
94+
"The 'activeonly' parameter has precedence over the 'acquired' parameter, i.e., when the 'activeonly' parameter is 'true', the 'acquired' parameter value will be ignored.")
95+
private boolean acquired = false;
96+
9297
@Parameter(name = ApiConstants.IS_RECURSIVE, type = CommandType.BOOLEAN,
9398
description = "Lists console sessions recursively per domain. If an account ID is informed, only the account's console sessions will be listed. Defaults to false.")
9499
private boolean recursive = false;
@@ -137,6 +142,10 @@ public boolean isActiveOnly() {
137142
return activeOnly;
138143
}
139144

145+
public boolean getAcquired() {
146+
return acquired;
147+
}
148+
140149
public boolean isRecursive() {
141150
return recursive;
142151
}

engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ public interface ConsoleSessionDao extends GenericDao<ConsoleSessionVO, Long> {
4141
Pair<List<ConsoleSessionVO>, Integer> listConsoleSessions(Long id, List<Long> domainIds, Long accountId, Long userId, Long hostId,
4242
Date startDate, Date endDate, Long instanceId,
4343
String consoleEndpointCreatorAddress, String clientAddress,
44-
boolean activeOnly, Long pageSizeVal, Long startIndex);
44+
boolean activeOnly, boolean acquired, Long pageSizeVal, Long startIndex);
4545
}

engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ public int expungeByVmList(List<Long> vmIds, Long batchSize) {
102102
public Pair<List<ConsoleSessionVO>, Integer> listConsoleSessions(Long id, List<Long> domainIds, Long accountId, Long userId, Long hostId,
103103
Date startDate, Date endDate, Long instanceId,
104104
String consoleEndpointCreatorAddress, String clientAddress,
105-
boolean activeOnly, Long pageSizeVal, Long startIndex) {
105+
boolean activeOnly, boolean acquired, Long pageSizeVal, Long startIndex) {
106106
Filter filter = new Filter(ConsoleSessionVO.class, CREATED, false, startIndex, pageSizeVal);
107107
SearchCriteria<ConsoleSessionVO> searchCriteria = createListConsoleSessionsSearchCriteria(id, domainIds, accountId, userId, hostId,
108-
startDate, endDate, instanceId, consoleEndpointCreatorAddress, clientAddress, activeOnly);
108+
startDate, endDate, instanceId, consoleEndpointCreatorAddress, clientAddress, activeOnly, acquired);
109109

110110
return searchAndCount(searchCriteria, filter, true);
111111
}
112112

113113
private SearchCriteria<ConsoleSessionVO> createListConsoleSessionsSearchCriteria(Long id, List<Long> domainIds, Long accountId, Long userId, Long hostId,
114114
Date startDate, Date endDate, Long instanceId,
115115
String consoleEndpointCreatorAddress, String clientAddress,
116-
boolean activeOnly) {
117-
SearchCriteria<ConsoleSessionVO> searchCriteria = createListConsoleSessionsSearchBuilder(activeOnly).create();
116+
boolean activeOnly, boolean acquired) {
117+
SearchCriteria<ConsoleSessionVO> searchCriteria = createListConsoleSessionsSearchBuilder(activeOnly, acquired).create();
118118

119119
searchCriteria.setParametersIfNotNull(ID, id);
120120
searchCriteria.setParametersIfNotNull(DOMAIN_IDS, domainIds.toArray());
@@ -130,7 +130,7 @@ private SearchCriteria<ConsoleSessionVO> createListConsoleSessionsSearchCriteria
130130
return searchCriteria;
131131
}
132132

133-
private SearchBuilder<ConsoleSessionVO> createListConsoleSessionsSearchBuilder(boolean activeOnly) {
133+
private SearchBuilder<ConsoleSessionVO> createListConsoleSessionsSearchBuilder(boolean activeOnly, boolean acquired) {
134134
SearchBuilder<ConsoleSessionVO> searchBuilder = createSearchBuilder();
135135

136136
searchBuilder.and(ID, searchBuilder.entity().getId(), SearchCriteria.Op.EQ);
@@ -147,6 +147,8 @@ private SearchBuilder<ConsoleSessionVO> createListConsoleSessionsSearchBuilder(b
147147
if (activeOnly) {
148148
searchBuilder.and(ACQUIRED, searchBuilder.entity().getAcquired(), SearchCriteria.Op.NNULL);
149149
searchBuilder.and(REMOVED, searchBuilder.entity().getRemoved(), SearchCriteria.Op.NULL);
150+
} else if (acquired) {
151+
searchBuilder.and(ACQUIRED, searchBuilder.entity().getAcquired(), SearchCriteria.Op.NNULL);
150152
}
151153

152154
searchBuilder.done();

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected Pair<List<ConsoleSessionVO>, Integer> listConsoleSessionsInternal(List
233233
return consoleSessionDao.listConsoleSessions(cmd.getId(), domainIds, accountId, userId,
234234
cmd.getHostId(), cmd.getStartDate(), cmd.getEndDate(), cmd.getInstanceId(),
235235
cmd.getConsoleEndpointCreatorAddress(), cmd.getClientAddress(), cmd.isActiveOnly(),
236-
cmd.getPageSizeVal(), cmd.getStartIndex());
236+
cmd.getAcquired(), cmd.getPageSizeVal(), cmd.getStartIndex());
237237
}
238238

239239
/**

server/src/test/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImplTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void listConsoleSessionsInternalTestNormalUsersShouldOnlyBeAllowedToListT
158158
Mockito.verify(consoleSessionDaoMock).listConsoleSessions(
159159
Mockito.any(), Mockito.eq(List.of(callerDomainId)), Mockito.eq(callerAccountId),
160160
Mockito.eq(callerUserId), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
161-
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
161+
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
162162
);
163163
}
164164

@@ -185,7 +185,7 @@ public void listConsoleSessionsInternalTestAdminsShouldBeAllowedToRetrieveOtherA
185185
Mockito.verify(consoleSessionDaoMock).listConsoleSessions(
186186
Mockito.any(), Mockito.eq(List.of(callerDomainId)), Mockito.eq(callerAccountId),
187187
Mockito.eq(callerUserId), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
188-
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
188+
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
189189
);
190190
}
191191

@@ -213,7 +213,7 @@ public void listConsoleSessionsInternalTestShouldNotFetchConsoleSessionsRecursiv
213213
Mockito.verify(consoleSessionDaoMock).listConsoleSessions(
214214
Mockito.any(), Mockito.eq(List.of(callerDomainId)), Mockito.eq(callerAccountId),
215215
Mockito.eq(callerUserId), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
216-
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
216+
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
217217
);
218218
}
219219

@@ -242,7 +242,7 @@ public void listConsoleSessionsInternalTestShouldFetchConsoleSessionsRecursively
242242
Mockito.verify(consoleSessionDaoMock).listConsoleSessions(
243243
Mockito.any(), Mockito.eq(domainIdsCallerHasAccessTo), Mockito.eq(callerAccountId),
244244
Mockito.eq(callerUserId), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
245-
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
245+
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(), Mockito.any()
246246
);
247247
}
248248

0 commit comments

Comments
 (0)