use of org.commonjava.indy.spi.pkg.ContentQuality in project indy by Commonjava.
the class DefaultDownloadManager method getStorageReference.
@Override
public Transfer getStorageReference(final List<ArtifactStore> stores, final String path, final TransferOperation op) throws IndyWorkflowException {
// final ArtifactPathInfo pathInfo = ArtifactPathInfo.parse( path );
final ContentQuality quality = getQuality(path);
Transfer transfer = null;
logger.debug("Checking {} stores to find one suitable for {} of: {}", stores.size(), op, path);
boolean suitableFound = false;
for (final ArtifactStore store : stores) {
if (storeIsSuitableFor(store, quality, op)) {
suitableFound = true;
logger.info("Attempting to retrieve storage reference in: {} for: {} (operation: {})", store, path, op);
transfer = getStorageReference(store, path);
logger.debug("Checking {} (exists? {}; file: {})", transfer, transfer != null && transfer.exists(), transfer == null ? "NONE" : transfer.getFullPath());
if (transfer != null && !transfer.exists() && (op == TransferOperation.DOWNLOAD || op == TransferOperation.LISTING)) {
transfer = null;
}
if (transfer != null) {
logger.info("Using transfer: {}", transfer);
break;
}
}
}
if (!stores.isEmpty() && !suitableFound) {
logger.warn("No suitable stores in list.");
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No suitable store available.");
}
return transfer;
}
use of org.commonjava.indy.spi.pkg.ContentQuality 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.spi.pkg.ContentQuality 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.spi.pkg.ContentQuality in project indy by Commonjava.
the class ScheduleManager method setSnapshotTimeouts.
public synchronized void setSnapshotTimeouts(final StoreKey key, final String path) throws IndySchedulerException {
if (!schedulerConfig.isEnabled()) {
logger.debug("Scheduler disabled.");
return;
}
HostedRepository deploy = null;
try {
final ArtifactStore store = dataManager.getArtifactStore(key);
if (store == null) {
return;
}
if (store instanceof HostedRepository) {
deploy = (HostedRepository) store;
} else if (store instanceof Group) {
final Group group = (Group) store;
deploy = findDeployPoint(group);
}
} catch (final IndyDataException e) {
logger.error(String.format("Failed to retrieve deploy point for: %s. Reason: %s", key, e.getMessage()), e);
}
if (deploy == null) {
return;
}
final ContentAdvisor advisor = StreamSupport.stream(Spliterators.spliteratorUnknownSize(contentAdvisor.iterator(), Spliterator.ORDERED), false).filter(Objects::nonNull).findFirst().orElse(null);
final ContentQuality quality = advisor == null ? null : advisor.getContentQuality(path);
if (quality == null) {
return;
}
if (ContentQuality.SNAPSHOT == quality && deploy.getSnapshotTimeoutSeconds() > 0) {
final int timeout = deploy.getSnapshotTimeoutSeconds();
// // logger.info( "[SNAPSHOT TIMEOUT SET] {}/{}; {}", deploy.getKey(), path, new Date( timeout ) );
// cancel( new StoreKeyMatcher( key, CONTENT_JOB_TYPE ), path );
scheduleContentExpiration(key, path, timeout);
}
}
use of org.commonjava.indy.spi.pkg.ContentQuality in project indy by Commonjava.
the class DefaultDownloadManager method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.util.FileManager#upload(java.util.List, java.lang.String,
* java.io.InputStream)
*/
@Override
public Transfer store(final List<? extends ArtifactStore> stores, final String path, final InputStream stream, final TransferOperation op, final EventMetadata eventMetadata) throws IndyWorkflowException {
final ContentQuality quality = getQuality(path);
HostedRepository selected = null;
for (final ArtifactStore store : stores) {
if (storeManager.isReadonly(store)) {
logger.info("The store {} is readonly, store operation not allowed");
continue;
}
if (storeIsSuitableFor(store, quality, op)) {
selected = (HostedRepository) store;
break;
}
}
if (selected == null) {
logger.warn("Cannot deploy. No valid deploy points in group.");
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "No deployment locations available.");
}
logger.info("Storing: {} in selected: {} with event metadata: {}", path, selected, eventMetadata);
store(selected, path, stream, op, eventMetadata);
return getStorageReference(selected.getKey(), path);
}
Aggregations