Skip to content

Commit 81482c9

Browse files
committed
add pagination for getAllArtifactStores
Signed-off-by: Harsh Modi <hmodi@redhat.com>
1 parent a44620b commit 81482c9

File tree

8 files changed

+79
-15
lines changed

8 files changed

+79
-15
lines changed

src/main/java/org/commonjava/indy/service/repository/controller/QueryController.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.commonjava.indy.service.repository.model.StoreType;
2929
import org.commonjava.indy.service.repository.model.dto.EndpointView;
3030
import org.commonjava.indy.service.repository.model.dto.EndpointViewListing;
31+
import org.commonjava.indy.service.repository.model.dto.ListArtifactStoreDTO;
3132
import org.commonjava.indy.service.repository.util.JaxRsUriFormatter;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
@@ -257,13 +258,14 @@ public Boolean isStoreDataEmpty()
257258
}
258259

259260
public EndpointViewListing getEndpointsListing( final String pkgType, final String baseUri,
260-
final JaxRsUriFormatter uriFormatter )
261+
final JaxRsUriFormatter uriFormatter, final String page )
261262
throws IndyWorkflowException
262263
{
263264
List<ArtifactStore> stores;
264265
try
265266
{
266-
stores = new ArrayList<>( storeManager.getAllArtifactStores() );
267+
ListArtifactStoreDTO result = storeManager.getAllArtifactStores(page);
268+
stores = new ArrayList<>( result.getItems() );
267269
if ( StringUtils.isNotBlank( pkgType ) && !"all".equals( pkgType ) && isValidPackageType( pkgType ) )
268270
{
269271
stores = stores.stream()
@@ -295,6 +297,13 @@ public EndpointViewListing getEndpointsListing( final String pkgType, final Stri
295297
return new EndpointViewListing( points );
296298
}
297299

300+
public EndpointViewListing getEndpointsListing( final String pkgType, final String baseUri,
301+
final JaxRsUriFormatter uriFormatter )
302+
throws IndyWorkflowException
303+
{
304+
return getEndpointsListing( pkgType, baseUri, uriFormatter, "" );
305+
}
306+
298307
public Map<String, List<String>> getStoreKeysByPackageType( final String pkgType )
299308
throws IndyWorkflowException
300309
{

src/main/java/org/commonjava/indy/service/repository/controller/StatsController.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.commonjava.indy.service.repository.model.StoreKey;
2323
import org.commonjava.indy.service.repository.model.dto.EndpointView;
2424
import org.commonjava.indy.service.repository.model.dto.EndpointViewListing;
25+
import org.commonjava.indy.service.repository.model.dto.ListArtifactStoreDTO;
2526
import org.commonjava.indy.service.repository.model.version.Versioning;
2627

2728
import jakarta.enterprise.context.ApplicationScoped;
@@ -57,13 +58,14 @@ public Versioning getVersionInfo()
5758
return versioning;
5859
}
5960

60-
public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter )
61-
throws IndyWorkflowException
61+
public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter, final String page )
62+
throws IndyWorkflowException
6263
{
6364
final List<ArtifactStore> stores;
6465
try
6566
{
66-
stores = new ArrayList<>( dataManager.getAllArtifactStores() );
67+
ListArtifactStoreDTO result = dataManager.getAllArtifactStores(page);
68+
stores = new ArrayList<>( result.getItems() );
6769
}
6870
catch ( final IndyDataException e )
6971
{
@@ -89,6 +91,12 @@ public EndpointViewListing getEndpointsListing( final String baseUri, final JaxR
8991
return new EndpointViewListing( points );
9092
}
9193

94+
public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter )
95+
throws IndyWorkflowException
96+
{
97+
return getEndpointsListing( baseUri, uriFormatter, "" );
98+
}
99+
92100
public Map<String, List<String>> getAllStoreKeys()
93101
throws IndyWorkflowException
94102
{

src/main/java/org/commonjava/indy/service/repository/data/StoreDataManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ Optional<ArtifactStore> getArtifactStore( StoreKey key )
8282
Set<ArtifactStore> getAllArtifactStores()
8383
throws IndyDataException;
8484

85+
/**
86+
* Return the full list of {@link ArtifactStore} instances of a given {@link StoreType} (hosted, remote, or group) available on the system.
87+
*/
88+
ListArtifactStoreDTO getAllArtifactStores(String page)
89+
throws IndyDataException;
90+
8591
/**
8692
* Return the {@link ArtifactStore} instances as a {@link Stream}.
8793
*/

src/main/java/org/commonjava/indy/service/repository/data/cassandra/CassandraStoreDataManager.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,19 @@ public void clear( ChangeSummary summary )
143143
// @WithSpan
144144
public Set<ArtifactStore> getAllArtifactStores()
145145
{
146-
Set<DtxArtifactStore> dtxArtifactStoreSet = storeQuery.getAllArtifactStores();
146+
ListArtifactStoreDTO result = getAllArtifactStores("");
147+
return result.getItems();
148+
}
149+
150+
@Override
151+
// @WithSpan
152+
public ListArtifactStoreDTO getAllArtifactStores(String page)
153+
{
154+
ListDtxArtifactStoreDTO result = storeQuery.getAllArtifactStores(page);
155+
Set<DtxArtifactStore> dtxArtifactStoreSet = result.getItems();
147156
Set<ArtifactStore> artifactStoreSet = new HashSet<>();
148157
dtxArtifactStoreSet.forEach( dtxArtifactStore -> artifactStoreSet.add( toArtifactStore( dtxArtifactStore ) ) );
149-
return artifactStoreSet;
158+
return new ListArtifactStoreDTO(artifactStoreSet, page, result.getNextPage());
150159
}
151160

152161
@Override

src/main/java/org/commonjava/indy/service/repository/data/cassandra/CassandraStoreQuery.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,40 @@ public Set<DtxArtifactStore> getArtifactStoresByPkgAndType( String packageType,
181181
return result.getItems();
182182
}
183183

184-
public Set<DtxArtifactStore> getAllArtifactStores()
184+
public ListDtxArtifactStoreDTO getAllArtifactStores( String page )
185185
{
186-
187186
BoundStatement bound = preparedArtifactStoresQuery.bind();
187+
188+
if (!page.isEmpty()) {
189+
PagingState currentPage = PagingState.fromString( page );
190+
bound.setPagingState( currentPage );
191+
}
192+
188193
ResultSet result = session.execute( bound );
189194

195+
PagingState nextPage = result.getExecutionInfo().getPagingState();
196+
int remaining = result.getAvailableWithoutFetching();
197+
198+
if (!page.isEmpty()) {
199+
remaining = Math.min( remaining, config.cassandraPageSize );
200+
}
201+
190202
Set<DtxArtifactStore> dtxArtifactStoreSet = new HashSet<>();
191-
result.forEach( row -> dtxArtifactStoreSet.add( toDtxArtifactStore( row ) ) );
203+
for (Row row: result)
204+
{
205+
dtxArtifactStoreSet.add( toDtxArtifactStore( row ) );
206+
if (--remaining == 0) {
207+
break;
208+
}
209+
}
210+
211+
return new ListDtxArtifactStoreDTO( dtxArtifactStoreSet, page, nextPage.toString() );
212+
}
192213

193-
return dtxArtifactStoreSet;
214+
public Set<DtxArtifactStore> getAllArtifactStores()
215+
{
216+
ListDtxArtifactStoreDTO result = getAllArtifactStores("");
217+
return result.getItems();
194218
}
195219

196220
public Boolean isEmpty()

src/main/java/org/commonjava/indy/service/repository/data/mem/MemoryStoreDataManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public Set<ArtifactStore> getAllArtifactStores()
121121
return new HashSet<>( stores.values() );
122122
}
123123

124+
@Override
125+
public ListArtifactStoreDTO getAllArtifactStores(String page)
126+
{
127+
return new ListArtifactStoreDTO(new HashSet<>( stores.values() ), page, "");
128+
}
129+
124130
@Override
125131
public Map<StoreKey, ArtifactStore> getArtifactStoresByKey()
126132
{

src/main/java/org/commonjava/indy/service/repository/jaxrs/RepositoryQueryResources.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,15 @@ public Response getStoreEmpty()
313313
@Path( "/endpoints/{packageType}" )
314314
@GET
315315
@Produces( APPLICATION_JSON )
316-
public Response getEndpoints( @PathParam( "packageType" ) final String pkgType, @Context final UriInfo uriInfo )
316+
public Response getEndpoints( @PathParam( "packageType" ) final String pkgType, @QueryParam( "page") String page,
317+
@Context final UriInfo uriInfo )
317318
{
318319
Response response;
319320
try
320321
{
321322
final String baseUri = uriInfo.getBaseUriBuilder().path( API_PREFIX ).build().toString();
322323

323-
final EndpointViewListing listing = queryController.getEndpointsListing( pkgType, baseUri, uriFormatter );
324+
final EndpointViewListing listing = queryController.getEndpointsListing( pkgType, baseUri, uriFormatter, page );
324325
response = responseHelper.formatOkResponseWithJsonEntity( listing );
325326

326327
logger.info( "\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing );

src/main/java/org/commonjava/indy/service/repository/jaxrs/version/StatsHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.commonjava.indy.service.repository.jaxrs.version;
1717

18+
import jakarta.ws.rs.QueryParam;
1819
import org.commonjava.indy.service.repository.controller.StatsController;
1920
import org.commonjava.indy.service.repository.exception.IndyWorkflowException;
2021
import org.commonjava.indy.service.repository.jaxrs.ResponseHelper;
@@ -114,14 +115,14 @@ public Response getPackageTypeNames()
114115
@Path( "/all-endpoints" )
115116
@GET
116117
@Produces( APPLICATION_JSON )
117-
public Response getAllEndpoints( @Context final UriInfo uriInfo )
118+
public Response getAllEndpoints( @QueryParam( "page") String page, @Context final UriInfo uriInfo )
118119
{
119120
Response response;
120121
try
121122
{
122123
final String baseUri = uriInfo.getBaseUriBuilder().path( Constants.API_PREFIX ).build().toString();
123124

124-
final EndpointViewListing listing = statsController.getEndpointsListing( baseUri, uriFormatter );
125+
final EndpointViewListing listing = statsController.getEndpointsListing( baseUri, uriFormatter, page );
125126
response = responseHelper.formatOkResponseWithJsonEntity( listing );
126127

127128
logger.info( "\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing );

0 commit comments

Comments
 (0)