Search in sources :

Example 21 with FileReference

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

the class FileDownloader method queueForAsyncDownload.

public synchronized Future<Optional<File>> queueForAsyncDownload(FileReferenceDownload fileReferenceDownload, Duration timeout) {
    FileReference fileReference = fileReferenceDownload.fileReference();
    Future<Optional<File>> inProgress = fileReferenceDownloader.addDownloadListener(fileReference, () -> getFile(fileReferenceDownload));
    if (inProgress != null) {
        log.log(LogLevel.DEBUG, () -> "Already downloading '" + fileReference.value() + "'");
        return inProgress;
    }
    Future<Optional<File>> future = queueForAsyncDownload(fileReferenceDownload);
    log.log(LogLevel.DEBUG, () -> "Queued '" + fileReference.value() + "' for download with timeout " + timeout);
    return future;
}
Also used : Optional(java.util.Optional) FileReference(com.yahoo.config.FileReference)

Example 22 with FileReference

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

the class FileReceiverTest method receiveCompressedParts.

@Test
public void receiveCompressedParts() throws IOException {
    File dirWithFiles = temporaryFolder.newFolder("files");
    FileWriter writerA = new FileWriter(new File(dirWithFiles, "a"));
    writerA.write("1");
    writerA.close();
    FileWriter writerB = new FileWriter(new File(dirWithFiles, "b"));
    writerB.write("2");
    writerB.close();
    byte[] data = CompressedFileReference.compress(dirWithFiles);
    transferCompressedData(new FileReference("ref"), "a", data);
    File downloadDir = new File(root, "ref");
    assertEquals("1", IOUtils.readFile(new File(downloadDir, "a")));
    assertEquals("2", IOUtils.readFile(new File(downloadDir, "b")));
}
Also used : FileWriter(java.io.FileWriter) FileReference(com.yahoo.config.FileReference) File(java.io.File) Test(org.junit.Test)

Example 23 with FileReference

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

the class FileReceiverTest method receiveMultiPartFile.

@Test
public void receiveMultiPartFile() throws IOException {
    String[] parts = new String[3];
    parts[0] = "first part\n";
    parts[1] = "second part\n";
    parts[2] = "third part\n";
    StringBuilder sb = new StringBuilder();
    for (String s : parts) {
        sb.append(s);
    }
    String all = sb.toString();
    transferPartsAndAssert(new FileReference("ref-a"), "myfile-1", all, 1);
    transferPartsAndAssert(new FileReference("ref-a"), "myfile-2", all, 2);
    transferPartsAndAssert(new FileReference("ref-a"), "myfile-3", all, 3);
}
Also used : FileReference(com.yahoo.config.FileReference) Test(org.junit.Test)

Example 24 with FileReference

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

the class BundleLoader method retainOnly.

/**
 * Returns the number of uninstalled bundles
 */
private int retainOnly(List<FileReference> newReferences) {
    Set<Bundle> bundlesToRemove = new HashSet<>(Arrays.asList(osgi.getBundles()));
    for (FileReference fileReferenceToKeep : newReferences) {
        if (reference2Bundles.containsKey(fileReferenceToKeep))
            bundlesToRemove.removeAll(reference2Bundles.get(fileReferenceToKeep));
    }
    bundlesToRemove.removeAll(initialBundles);
    for (Bundle bundle : bundlesToRemove) {
        log.info("Removing bundle '" + bundle.toString() + "'");
        osgi.uninstall(bundle);
    }
    Set<FileReference> fileReferencesToRemove = new HashSet<>(reference2Bundles.keySet());
    fileReferencesToRemove.removeAll(newReferences);
    for (FileReference fileReferenceToRemove : fileReferencesToRemove) {
        reference2Bundles.remove(fileReferenceToRemove);
    }
    return bundlesToRemove.size();
}
Also used : Bundle(org.osgi.framework.Bundle) FileReference(com.yahoo.config.FileReference) HashSet(java.util.HashSet)

Example 25 with FileReference

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

the class ContainerTestBase method complete.

public void complete() {
    try {
        Container container = new Container(new CloudSubscriberFactory(dirConfigSource().configSource()), dirConfigSource().configId(), new ContainerTest.TestDeconstructor(), new Osgi() {

            @SuppressWarnings("unchecked")
            @Override
            public Class<Object> resolveClass(BundleInstantiationSpecification spec) {
                try {
                    return (Class<Object>) Class.forName(spec.classId.getName());
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public BundleClasses getBundleClasses(ComponentSpecification bundle, Set<String> packagesToScan) {
                throw new UnsupportedOperationException("getBundleClasses not supported");
            }

            @Override
            public void useBundles(Collection<FileReference> bundles) {
            }

            @Override
            public Bundle getBundle(ComponentSpecification spec) {
                throw new UnsupportedOperationException("getBundle not supported.");
            }
        });
        componentGraph = container.runOnce(componentGraph, Guice.createInjector());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Osgi(com.yahoo.container.di.Osgi) ComponentSpecification(com.yahoo.component.ComponentSpecification) Bundle(org.osgi.framework.Bundle) CloudSubscriberFactory(com.yahoo.container.di.CloudSubscriberFactory) BundleInstantiationSpecification(com.yahoo.container.bundle.BundleInstantiationSpecification) ContainerTest(com.yahoo.container.di.ContainerTest) Container(com.yahoo.container.di.Container) FileReference(com.yahoo.config.FileReference)

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