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