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;
}
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);
}
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);
}
}
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;
}
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;
}
}
Aggregations