Search in sources :

Example 66 with Group

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

the class KojiContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation operation) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("KOJI: Delegating initial getTransfer() attempt for: {}/{}", store.getKey(), path);
    Transfer result = delegate.getTransfer(store, path, operation);
    if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && TransferOperation.DOWNLOAD == operation && StoreType.group == store.getKey().getType()) {
        logger.info("KOJI: Checking for Koji build matching: {}", path);
        Group group = (Group) store;
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            EventMetadata eventMetadata = new EventMetadata().set(ContentManager.ENTRY_POINT_STORE, store.getKey());
            result = delegate.retrieve(kojiProxy, path, eventMetadata);
        }
        if (result != null && result.exists()) {
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
        }
    }
    // Finally, pass the Transfer back.
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Logger(org.slf4j.Logger) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 67 with Group

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

the class ReuseExistingRepoIntoConfiguredGroupTest method skimPomForExistingRepoAndAddItInGroup.

@Test
public void skimPomForExistingRepoAndAddItInGroup() throws Exception {
    RemoteRepository repo = new RemoteRepository(REPO, server.formatUrl(REPO));
    repo.setAllowReleases(Boolean.TRUE);
    repo.setAllowSnapshots(Boolean.FALSE);
    repo = client.stores().create(repo, "Pre stored remote repo", RemoteRepository.class);
    final StoreKey remoteRepoKey = repo.getKey();
    final PomRef ref = loadPom("one-repo", Collections.singletonMap("one-repo.url", server.formatUrl(REPO)));
    server.expect("HEAD", server.formatUrl(REPO, "/"), 200, (String) null);
    server.expect(server.formatUrl(TEST_REPO, ref.path), 200, ref.pom);
    final StoreKey pubGroupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, StoreType.group, PUBLIC);
    Group g = client.stores().load(pubGroupKey, Group.class);
    assertThat("Group membership should not contain implied before getting pom.", g.getConstituents().contains(remoteRepoKey), equalTo(false));
    logger.debug("Start fetching pom!");
    final InputStream stream = client.content().get(pubGroupKey, ref.path);
    final String downloaded = IOUtils.toString(stream);
    IOUtils.closeQuietly(stream);
    System.out.println("Waiting 5s for events to run.");
    Thread.sleep(5000);
    g = client.stores().load(pubGroupKey, Group.class);
    assertThat("Group membership does not contain implied repository", g.getConstituents().contains(remoteRepoKey), equalTo(true));
    repo = client.stores().load(new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, StoreType.remote, TEST_REPO), RemoteRepository.class);
    String metadata = repo.getMetadata(ImpliedRepoMetadataManager.IMPLIED_STORES);
    assertThat("Reference to repositories implied by POMs in this repo is missing from metadata.", metadata.contains("remote:" + REPO), equalTo(true));
    repo = client.stores().load(remoteRepoKey, RemoteRepository.class);
    metadata = repo.getMetadata(ImpliedRepoMetadataManager.IMPLIED_BY_STORES);
    assertThat("Backref to repo with pom that implies this repo is missing from metadata.", metadata.contains("remote:" + TEST_REPO), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 68 with Group

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

the class ImpliedReposQueryDelegate method getGroupsContaining.

@Override
public Set<Group> getGroupsContaining(StoreKey key) throws IndyDataException {
    ArtifactStore store = dataManager.getArtifactStore(key);
    if (store != null) {
        boolean storeIsImplied = IMPLIED_REPO_ORIGIN.equals(store.getMetadata(METADATA_ORIGIN));
        Set<Group> delegateGroups = delegate().getGroupsContaining(key);
        if (!storeIsImplied || delegateGroups == null || delegateGroups.isEmpty()) {
            return delegateGroups;
        }
        return delegateGroups.stream().filter((group) -> config.isEnabledForGroup(group.getName())).collect(Collectors.toSet());
    }
    return delegate().getGroupsContaining(key);
}
Also used : ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IMPLIED_REPO_ORIGIN(org.commonjava.indy.implrepo.data.ImpliedReposStoreDataManagerDecorator.IMPLIED_REPO_ORIGIN) LoggerFactory(org.slf4j.LoggerFactory) METADATA_ORIGIN(org.commonjava.indy.model.core.ArtifactStore.METADATA_ORIGIN) DelegatingArtifactStoreQuery(org.commonjava.indy.data.DelegatingArtifactStoreQuery) Set(java.util.Set) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) ImpliedRepoConfig(org.commonjava.indy.implrepo.conf.ImpliedRepoConfig) Collections(java.util.Collections) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Example 69 with Group

use of org.commonjava.indy.model.core.Group 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 70 with Group

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

the class AbstractMaintFunctionalTest method setupTestStores.

@Before
public void setupTestStores() throws Exception {
    setupChangelog = "Create test structures";
    final StoreKey groupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, group, PUBLIC);
    if (client.stores().exists(groupKey)) {
        System.out.println("Loading pre-existing public group.");
        pubGroup = client.stores().load(groupKey, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        pubGroup = client.stores().create(new Group(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, PUBLIC), setupChangelog, Group.class);
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) StoreKey(org.commonjava.indy.model.core.StoreKey) Before(org.junit.Before)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22