use of org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO in project indy by Commonjava.
the class NFCGetMissingAndPaginationTest method run.
@Test
public void run() throws Exception {
// Get NFC cache size
// NotFoundCacheInfoDTO info = client.module( IndyNfcClientModule.class ).getInfo( hosted.getKey() );
// assertEquals( info.getSize(), 15 );
NotFoundCacheInfoDTO info = client.module(IndyNfcClientModule.class).getInfo(remote.getKey());
assertEquals(info.getSize(), 15);
info = client.module(IndyNfcClientModule.class).getInfo(group.getKey());
assertEquals(info.getSize(), 15);
// Get NFC for hosted
// NotFoundCacheDTO dto = client.module( IndyNfcClientModule.class )
// .getAllNfcContentInStore( StoreType.hosted, hosted.getName() );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// Get NFC for remote
NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName());
assertThat(dto, notNullValue());
assertThat_DtoContainsPathsForRepository(dto, paths, remote);
// Get NFC for all
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// assertThat_DtoContainsPathsForRepository( dto, paths, remote );
// Pagination - pageIndex starts from 0!
int pageSize = 10;
List<String> pageOne = getPathsInPage(paths, 0, pageSize);
List<String> pageTwo = getPathsInPage(paths, 1, pageSize);
// Get NFC for page one
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName(), 0, pageSize);
assertThat_DtoContainsPathsForRepository(dto, pageOne, remote);
// Get NFC for page two
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName(), 1, pageSize);
assertThat_DtoContainsPathsForRepository(dto, pageTwo, remote);
// Get NFC for all with paging
// pageSize = 10;
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( 0, pageSize );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, hosted );
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( 1, pageSize );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, pageTwo, remote );
// Clear NFC for hosted
// client.module( IndyNfcClientModule.class ).clearInStore( StoreType.hosted, hosted.getName(), null );
// dto = client.module( IndyNfcClientModule.class ).getAllNfcContent( );
// assertThat( dto, notNullValue() );
// assertThat_DtoContainsPathsForRepository( dto, paths, remote );
// assertThat_DtoContainsNoneForRepository( dto, hosted );
// Clear NFC for remote
client.module(IndyNfcClientModule.class).clearInStore(StoreType.remote, remote.getName(), null);
dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.remote, remote.getName());
assertThat(dto, notNullValue());
assertThat_DtoContainsNoneForRepository(dto, remote);
// assertThat_DtoContainsNoneForRepository( dto, hosted );
// Get NFC cache size and should be 0
// info = client.module( IndyNfcClientModule.class ).getInfo( hosted.getKey() );
// assertEquals( info.getSize(), 0 );
info = client.module(IndyNfcClientModule.class).getInfo(remote.getKey());
assertEquals(info.getSize(), 0);
info = client.module(IndyNfcClientModule.class).getInfo(group.getKey());
assertEquals(info.getSize(), 0);
testExpiration();
client.module(IndyNfcClientModule.class).clearAll();
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO in project indy by Commonjava.
the class NfcResource method getStoreInfo.
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}/info")
@ApiOperation("Get not-found cache information, e.g., size, etc")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheInfoDTO.class, message = "The info of not-found cache") })
@GET
@Produces(ApplicationContent.application_json)
public Response getStoreInfo(@ApiParam(name = "packageType", required = true, value = "type of package (eg. maven, npm, generic-http)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "name of the store") @PathParam("name") final String name) {
Response response;
final StoreType type = StoreType.get(t);
final StoreKey key = new StoreKey(packageType, type, name);
try {
NotFoundCacheInfoDTO dto = controller.getInfo(key);
response = responseHelper.formatOkResponseWithJsonEntity(dto);
} catch (final IndyWorkflowException e) {
response = responseHelper.formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO in project indy by Commonjava.
the class NfcController method getInfo.
public NotFoundCacheInfoDTO getInfo() {
NotFoundCacheInfoDTO dto = new NotFoundCacheInfoDTO();
dto.setSize(((AbstractNotFoundCache) cache).getSize());
return dto;
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO in project indy by Commonjava.
the class NfcController method getInfo.
public NotFoundCacheInfoDTO getInfo(StoreKey key) throws IndyWorkflowException {
NotFoundCacheInfoDTO dto = new NotFoundCacheInfoDTO();
final AtomicLong size = new AtomicLong(0);
try {
switch(key.getType()) {
case group:
{
// Warn: This is very expensive if group holds thousands of repositories
final List<StoreKey> stores = storeManager.query().getOrderedConcreteStoresInGroup(key.getPackageType(), key.getName()).stream().map(artifactStore -> artifactStore.getKey()).collect(Collectors.toList());
if (stores.size() >= MAX_GROUP_MEMBER_SIZE_FOR_GET_MISSING) {
throw new IndyWorkflowException(SC_UNPROCESSABLE_ENTITY, "Get missing info for group failed (too many members), size: " + stores.size());
}
for (final StoreKey storeKey : stores) {
size.addAndGet(((AbstractNotFoundCache) cache).getSize(storeKey));
}
break;
}
default:
{
size.addAndGet(((AbstractNotFoundCache) cache).getSize(key));
break;
}
}
dto.setSize(size.get());
return dto;
} catch (final IndyDataException e) {
throw new IndyWorkflowException("Failed to get info for ArtifactStore: %s.", e, key);
}
}
use of org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO in project indy by Commonjava.
the class NFCGetMissingAndPaginationTest method testExpiration.
private void testExpiration() throws Exception {
RemoteRepository r = new RemoteRepository(MAVEN_PKG_KEY, "remote_exp", server.formatUrl("remote_exp"));
r.setNfcTimeoutSeconds(3);
r = client.stores().create(r, "create", RemoteRepository.class);
// Populate NFC data
for (String path : paths) {
try (InputStream inputStream = client.content().get(r.getKey(), path)) {
}
}
NotFoundCacheInfoDTO info = client.module(IndyNfcClientModule.class).getInfo(r.getKey());
assertEquals(info.getSize(), 15);
sleep(3000);
info = client.module(IndyNfcClientModule.class).getInfo(r.getKey());
assertEquals(info.getSize(), 0);
}
Aggregations