Skip to content

API: Fix pagination issue with listing LDAP configuration #11444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 4.20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public String getLastnameAttribute(final Long domainId) {

public String getProviderUrl(final Long domainId) {
final String protocol = getSSLStatus(domainId) == true ? "ldaps://" : "ldap://";
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(null, 0, domainId);
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(null, 0, domainId, null, null);
final StringBuilder providerUrls = new StringBuilder();
String delim = "";
for (final LdapConfigurationVO resource : result.first()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(fin
final int port = cmd.getPort();
final Long domainId = cmd.getDomainId();
final boolean listAll = cmd.listAll();
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll, cmd.getStartIndex(), cmd.getPageSizeVal());
return new Pair<List<? extends LdapConfigurationVO>, Integer>(result.first(), result.second());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface LdapConfigurationDao extends GenericDao<LdapConfigurationVO, Lo

LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll);

Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId);
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, Long offset, Long limit);

Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll);
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll, Long offset, Long limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;


import com.cloud.utils.db.Filter;
import org.springframework.stereotype.Component;

import org.apache.cloudstack.ldap.LdapConfigurationVO;
Expand Down Expand Up @@ -63,29 +64,29 @@ public LdapConfigurationVO findByHostname(final String hostname) {

@Override
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false, null, null);
return findOneBy(sc);
}

@Override
public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll, null, null);
return findOneBy(sc);
}

@Override
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
return searchAndCount(sc, null);
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, Long offset, Long limit) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false, offset, limit);
return searchAndCount(sc, new Filter(LdapConfigurationVO.class, "id", true, offset, limit));
}

@Override
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
return searchAndCount(sc, null);
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll, Long offset, Long limit) {
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll, offset, limit);
return searchAndCount(sc, new Filter(LdapConfigurationVO.class, "id", true, offset, limit));
}

private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) {
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll, Long offset, Long limit) {
SearchCriteria<LdapConfigurationVO> sc;
if (domainId != null) {
// If domainid is present, ignore listall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void setup() throws Exception {
lenient().when(userManagerFactory.getInstance(LdapUserManager.Provider.OPENLDAP)).thenReturn(new OpenLdapUserManagerImpl(configuration));
// construct an elaborate structure around a single object
Pair<List<LdapConfigurationVO>, Integer> vos = new Pair<List<LdapConfigurationVO>, Integer>( Collections.singletonList(configurationVO),1);
lenient().when(configurationDao.searchConfigurations(null, 0, 1L)).thenReturn(vos);
lenient().when(configurationDao.searchConfigurations(null, 0, 1L, 1L, 20L)).thenReturn(vos);

contextFactory = new LdapContextFactory(configuration);
ldapManager = new LdapManagerImpl(configurationDao, contextFactory, userManagerFactory, configuration);
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/view/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
:loading="loading"
:columns="isOrderUpdatable() ? columns : columns.filter(x => x.dataIndex !== 'order')"
:dataSource="items"
:rowKey="(record, idx) => record.id || record.name || record.usageType || idx + '-' + Math.random()"
:rowKey="(record, idx) => hasNoUniqueKey() ? (idx + '-' + Math.random()) : (record.id || record.name || record.usageType || idx + '-' + Math.random())"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about making the key/id be the concatenation of hostnam+”-“+port+”-“+domainid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point @DaanHoogland

also, can we create a method for this ? @Pearl1594

:pagination="false"
:rowSelection="explicitlyAllowRowSelection || enableGroupAction() || $route.name === 'event' ? {selectedRowKeys: selectedRowKeys, onChange: onSelectChange, columnWidth: 30} : null"
:rowClassName="getRowClassName"
Expand Down Expand Up @@ -742,6 +742,9 @@ export default {
'webhook', 'webhookdeliveries', 'sharedfs', 'ipv4subnets', 'asnumbers'
].includes(this.$route.name)
},
hasNoUniqueKey () {
return ['/ldapsetting'].some(prefix => this.$route.path.startsWith(prefix))
},
getDateAtTimeZone (date, timezone) {
return date ? moment(date).tz(timezone).format('YYYY-MM-DD HH:mm:ss') : null
},
Expand Down
Loading