Search in sources :

Example 61 with ArtifactStore

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

the class ImpliedRepoMaintainer method initJob.

private boolean initJob(final ImpliedRepoMaintJob job) {
    // we might be able to fix the repo-removal problem too.
    if (!(job.store instanceof Group)) {
        logger.debug("ImpliedRepoMaint: Ignoring non-group: {}", job.store.getKey());
        return false;
    }
    if (!config.isEnabledForGroup(job.store.getName())) {
        logger.debug("ImpliedRepoMaint: Implied repositories not enabled for group: {}", job.store.getKey());
        return false;
    }
    logger.debug("Processing group: {} for stores implied by membership which are not yet in the membership", job.store.getName());
    job.group = (Group) job.store;
    try {
        // getOrderedStoresInGroup(), but we can't use persisted info...
        job.members = loadMemberStores(job.group, job);
        // getOrderedConcreteStores(), but we can't use the persisted info...
        final LinkedHashSet<ArtifactStore> reachable = new LinkedHashSet<>(job.members.size());
        for (final ArtifactStore member : job.members) {
            if (member instanceof Group) {
                reachable.addAll(loadMemberStores((Group) member, job));
            } else {
                reachable.add(member);
            }
        }
        job.reachableMembers = new ArrayList<>(reachable);
        logger.debug("For group: {}\n Members: {}\n  Reachable Concrete Members: {}", job.group.getKey(), job.members, job.reachableMembers);
    } catch (final IndyDataException e) {
        logger.error("Failed to retrieve member stores for group: " + job.group.getName(), e);
    }
    if (job.members == null) {
        logger.debug("ImpliedRepoMaint: Group: {} has no membership", job.store.getKey());
        return false;
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Example 62 with ArtifactStore

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

the class ImpliedReposQueryDelegate method getOrderedConcreteStoresInGroup.

@Override
public List<ArtifactStore> getOrderedConcreteStoresInGroup(String groupName) throws IndyDataException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Retrieving ordered concrete (recursive) members for group: {}", groupName);
    List<ArtifactStore> result = delegate().getOrderedConcreteStoresInGroup(groupName);
    if (logger.isTraceEnabled()) {
        logger.trace("Raw ordered concrete membership for group: {} is:\n  {}", groupName, StringUtils.join(result, "\n  "));
    }
    result = maybeFilter(groupName, result);
    if (logger.isTraceEnabled()) {
        logger.trace("Filtered for implied-repos: ordered concrete membership for group: {} is now:\n  {}", groupName, StringUtils.join(result, "\n  "));
    }
    return result;
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger)

Example 63 with ArtifactStore

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

the class SetBackSettingsManager method updateSettingsForGroup.

private DataFile updateSettingsForGroup(final Group group) throws SetBackDataException {
    if (!config.isEnabled()) {
        throw new SetBackDataException("SetBack is disabled!");
    }
    logger.info("Updating set-back settings.xml for group: {}", group.getName());
    List<ArtifactStore> concreteStores;
    try {
        concreteStores = storeManager.query().packageType(group.getPackageType()).getOrderedConcreteStoresInGroup(group.getName());
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve concrete membership for group: {}. Reason: {}", group.getName(), e.getMessage()), e);
        return null;
    }
    final List<RemoteRepository> remotes = new ArrayList<RemoteRepository>();
    for (final ArtifactStore cs : concreteStores) {
        if (StoreType.remote == cs.getKey().getType()) {
            remotes.add((RemoteRepository) cs);
        }
    }
    return updateSettings(group, concreteStores, remotes);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 64 with ArtifactStore

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

the class SetBackSettingsManagerTest method generateSettings.

private List<String> generateSettings(final StoreKey key) throws Exception {
    final ArtifactStore store = storeManager.getArtifactStore(key);
    final DataFile settings = manager.generateStoreSettings(store);
    assertThat("settings.xml returned from generateStoreSettings(..) for: " + key + " does not exist!", settings.exists(), equalTo(true));
    final List<String> lines = readSettings(key, true);
    final String localRepoLine = String.format("<localRepository>%s</localRepository>", normalize(USER_HOME, ".m2/repository-" + key.getType().singularEndpointName() + "-" + key.getName()));
    assertThat("Local repository for: " + key + " not configured", lines.contains(localRepoLine), equalTo(true));
    return lines;
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Example 65 with ArtifactStore

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

the class IndyLocationExpander method expand.

/**
     * For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are 
     * specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
     * {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
     */
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
    final List<Location> result = new ArrayList<Location>();
    for (final Location location : locations) {
        if (location instanceof GroupLocation) {
            final GroupLocation gl = (GroupLocation) location;
            try {
                logger.debug("Expanding group: {}", gl.getKey());
                final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
                if (members != null) {
                    for (final ArtifactStore member : members) {
                        if (!result.contains(member)) {
                            logger.debug("expansion += {}", member.getKey());
                            result.add(LocationUtils.toLocation(member));
                        }
                    }
                    logger.debug("Expanded group: {} to:\n  {}", gl.getKey(), new JoinString("\n  ", result));
                }
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
            }
        } else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
            final StoreKey key = ((KeyedLocation) location).getKey();
            try {
                final ArtifactStore store = data.getArtifactStore(key);
                if (store == null) {
                    throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
                }
                logger.debug("Adding single store: {} for location: {}", store, location);
                result.add(LocationUtils.toLocation(store));
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
            }
        } else {
            logger.debug("No expansion available for location: {}", location);
            result.add(location);
        }
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TransferException(org.commonjava.maven.galley.TransferException) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8