Search in sources :

Example 71 with Group

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

the class AbstractSkimFunctionalTest method setupTestStores.

@Before
public void setupTestStores() throws Exception {
    final String changelog = "Create test structures";
    final String url = server.formatUrl(TEST_REPO);
    final RemoteRepository testRepo = client.stores().create(new RemoteRepository(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, TEST_REPO, url), changelog, RemoteRepository.class);
    Group g;
    final StoreKey groupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, group, PUBLIC);
    if (client.stores().exists(groupKey)) {
        System.out.println("Loading pre-existing public group.");
        g = client.stores().load(groupKey, Group.class);
    } else {
        System.out.println("Creating new group 'public'");
        g = client.stores().create(new Group(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, PUBLIC), changelog, Group.class);
    }
    g.setConstituents(Collections.singletonList(testRepo.getKey()));
    client.stores().update(g, changelog);
}
Also used : Group(org.commonjava.indy.model.core.Group) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Before(org.junit.Before)

Example 72 with Group

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

the class StoreContentListener method clearPaths.

/**
 * List the paths in target store and clean up the paths in affected groups.
 *
 * If groups are given, use them (for group update since all members share same group hierarchy). Otherwise,
 * query the affected groups (for store deletion and dis/enable event).
 */
private void clearPaths(final Set<StoreKey> keys, Predicate<? super String> pathFilter, final Set<Group> groups, final boolean deleteOriginPath) {
    // NOSSUP-76 we still need to use synchronized/drain way to clean the paths now, because sometimes the new used metadata
    // not updated in time when some builds want to consume them as the obsolete metadata not cleared under
    // async way.
    DrainingExecutorCompletionService<Integer> clearService = new DrainingExecutorCompletionService<>(cleanupExecutor);
    keys.forEach(key -> {
        ArtifactStore origin;
        try {
            origin = storeDataManager.getArtifactStore(key);
        } catch (IndyDataException e) {
            logger.error("Failed to retrieve store: " + key, e);
            return;
        }
        Set<Group> affected = groups;
        if (affected == null) {
            try {
                affected = (storeDataManager.query().getGroupsAffectedBy(key));
            } catch (IndyDataException e) {
                logger.error("Failed to retrieve groups affected by: " + key, e);
                return;
            }
        }
        logger.debug("Submit clean job for origin: {}", origin);
        final Set<Group> affectedGroups = affected;
        clearService.submit(clearPathsProcessor(origin, pathFilter, affectedGroups, deleteOriginPath));
    });
    drainAndCount(clearService, "stores: " + keys);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService)

Example 73 with Group

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

the class DefaultContentManager method retrieve.

@Override
@Measure
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Transfer item;
    if (group == store.getKey().getType()) {
        List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
        if (logger.isDebugEnabled()) {
            logger.debug("{} is a group. Attempting downloads from (in order):\n  {}", store.getKey(), StringUtils.join(members, "\n  "));
        }
        item = contentGeneratorManager.generateGroupFileContent((Group) store, members, path, eventMetadata);
        boolean generated = (item != null);
        if (!generated) {
            if (PathMaskChecker.checkMask(store, path)) {
                for (final ArtifactStore member : members) {
                    try {
                        item = doRetrieve(member, path, eventMetadata);
                    } catch (IndyWorkflowException e) {
                        logger.error("Failed to retrieve artifact from for path {} from {} in group {}, error is: {}", path, member, store, e.getMessage());
                    }
                    if (item != null) {
                        // get the item from the first member store
                        break;
                    }
                }
            }
        }
    } else {
        item = doRetrieve(store, path, eventMetadata);
    }
    if (item != null) {
        logger.info("Returning transfer {} from {}", item, store.getKey());
    } else {
        logger.trace("Not found path {} from {}", path, store.getKey());
    }
    return item;
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 74 with Group

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

the class DefaultContentManager method clearNFCEntries.

@Measure
protected void clearNFCEntries(final KeyedLocation kl, final String path, EventMetadata eventMetadata) {
    try {
        Set<Group> groups = storeManager.affectedBy(Arrays.asList(kl.getKey()), eventMetadata);
        groups.stream().map((g) -> new ConcreteResource(LocationUtils.toLocation(g), path)).forEach((cr) -> nfc.clearMissing(cr));
        nfc.clearMissing(new ConcreteResource(kl, path));
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to clear NFC entries affected by upload of: %s to: %s. Reason: %s", path, kl.getKey(), e.getMessage()), e);
    }
}
Also used : Arrays(java.util.Arrays) HTTP_METADATA_EXT(org.commonjava.maven.galley.io.SpecialPathConstants.HTTP_METADATA_EXT) ContentDigester(org.commonjava.indy.content.ContentDigester) GroupRepositoryFilterManager(org.commonjava.indy.core.content.group.GroupRepositoryFilterManager) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) LoggerFactory(org.slf4j.LoggerFactory) ContentUtils.dedupeListing(org.commonjava.indy.util.ContentUtils.dedupeListing) StringUtils(org.apache.commons.lang3.StringUtils) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) TransferManager(org.commonjava.maven.galley.TransferManager) CASCADE(org.commonjava.indy.IndyContentConstants.CASCADE) DownloadManager(org.commonjava.indy.content.DownloadManager) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) IOException(java.io.IOException) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IGNORE_READONLY(org.commonjava.indy.data.StoreDataManager.IGNORE_READONLY) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreResource(org.commonjava.indy.content.StoreResource) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 75 with Group

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

the class DefaultContentManager method exists.

@Override
@Measure
public // TODO: to add content generation handling here, for things like merged metadata, checksum files, etc.
boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Checking existence of: {} in: {}", path, store.getKey());
    if (store instanceof Group) {
        List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
        logger.trace("Trying to retrieve suitable transfer for: {} in group: {}", path, store.getName());
        logger.trace("Members in group {}: {}", store.getName(), members);
        for (ArtifactStore member : members) {
            if (exists(member, path)) {
                return true;
            }
        }
        return false;
    } else {
        return downloadManager.exists(store, path);
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

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