Search in sources :

Example 61 with IndyDataException

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

the class IndexingContentManagerDecorator method getIndexedMemberTransfer.

private Transfer getIndexedMemberTransfer(final Group group, final String path, TransferOperation op, ContentManagementFunction func) throws IndyWorkflowException {
    StoreKey topKey = group.getKey();
    List<StoreKey> toProcess = new ArrayList<>(group.getConstituents());
    Set<StoreKey> seen = new HashSet<>();
    while (!toProcess.isEmpty()) {
        StoreKey key = toProcess.remove(0);
        seen.add(key);
        final ArtifactStore member;
        try {
            member = storeDataManager.getArtifactStore(key);
            if (member == null) {
                continue;
            }
        } catch (IndyDataException e) {
            Logger logger = LoggerFactory.getLogger(getClass());
            logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", key, topKey, e.getMessage()), e);
            continue;
        }
        Transfer transfer = getIndexedTransfer(key, topKey, path, op);
        if (transfer == null && StoreType.group != key.getType()) {
            // don't call this for constituents that are groups...we'll manually traverse the membership below...
            transfer = func.apply(member);
        }
        if (transfer != null) {
            indexManager.indexTransferIn(transfer, key, topKey);
            return transfer;
        } else if (StoreType.group == key.getType()) {
            int i = 0;
            for (StoreKey memberKey : ((Group) member).getConstituents()) {
                if (!seen.contains(memberKey)) {
                    toProcess.add(i, memberKey);
                    i++;
                }
            }
        }
    }
    return null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet)

Example 62 with IndyDataException

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

the class ArtifactStoreSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    String[] names;
    final StoreURIMatcher matcher = new StoreURIMatcher(folderUri);
    if (matcher.hasStorePath() || matcher.hasStoreName()) {
        String path = matcher.getStorePath();
        if (isEmpty(path)) {
            path = PathUtils.ROOT;
        }
        final StoreKey key = matcher.getStoreKey();
        try {
            if (key != null && StoreType.group == key.getType()) {
                final List<ArtifactStore> stores = indy.query().packageType(key.getPackageType()).getOrderedStoresInGroup(key.getName());
                final Set<String> noms = new TreeSet<>();
                for (final ArtifactStore store : stores) {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists()) {
                        continue;
                    }
                    if (!item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        continue;
                    }
                    noms.addAll(Arrays.asList(item.list()));
                }
                names = noms.toArray(new String[noms.size()]);
            } else {
                final ArtifactStore store = indy.getArtifactStore(key);
                if (store == null) {
                    logger.error("Cannot find ArtifactStore to match key: {}.", key);
                    names = new String[] {};
                } else {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists() || !item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        names = new String[] {};
                    } else {
                        names = item.list();
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStore(s) for key: %s. Reason: %s", key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        } catch (final IOException e) {
            logger.error(String.format("Failed to list %s in %s. Reason: %s", path, key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else if (matcher.hasStoreType()) {
        String packageType = matcher.getPackageType();
        final StoreType type = matcher.getStoreType();
        try {
            List<String> noms = indy.query().packageType(packageType).storeTypes(type).stream().map(ArtifactStore::getName).collect(Collectors.toList());
            names = noms.toArray(new String[noms.size()]);
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStores of type: %s. Reason: %s", type, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else {
        names = new String[] { StoreType.hosted.singularEndpointName(), StoreType.group.singularEndpointName(), StoreType.remote.singularEndpointName() };
    }
    return names;
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) WebdavException(net.sf.webdav.exceptions.WebdavException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) Transfer(org.commonjava.maven.galley.model.Transfer) List(java.util.List)

Example 63 with IndyDataException

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

the class ArtifactStoreSubStore method getStorageAdviceFor.

private StorageAdvice getStorageAdviceFor(final StoreURIMatcher matcher) throws WebdavException {
    final String uri = matcher.getURI();
    final StoreKey key = matcher.getStoreKey();
    ArtifactStore store;
    try {
        store = indy.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve artifact store: %s for URI: %s\nReason: %s", key, uri, e.getMessage()), e);
        throw new WebdavException("Cannot create: " + uri);
    }
    if (store == null) {
        throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
    }
    StorageAdvice advice;
    try {
        advice = advisor.getStorageAdvice(store);
    } catch (final DotMavenException e) {
        logger.error(String.format("Failed to retrieve storage advice for: %s (URI: %s)\nReason: %s", key, uri, e.getMessage()), e);
        throw new WebdavException("Cannot create: " + uri);
    }
    if (!advice.isDeployable()) {
        throw new WebdavException("Read-only area. Cannot create: " + uri);
    }
    return advice;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) WebdavException(net.sf.webdav.exceptions.WebdavException) StoreKey(org.commonjava.indy.model.core.StoreKey) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 64 with IndyDataException

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

the class ArtifactStoreSubStore method getTransfer.

private Transfer getTransfer(final StoreURIMatcher matcher) throws WebdavException {
    final String resourceUri = matcher.getURI();
    if (!matcher.hasStorePath()) {
        throw new WebdavException("No store-level path specified: '" + resourceUri + "'. This URI references either a list of stores, a root store directory, or something else that cannot be read as a file.");
    }
    final String path = matcher.getStorePath();
    final StoreKey key = matcher.getStoreKey();
    Transfer item = null;
    try {
        if (key != null && StoreType.group == key.getType()) {
            final List<ArtifactStore> stores = indy.query().packageType(key.getPackageType()).enabledState(true).getOrderedStoresInGroup(key.getName());
            for (final ArtifactStore store : stores) {
                //                    logger.info( "Getting Transfer for: {} from: {}", path, store );
                final Transfer si = fileManager.getStorageReference(store, path);
                if (si.exists()) {
                    //                        logger.info( "Using Transfer: {} for path: {}", si, path );
                    item = si;
                    break;
                }
            }
        } else {
            final ArtifactStore store = indy.getArtifactStore(key);
            if (store == null) {
                throw new WebdavException("Cannot find store: " + key);
            }
            //                logger.info( "Getting Transfer for: {} from: {}", path, store );
            final Transfer si = fileManager.getStorageReference(store, path);
            if (si.exists()) {
                //                    logger.info( "Using Transfer: {} for path: {}", si, path );
                item = si;
            }
        }
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to lookup ArtifactStore(s) for key: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to get content for: " + resourceUri);
    }
    return item;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 65 with IndyDataException

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

the class SettingsSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    final SettingsURIMatcher matcher = new SettingsURIMatcher(folderUri);
    final Set<String> names = new TreeSet<String>();
    if (matcher.isSettingsRootResource()) {
        for (final StoreType type : StoreType.values()) {
            names.add(type.singularEndpointName());
        }
    } else if (matcher.isSettingsTypeResource()) {
        final StoreType type = matcher.getStoreType();
        List<? extends ArtifactStore> all;
        try {
            all = indy.query().packageType(MAVEN_PKG_KEY).storeTypes(type).getAll();
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to retrieve list of artifact stores: %s", e.getMessage()), e);
            throw new WebdavException("Failed to retrieve list of settings configurations.");
        }
        for (final ArtifactStore store : all) {
            final String storeName = formatSettingsResourceName(store.getKey().getType(), store.getName());
            //                logger.info( "\n\nCreating settings resource for: '{}'\n\n", storeName );
            names.add(storeName);
        }
    }
    return names.toArray(new String[names.size()]);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) SettingsURIMatcher(org.commonjava.indy.dotmaven.util.SettingsURIMatcher) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) WebdavException(net.sf.webdav.exceptions.WebdavException) List(java.util.List)

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