Search in sources :

Example 1 with ArtifactStorePostRescanEvent

use of org.commonjava.indy.change.event.ArtifactStorePostRescanEvent in project indy by Commonjava.

the class KojiRemoteContenIndexingRescanManager method indexPostRescan.

public void indexPostRescan(@Observes final ArtifactStorePostRescanEvent e) throws IndyWorkflowException {
    Collection<ArtifactStore> repos = e.getStores();
    for (ArtifactStore repo : repos) {
        if (repo.getType() == StoreType.remote && repo.getName().startsWith(KOJI_ORIGIN)) {
            LOGGER.trace("Rebuild content index for koji remote: {}", repo.getKey());
            final RemoteRepository kojiRemote = (RemoteRepository) repo;
            try {
                Set<Group> affected = storeDataManager.query().getGroupsAffectedBy(kojiRemote.getKey());
                Set<StoreKey> affetctedGroupKeys = affected.stream().map(g -> g.getKey()).collect(Collectors.toSet());
                StoreKey[] gKeys = affetctedGroupKeys.toArray(new StoreKey[affetctedGroupKeys.size()]);
                kojiRemote.getPathMaskPatterns().forEach(path -> contentIndexManager.indexPathInStores(path, kojiRemote.getKey(), gKeys));
            } catch (IndyDataException ex) {
                LOGGER.error(String.format("Can not get the affected groups for hosted repo %s due to %s", kojiRemote.getKey(), ex.getMessage()), ex);
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ArtifactStorePostRescanEvent(org.commonjava.indy.change.event.ArtifactStorePostRescanEvent) Collectors(java.util.stream.Collectors) Group(org.commonjava.indy.model.core.Group) KOJI_ORIGIN(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN) Inject(javax.inject.Inject) ArtifactStorePreRescanEvent(org.commonjava.indy.change.event.ArtifactStorePreRescanEvent) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ContentIndexRescanManager(org.commonjava.indy.content.index.ContentIndexRescanManager) Observes(javax.enterprise.event.Observes) ContentIndexManager(org.commonjava.indy.content.index.ContentIndexManager) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with ArtifactStorePostRescanEvent

use of org.commonjava.indy.change.event.ArtifactStorePostRescanEvent in project indy by Commonjava.

the class HostedContentIndexRescanManager method indexPostRescan.

public void indexPostRescan(@Observes final ArtifactStorePostRescanEvent e) throws IndyWorkflowException {
    if (!indexConfig.isEnabled()) {
        LOGGER.debug("Content index is disabled.");
        return;
    }
    Collection<ArtifactStore> hostedStores = e.getStores();
    for (ArtifactStore repo : hostedStores) {
        if (repo.getType() == StoreType.hosted) {
            LOGGER.trace("Rebuild content index for {}", repo.getKey());
            final HostedRepository hosted = (HostedRepository) repo;
            try {
                List<Transfer> transfers = downloadManager.listRecursively(hosted.getKey(), DownloadManager.ROOT_PATH);
                Set<Group> affected = storeDataManager.query().getGroupsAffectedBy(hosted.getKey());
                Set<StoreKey> affetctedGroupKeys = affected.stream().map(g -> g.getKey()).collect(Collectors.toSet());
                StoreKey[] gKeys = affetctedGroupKeys.toArray(new StoreKey[affetctedGroupKeys.size()]);
                transfers.forEach(txfr -> contentIndexManager.indexPathInStores(txfr.getPath(), hosted.getKey(), gKeys));
            } catch (IndyWorkflowException ex) {
                LOGGER.error(String.format("Can not list resource correctly for hosted repo %s due to %s", hosted.getKey(), ex.getMessage()), ex);
            } catch (IndyDataException ex) {
                LOGGER.error(String.format("Can not get the affected groups for hosted repo %s due to %s", hosted.getKey(), ex.getMessage()), ex);
            }
        }
    }
}
Also used : IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) LoggerFactory(org.slf4j.LoggerFactory) ArtifactStorePostRescanEvent(org.commonjava.indy.change.event.ArtifactStorePostRescanEvent) Group(org.commonjava.indy.model.core.Group) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Observes(javax.enterprise.event.Observes) ContentIndexManager(org.commonjava.indy.content.index.ContentIndexManager) DownloadManager(org.commonjava.indy.content.DownloadManager) StoreKey(org.commonjava.indy.model.core.StoreKey) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) ArtifactStorePreRescanEvent(org.commonjava.indy.change.event.ArtifactStorePreRescanEvent) List(java.util.List) HostedRepository(org.commonjava.indy.model.core.HostedRepository) ContentIndexRescanManager(org.commonjava.indy.content.index.ContentIndexRescanManager) StoreResource(org.commonjava.indy.content.StoreResource) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Group(org.commonjava.indy.model.core.Group) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Aggregations

Collection (java.util.Collection)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Observes (javax.enterprise.event.Observes)2 Inject (javax.inject.Inject)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 ArtifactStorePostRescanEvent (org.commonjava.indy.change.event.ArtifactStorePostRescanEvent)2 ArtifactStorePreRescanEvent (org.commonjava.indy.change.event.ArtifactStorePreRescanEvent)2 ContentIndexManager (org.commonjava.indy.content.index.ContentIndexManager)2 ContentIndexRescanManager (org.commonjava.indy.content.index.ContentIndexRescanManager)2 IndyDataException (org.commonjava.indy.data.IndyDataException)2 StoreDataManager (org.commonjava.indy.data.StoreDataManager)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 Group (org.commonjava.indy.model.core.Group)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 StoreType (org.commonjava.indy.model.core.StoreType)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 List (java.util.List)1