Search in sources :

Example 1 with ImpliedReposException

use of org.commonjava.indy.implrepo.ImpliedReposException in project indy by Commonjava.

the class ImpliedRepoClientModule method setStoresImpliedBy.

public void setStoresImpliedBy(final ArtifactStore store, final List<StoreKey> implied, final String changelog) throws IndyClientException {
    final List<ArtifactStore> stores = new ArrayList<>();
    for (final StoreKey storeKey : implied) {
        final ArtifactStore is = getClient().stores().load(storeKey.getType(), storeKey.getName(), storeKey.getType().getStoreClass());
        if (is == null) {
            throw new IndyClientException("No such store: %s. Cannot add to the implied-store list for: %s", storeKey, store.getKey());
        }
        stores.add(is);
    }
    try {
        metadataManager.addImpliedMetadata(store, stores);
    } catch (final ImpliedReposException e) {
        throw new IndyClientException("Failed to set implied-store metadata: %s", e, e.getMessage());
    }
    stores.add(store);
    for (final ArtifactStore toSave : stores) {
        logger.info("Updating implied-store metadata in: {} triggered by adding implications to: {}", toSave.getKey(), store.getKey());
        getClient().stores().update(toSave, changelog);
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 2 with ImpliedReposException

use of org.commonjava.indy.implrepo.ImpliedReposException in project indy by Commonjava.

the class ImpliedRepoMetadataManager method updateImpliedBy.

public void updateImpliedBy(final ArtifactStore store, final ArtifactStore origin) throws ImpliedReposException {
    final String metadata = store.getMetadata(IMPLIED_BY_STORES);
    ImpliedRemotesWrapper wrapper;
    if (metadata == null) {
        wrapper = new ImpliedRemotesWrapper(Collections.singletonList(origin.getKey()));
    } else {
        try {
            wrapper = mapper.readValue(metadata, ImpliedRemotesWrapper.class);
            if (!wrapper.addItem(origin.getKey())) {
                // nothing to change; set to null to signal that nothing should change.
                wrapper = null;
            }
        } catch (final IOException e) {
            throw new ImpliedReposException("Failed to de-serialize implied-by stores from: %s\nJSON: %s\nError: %s", e, store.getKey(), metadata, e.getMessage());
        }
    }
    if (wrapper != null) {
        try {
            store.setMetadata(IMPLIED_BY_STORES, mapper.writeValueAsString(wrapper));
        } catch (final JsonProcessingException e) {
            throw new ImpliedReposException("Failed to serialize implied-by stores to: %s\nJSON: %s\nError: %s", e, store.getKey(), metadata, e.getMessage());
        }
    }
}
Also used : IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 3 with ImpliedReposException

use of org.commonjava.indy.implrepo.ImpliedReposException in project indy by Commonjava.

the class ImpliedRepoMetadataManager method addImpliedMetadata.

// TODO: Need to deal with pre-existing implications.
public void addImpliedMetadata(final ArtifactStore origin, final List<ArtifactStore> implied) throws ImpliedReposException {
    try {
        final List<StoreKey> impliedKeys = new ArrayList<>(implied.size());
        for (final ArtifactStore store : implied) {
            impliedKeys.add(store.getKey());
            updateImpliedBy(store, origin);
        }
        origin.setMetadata(IMPLIED_STORES, mapper.writeValueAsString(new ImpliedRemotesWrapper(impliedKeys)));
    } catch (final JsonProcessingException e) {
        throw new ImpliedReposException("Failed to serialize implied stores: %s to JSON: %s. Error: %s", e, implied, origin.getKey(), e.getMessage());
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 4 with ImpliedReposException

use of org.commonjava.indy.implrepo.ImpliedReposException in project indy by Commonjava.

the class ImpliedRepoMaintainer method processImpliedRepos.

private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
    final Set<StoreKey> processed = new HashSet<>();
    // implications. Reachable means they could be in nested groups.
    for (final ArtifactStore member : job.reachableMembers) {
        processed.add(member.getKey());
    }
    logger.debug("Preset processed-implications to reachable members:\n  {}", new JoinString("\n  ", processed));
    int lastLen = 0;
    boolean changed = false;
    job.added = new ArrayList<>();
    // As soon as we go an iteration without adding a new member, we've captured everything.
    do {
        lastLen = job.members.size();
        for (final ArtifactStore member : new ArrayList<>(job.members)) {
            logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
            processed.add(member.getKey());
            List<StoreKey> implied;
            try {
                implied = metadataManager.getStoresImpliedBy(member);
            } catch (final ImpliedReposException e) {
                logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
                continue;
            }
            if (implied == null || implied.isEmpty()) {
                continue;
            }
            implied.removeAll(processed);
            for (final StoreKey key : implied) {
                logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
                ArtifactStore impliedStore;
                try {
                    impliedStore = storeManager.getArtifactStore(key);
                } catch (final IndyDataException e) {
                    logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
                    continue;
                }
                logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
                processed.add(key);
                job.added.add(key);
                job.group.addConstituent(key);
                job.members.add(impliedStore);
                changed = true;
            }
        }
    } while (job.members.size() > lastLen);
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with ImpliedReposException

use of org.commonjava.indy.implrepo.ImpliedReposException in project indy by Commonjava.

the class ImpliedRepositoryDetector method addImpliedMetadata.

private boolean addImpliedMetadata(final ImplicationsJob job) {
    try {
        logger.debug("Adding implied-repo metadata to: {} and {}", job.store, new JoinString(", ", job.implied));
        metadataManager.addImpliedMetadata(job.store, job.implied);
        return true;
    } catch (final ImpliedReposException e) {
        logger.error("Failed to store list of implied stores in: " + job.store.getKey(), e);
    }
    return false;
}
Also used : JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Aggregations

ImpliedReposException (org.commonjava.indy.implrepo.ImpliedReposException)5 ArrayList (java.util.ArrayList)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 StoreKey (org.commonjava.indy.model.core.StoreKey)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 IndyClientException (org.commonjava.indy.client.core.IndyClientException)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1