Search in sources :

Example 76 with StoreType

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

the class InfinispanStoreDataMigrationAction method loadFromDiskAnd.

/**
 * Copy from DataFileStoreUtils. This is one-off action.
 */
private void loadFromDiskAnd(DataFileManager manager, IndyObjectMapper serializer, final ChangeSummary summary, Consumer<ArtifactStore> consumer) {
    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 {
                            consumer.accept(store);
                        }
                    } catch (final IOException e) {
                        logger.error(String.format("Failed to load %s store: %s. Reason: %s", type, f, e.getMessage()), e);
                        try {
                            f.delete(summary);
                        } catch (IOException e1) {
                            logger.error("Failed to delete invalid store definition file: " + f, e);
                        }
                    }
                }
            }
        }
    }
}
Also used : DataFile(org.commonjava.indy.subsys.datafile.DataFile) StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IOException(java.io.IOException)

Example 77 with StoreType

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

the class InfinispanStoreDataManager method removeArtifactStoreInternal.

@Override
protected synchronized ArtifactStore removeArtifactStoreInternal(StoreKey key) {
    final ArtifactStore store = stores.remove(key);
    final Map<StoreType, Set<StoreKey>> typedKeys = storesByPkg.get(key.getPackageType());
    if (typedKeys != null) {
        final Set<StoreKey> keys = typedKeys.get(key.getType());
        if (keys != null) {
            keys.remove(key);
        }
    }
    return store;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashSet(java.util.HashSet) Set(java.util.Set) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 78 with StoreType

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

the class InfinispanStoreDataManager method putArtifactStoreInternal.

@Override
protected synchronized ArtifactStore putArtifactStoreInternal(StoreKey storeKey, ArtifactStore store) {
    final ArtifactStore added = stores.put(storeKey, store);
    final Map<StoreType, Set<StoreKey>> typedKeys = storesByPkg.computeIfAbsent(storeKey.getPackageType(), k -> new HashMap<>());
    final Set<StoreKey> keys = typedKeys.computeIfAbsent(storeKey.getType(), k -> new HashSet<>());
    keys.add(storeKey);
    return added;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashSet(java.util.HashSet) Set(java.util.Set) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)78 StoreKey (org.commonjava.indy.model.core.StoreKey)64 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)36 Response (javax.ws.rs.core.Response)34 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponse (io.swagger.annotations.ApiResponse)27 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)27 Path (javax.ws.rs.Path)25 ApiResponses (io.swagger.annotations.ApiResponses)24 IOException (java.io.IOException)20 GET (javax.ws.rs.GET)15 Produces (javax.ws.rs.Produces)15 Logger (org.slf4j.Logger)14 Transfer (org.commonjava.maven.galley.model.Transfer)13 List (java.util.List)12 Inject (javax.inject.Inject)12 DELETE (javax.ws.rs.DELETE)12 IndyDataException (org.commonjava.indy.data.IndyDataException)12 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)11 LoggerFactory (org.slf4j.LoggerFactory)11