Search in sources :

Example 91 with Slime

use of com.yahoo.slime.Slime in project vespa by vespa-engine.

the class JSONString method inspect.

public Inspector inspect() {
    if (value == null) {
        JsonDecoder decoder = new JsonDecoder();
        Slime slime = decoder.decode(new Slime(), Utf8.toBytes(content));
        if (slime.get().field("error_message").valid() && slime.get().field("partial_result").valid() && slime.get().field("offending_input").valid()) {
            // probably a json parse error...
            value = new Value.StringValue(content);
        } else if (slime.get().type() == com.yahoo.slime.Type.OBJECT || slime.get().type() == com.yahoo.slime.Type.ARRAY) {
            // valid json object or array
            value = new SlimeAdapter(slime.get());
        } else {
            // 'valid' json, but leaf value
            value = new Value.StringValue(content);
        }
    }
    return value;
}
Also used : JsonDecoder(com.yahoo.slime.JsonDecoder) SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) Value(com.yahoo.data.access.simple.Value) Slime(com.yahoo.slime.Slime)

Example 92 with Slime

use of com.yahoo.slime.Slime in project vespa by vespa-engine.

the class DocsumDefinitionSet method lazyDecode.

/**
 * Makes data available for decoding for the given hit.
 *
 * @param summaryClass the requested summary class
 * @param data docsum data from backend
 * @param hit the Hit corresponding to this document summary
 * @return Error message or null on success.
 * @throws ConfigurationException if the summary class of this hit is missing
 */
public final String lazyDecode(String summaryClass, byte[] data, FastHit hit) {
    ByteBuffer buffer = ByteBuffer.wrap(data);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    long docsumClassId = buffer.getInt();
    if (docsumClassId != SLIME_MAGIC_ID) {
        throw new IllegalArgumentException("Only expecting SchemaLess docsums - summary class:" + summaryClass + " hit:" + hit);
    }
    DocsumDefinition docsumDefinition = lookupDocsum(summaryClass);
    Slime value = BinaryFormat.decode(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    Inspector docsum = new SlimeAdapter(value.get());
    if (docsum.type() != OBJECT) {
        return "Hit " + hit + " failed: " + docsum.asString();
    }
    hit.addSummary(docsumDefinition, docsum);
    return null;
}
Also used : SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) Inspector(com.yahoo.data.access.Inspector) Slime(com.yahoo.slime.Slime) ByteBuffer(java.nio.ByteBuffer)

Example 93 with Slime

use of com.yahoo.slime.Slime in project vespa by vespa-engine.

the class ConfigTester method createConfigPayload.

static ConfigPayload createConfigPayload(String key, String value) {
    Slime slime = new Slime();
    slime.setObject().setString(key, value);
    return new ConfigPayload(slime);
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Slime(com.yahoo.slime.Slime)

Example 94 with Slime

use of com.yahoo.slime.Slime in project vespa by vespa-engine.

the class SessionHandler method createDeployLog.

// TODO: Refactor to use the one in ApplicationRepository and remove
protected Slime createDeployLog() {
    Slime deployLog = new Slime();
    deployLog.setObject();
    return deployLog;
}
Also used : Slime(com.yahoo.slime.Slime)

Example 95 with Slime

use of com.yahoo.slime.Slime in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method test_application_lock_failure.

@Test
public void test_application_lock_failure() throws InterruptedException, IOException {
    String message = "Timed out after waiting PT1M to acquire lock '/provision/v1/locks/foo/bar/default'";
    SessionThrowingException session = new SessionThrowingException(new ApplicationLockException(new UncheckedTimeoutException(message)));
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertEquals(500, response.getStatus());
    Slime data = getData(response);
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.APPLICATION_LOCK_FAILURE.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) ApplicationLockException(com.yahoo.config.provision.ApplicationLockException) Test(org.junit.Test)

Aggregations

Slime (com.yahoo.slime.Slime)131 Cursor (com.yahoo.slime.Cursor)76 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)22 DefParser (com.yahoo.config.codegen.DefParser)14 InnerCNode (com.yahoo.config.codegen.InnerCNode)14 StringReader (java.io.StringReader)14 JsonFormat (com.yahoo.slime.JsonFormat)10 ApplicationId (com.yahoo.config.provision.ApplicationId)9 Inspector (com.yahoo.slime.Inspector)9 Application (com.yahoo.vespa.hosted.controller.Application)9 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)8 IOException (java.io.IOException)8 Version (com.yahoo.component.Version)7 JsonDecoder (com.yahoo.slime.JsonDecoder)6 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)6 HttpResponse (com.yahoo.container.jdisc.HttpResponse)5 DeployLogger (com.yahoo.config.application.api.DeployLogger)4 TenantName (com.yahoo.config.provision.TenantName)4