Search in sources :

Example 1 with IndyDataException

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

the class IndexingContentManagerDecorator method store.

//    @Override
//    public Transfer store( final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op )
//            throws IndyWorkflowException
//    {
//        return store( stores, path, stream, op, new EventMetadata() );
//    }
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final StoreKey topKey, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Transfer transfer = delegate.store(stores, topKey, path, stream, op, eventMetadata);
    if (transfer != null) {
        indexManager.indexTransferIn(transfer, topKey);
        try {
            ArtifactStore topStore = storeDataManager.getArtifactStore(topKey);
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(topStore), path));
        } catch (IndyDataException e) {
            Logger logger = LoggerFactory.getLogger(getClass());
            logger.error(String.format("Failed to retrieve top store: %s for NFC management. Reason: %s", topKey, e.getMessage()), e);
        }
    }
    return transfer;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 2 with IndyDataException

use of org.commonjava.indy.data.IndyDataException 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 3 with IndyDataException

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

the class DataFileStoreDataManager method readDefinitions.

@PostConstruct
public void readDefinitions() {
    final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Reading definitions from disk, culling invalid definition files.");
    try {
        DataFile[] packageDirs = manager.getDataFile(INDY_STORE).listFiles((f) -> true);
        for (DataFile pkgDir : packageDirs) {
            for (StoreType type : StoreType.values()) {
                DataFile[] files = pkgDir.getChild(type.singularEndpointName()).listFiles(f -> true);
                if (files != null) {
                    for (final DataFile f : files) {
                        try {
                            final String json = f.readString();
                            final ArtifactStore store = serializer.readValue(json, type.getStoreClass());
                            if (store == null) {
                                f.delete(summary);
                            } else {
                                storeArtifactStore(store, summary, false, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, LOAD_FROM_DISK));
                            }
                        } catch (final IOException e) {
                            logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
                        }
                    }
                }
            }
        }
        started = true;
    } catch (final IndyDataException e) {
        throw new IllegalStateException("Failed to start store data manager: " + e.getMessage(), e);
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PostConstruct(javax.annotation.PostConstruct)

Example 4 with IndyDataException

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

the class DataFileStoreDataManager method clear.

@Override
public void clear(final ChangeSummary summary) throws IndyDataException {
    super.clear(summary);
    final DataFile basedir = manager.getDataFile(INDY_STORE);
    try {
        basedir.delete(summary);
    } catch (final IOException e) {
        throw new IndyDataException("Failed to delete Indy storage files: {}", e, e.getMessage());
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) IndyDataException(org.commonjava.indy.data.IndyDataException) IOException(java.io.IOException)

Example 5 with IndyDataException

use of org.commonjava.indy.data.IndyDataException 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)

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