use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileDBRegistry method addFile.
@Override
public synchronized FileReference addFile(String relativePath) {
Optional<FileReference> cachedReference = Optional.ofNullable(fileReferenceCache.get(relativePath));
return cachedReference.orElseGet(() -> {
FileReference newRef = manager.addFile(relativePath);
entries.add(new Entry(relativePath, newRef));
fileReferenceCache.put(relativePath, newRef);
return newRef;
});
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class FileDBRegistry method addUri.
@Override
public synchronized FileReference addUri(String uri) {
String relativePath = uriToRelativeFile(uri);
Optional<FileReference> cachedReference = Optional.ofNullable(fileReferenceCache.get(uri));
return cachedReference.orElseGet(() -> {
FileReference newRef = manager.addUri(uri, relativePath);
entries.add(new Entry(uri, newRef));
fileReferenceCache.put(uri, newRef);
return newRef;
});
}
use of com.yahoo.config.FileReference in project vespa by vespa-engine.
the class ConfigPayloadApplier method setMapLeafValue.
private void setMapLeafValue(String key, Object value) {
NamedBuilder parent = stack.peek();
ConfigBuilder builder = parent.builder();
String methodName = parent.peekName();
// trace("class to obtain method from: " + builder.getClass().getName());
try {
// Need to convert reference into actual path if 'path' type is used
if (isPathField(builder, methodName)) {
FileReference wrappedPath = resolvePath((String) value);
invokeSetter(builder, methodName, key, wrappedPath);
} else {
invokeSetter(builder, methodName, key, value);
}
} catch (InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Name: " + methodName + ", value '" + value + "'", e);
} catch (NoSuchMethodException e) {
log.log(LogLevel.INFO, "Skipping unknown field " + methodName + " in " + rootBuilder);
}
}
use of com.yahoo.config.FileReference 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.config.FileReference in project vespa by vespa-engine.
the class FileServer method startFileServing.
public void startFileServing(String fileName, Receiver target) {
FileReference reference = new FileReference(fileName);
File file = root.getFile(reference);
if (file.exists()) {
pushExecutor.execute(() -> serveFile(reference, target));
}
}
Aggregations