Search in sources :

Example 1 with NotFoundCacheInfoDTO

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();
}
Also used : NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) Test(org.junit.Test)

Example 2 with NotFoundCacheInfoDTO

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with NotFoundCacheInfoDTO

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;
}
Also used : NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO)

Example 4 with NotFoundCacheInfoDTO

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);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) AbstractNotFoundCache(org.commonjava.indy.core.inject.AbstractNotFoundCache) NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO) AtomicLong(java.util.concurrent.atomic.AtomicLong) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) List(java.util.List) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 5 with NotFoundCacheInfoDTO

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);
}
Also used : NotFoundCacheInfoDTO(org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule)

Aggregations

NotFoundCacheInfoDTO (org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 IndyNfcClientModule (org.commonjava.indy.client.core.module.IndyNfcClientModule)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 AbstractNotFoundCache (org.commonjava.indy.core.inject.AbstractNotFoundCache)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)1 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)1