Search in sources :

Example 21 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class DefaultContentManager method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Transfer item;
    if (group == store.getKey().getType()) {
        List<ArtifactStore> members;
        try {
            members = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
        }
        if (logger.isDebugEnabled()) {
            logger.debug("{} is a group. Attempting downloads from (in order):\n  {}", store.getKey(), StringUtils.join(members, "\n  "));
        }
        item = null;
        boolean generated = false;
        for (final ContentGenerator generator : contentGenerators) {
            if (generator.canProcess(path)) {
                item = generator.generateGroupFileContent((Group) store, members, path, eventMetadata);
                logger.debug("From content {}.generateGroupFileContent: {} (exists? {})", generator.getClass().getSimpleName(), item, item != null && item.exists());
                generated = true;
                break;
            }
        }
        if (!generated) {
            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) {
                    break;
                }
            }
        }
    } else {
        item = doRetrieve(store, path, eventMetadata);
    }
    logger.info("Returning transfer: {}", item);
    return item;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ContentGenerator(org.commonjava.indy.content.ContentGenerator) 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)

Example 22 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ScheduleManager method setProxyTimeouts.

public synchronized void setProxyTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
    if (!schedulerConfig.isEnabled()) {
        logger.debug("Scheduler disabled.");
        return;
    }
    RemoteRepository repo = null;
    try {
        repo = (RemoteRepository) dataManager.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve store for: %s. Reason: %s", key, e.getMessage()), e);
    }
    if (repo == null) {
        return;
    }
    int timeout = config.getPassthroughTimeoutSeconds();
    final ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(repo), path);
    final SpecialPathInfo info = specialPathManager.getSpecialPathInfo(resource);
    if (!repo.isPassthrough()) {
        if ((info != null && info.isMetadata()) && repo.getMetadataTimeoutSeconds() > 0) {
            logger.debug("Using metadata timeout for: {}", resource);
            timeout = repo.getMetadataTimeoutSeconds();
        } else {
            if (info == null) {
                logger.debug("No special path info for: {}", resource);
            } else {
                logger.debug("{} is a special path, but not metadata.", resource);
            }
            timeout = repo.getCacheTimeoutSeconds();
        }
    }
    if (timeout > 0) {
        //            logger.info( "[PROXY TIMEOUT SET] {}/{}; {}", repo.getKey(), path, new Date( System.currentTimeMillis()
        //                + timeout ) );
        cancel(new StoreKeyMatcher(key, CONTENT_JOB_TYPE), path);
        scheduleContentExpiration(key, path, timeout);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Example 23 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ImpliedRepositoryDetector method updateExistingGroups.

private boolean updateExistingGroups(final ImplicationsJob job) {
    final StoreKey key = job.store.getKey();
    boolean anyChanged = false;
    try {
        final Set<Group> groups = storeManager.query().packageType(MAVEN_PKG_KEY).getGroupsContaining(key);
        if (groups != null) {
            logger.debug("{} groups contain: {}\n  {}", groups.size(), key, new JoinString("\n  ", groups));
            final String message = String.format("Adding repositories implied by: %s\n\n  %s", key, StringUtils.join(job.implied, "\n  "));
            final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, message);
            for (final Group g : groups) {
                Group group = g.copyOf();
                boolean changed = false;
                for (final ArtifactStore implied : job.implied) {
                    boolean groupChanged = group.addConstituent(implied);
                    changed = groupChanged || changed;
                    logger.debug("After attempting to add: {} to group: {}, changed status is: {}", implied, group, changed);
                }
                if (changed) {
                    storeManager.storeArtifactStore(group, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_REPOS, job.implied));
                }
                anyChanged = changed || anyChanged;
            }
        }
    } catch (final IndyDataException e) {
        logger.error("Failed to lookup groups containing: " + key, e);
    }
    return anyChanged;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 24 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ImpliedReposOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> remoteRepositories;
    try {
        remoteRepositories = storeDataManager.query().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    remoteRepositories.forEach((repo) -> {
        if (repo.getName().startsWith("i-")) {
            repo.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
            toStore.add(repo);
        }
    });
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding implied-repository origin metadata"), false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with implied-repos origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
        }
    }
    return !toStore.isEmpty();
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 25 with IndyDataException

use of org.commonjava.indy.data.IndyDataException 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) {
        return Collections.emptySet();
    }
    boolean storeIsImplied = IMPLIED_REPO_ORIGIN.equals(store.getMetadata(METADATA_ORIGIN));
    Set<Group> delegateGroups = delegate().getGroupsContaining(key);
    if (!storeIsImplied || delegateGroups == null || delegateGroups.isEmpty()) {
        return delegateGroups;
    }
    Set<Group> result = delegateGroups.stream().filter((group) -> config.isEnabledForGroup(group.getName())).collect(Collectors.toSet());
    return result;
}
Also used : ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) StringUtils(org.apache.commons.lang.StringUtils) 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) 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)

Aggregations

IndyDataException (org.commonjava.indy.data.IndyDataException)75 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)50 StoreKey (org.commonjava.indy.model.core.StoreKey)30 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)26 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)24 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)24 Transfer (org.commonjava.maven.galley.model.Transfer)19 ArrayList (java.util.ArrayList)17 Group (org.commonjava.indy.model.core.Group)17 IOException (java.io.IOException)16 Logger (org.slf4j.Logger)16 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)14 HashSet (java.util.HashSet)10 List (java.util.List)7 StoreType (org.commonjava.indy.model.core.StoreType)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 ContentGenerator (org.commonjava.indy.content.ContentGenerator)5 InputStream (java.io.InputStream)4