From 66968738c08e383b9b574bf75e27fc8d6127c6a4 Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Tue, 12 Mar 2019 16:30:50 +0200 Subject: [PATCH] implemented getPage4 and getPage6 using getAll4 and getAll6, sorting and filtering --- src/lib/dhcpsrv/cql_host_data_source.cc | 48 +++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc index 7e5c974c7a..42e7b91662 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.cc +++ b/src/lib/dhcpsrv/cql_host_data_source.cc @@ -1985,19 +1985,47 @@ CqlHostDataSourceImpl::getAll6(const SubnetID& subnet_id) const { // paging at the API level. ConstHostCollection -CqlHostDataSourceImpl::getPage4(const SubnetID& /*subnet_id*/, - uint64_t /*lower_host_id*/, - const HostPageSize& /*page_size*/) const { - isc_throw(NotImplemented, - "reservation-get-page is not supported by Cassandra"); +CqlHostDataSourceImpl::getPage4(const SubnetID& subnet_id, + uint64_t lower_host_id, + const HostPageSize& page_size) const { + ConstHostCollection hosts = getAll4(subnet_id); + std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) { + return a->getHostId() > b->getHostId(); + }); + ConstHostCollection result; + size_t count = 0; + for (auto host : hosts) { + if (host->getHostId() > lower_host_id) { + result.push_back(host); + count++; + if (count == page_size.page_size_) { + break; + } + } + } + return (result); } ConstHostCollection -CqlHostDataSourceImpl::getPage6(const SubnetID& /*subnet_id*/, - uint64_t /*lower_host_id*/, - const HostPageSize& /*page_size*/) const { - isc_throw(NotImplemented, - "reservation-get-page is not supported by Cassandra"); +CqlHostDataSourceImpl::getPage6(const SubnetID& subnet_id, + uint64_t lower_host_id, + const HostPageSize& page_size) const { + ConstHostCollection hosts = getAll6(subnet_id); + std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) { + return a->getHostId() > b->getHostId(); + }); + ConstHostCollection result; + size_t count = 0; + for (auto host : hosts) { + if (host->getHostId() > lower_host_id) { + result.push_back(host); + count++; + if (count == page_size.page_size_) { + break; + } + } + } + return (result); } ConstHostCollection -- 2.47.2