Search in sources :

Example 1 with AbstractNotFoundCache

use of org.commonjava.indy.core.inject.AbstractNotFoundCache 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 2 with AbstractNotFoundCache

use of org.commonjava.indy.core.inject.AbstractNotFoundCache in project indy by Commonjava.

the class NfcController method getAllMissing.

public Pagination<NotFoundCacheDTO> getAllMissing(Page page) {
    return new DefaultPagination<>(page, (handler) -> {
        Map<Location, Set<String>> allMissing = ((AbstractNotFoundCache) cache).getAllMissing(page.getPageIndex(), page.getPageSize());
        NotFoundCacheDTO dto = getNotFoundCacheDTO(allMissing);
        return dto;
    });
}
Also used : AbstractNotFoundCache(org.commonjava.indy.core.inject.AbstractNotFoundCache) Set(java.util.Set) DefaultPagination(org.commonjava.indy.core.model.DefaultPagination) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LocationUtils.toLocation(org.commonjava.indy.util.LocationUtils.toLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

AbstractNotFoundCache (org.commonjava.indy.core.inject.AbstractNotFoundCache)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 DefaultPagination (org.commonjava.indy.core.model.DefaultPagination)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 StoreKey (org.commonjava.indy.model.core.StoreKey)1 NotFoundCacheDTO (org.commonjava.indy.model.core.dto.NotFoundCacheDTO)1 NotFoundCacheInfoDTO (org.commonjava.indy.model.core.dto.NotFoundCacheInfoDTO)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1 LocationUtils.toLocation (org.commonjava.indy.util.LocationUtils.toLocation)1 Location (org.commonjava.maven.galley.model.Location)1