Search in sources :

Example 1 with ArtifactStore

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

the class IndexingContentManagerDecorator method getIndexedTransfer.

private Transfer getIndexedTransfer(final StoreKey storeKey, final StoreKey topKey, final String path, final TransferOperation op) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Looking for indexed path: {} in: {} (entry point: {})", path, storeKey, topKey);
    try {
        ArtifactStore store = storeDataManager.getArtifactStore(storeKey);
        if (store.isDisabled()) {
            logger.info("Content not available in index caching layer due to store disabled for {} in group {}", storeKey, topKey);
            return null;
        }
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", storeKey, topKey, e.getMessage()), e);
        //TODO: Need further check if it is suitable to throw a IndyWorkflowException here.
        return null;
    }
    IndexedStorePath storePath = indexManager.getIndexedStorePath(storeKey, path);
    if (storePath != null) {
        Transfer transfer = delegate.getTransfer(storeKey, path, op);
        if (transfer == null || !transfer.exists()) {
            logger.trace("Found obsolete index entry: {}. De-indexing from: {} and {}", storeKey, topKey);
            // something happened to the underlying Transfer...de-index it, and don't return it.
            indexManager.deIndexStorePath(storeKey, path);
            if (topKey != null) {
                indexManager.deIndexStorePath(topKey, path);
            }
        } else {
            logger.trace("Found it!");
            return transfer;
        }
    }
    return null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) Logger(org.slf4j.Logger)

Example 2 with ArtifactStore

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

the class MemoryArtifactStoreQuery method getGroupOrdering.

private List<ArtifactStore> getGroupOrdering(final String groupName, final Map<StoreKey, ArtifactStore> stores, final boolean includeGroups, final boolean recurseGroups) throws IndyDataException {
    if (packageType == null) {
        throw new IndyDataException("packageType must be set on the query before calling this method!");
    }
    final Group master = (Group) stores.get(new StoreKey(packageType, StoreType.group, groupName));
    if (master == null) {
        return Collections.emptyList();
    }
    final List<ArtifactStore> result = new ArrayList<>();
    recurseGroup(master, stores, result, new HashSet<>(), includeGroups, recurseGroups);
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with ArtifactStore

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

the class MemoryStoreDataManager method deleteArtifactStore.

@Override
public void deleteArtifactStore(final StoreKey key, final ChangeSummary summary, final EventMetadata eventMetadata) throws IndyDataException {
    Logger logger = LoggerFactory.getLogger(getClass());
    ReentrantLock opLock = getOpLock(key);
    try {
        logger.info("DELETE operation starting for store: {}", key);
        opLock.lock();
        final ArtifactStore store = stores.get(key);
        if (store == null) {
            logger.warn("No store found for: {}", key);
            return;
        }
        if (isReadonly(store)) {
            throw new IndyDataException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to delete this store, please modify it to non-readonly", store.getKey());
        }
        preDelete(store, summary, true, eventMetadata);
        ArtifactStore removed = stores.remove(key);
        logger.info("REMOVED store: {}", removed);
        postDelete(store, summary, true, eventMetadata);
    } finally {
        opLock.unlock();
        logger.trace("Delete operation complete: {}", key);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger)

Example 4 with ArtifactStore

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

the class DataFileStoreDataManager method store.

private void store(final boolean skipIfExists, final ChangeSummary summary, final ArtifactStore... stores) throws IndyDataException {
    for (final ArtifactStore store : stores) {
        final DataFile f = manager.getDataFile(INDY_STORE, store.getPackageType(), store.getType().singularEndpointName(), store.getName() + ".json");
        if (skipIfExists && f.exists()) {
            continue;
        }
        final DataFile d = f.getParent();
        if (!d.mkdirs()) {
            throw new IndyDataException("Cannot create storage directory: {} for definition: {}", d, store);
        }
        try {
            final String json = serializer.writeValueAsString(store);
            f.writeString(json, "UTF-8", summary);
            logger.debug("Persisted {} to disk at: {}\n{}", store, f, json);
        } catch (final IOException e) {
            throw new IndyDataException("Cannot write definition: {} to: {}. Reason: {}", e, store, f, e.getMessage());
        }
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException)

Example 5 with ArtifactStore

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

the class NfcController method getMissing.

public NotFoundCacheDTO getMissing(final StoreKey key) throws IndyWorkflowException {
    final NotFoundCacheDTO dto = new NotFoundCacheDTO();
    if (key.getType() == group) {
        List<ArtifactStore> stores;
        try {
            stores = storeManager.query().packageType(key.getPackageType()).getOrderedConcreteStoresInGroup(key.getName());
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to retrieve concrete constituent ArtifactStores for: %s.", e, key);
        }
        final List<? extends KeyedLocation> locations = toLocations(stores);
        for (final KeyedLocation location : locations) {
            final Set<String> missing = cache.getMissing(location);
            if (missing != null && !missing.isEmpty()) {
                final List<String> paths = new ArrayList<String>(missing);
                Collections.sort(paths);
                dto.addSection(location.getKey(), paths);
            }
        }
    } else {
        ArtifactStore store;
        try {
            store = storeManager.getArtifactStore(key);
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Failed to retrieve ArtifactStore: %s.", e, key);
        }
        if (store != null) {
            final Set<String> missing = cache.getMissing(toLocation(store));
            final List<String> paths = new ArrayList<String>(missing);
            Collections.sort(paths);
            dto.addSection(key, paths);
        }
    }
    return dto;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArrayList(java.util.ArrayList) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17