Search in sources :

Example 16 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method post_with_patch_method_override_in_header_is_handled_as_patch.

@Test
public void post_with_patch_method_override_in_header_is_handled_as_patch() throws Exception {
    Request req = new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentRestartGeneration\": 1}"), Request.Method.POST);
    req.getHeaders().add("X-HTTP-Method-Override", "PATCH");
    assertResponse(req, "{\"message\":\"Updated host4.yahoo.com\"}");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 17 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method post_with_invalid_method_override_in_header_gives_sane_error_message.

@Test
public void post_with_invalid_method_override_in_header_gives_sane_error_message() throws Exception {
    Request req = new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentRestartGeneration\": 1}"), Request.Method.POST);
    req.getHeaders().add("X-HTTP-Method-Override", "GET");
    assertResponse(req, 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Illegal X-HTTP-Method-Override header for POST request. Accepts 'PATCH' but got 'GET'\"}");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 18 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method acl_request_by_tenant_node.

@Test
public void acl_request_by_tenant_node() throws Exception {
    String hostname = "foo.yahoo.com";
    assertResponse(new Request("http://localhost:8080/nodes/v2/node", ("[" + asNodeJson(hostname, "default") + "]").getBytes(StandardCharsets.UTF_8), Request.Method.POST), "{\"message\":\"Added 1 nodes to the provisioned state\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/" + hostname, new byte[0], Request.Method.PUT), "{\"message\":\"Moved foo.yahoo.com to dirty\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/" + hostname, new byte[0], Request.Method.PUT), "{\"message\":\"Moved foo.yahoo.com to ready\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/acl/" + hostname), "acl-tenant-node.json");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 19 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method test_invalid_requests.

@Test
public void test_invalid_requests() throws Exception {
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/node-does-not-exist", new byte[0], Request.Method.GET), 404, "{\"error-code\":\"NOT_FOUND\",\"message\":\"No node with hostname 'node-does-not-exist'\"}");
    // Attempt to fail and ready an allocated node without going through dirty
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/node-does-not-exist", new byte[0], Request.Method.PUT), 404, "{\"error-code\":\"NOT_FOUND\",\"message\":\"Could not move node-does-not-exist to failed: Node not found\"}");
    // Attempt to fail and ready an allocated node without going through dirty
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host1.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host1.yahoo.com to failed\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host1.yahoo.com", new byte[0], Request.Method.PUT), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Can not set failed node host1.yahoo.com allocated to tenant1.application1.instance1 as 'container/id1/0/0' ready. It is not dirty.\"}");
    // (... while dirty then ready works (the ready move will be initiated by node maintenance))
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/host1.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host1.yahoo.com to dirty\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host1.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host1.yahoo.com to ready\"}");
    // Attempt to park and ready an allocated node without going through dirty
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/parked/host2.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host2.yahoo.com to parked\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host2.yahoo.com", new byte[0], Request.Method.PUT), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Can not set parked node host2.yahoo.com allocated to tenant2.application2.instance2 as 'content/id2/0/0' ready. It is not dirty.\"}");
    // (... while dirty then ready works (the ready move will be initiated by node maintenance))
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/host2.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host2.yahoo.com to dirty\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host2.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host2.yahoo.com to ready\"}");
    // Attempt to DELETE a node which is not put in a deletable state first
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com", new byte[0], Request.Method.DELETE), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Failed to delete host2.yahoo.com: Node host2.yahoo.com can only be removed from following states: provisioned, failed, parked\"}");
    // PUT current restart generation with string instead of long
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentRestartGeneration\": \"1\"}"), Request.Method.PATCH), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set field 'currentRestartGeneration': Expected a LONG value, got a STRING\"}");
    // PUT flavor with long instead of string
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"flavor\": 1}"), Request.Method.PATCH), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set field 'flavor': Expected a STRING value, got a LONG\"}");
    // Attempt to set unallocated node active
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/active/host2.yahoo.com", new byte[0], Request.Method.PUT), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set host2.yahoo.com active. It has no allocation.\"}");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 20 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class JDiscContainerRequestTest method requireThatRequestHandlerThatThrowsDelayedInWriteWorks.

@Test(expected = DelayedWriteException.class)
public void requireThatRequestHandlerThatThrowsDelayedInWriteWorks() throws InterruptedException {
    String DATA = "we have no bananas today";
    Request req = new Request("http://banana/delayedthrowwrite", DATA.getBytes(Utf8.getCharset()));
    try (JDisc container = JDisc.fromServicesXml(getXML(DelayedThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/delayedthrowwrite"), Networking.disable)) {
        Response response = container.handleRequest(req);
        req.toString();
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Aggregations

Request (com.yahoo.application.container.handler.Request)46 Test (org.junit.Test)44 StringContains.containsString (org.hamcrest.core.StringContains.containsString)17 HttpGet (org.apache.http.client.methods.HttpGet)14 Response (com.yahoo.application.container.handler.Response)7 StringEntity (org.apache.http.entity.StringEntity)7 HttpPut (org.apache.http.client.methods.HttpPut)4 HttpPost (org.apache.http.client.methods.HttpPost)3 Application (com.yahoo.vespa.hosted.controller.Application)2 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)2 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)2 HttpResponse (org.apache.http.HttpResponse)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 MockHttpHandler (com.yahoo.application.container.handlers.MockHttpHandler)1 MockRenderer (com.yahoo.application.container.renderers.MockRenderer)1 Version (com.yahoo.component.Version)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 DiscFilterRequest (com.yahoo.jdisc.http.filter.DiscFilterRequest)1 ServletOrJdiscHttpRequest (com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest)1