Search in sources :

Example 31 with Slime

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

the class PayloadTest method testEquals.

@Test
public void testEquals() {
    final String foo1 = "foo 1";
    final String foo2 = "foo 2";
    Payload a = Payload.from(foo1);
    Payload b = Payload.from(foo1);
    Payload c = Payload.from(foo2);
    Slime slime = new Slime();
    slime.setString(foo1);
    Payload d = Payload.from(new ConfigPayload(slime));
    slime.setString(foo1);
    Payload e = Payload.from(new ConfigPayload(slime));
    slime.setString("foo 2");
    Payload f = Payload.from(new ConfigPayload(slime));
    Payload g = null;
    Payload h = null;
    Payload i = null;
    Payload j = null;
    try {
        g = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        h = Payload.from(new Utf8Array(foo1.getBytes("UTF-8")), CompressionInfo.uncompressed());
        LZ4PayloadCompressor compressor = new LZ4PayloadCompressor();
        CompressionInfo info = CompressionInfo.create(CompressionType.LZ4, foo2.length());
        Utf8Array compressed = new Utf8Array(compressor.compress(foo2.getBytes()));
        i = Payload.from(compressed, info);
        j = Payload.from(compressed, info);
    } catch (UnsupportedEncodingException e1) {
        fail();
    }
    new EqualsTester().addEqualityGroup(a, b, g, h).addEqualityGroup(c).addEqualityGroup(d, e).addEqualityGroup(f).addEqualityGroup(i, j).testEquals();
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) EqualsTester(com.google.common.testing.EqualsTester) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Slime(com.yahoo.slime.Slime) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 32 with Slime

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

the class ApplicationApiHandler method handlePOST.

@Override
protected HttpResponse handlePOST(HttpRequest request) {
    Tenant tenant = getExistingTenant(request);
    TenantName tenantName = tenant.getName();
    TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
    PrepareParams prepareParams = PrepareParams.fromHttpRequest(request, tenantName, zookeeperBarrierTimeout);
    Slime deployLog = createDeployLog();
    DeployLogger logger = SessionCreateHandler.createLogger(request, deployLog, tenantName);
    String name = SessionCreateHandler.getNameProperty(request, logger);
    SessionCreateHandler.validateDataAndHeader(request);
    PrepareResult result = applicationRepository.createSessionAndPrepareAndActivate(tenant, request.getData(), request.getHeader(contentTypeHeader), timeoutBudget, name, prepareParams, shouldIgnoreLockFailure(request), shouldIgnoreSessionStaleFailure(request), Instant.now());
    return new SessionPrepareAndActivateResponse(result, tenantName, request, prepareParams.getApplicationId(), zone);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) DeployLogger(com.yahoo.config.application.api.DeployLogger) Slime(com.yahoo.slime.Slime) PrepareParams(com.yahoo.vespa.config.server.session.PrepareParams)

Example 33 with Slime

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

the class SessionCreateHandler method handlePOST.

@Override
protected HttpResponse handlePOST(HttpRequest request) {
    Slime deployLog = createDeployLog();
    final TenantName tenantName = Utils.getTenantNameFromSessionRequest(request);
    Utils.checkThatTenantExists(tenants, tenantName);
    Tenant tenant = tenants.getTenant(tenantName);
    TimeoutBudget timeoutBudget = SessionHandler.getTimeoutBudget(request, zookeeperBarrierTimeout);
    DeployLogger logger = createLogger(request, deployLog, tenantName);
    long sessionId;
    if (request.hasProperty("from")) {
        ApplicationId applicationId = getFromApplicationId(request);
        sessionId = applicationRepository.createSessionFromExisting(tenant, logger, timeoutBudget, applicationId);
    } else {
        validateDataAndHeader(request);
        String name = getNameProperty(request, logger);
        sessionId = applicationRepository.createSession(tenant, timeoutBudget, request.getData(), request.getHeader(ApplicationApiHandler.contentTypeHeader), name);
    }
    return createResponse(request, tenantName, deployLog, sessionId);
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) TenantName(com.yahoo.config.provision.TenantName) TimeoutBudget(com.yahoo.vespa.config.server.TimeoutBudget) DeployLogger(com.yahoo.config.application.api.DeployLogger) Slime(com.yahoo.slime.Slime) ApplicationId(com.yahoo.config.provision.ApplicationId)

Example 34 with Slime

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

the class SessionPrepareHandlerTest method test_that_nullpointerexception_gives_internal_server_error.

@Test
public void test_that_nullpointerexception_gives_internal_server_error() throws InterruptedException, IOException {
    String message = "No nodes available";
    SessionThrowingException session = new SessionThrowingException(new NullPointerException(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.INTERNAL_SERVER_ERROR.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) Test(org.junit.Test)

Example 35 with Slime

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

the class SessionPrepareHandlerTest method test_out_of_capacity_response.

@Test
public void test_out_of_capacity_response() throws InterruptedException, IOException {
    String message = "Internal error";
    SessionThrowingException session = new SessionThrowingException(new OutOfCapacityException(message));
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertEquals(400, response.getStatus());
    Slime data = getData(response);
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.OUT_OF_CAPACITY.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) 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