Search in sources :

Example 26 with FileReference

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;
    });
}
Also used : FileReference(com.yahoo.config.FileReference)

Example 27 with FileReference

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;
    });
}
Also used : FileReference(com.yahoo.config.FileReference)

Example 28 with FileReference

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);
    }
}
Also used : ConfigBuilder(com.yahoo.config.ConfigBuilder) FileReference(com.yahoo.config.FileReference) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 29 with FileReference

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();
}
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 30 with FileReference

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));
    }
}
Also used : FileReference(com.yahoo.config.FileReference) CompressedFileReference(com.yahoo.vespa.filedistribution.CompressedFileReference) File(java.io.File)

Aggregations

FileReference (com.yahoo.config.FileReference)37 Test (org.junit.Test)10 File (java.io.File)9 Int32Value (com.yahoo.jrt.Int32Value)4 IOException (java.io.IOException)3 Bundle (org.osgi.framework.Bundle)3 StringValue (com.yahoo.jrt.StringValue)2 CompressedFileReference (com.yahoo.vespa.filedistribution.CompressedFileReference)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ByteBuffer (java.nio.ByteBuffer)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 Optional (java.util.Optional)2 ComponentSpecification (com.yahoo.component.ComponentSpecification)1 ConfigBuilder (com.yahoo.config.ConfigBuilder)1 ComponentInfo (com.yahoo.config.application.api.ComponentInfo)1 MockFileRegistry (com.yahoo.config.model.application.provider.MockFileRegistry)1 UserConfigRepo (com.yahoo.config.model.producer.UserConfigRepo)1 MockHosts (com.yahoo.config.model.test.MockHosts)1 BundleInstantiationSpecification (com.yahoo.container.bundle.BundleInstantiationSpecification)1 CloudSubscriberFactory (com.yahoo.container.di.CloudSubscriberFactory)1