Search in sources :

Example 11 with ArtifactStore

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

the class ValidationRequest method getSourcePaths.

public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
    if (requestPaths == null) {
        Set<String> paths = null;
        if (promoteRequest instanceof PathsPromoteRequest) {
            paths = ((PathsPromoteRequest) promoteRequest).getPaths();
        }
        if (paths == null) {
            ArtifactStore store = null;
            try {
                store = tools.getArtifactStore(promoteRequest.getSource());
            } catch (IndyDataException e) {
                throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
            }
            if (store != null) {
                try {
                    paths = new HashSet<>();
                    listRecursively(store, "/", paths);
                } catch (IndyWorkflowException e) {
                    throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
                }
            }
        }
        requestPaths = paths;
    }
    if (!includeMetadata || !includeChecksums) {
        Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
        return requestPaths.stream().filter(filter).collect(Collectors.toSet());
    }
    return requestPaths;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Predicate(java.util.function.Predicate) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) List(java.util.List) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreResource(org.commonjava.indy.content.StoreResource) PromotionValidationTools(org.commonjava.indy.promote.validate.PromotionValidationTools) PromoteRequest(org.commonjava.indy.promote.model.PromoteRequest) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) PromotionValidationException(org.commonjava.indy.promote.validate.PromotionValidationException)

Example 12 with ArtifactStore

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

the class MavenMetadataGenerator method mergeMissing.

private MetadataIncrementalResult mergeMissing(final Group group, final MetadataIncrementalResult incrementalResult, final String toMergePath, String description, BiFunction<ArtifactStore, String, Callable<MetadataResult>> func) throws IndyWorkflowException {
    Set<ArtifactStore> missing = incrementalResult.missing;
    Metadata master = incrementalResult.result;
    logger.debug("Merge member metadata for {}, {}, missing: {}, size: {}", group.getKey(), description, missing, missing.size());
    DrainingExecutorCompletionService<MetadataResult> svc = new DrainingExecutorCompletionService<>(mavenMDGeneratorService);
    detectOverloadVoid(() -> missing.forEach(store -> svc.submit(func.apply(store, toMergePath))));
    // return stores failed download
    Set<ArtifactStore> resultingMissing = new HashSet<>();
    Set<StoreKey> included = new HashSet<>();
    try {
        svc.drain(mr -> {
            if (mr != null) {
                if (mr.missing) {
                    resultingMissing.add(mr.store);
                } else {
                    included.add(mr.store.getKey());
                    merger.merge(master, mr.metadata, group, toMergePath);
                    putToMetadataCache(mr.store.getKey(), toMergePath, new MetadataInfo(mr.metadata));
                }
            }
        });
    } catch (InterruptedException e) {
        logger.debug("Interrupted while merging " + description + " member metadata.");
    } catch (ExecutionException e) {
        throw new IndyWorkflowException("Failed to merge downloaded " + description + " member metadata.", e);
    }
    return new MetadataIncrementalResult(resultingMissing, included, master);
}
Also used : HTTP_METADATA_EXT(org.commonjava.maven.galley.io.SpecialPathConstants.HTTP_METADATA_EXT) Date(java.util.Date) BiFunction(java.util.function.BiFunction) MergedContentAction(org.commonjava.indy.content.MergedContentAction) PathUtils.normalize(org.commonjava.maven.galley.util.PathUtils.normalize) StringUtils(org.apache.commons.lang3.StringUtils) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) GROUP_METADATA_GENERATED(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Document(org.w3c.dom.Document) TraceManager.addFieldToActiveSpan(org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan) Map(java.util.Map) StoreKey(org.commonjava.indy.model.core.StoreKey) Instance(javax.enterprise.inject.Instance) GROUP_METADATA_EXISTS(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) GroupMergeHelper(org.commonjava.indy.core.content.group.GroupMergeHelper) MavenMetadataMerger(org.commonjava.indy.pkg.maven.content.group.MavenMetadataMerger) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) LOCAL_SNAPSHOT_VERSION_PART(org.commonjava.atlas.maven.ident.util.SnapshotUtils.LOCAL_SNAPSHOT_VERSION_PART) PostConstruct(javax.annotation.PostConstruct) XMLInfrastructure(org.commonjava.maven.galley.maven.parse.XMLInfrastructure) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) Plugin(org.apache.maven.artifact.repository.metadata.Plugin) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) Locker(org.commonjava.cdi.util.weft.Locker) MavenMetadataProvider(org.commonjava.indy.pkg.maven.content.group.MavenMetadataProvider) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) VersionUtils(org.commonjava.atlas.maven.ident.util.VersionUtils) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TypeAndClassifier(org.commonjava.atlas.maven.ident.ref.TypeAndClassifier) GalleyMavenXMLException(org.commonjava.maven.galley.maven.parse.GalleyMavenXMLException) PathUtils.parentPath(org.commonjava.maven.galley.util.PathUtils.parentPath) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) SnapshotPart(org.commonjava.atlas.maven.ident.version.part.SnapshotPart) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) OutputStream(java.io.OutputStream) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) LocationUtils(org.commonjava.indy.util.LocationUtils) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) UTF_8(java.nio.charset.StandardCharsets.UTF_8) TraceManager(org.commonjava.o11yphant.trace.TraceManager) IOUtils.closeQuietly(org.apache.commons.io.IOUtils.closeQuietly) IOException(java.io.IOException) SnapshotUtils.generateUpdateTimestamp(org.commonjava.atlas.maven.ident.util.SnapshotUtils.generateUpdateTimestamp) SimpleTypeAndClassifier(org.commonjava.atlas.maven.ident.ref.SimpleTypeAndClassifier) SnapshotUtils(org.commonjava.atlas.maven.ident.util.SnapshotUtils) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Paths(java.nio.file.Paths) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) StoreResource(org.commonjava.indy.content.StoreResource) SnapshotUtils.getCurrentTimestamp(org.commonjava.atlas.maven.ident.util.SnapshotUtils.getCurrentTimestamp) TypeMapping(org.commonjava.maven.galley.model.TypeMapping) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) AbstractMergedContentGenerator(org.commonjava.indy.core.content.AbstractMergedContentGenerator) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) StoreKey(org.commonjava.indy.model.core.StoreKey) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 13 with ArtifactStore

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

the class MetadataStoreListener method onMetadataFileForceDelete.

/**
 * Indy normally does not handle FileDeletionEvent when the cached metadata files were deleted due to store
 * enable/disable/delete, etc. Lately we add a force-deletion for group/remote-repo cache files. This requires to
 * delete affected group metadata files and clear ISPN cache too. We use this method for just this case, i.e.,
 * only if CHECK_CACHE_ONLY is true.
 */
public void onMetadataFileForceDelete(@Observes final FileDeletionEvent event) {
    EventMetadata eventMetadata = event.getEventMetadata();
    if (!Boolean.TRUE.equals(eventMetadata.get(CHECK_CACHE_ONLY))) {
        return;
    }
    logger.trace("Got file-delete event: {}", event);
    Transfer transfer = event.getTransfer();
    String path = transfer.getPath();
    if (!path.endsWith(METADATA_NAME)) {
        logger.trace("Not {} , path: {}", METADATA_NAME, path);
        return;
    }
    Location loc = transfer.getLocation();
    if (!(loc instanceof KeyedLocation)) {
        logger.trace("Ignore FileDeletionEvent, not a KeyedLocation, location: {}", loc);
        return;
    }
    KeyedLocation keyedLocation = (KeyedLocation) loc;
    StoreKey storeKey = keyedLocation.getKey();
    try {
        ArtifactStore store = storeManager.getArtifactStore(storeKey);
        metadataGenerator.clearAllMerged(store, path);
    } catch (IndyDataException e) {
        logger.error("Handle FileDeletionEvent failed", e);
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 14 with ArtifactStore

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

the class AbstractStoreDataManager method doStore.

private Boolean doStore(StoreKey k, ArtifactStore store, ChangeSummary summary, AtomicReference<IndyDataException> error, boolean skipIfExists, boolean fireEvents, EventMetadata eventMetadata) {
    ArtifactStore original = getArtifactStoreInternal(k);
    if (original == store) {
        // if they're the same instance, preUpdate events may not work correctly!
        logger.warn("Storing changes on existing instance of: {}! You forgot to call {}.copyOf().", store, store.getClass().getSimpleName());
    }
    if (skipIfExists && original != null) {
        logger.info("Skip storing for {} (repo exists)", original);
        return true;
    }
    try {
        if (eventMetadata != null && summary != null) {
            eventMetadata.set(StoreDataManager.CHANGE_SUMMARY, summary);
        }
        logger.debug("Starting pre-store actions for {}", k);
        preStore(store, original, summary, original != null, fireEvents, eventMetadata);
        logger.debug("Pre-store actions complete for {}", k);
    } catch (IndyDataException e) {
        error.set(e);
        return false;
    }
    logger.debug("Put {} to stores map", k);
    final ArtifactStore old = putArtifactStoreInternal(store.getKey(), store);
    try {
        logger.debug("Starting post-store actions for {}", k);
        postStore(store, original, summary, original != null, fireEvents, eventMetadata);
        logger.debug("Post-store actions complete for {}", k);
    } catch (final IndyDataException e) {
        if (old != null) {
            logger.error("postStore() failed for {}. Rollback to old value: {}", store, old);
            putArtifactStoreInternal(old.getKey(), old);
        }
        error.set(e);
        return false;
    }
    return true;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Example 15 with ArtifactStore

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

the class AbstractStoreDataManager method deleteArtifactStore.

@Override
@Measure
public void deleteArtifactStore(final StoreKey key, final ChangeSummary summary, final EventMetadata eventMetadata) throws IndyDataException {
    AtomicReference<IndyDataException> error = new AtomicReference<>();
    opLocks.lockAnd(key, LOCK_TIMEOUT_SECONDS, k -> {
        try {
            final ArtifactStore store = getArtifactStoreInternal(k);
            if (store == null) {
                logger.warn("No store found for: {}", k);
                return null;
            }
            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 = removeArtifactStoreInternal(k);
            logger.info("REMOVED store: {}", removed);
            postDelete(store, summary, true, eventMetadata);
        } catch (IndyDataException e) {
            error.set(e);
        }
        return null;
    }, (k, lock) -> {
        error.set(new IndyDataException("Failed to lock: %s for DELETE after %d seconds.", k, LOCK_TIMEOUT_SECONDS));
        return false;
    });
    IndyDataException ex = error.get();
    if (ex != null) {
        throw ex;
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

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