use of com.yahoo.vespa.filedistribution.FileReferenceDownload in project vespa by vespa-engine.
the class FileServer method serveFile.
private void serveFile(String fileReference, Request request, Receiver receiver) {
FileApiErrorCodes result;
try {
log.log(LogLevel.DEBUG, () -> "Received request for reference '" + fileReference + "' from " + request.target());
result = hasFile(fileReference) ? FileApiErrorCodes.OK : FileApiErrorCodes.NOT_FOUND;
if (result == FileApiErrorCodes.OK) {
startFileServing(fileReference, receiver);
} else {
// This is to avoid config servers asking each other for a file that does not exist
if (request.parameters().size() == 1 || request.parameters().get(1).asInt32() == 0) {
log.log(LogLevel.DEBUG, "File not found, downloading from another source");
downloader.getFile(new FileReferenceDownload(new FileReference(fileReference), false));
} else {
log.log(LogLevel.DEBUG, "File not found, will not download from another source since request came from another config server");
result = FileApiErrorCodes.NOT_FOUND;
}
}
} catch (IllegalArgumentException e) {
result = FileApiErrorCodes.NOT_FOUND;
log.warning("Failed serving file reference '" + fileReference + "', request was from " + request.target() + ", with error " + e.toString());
}
request.returnValues().add(new Int32Value(result.getCode())).add(new StringValue(result.getDescription()));
request.returnRequest();
}
use of com.yahoo.vespa.filedistribution.FileReferenceDownload in project vespa by vespa-engine.
the class RpcServer method setFileReferencesToDownload.
@SuppressWarnings({ "UnusedDeclaration" })
public final void setFileReferencesToDownload(Request req) {
String[] fileReferenceStrings = req.parameters().get(0).asStringArray();
Stream.of(fileReferenceStrings).map(FileReference::new).forEach(fileReference -> downloader.queueForAsyncDownload(new FileReferenceDownload(fileReference, false)));
req.returnValues().add(new Int32Value(0));
}
Aggregations