Search in sources :

Example 1 with Group

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

the class DeleteGroupMemberTest method run.

@Test
public void run() throws Exception {
    final String named = "test";
    expectRepoAutoCreation(named);
    final RemoteRepository r = client.stores().load(StoreType.remote, named, RemoteRepository.class);
    assertThat(r, notNullValue());
    Group group = new Group("group", r.getKey());
    group = client.stores().create(group, "Adding test group", Group.class);
    client.stores().delete(StoreType.remote, named, "Removing test repo");
    System.out.println("Waiting for server events to clear...");
    synchronized (this) {
        wait(3000);
    }
    final StoreListingDTO<RemoteRepository> remotes = client.stores().listRemoteRepositories();
    boolean found = false;
    for (final RemoteRepository remote : remotes) {
        if (remote.getName().equals(named)) {
            found = true;
            break;
        }
    }
    assertThat(found, equalTo(false));
    group = client.stores().load(StoreType.group, group.getName(), Group.class);
    assertThat(group.getConstituents().isEmpty(), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Test(org.junit.Test)

Example 2 with Group

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

the class MemoryArtifactStoreQuery method getGroupOrdering.

private List<ArtifactStore> getGroupOrdering(final String groupName, final Map<StoreKey, ArtifactStore> stores, final boolean includeGroups, final boolean recurseGroups) throws IndyDataException {
    if (packageType == null) {
        throw new IndyDataException("packageType must be set on the query before calling this method!");
    }
    final Group master = (Group) stores.get(new StoreKey(packageType, StoreType.group, groupName));
    if (master == null) {
        return Collections.emptyList();
    }
    final List<ArtifactStore> result = new ArrayList<>();
    recurseGroup(master, stores, result, new HashSet<>(), includeGroups, recurseGroups);
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with Group

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

the class StoreDataSetupAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Initializing default data.");
    boolean changed = false;
    try {
        logger.info("Verfiying that Indy basic stores are installed...");
        storeManager.install();
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(RemoteRepository.class).containsByName("central")) {
            final RemoteRepository central = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2/");
            central.setCacheTimeoutSeconds(86400);
            storeManager.storeArtifactStore(central, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(HostedRepository.class).containsByName("local-deployments")) {
            final HostedRepository local = new HostedRepository(MAVEN_PKG_KEY, "local-deployments");
            local.setAllowReleases(true);
            local.setAllowSnapshots(true);
            local.setSnapshotTimeoutSeconds(86400);
            storeManager.storeArtifactStore(local, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
        if (!storeManager.query().packageType(MAVEN_PKG_KEY).storeType(Group.class).containsByName("public")) {
            final Group pub = new Group(MAVEN_PKG_KEY, "public");
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, "central"));
            pub.addConstituent(new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, "local-deployments"));
            storeManager.storeArtifactStore(pub, summary, true, true, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, DEFAULT_SETUP));
            changed = true;
        }
    } catch (final IndyDataException e) {
        throw new RuntimeException("Failed to boot indy components: " + e.getMessage(), e);
    }
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 4 with Group

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

the class StoreContentListener method removeAllSupercededMemberContent.

// TODO: If we find points where a new HostedRepository is added, we should be using its comprehensive index to minimize the index damage to the group.
private void removeAllSupercededMemberContent(final ArtifactStore store, final Map<ArtifactStore, ArtifactStore> changeMap) {
    Logger logger = LoggerFactory.getLogger(getClass());
    StoreKey key = store.getKey();
    // we're only interested in groups, since only adjustments to group memberships can invalidate indexed content.
    if (StoreType.group == key.getType()) {
        List<StoreKey> newMembers = ((Group) store).getConstituents();
        logger.debug("New members of: {} are: {}", store, newMembers);
        Group group = (Group) changeMap.get(store);
        List<StoreKey> oldMembers = group.getConstituents();
        logger.debug("Old members of: {} are: {}", group, oldMembers);
        int commonSize = Math.min(newMembers.size(), oldMembers.size());
        int divergencePoint;
        // look in the members that overlap in new/old groups and see if there are changes that would
        // indicate member reordering. If so, it might lead previously suppressed results to be prioritized,
        // which would invalidate part of the content index for the group.
        boolean foundDivergence = false;
        for (divergencePoint = 0; divergencePoint < commonSize; divergencePoint++) {
            logger.debug("Checking for common member at index: {}", divergencePoint);
            if (!oldMembers.get(divergencePoint).equals(newMembers.get(divergencePoint))) {
                foundDivergence = true;
                break;
            }
        }
        //      that include the one we're affecting directly here...using clearIndexedPathFrom() to do this.
        if (!foundDivergence) {
            if (newMembers.size() < oldMembers.size()) {
                divergencePoint = commonSize;
            } else {
                divergencePoint = newMembers.size();
            }
        }
        logger.debug("group membership divergence point: {}", divergencePoint);
        Set<StoreKey> affectedMembers = new HashSet<>();
        boolean removeMergableOnly = divergencePoint >= oldMembers.size();
        // group content index entries for those.
        if (divergencePoint < oldMembers.size()) {
            for (int i = divergencePoint; i < oldMembers.size(); i++) {
                affectedMembers.add(oldMembers.get(i));
            }
        } else {
            // See [NOS-128]
            for (int i = divergencePoint - 1; i >= commonSize; i--) {
                affectedMembers.add(newMembers.get(i));
            }
        }
        logger.debug("Got members affected by membership divergence: {}", affectedMembers);
        if (!affectedMembers.isEmpty()) {
            Set<Group> groups = new HashSet<>();
            groups.add(group);
            try {
                groups.addAll(storeDataManager.query().packageType(group.getPackageType()).getGroupsAffectedBy(group.getKey()));
            } catch (IndyDataException e) {
                logger.error(String.format("Cannot retrieve groups affected by: %s. Reason: %s", group.getKey(), e.getMessage()), e);
            }
            logger.debug("Got affected groups: {}", groups);
            affectedMembers.parallelStream().forEach((memberKey) -> {
                logger.debug("Listing all {}paths in: {}", (removeMergableOnly ? "mergeable " : ""), memberKey);
                Set<String> paths = listPaths(memberKey, removeMergableOnly ? mergablePathStrings() : (p) -> true);
                logger.debug("Got mergable transfers from diverged portion of membership: {}", paths);
                clearPaths(paths, memberKey, groups, false);
            });
        }
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactStoreEnablementEvent(org.commonjava.indy.change.event.ArtifactStoreEnablementEvent) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Observes(javax.enterprise.event.Observes) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ArtifactStoreDeletePreEvent(org.commonjava.indy.change.event.ArtifactStoreDeletePreEvent) StoreKey(org.commonjava.indy.model.core.StoreKey) Instance(javax.enterprise.inject.Instance) ROOT(org.commonjava.maven.galley.util.PathUtils.ROOT) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreContentAction(org.commonjava.indy.content.StoreContentAction) Predicate(java.util.function.Predicate) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) IOException(java.io.IOException) List(java.util.List) Stream(java.util.stream.Stream) ArtifactStorePreUpdateEvent(org.commonjava.indy.change.event.ArtifactStorePreUpdateEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Collections(java.util.Collections) ArtifactStoreUpdateType(org.commonjava.indy.change.event.ArtifactStoreUpdateType) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) Group(org.commonjava.indy.model.core.Group) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) HashSet(java.util.HashSet)

Example 5 with Group

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

the class SetBackSettingsManagerTest method settingsForGroup_OneRemoteOneHosted_HostedOmittedButAddedInComment.

@Test
public void settingsForGroup_OneRemoteOneHosted_HostedOmittedButAddedInComment() throws Exception {
    final RemoteRepository remote = new RemoteRepository(MAVEN_PKG_KEY, "test", "http://foo.bar/");
    remote.setDescription("Test Repository");
    final HostedRepository hosted = new HostedRepository(MAVEN_PKG_KEY, "test-hosted");
    store(remote);
    store(hosted);
    final Group group = new Group(MAVEN_PKG_KEY, "test-group", remote.getKey(), hosted.getKey());
    store(group);
    System.out.println("Group members:\n  " + join(group.getConstituents(), "\n  "));
    assertThat(readSettings(group.getKey(), false), equalTo(null));
    final List<String> lines = generateSettings(group.getKey());
    assertThat("No repository with id: " + remote.getName() + " found in settings.xml for group!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
    assertThat("Repository with id: " + hosted.getName() + " Should not be present in settings.xml for group!", lines.contains("<id>" + remote.getName() + "</id>"), equalTo(true));
    assertThat("No entry for remote: " + remote.getKey().toString() + " found in settings.xml constituency comment!", lines.contains("* " + remote.getKey()), equalTo(true));
    assertThat("No entry for hosted: " + hosted.getKey().toString() + " found in settings.xml constituency comment!", lines.contains("* " + hosted.getKey()), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test)

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