Search in sources :

Example 11 with FileReference

use of com.yahoo.config.FileReference in project vespa by vespa-engine.

the class FileDirectory method addFile.

public FileReference addFile(File source) {
    try {
        Long hash = computeReference(source);
        FileReference reference = new FileReference(Long.toHexString(hash));
        return addFile(source, reference);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : IOException(java.io.IOException) FileReference(com.yahoo.config.FileReference)

Example 12 with FileReference

use of com.yahoo.config.FileReference in project vespa by vespa-engine.

the class FileDirectoryTest method requireThatFileReferenceWithFilesWorks.

@Test
public void requireThatFileReferenceWithFilesWorks() throws IOException {
    FileReference foo = createFile("foo");
    FileReference bar = createFile("bar");
    assertTrue(fileDirectory.getFile(foo).exists());
    assertEquals("ea315b7acac56246", foo.value());
    assertTrue(fileDirectory.getFile(bar).exists());
    assertEquals("2b8e97f15c854e1d", bar.value());
}
Also used : FileReference(com.yahoo.config.FileReference) Test(org.junit.Test)

Example 13 with FileReference

use of com.yahoo.config.FileReference in project vespa by vespa-engine.

the class BundleLoader method installWithFileDistribution.

private void installWithFileDistribution(List<FileReference> bundlesToInstall, FileAcquirer fileAcquirer) {
    for (FileReference reference : bundlesToInstall) {
        try {
            log.info("Installing bundle with reference '" + reference.value() + "'");
            List<Bundle> bundles = obtainBundles(reference, fileAcquirer);
            reference2Bundles.put(reference, bundles);
        } catch (Exception e) {
            throw new RuntimeException("Could not install bundle '" + reference + "'", e);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) FileReference(com.yahoo.config.FileReference)

Example 14 with FileReference

use of com.yahoo.config.FileReference in project vespa by vespa-engine.

the class FileDistributionRpcServer method getActiveFileReferencesStatus.

@SuppressWarnings({ "UnusedDeclaration" })
public final void getActiveFileReferencesStatus(Request req) {
    Map<FileReference, Double> downloadStatus = downloader.downloadStatus();
    String[] fileRefArray = new String[downloadStatus.keySet().size()];
    fileRefArray = downloadStatus.keySet().stream().map(FileReference::value).collect(Collectors.toList()).toArray(fileRefArray);
    double[] downloadStatusArray = new double[downloadStatus.values().size()];
    int i = 0;
    for (Double d : downloadStatus.values()) {
        downloadStatusArray[i++] = d;
    }
    req.returnValues().add(new StringArray(fileRefArray));
    req.returnValues().add(new DoubleArray(downloadStatusArray));
}
Also used : StringArray(com.yahoo.jrt.StringArray) FileReference(com.yahoo.config.FileReference) DoubleArray(com.yahoo.jrt.DoubleArray)

Example 15 with FileReference

use of com.yahoo.config.FileReference in project vespa by vespa-engine.

the class FileDistributionRpcServer method downloadFile.

private void downloadFile(Request req) {
    FileReference fileReference = new FileReference(req.parameters().get(0).asString());
    log.log(LogLevel.DEBUG, () -> "getFile() called for file reference '" + fileReference.value() + "'");
    Optional<File> pathToFile = downloader.getFile(fileReference);
    try {
        if (pathToFile.isPresent()) {
            req.returnValues().add(new StringValue(pathToFile.get().getAbsolutePath()));
            log.log(LogLevel.DEBUG, () -> "File reference '" + fileReference.value() + "' available at " + pathToFile.get());
        } else {
            log.log(LogLevel.INFO, "File reference '" + fileReference.value() + "' not found, returning error");
            req.setError(fileReferenceDoesNotExists, "File reference '" + fileReference.value() + "' not found");
        }
    } catch (Throwable e) {
        log.log(LogLevel.WARNING, "File reference '" + fileReference.value() + "' got exception: " + e.getMessage());
        req.setError(fileReferenceInternalError, "File reference '" + fileReference.value() + "' removed");
    }
    req.returnRequest();
}
Also used : FileReference(com.yahoo.config.FileReference) StringValue(com.yahoo.jrt.StringValue) 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