Skip to content
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

Cherry-pick from main #133

Merged
merged 2 commits into from
Jan 11, 2024
Merged
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 @@ -28,7 +28,10 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static jakarta.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;

Expand Down Expand Up @@ -85,4 +88,24 @@ public EndpointViewListing getEndpointsListing( final String baseUri, final JaxR
return new EndpointViewListing( points );
}

public Map<String, List<String>> getAllStoreKeys()
throws IndyWorkflowException
{
final List<ArtifactStore> stores;
try
{
final Map<String, List<String>> result = new HashMap<>();
stores = new ArrayList<>( dataManager.getAllArtifactStores() );
List<String> items = stores.stream().map( s-> s.getKey().toString() ).collect( Collectors.toList() );
result.put("items", items);
return result;
}
catch ( final IndyDataException e )
{
throw new IndyWorkflowException( INTERNAL_SERVER_ERROR.getStatusCode(),
"Failed to retrieve all store keys: {}", e, e.getMessage() );
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -132,4 +135,33 @@ public Response getAllEndpoints( @Context final UriInfo uriInfo )
return response;
}

@Operation(
summary = "Retrieve a listing of the artifact stores keys available on the system." )
@APIResponse( responseCode = "200",
content = @Content( schema = @Schema( implementation = Map.class ) ),
description = "The artifact store keys listing" )
@Path( "/all-storekeys" )
@GET
@Produces( APPLICATION_JSON )
public Response getAllStoreKeys( @Context final UriInfo uriInfo )
{
Response response;
try
{

Map<String, List<String>> result = statsController.getAllStoreKeys();

response = responseHelper.formatOkResponseWithJsonEntity( result );

logger.debug( "\n\n\n\n\n\n{} Sent all-keys:\n\n{}\n\n\n\n\n\n\n", new Date(), result );
}
catch ( final IndyWorkflowException e )
{
logger.error( String.format( "Failed to retrieve store keys listing: %s", responseHelper.formatEntity( e ) ),
e );
response = responseHelper.formatResponse( e );
}
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ public void testGetAllEndpoints()
.body( "size()", is( 1 ) )
.body( "items.size()", greaterThan( 1 ) );
}

@Test
public void testGetAllStoreKeys()
{
given().get( "/api/stats/all-storekeys" )
.then()
.statusCode( OK.getStatusCode() )
.body( "size()", is( 1 ) )
.body( "items.size()", greaterThan( 1 ) );
}
}
Loading