Skip to content

Commit

Permalink
add pagination for getAllArtifactStores
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Modi <[email protected]>
  • Loading branch information
hjmodi committed Apr 5, 2024
1 parent a44620b commit 50074b1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.commonjava.indy.service.repository.model.StoreKey;
import org.commonjava.indy.service.repository.model.dto.EndpointView;
import org.commonjava.indy.service.repository.model.dto.EndpointViewListing;
import org.commonjava.indy.service.repository.model.dto.ListArtifactStoreDTO;
import org.commonjava.indy.service.repository.model.version.Versioning;

import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -57,13 +58,14 @@ public Versioning getVersionInfo()
return versioning;
}

public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter )
throws IndyWorkflowException
public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter, final String page )
throws IndyWorkflowException
{
final List<ArtifactStore> stores;
try
{
stores = new ArrayList<>( dataManager.getAllArtifactStores() );
ListArtifactStoreDTO result = dataManager.getAllArtifactStores(page);
stores = new ArrayList<>( result.getItems() );
}
catch ( final IndyDataException e )
{
Expand All @@ -89,6 +91,12 @@ public EndpointViewListing getEndpointsListing( final String baseUri, final JaxR
return new EndpointViewListing( points );
}

public EndpointViewListing getEndpointsListing( final String baseUri, final JaxRsUriFormatter uriFormatter )
throws IndyWorkflowException
{
return getEndpointsListing( baseUri, uriFormatter, "" );
}

public Map<String, List<String>> getAllStoreKeys()
throws IndyWorkflowException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ Optional<ArtifactStore> getArtifactStore( StoreKey key )
Set<ArtifactStore> getAllArtifactStores()
throws IndyDataException;

/**
* Return the full list of {@link ArtifactStore} instances of a given {@link StoreType} (hosted, remote, or group) available on the system.
*/
ListArtifactStoreDTO getAllArtifactStores(String page)
throws IndyDataException;

/**
* Return the {@link ArtifactStore} instances as a {@link Stream}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,19 @@ public void clear( ChangeSummary summary )
// @WithSpan
public Set<ArtifactStore> getAllArtifactStores()
{
Set<DtxArtifactStore> dtxArtifactStoreSet = storeQuery.getAllArtifactStores();
ListArtifactStoreDTO result = getAllArtifactStores("");
return result.getItems();
}

@Override
// @WithSpan
public ListArtifactStoreDTO getAllArtifactStores(String page)
{
ListDtxArtifactStoreDTO result = storeQuery.getAllArtifactStores(page);
Set<DtxArtifactStore> dtxArtifactStoreSet = result.getItems();
Set<ArtifactStore> artifactStoreSet = new HashSet<>();
dtxArtifactStoreSet.forEach( dtxArtifactStore -> artifactStoreSet.add( toArtifactStore( dtxArtifactStore ) ) );
return artifactStoreSet;
return new ListArtifactStoreDTO(artifactStoreSet, page, result.getNextPage());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,40 @@ public Set<DtxArtifactStore> getArtifactStoresByPkgAndType( String packageType,
return result.getItems();
}

public Set<DtxArtifactStore> getAllArtifactStores()
public ListDtxArtifactStoreDTO getAllArtifactStores( String page )
{

BoundStatement bound = preparedArtifactStoresQuery.bind();

if (!page.isEmpty()) {
PagingState currentPage = PagingState.fromString( page );
bound.setPagingState( currentPage );
}

ResultSet result = session.execute( bound );

PagingState nextPage = result.getExecutionInfo().getPagingState();
int remaining = result.getAvailableWithoutFetching();

if (!page.isEmpty()) {
remaining = Math.min( remaining, config.cassandraPageSize );
}

Set<DtxArtifactStore> dtxArtifactStoreSet = new HashSet<>();
result.forEach( row -> dtxArtifactStoreSet.add( toDtxArtifactStore( row ) ) );
for (Row row: result)
{
dtxArtifactStoreSet.add( toDtxArtifactStore( row ) );
if (--remaining == 0) {
break;
}
}

return new ListDtxArtifactStoreDTO( dtxArtifactStoreSet, page, nextPage.toString() );
}

return dtxArtifactStoreSet;
public Set<DtxArtifactStore> getAllArtifactStores()
{
ListDtxArtifactStoreDTO result = getAllArtifactStores("");
return result.getItems();
}

public Boolean isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public Set<ArtifactStore> getAllArtifactStores()
return new HashSet<>( stores.values() );
}

@Override
public ListArtifactStoreDTO getAllArtifactStores(String page)
{
return new ListArtifactStoreDTO(new HashSet<>( stores.values() ), page, "");
}

@Override
public Map<StoreKey, ArtifactStore> getArtifactStoresByKey()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.commonjava.indy.service.repository.jaxrs.version;

import jakarta.ws.rs.QueryParam;
import org.commonjava.indy.service.repository.controller.StatsController;
import org.commonjava.indy.service.repository.exception.IndyWorkflowException;
import org.commonjava.indy.service.repository.jaxrs.ResponseHelper;
Expand Down Expand Up @@ -114,14 +115,14 @@ public Response getPackageTypeNames()
@Path( "/all-endpoints" )
@GET
@Produces( APPLICATION_JSON )
public Response getAllEndpoints( @Context final UriInfo uriInfo )
public Response getAllEndpoints( @QueryParam( "page") String page, @Context final UriInfo uriInfo )
{
Response response;
try
{
final String baseUri = uriInfo.getBaseUriBuilder().path( Constants.API_PREFIX ).build().toString();

final EndpointViewListing listing = statsController.getEndpointsListing( baseUri, uriFormatter );
final EndpointViewListing listing = statsController.getEndpointsListing( baseUri, uriFormatter, page );
response = responseHelper.formatOkResponseWithJsonEntity( listing );

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

0 comments on commit 50074b1

Please sign in to comment.