use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class DefaultDownloadManager method getStorageReference.
@Override
public Transfer getStorageReference(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
if (storeIsSuitableFor(store, quality, op)) {
return getStorageReference(store, path);
}
logger.warn("Store {} not suitable for: {}", store, op);
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Store is not suitable for this operation.");
}
use of org.commonjava.indy.IndyWorkflowException 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
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() != StoreType.hosted) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Cannot deploy to non-deploy point artifact store: {}.", store.getKey());
}
if (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 != null && 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 {
return transfers.store(new ConcreteResource(LocationUtils.toLocation(store), path), stream, eventMetadata);
} catch (final BadGatewayException e) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), 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) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), 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) {
Location location = e.getLocation();
KeyedLocation kl = (KeyedLocation) location;
fileEventManager.fire(new IndyStoreErrorEvent(kl.getKey(), 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());
}
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class StatsController method getEndpointsListing.
public EndpointViewListing getEndpointsListing(final String baseUri, final UriFormatter uriFormatter) throws IndyWorkflowException {
final List<ArtifactStore> stores = new ArrayList<ArtifactStore>();
try {
stores.addAll(dataManager.getAllArtifactStores());
} catch (final IndyDataException e) {
throw new IndyWorkflowException(ApplicationStatus.SERVER_ERROR.code(), "Failed to retrieve all endpoints: {}", e, e.getMessage());
}
final List<EndpointView> points = new ArrayList<EndpointView>();
for (final ArtifactStore store : stores) {
final StoreKey key = store.getKey();
final String resourceUri = uriFormatter.formatAbsolutePathTo(baseUri, "content", key.getPackageType(), key.getType().singularEndpointName(), key.getName());
final EndpointView point = new EndpointView(store, resourceUri);
if (!points.contains(point)) {
points.add(point);
}
}
return new EndpointViewListing(points);
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class StoreContentListener method listPaths.
private Set<String> listPaths(StoreKey key, Predicate<? super String> pathFilter) {
Logger logger = LoggerFactory.getLogger(getClass());
Transfer root = null;
try {
Set<String> paths = new HashSet<>();
root = directContentAccess.getTransfer(key, ROOT);
root.lockWrite();
List<Transfer> toProcess = new ArrayList<>();
toProcess.add(root);
while (!toProcess.isEmpty()) {
Transfer next = toProcess.remove(0);
try {
Stream.of(next.list()).forEach(filename -> {
Transfer t = next.getChild(filename);
if (t.isDirectory()) {
logger.debug("Adding directory path for processing: {}", t.getPath());
toProcess.add(t);
} else {
logger.trace("Testing file path: {}", t.getPath());
if (pathFilter.test(t.getPath())) {
logger.trace("Adding file path to results: {}", t.getPath());
paths.add(t.getPath());
} else {
logger.trace("Skipping file path: {}", t.getPath());
}
}
});
} catch (IOException e) {
logger.error(String.format("Failed to list contents of: %s. Reason: %s", next, e), e);
}
}
return paths;
} catch (IndyWorkflowException e) {
logger.error(String.format("Failed to retrieve root directory reference for: %s. Reason: %s", key, e), e);
} finally {
if (root != null) {
root.unlock();
}
}
return Collections.emptySet();
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class AbstractMergedContentGenerator method clearMergedFile.
protected void clearMergedFile(final Group group, final String path) {
try {
// delete so it'll be recomputed.
final Transfer target = fileManager.getTransfer(group, path);
if (target.exists()) {
logger.debug("Deleting merged file: {}", target);
target.delete(false);
if (target.exists()) {
logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
}
helper.deleteChecksumsAndMergeInfo(group, path);
} else {
ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
nfc.clearMissing(resource);
}
} catch (final IndyWorkflowException | IOException e) {
logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
}
}
Aggregations