Search in sources :

Example 1 with FileReferenceDownload

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();
}
Also used : FileReferenceDownload(com.yahoo.vespa.filedistribution.FileReferenceDownload) Int32Value(com.yahoo.jrt.Int32Value) FileReference(com.yahoo.config.FileReference) CompressedFileReference(com.yahoo.vespa.filedistribution.CompressedFileReference) StringValue(com.yahoo.jrt.StringValue)

Example 2 with FileReferenceDownload

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));
}
Also used : FileReferenceDownload(com.yahoo.vespa.filedistribution.FileReferenceDownload) Int32Value(com.yahoo.jrt.Int32Value)

Aggregations

Int32Value (com.yahoo.jrt.Int32Value)2 FileReferenceDownload (com.yahoo.vespa.filedistribution.FileReferenceDownload)2 FileReference (com.yahoo.config.FileReference)1 StringValue (com.yahoo.jrt.StringValue)1 CompressedFileReference (com.yahoo.vespa.filedistribution.CompressedFileReference)1