Search in sources :

Example 1 with NotFoundCacheDTO

use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.

the class NfcController method getMissing.

public NotFoundCacheDTO getMissing(final StoreKey key) throws IndyWorkflowException {
    final NotFoundCacheDTO dto = new NotFoundCacheDTO();
    if (key.getType() == group) {
        List<ArtifactStore> stores;
        try {
            stores = storeManager.query().packageType(key.getPackageType()).getOrderedConcreteStoresInGroup(key.getName());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to retrieve concrete constituent ArtifactStores for: %s.", e, key);
        }
        final List<? extends KeyedLocation> locations = toLocations(stores);
        for (final KeyedLocation location : locations) {
            final Set<String> missing = cache.getMissing(location);
            if (missing != null && !missing.isEmpty()) {
                final List<String> paths = new ArrayList<String>(missing);
                Collections.sort(paths);
                dto.addSection(location.getKey(), paths);
            }
        }
    } else {
        ArtifactStore store;
        try {
            store = storeManager.getArtifactStore(key);
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to retrieve ArtifactStore: %s.", e, key);
        }
        if (store != null) {
            final Set<String> missing = cache.getMissing(toLocation(store));
            final List<String> paths = new ArrayList<String>(missing);
            Collections.sort(paths);
            dto.addSection(key, paths);
        }
    }
    return dto;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO)

Example 2 with NotFoundCacheDTO

use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.

the class NfcResource method deprecatedGetStore.

@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) NfcController(org.commonjava.indy.core.ctl.NfcController) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) StringUtils.isNotEmpty(org.apache.commons.lang.StringUtils.isNotEmpty) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) DELETE(javax.ws.rs.DELETE) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) 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 NotFoundCacheDTO

use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.

the class HostedMissingAddToNFCTest method run.

@Test
public void run() throws Exception {
    try (InputStream inputStream = client.content().get(hosted.getKey(), JAR_PATH)) {
        assertThat(inputStream, notNullValue());
    }
    try (InputStream inputStream = client.content().get(hosted.getKey(), POM_PATH)) {
        assertThat(inputStream, IsNull.nullValue());
    }
    NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.hosted, hosted.getName());
    assertThat(dto, notNullValue());
    assertThat(dto.getSections(), notNullValue());
    NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().filter(d -> d.getKey().equals(hosted.getKey())).findFirst().orElse(null);
    assertThat(nfcSectionDto, notNullValue());
    assertThat(nfcSectionDto.getPaths(), notNullValue());
    assertThat(nfcSectionDto.getPaths().contains(POM_PATH), equalTo(true));
    client.content().store(hosted.getKey(), POM_PATH, new ByteArrayInputStream("This is the pom".getBytes()));
    try (InputStream inputStream = client.content().get(hosted.getKey(), POM_PATH)) {
        assertThat(inputStream, notNullValue());
    }
    dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.hosted, hosted.getName());
    assertThat(dto, notNullValue());
    assertThat(dto.getSections(), notNullValue());
    nfcSectionDto = dto.getSections().stream().filter(d -> d.getKey().equals(hosted.getKey())).findFirst().orElse(null);
    assertThat(nfcSectionDto, notNullValue());
    assertThat(nfcSectionDto.getPaths(), nullValue());
    try (InputStream inputStream = client.content().get(hosted.getKey(), META_PATH)) {
        assertThat(inputStream, notNullValue());
    }
}
Also used : IsNull(org.hamcrest.core.IsNull) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) StoreType(org.commonjava.indy.model.core.StoreType) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) NotFoundCacheSectionDTO(org.commonjava.indy.model.core.dto.NotFoundCacheSectionDTO) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Ignore(org.junit.Ignore) ByteArrayInputStream(java.io.ByteArrayInputStream) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundCacheSectionDTO(org.commonjava.indy.model.core.dto.NotFoundCacheSectionDTO) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 4 with NotFoundCacheDTO

use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO in project indy by Commonjava.

the class NFCForTwoGroupsWithSameHostedTest method run.

@Test
public void run() throws Exception {
    try (InputStream inputStream = client.content().get(a.getKey(), PATH)) {
        assertThat(inputStream, nullValue());
    }
    // NotFoundCacheDTO dto = client.module( IndyNfcClientModule.class ).getAllNfcContentInStore( StoreType.group, a.getName() );
    // 
    // assertThat( dto, notNullValue() );
    // assertThat( dto.getSections(), notNullValue() );
    // NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().findFirst().orElse( null );
    // assertThat( nfcSectionDto, notNullValue() );
    // assertThat( nfcSectionDto.getPaths(), notNullValue() );
    // assertThat( nfcSectionDto.getPaths().contains( PATH ), equalTo( true ) );
    // dto = client.module( IndyNfcClientModule.class ).getAllNfcContentInStore( StoreType.hosted, x.getName() );
    // 
    // assertThat( dto, notNullValue() );
    // assertThat( dto.getSections(), notNullValue() );
    // nfcSectionDto = dto.getSections().stream().findFirst().orElse( null );
    // assertThat( nfcSectionDto, notNullValue() );
    // assertThat( nfcSectionDto.getPaths(), notNullValue() );
    // assertThat( nfcSectionDto.getPaths().contains( PATH ), equalTo( true ) );
    client.content().store(b.getKey(), PATH, new ByteArrayInputStream("This is the pom".getBytes()));
    try (InputStream inputStream = client.content().get(b.getKey(), PATH)) {
        assertThat(inputStream, notNullValue());
    }
    try (InputStream inputStream = client.content().get(a.getKey(), PATH)) {
        assertThat(inputStream, notNullValue());
    }
    NotFoundCacheDTO dto = client.module(IndyNfcClientModule.class).getAllNfcContentInStore(StoreType.group, a.getName());
    NotFoundCacheSectionDTO nfcSectionDto = dto.getSections().stream().findFirst().orElse(null);
    assertThat(nfcSectionDto, nullValue());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundCacheSectionDTO(org.commonjava.indy.model.core.dto.NotFoundCacheSectionDTO) IndyNfcClientModule(org.commonjava.indy.client.core.module.IndyNfcClientModule) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 5 with NotFoundCacheDTO

use of org.commonjava.indy.model.core.dto.NotFoundCacheDTO 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)

Aggregations

NotFoundCacheDTO (org.commonjava.indy.model.core.dto.NotFoundCacheDTO)14 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 StoreType (org.commonjava.indy.model.core.StoreType)5 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)5 ApiResponse (io.swagger.annotations.ApiResponse)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Response (javax.ws.rs.core.Response)4 IndyNfcClientModule (org.commonjava.indy.client.core.module.IndyNfcClientModule)4 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 Page (org.commonjava.indy.core.model.Page)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2