Search in sources :

Example 16 with Inspector

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser)

Example 17 with Inspector

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);
        }
    }
}
Also used : ObjectTraverser(com.yahoo.slime.ObjectTraverser) Inspector(com.yahoo.slime.Inspector) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with Inspector

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);
        }
    });
}
Also used : Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser)

Example 19 with 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);
}
Also used : JsonDecoder(com.yahoo.slime.JsonDecoder) ArrayList(java.util.ArrayList) Inspector(com.yahoo.slime.Inspector) Slime(com.yahoo.slime.Slime)

Example 20 with Inspector

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));
}
Also used : Cursor(com.yahoo.slime.Cursor) BinaryFormat(com.yahoo.slime.BinaryFormat) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) HashMap(java.util.HashMap) Compressor(com.yahoo.compress.Compressor) FastHit(com.yahoo.prelude.fastsearch.FastHit) ArrayList(java.util.ArrayList) List(java.util.List) CompressionType(com.yahoo.compress.CompressionType) Map(java.util.Map) GlobalId(com.yahoo.document.GlobalId) ArrayList(java.util.ArrayList) Compressor(com.yahoo.compress.Compressor) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) GlobalId(com.yahoo.document.GlobalId) Inspector(com.yahoo.slime.Inspector) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Inspector (com.yahoo.slime.Inspector)27 ArrayTraverser (com.yahoo.slime.ArrayTraverser)10 Slime (com.yahoo.slime.Slime)10 IOException (java.io.IOException)6 Cursor (com.yahoo.slime.Cursor)4 SlimeUtils (com.yahoo.vespa.config.SlimeUtils)4 CompressionType (com.yahoo.compress.CompressionType)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 JsonDecoder (com.yahoo.slime.JsonDecoder)3 Tenant (com.yahoo.vespa.hosted.controller.api.Tenant)3 TenantId (com.yahoo.vespa.hosted.controller.api.identifiers.TenantId)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Version (com.yahoo.component.Version)2 ObjectTraverser (com.yahoo.slime.ObjectTraverser)2 Utf8Array (com.yahoo.text.Utf8Array)2 AthenzDomain (com.yahoo.vespa.athenz.api.AthenzDomain)2 Change (com.yahoo.vespa.hosted.controller.application.Change)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2