use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ProvisionInfo method fromSlime.
private static ProvisionInfo fromSlime(Inspector inspector, Optional<NodeFlavors> nodeFlavors) {
Inspector array = inspector.field(mappingKey);
Set<HostSpec> hosts = new LinkedHashSet<>();
array.traverse(new ArrayTraverser() {
@Override
public void entry(int i, Inspector inspector) {
hosts.add(hostsFromSlime(inspector.field(hostSpecKey), nodeFlavors));
}
});
return new ProvisionInfo(hosts);
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ConfigPayloadApplier method handleOBJECT.
private void handleOBJECT(Inspector inspector) {
trace("Object");
printStack();
inspector.traverse(new ObjectTraverser() {
@Override
public void field(String name, Inspector inspector) {
handleObjectEntry(name, inspector);
}
});
trace("Should pop a builder from stack");
NamedBuilder builder = stack.pop();
printStack();
// Need to set e.g struct(Struct.Builder) here
if (!stack.empty()) {
trace("builder= " + builder);
try {
invokeSetter(stack.peek().builder, builder.peekName(), builder.builder);
} catch (Exception e) {
throw new RuntimeException("Could not set '" + builder.peekName() + "' for value '" + builder.builder() + "'", e);
}
}
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ConfigPayloadApplier method handleARRAY.
private void handleARRAY(Inspector inspector) {
trace("Array");
inspector.traverse(new ArrayTraverser() {
@Override
public void entry(int idx, Inspector inspector) {
handleArrayEntry(idx, inspector);
}
});
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class ProjectBundleClassPaths method load.
static ProjectBundleClassPaths load(byte[] bytes) {
Slime slime = new Slime();
new JsonDecoder().decode(slime, bytes);
Inspector inspector = slime.get();
BundleClasspathMapping mainBundle = BundleClasspathMapping.load(inspector.field("mainBundle"));
Inspector dependenciesInspector = inspector.field("providedDependencies");
List<BundleClasspathMapping> providedDependencies = new ArrayList<>();
for (int i = 0; i < dependenciesInspector.entries(); i++) {
providedDependencies.add(BundleClasspathMapping.load(dependenciesInspector.entry(i)));
}
return new ProjectBundleClassPaths(mainBundle, providedDependencies);
}
use of com.yahoo.slime.Inspector in project vespa by vespa-engine.
the class MockClient method getDocsums.
@Override
public void getDocsums(List<FastHit> hitsContext, NodeConnection node, CompressionType compression, int uncompressedSize, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
if (malfunctioning) {
responseReceiver.receive(GetDocsumsResponseOrError.fromError("Malfunctioning"));
return;
}
Inspector request = BinaryFormat.decode(compressor.decompress(compressedSlime, compression, uncompressedSize)).get();
String docsumClass = request.field("class").asString();
List<Map<String, Object>> docsumsToReturn = new ArrayList<>();
request.field("gids").traverse((ArrayTraverser) (index, gid) -> {
GlobalId docId = new GlobalId(gid.asData());
docsumsToReturn.add(docsums.get(new DocsumKey(node.toString(), docId, docsumClass)));
});
Slime responseSlime = new Slime();
Cursor root = responseSlime.setObject();
Cursor docsums = root.setArray("docsums");
for (Map<String, Object> docsumFields : docsumsToReturn) {
Cursor docsumItem = docsums.addObject();
Cursor docsum = docsumItem.setObject("docsum");
for (Map.Entry<String, Object> field : docsumFields.entrySet()) {
if (field.getValue() instanceof Integer)
docsum.setLong(field.getKey(), (Integer) field.getValue());
else if (field.getValue() instanceof String)
docsum.setString(field.getKey(), (String) field.getValue());
else
throw new RuntimeException();
}
}
byte[] slimeBytes = BinaryFormat.encode(responseSlime);
Compressor.Compression compressionResult = compressor.compress(compression, slimeBytes);
GetDocsumsResponse response = new GetDocsumsResponse(compressionResult.type().getCode(), slimeBytes.length, compressionResult.data(), hitsContext);
responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response));
}
Aggregations