use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentManager method exists.
@Override
@Measure
public // TODO: to add content generation handling here, for things like merged metadata, checksum files, etc.
boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Checking existence of: {} in: {}", path, store.getKey());
if (store instanceof Group) {
List<ArtifactStore> members = getOrderedConcreteStoresAndFilter((Group) store, path);
logger.trace("Trying to retrieve suitable transfer for: {} in group: {}", path, store.getName());
logger.trace("Members in group {}: {}", store.getName(), members);
for (ArtifactStore member : members) {
if (exists(member, path)) {
return true;
}
}
return false;
} else {
return downloadManager.exists(store, path);
}
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class ContentController method store.
@Measure
public Transfer store(final StoreKey key, final String path, final InputStream stream, final EventMetadata eventMetadata) throws IndyWorkflowException {
final ArtifactStore store = getStore(key);
validatePath(key, path);
logger.info("Storing: {} in: {} with event metadata: {}", path, store, eventMetadata);
return contentManager.store(store, path, stream, TransferOperation.UPLOAD, eventMetadata);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultDownloadManager method list.
@Override
@Measure
public List<StoreResource> list(final List<? extends ArtifactStore> stores, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
final String dir = PathUtils.dirname(path);
final List<StoreResource> result = new ArrayList<>();
try {
final List<ListingResult> results = transfers.listAll(locationExpander.expand(new VirtualResource(LocationUtils.toLocations(stores), path)), eventMetadata);
for (final ListingResult lr : results) {
if (lr != null && lr.getListing() != null) {
for (final String file : lr.getListing()) {
result.add(new StoreResource((KeyedLocation) lr.getLocation(), dir, file));
}
}
}
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
} catch (final TransferException e) {
logger.error(e.getMessage(), e);
throw new IndyWorkflowException("Failed to list ALL paths: {} from: {}. Reason: {}", e, path, stores, e.getMessage());
}
return dedupeListing(result);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultDownloadManager method getStorageReference.
@Override
@Measure
public Transfer getStorageReference(final ArtifactStore store, final String... path) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.trace("Retrieving cache reference (Transfer) to: {} in: {}", Arrays.asList(path), store.getKey());
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
return transfers.getCacheReference(resource);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(org.commonjava.indy.core.model.DeployPoint,
* java.lang.String, java.io.InputStream)
*/
@Override
@Measure
public Transfer store(final ArtifactStore store, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
if (store.getKey().getType() == StoreType.group) {
// FIXME: Why is this null? Investigate.
return null;
}
if (store.getKey().getType() != hosted) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
}
if (!isIgnoreReadonly(eventMetadata) && storeManager.isReadonly(store)) {
throw new IndyWorkflowException(ApplicationStatus.METHOD_NOT_ALLOWED.code(), "The store {} is readonly. If you want to store any content to this store, please modify it to non-readonly", store.getKey());
}
if (store instanceof HostedRepository) {
final HostedRepository deploy = (HostedRepository) store;
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
if (quality != ContentQuality.METADATA) {
if (quality == ContentQuality.SNAPSHOT) {
if (!deploy.isAllowSnapshots()) {
logger.error("Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store snapshot in non-snapshot deploy point: {}", deploy.getName());
}
} else if (!deploy.isAllowReleases()) {
logger.error("Cannot store release in snapshot-only deploy point: {}", deploy.getName());
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot store release in snapshot-only deploy point: {}", deploy.getName());
}
}
}
try {
Location loc = LocationUtils.toLocation(store);
boolean resetReadonly = (!loc.allowsStoring() && isIgnoreReadonly(eventMetadata));
if (resetReadonly) {
loc = LocationUtils.getNonReadonlyLocation(loc);
}
ConcreteResource resource = new ConcreteResource(loc, path);
Transfer txfr = transfers.store(resource, stream, eventMetadata);
nfc.clearMissing(resource);
return txfr;
} catch (final BadGatewayException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Bad gateway: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferTimeoutException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Timeout: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (final TransferLocationException e) {
fireIndyStoreErrorEvent(e);
logger.warn("Location Error: " + e.getMessage(), e);
throw new IndyWorkflowException("Failed to store path: {} in: {}. Reason: {}", e, path, store, e.getMessage());
} catch (TransferException e) {
logger.error(String.format("Failed to store: %s in: %s. Reason: %s", path, store.getKey(), e.getMessage()), e);
throw new IndyWorkflowException("Failed to store: %s in: %s. Reason: %s", e, path, store.getKey(), e.getMessage());
}
}
Aggregations