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);
}
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;
}
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());
}
}
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;
});
}
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;
});
}
Aggregations