use of org.commonjava.indy.util.ValuePipe in project indy by Commonjava.
the class PromotionManager method doPathTransfer.
private PathTransferResult doPathTransfer(Transfer transfer, final ArtifactStore tgt, final PathsPromoteRequest request, final Set<Group> affectedGroups) throws IndyWorkflowException {
logger.debug("Do path transfer, transfer: {}, target: {}", transfer, tgt);
if (transfer == null) {
final String error = String.format("Warning: doPathTransfer cannot process null transfer to target: %s", tgt);
logger.error(error);
// FIXME: throw IndyWorkflowException is better?
PathTransferResult result = new PathTransferResult("");
result.error = error;
return result;
}
long begin = System.currentTimeMillis();
final String path = transfer.getPath();
PathTransferResult result = new PathTransferResult(path);
if (!transfer.exists()) {
logger.debug("Transfer not exist, {}", transfer);
SpecialPathInfo pathInfo = specialPathManager.getSpecialPathInfo(transfer, tgt.getPackageType());
// i.e. it's something we would generate on demand for another file.
if (pathInfo != null && !pathInfo.isDecoratable()) {
logger.info("Skipping missing, not decoratable path: {}", transfer);
result.skipped = true;
return result;
}
if (promotionHelper.isRemoteTransfer(transfer)) {
// try re-download it for remote artifacts
transfer = promotionHelper.redownload(transfer);
}
if (transfer == null || !transfer.exists()) {
String msg = String.format("Failed to promote: %s. Source file not exists.", transfer);
logger.info(msg);
result.error = msg;
return result;
}
}
Transfer target = contentManager.getTransfer(tgt, path, UPLOAD);
EventMetadata eventMetadata = new EventMetadata().set(IGNORE_READONLY, true);
/*
* if we hit an existing metadata.xml, we remove it from both target repo and affected groups. The metadata
* will be regenerated on next request.
*/
SpecialPathInfo pathInfo = specialPathManager.getSpecialPathInfo(target, tgt.getPackageType());
if (pathInfo != null && pathInfo.isMetadata()) {
try {
if (target != null && target.exists()) {
contentManager.delete(tgt, path, eventMetadata);
}
result.skipped = true;
logger.info("Metadata, mark as skipped and remove it if exists, target: {}", target);
} catch (IndyWorkflowException e) {
String msg = String.format("Failed to promote metadata: %s. Target: %s. Error: %s", transfer, request.getTarget(), e.getMessage());
logger.error(msg, e);
result.error = msg;
}
return result;
}
if (target != null && target.exists()) {
/*
* e.g., fail in case of promotion of built artifacts into pnc-builds while it should pass (skip them)
* in case of promotion of dependencies into shared-imports.
*/
if (request.isFailWhenExists()) {
String msg = String.format("Failed to promote: %s. Target: %s. Target file already exists.", transfer, request.getTarget());
logger.info(msg);
result.error = msg;
} else {
result.skipped = true;
}
return result;
}
logger.debug("Store target transfer: {}", target);
eventMetadata.set(AFFECTED_GROUPS, new ValuePipe<>(affectedGroups)).set(TARGET_STORE, tgt);
try (InputStream stream = transfer.openInputStream(true)) {
contentManager.store(tgt, path, stream, UPLOAD, eventMetadata);
} catch (final IOException e) {
String msg = String.format("Failed to promote: %s. Error: %s", transfer, e.getMessage());
result.error = msg;
logger.error(msg, e);
}
logger.info("Promotion transfer completed, target: {}, path: {}, timeInMillSeconds: {}", tgt.getKey(), path, timeInMillSeconds(begin));
return result;
}
Aggregations