Search in sources :

Example 6 with FileReference

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

the class FileDistributorTestCase method fileDistributor.

@Test
public void fileDistributor() {
    MockHosts hosts = new MockHosts();
    FileDistributor fileDistributor = new FileDistributor(new MockFileRegistry(), null);
    String file1 = "component/path1";
    String file2 = "component/path2";
    FileReference ref1 = fileDistributor.sendFileToHosts(file1, Arrays.asList(hosts.host1, hosts.host2));
    FileReference ref2 = fileDistributor.sendFileToHosts(file2, Arrays.asList(hosts.host3));
    assertEquals(new HashSet<>(Arrays.asList(hosts.host1, hosts.host2, hosts.host3)), fileDistributor.getTargetHosts());
    assertTrue(ref1 != null);
    assertTrue(ref2 != null);
    MockFileDistribution dbHandler = new MockFileDistribution();
    fileDistributor.sendDeployedFiles(dbHandler);
    // One time for each host
    assertEquals(3, dbHandler.filesToDownloadCalled);
}
Also used : MockHosts(com.yahoo.config.model.test.MockHosts) FileReference(com.yahoo.config.FileReference) MockFileRegistry(com.yahoo.config.model.application.provider.MockFileRegistry) Test(org.junit.Test)

Example 7 with FileReference

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

the class ConfigPayloadApplier method isPathField.

private boolean isPathField(Object builder, String methodName) {
    String key = pathFieldKey(builder, methodName);
    if (pathFieldSet.contains(key)) {
        return true;
    }
    boolean isPath = false;
    try {
        Field field = builder.getClass().getDeclaredField(methodName);
        // Paths are stored as FileReference in Builder.
        java.lang.reflect.Type fieldType = field.getGenericType();
        if (fieldType instanceof Class<?> && fieldType == FileReference.class) {
            isPath = true;
        } else if (fieldType instanceof ParameterizedType) {
            isPath = isParameterizedWithPath((ParameterizedType) fieldType);
        }
    } catch (NoSuchFieldException e) {
    }
    if (isPath) {
        pathFieldSet.add(key);
    }
    return isPath;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) FileReference(com.yahoo.config.FileReference)

Example 8 with FileReference

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

the class ConfigPayloadApplier method setValueForLeafNode.

// Sets values for leaf nodes (uses private accessors that take string as argument)
private void setValueForLeafNode(Object builder, String methodName, Inspector value) {
    try {
        // Need to convert reference into actual path if 'path' type is used
        if (isPathField(builder, methodName)) {
            FileReference wrappedPath = resolvePath(Utf8.toString(value.asUtf8()));
            invokeSetter(builder, methodName, wrappedPath);
        } else {
            Object object = getValueFromInspector(value);
            invokeSetter(builder, methodName, object);
        }
    } catch (InvocationTargetException | IllegalAccessException e) {
        throw new RuntimeException("Name: " + methodName + ", value '" + value + "'", e);
    } catch (NoSuchMethodException e) {
        log.log(LogLevel.INFO, "Skipping unknown field " + methodName + " in " + builder.getClass());
    }
}
Also used : FileReference(com.yahoo.config.FileReference) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with FileReference

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

the class FileDBRegistry method addUri.

public synchronized FileReference addUri(String uri, FileReference reference) {
    String relativePath = uriToRelativeFile(uri);
    Optional<FileReference> cachedReference = Optional.ofNullable(fileReferenceCache.get(uri));
    return cachedReference.orElseGet(() -> {
        FileReference newRef = manager.addUri(uri, relativePath, reference);
        entries.add(new Entry(uri, newRef));
        fileReferenceCache.put(uri, newRef);
        return newRef;
    });
}
Also used : FileReference(com.yahoo.config.FileReference)

Example 10 with FileReference

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

the class FileDBRegistry method addFile.

public synchronized FileReference addFile(String relativePath, FileReference reference) {
    Optional<FileReference> cachedReference = Optional.ofNullable(fileReferenceCache.get(relativePath));
    return cachedReference.orElseGet(() -> {
        FileReference newRef = manager.addFile(relativePath, reference);
        entries.add(new Entry(relativePath, newRef));
        fileReferenceCache.put(relativePath, newRef);
        return newRef;
    });
}
Also used : 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