Search in sources :

Example 41 with Request

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

the class RestApiTest method test_hardware_patching_of_docker_host.

@Test
public void test_hardware_patching_of_docker_host() throws Exception {
    assertHardwareFailure(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com"), Optional.of(false));
    assertHardwareFailure(new Request("http://localhost:8080/nodes/v2/node/dockerhost2.yahoo.com"), Optional.of(false));
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost2.yahoo.com", Utf8.toBytes("{" + "\"hardwareFailureDescription\": \"memory_mcelog\"" + "}"), Request.Method.PATCH), "{\"message\":\"Updated dockerhost2.yahoo.com\"}");
    assertHardwareFailure(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com"), Optional.of(true));
    assertHardwareFailure(new Request("http://localhost:8080/nodes/v2/node/dockerhost2.yahoo.com"), Optional.of(true));
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 42 with Request

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

the class RestApiTest method patching_dirty_node_does_not_increase_reboot_generation.

@Test
public void patching_dirty_node_does_not_increase_reboot_generation() throws Exception {
    assertResponse(new Request("http://localhost:8080/nodes/v2/node", ("[" + asNodeJson("foo.yahoo.com", "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/failed/foo.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved foo.yahoo.com to failed\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/foo.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved foo.yahoo.com to dirty\"}");
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/foo.yahoo.com"), "\"rebootGeneration\":1");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/foo.yahoo.com", Utf8.toBytes("{\"currentRebootGeneration\": 42}"), Request.Method.PATCH), "{\"message\":\"Updated foo.yahoo.com\"}");
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/foo.yahoo.com"), "\"rebootGeneration\":1");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 43 with Request

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

the class RestApiTest method test_node_patch_to_remove_docker_ready_fields.

@Test
public void test_node_patch_to_remove_docker_ready_fields() throws Exception {
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com", Utf8.toBytes("{" + "\"currentVespaVersion\": \"\"," + "\"currentDockerImage\": \"\"" + "}"), Request.Method.PATCH), "{\"message\":\"Updated host5.yahoo.com\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com"), "node5-after-changes.json");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 44 with Request

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

the class RestApiTest method test_hardware_divergence_patching.

@Test
public void test_hardware_divergence_patching() throws Exception {
    // Add report
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com", Utf8.toBytes("{\"hardwareDivergence\": \"{\\\"actualCpuCores\\\":2}\"}"), Request.Method.PATCH), "{\"message\":\"Updated host6.yahoo.com\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com"), "node6-after-changes.json");
    // Empty report is rejected
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com", Utf8.toBytes("{\"hardwareDivergence\": \"\"}"), Request.Method.PATCH), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Could not set field 'hardwareDivergence': Hardware divergence must be non-empty, but was ''\"}");
    // Clear report
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com", Utf8.toBytes("{\"hardwareDivergence\": null}"), Request.Method.PATCH), "{\"message\":\"Updated host6.yahoo.com\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com"), "node6.json");
    // Clear on quoted "null" report
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com", Utf8.toBytes("{\"hardwareDivergence\": \"null\"}"), Request.Method.PATCH), "{\"message\":\"Updated host6.yahoo.com\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host6.yahoo.com"), "node6.json");
}
Also used : Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 45 with Request

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

the class RestApiTest method test_requests.

/**
 * This test gives examples of all the requests that can be made to nodes/v2
 */
@Test
public void test_requests() throws Exception {
    // GET
    assertFile(new Request("http://localhost:8080/nodes/v2/"), "root.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/state/"), "states.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/state/?recursive=true"), "states-recursive.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/state/active?recursive=true"), "active-nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/"), "nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true"), "nodes-recursive.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "node2.json");
    // GET with filters
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&hostname=host6.yahoo.com%20host2.yahoo.com"), "application2-nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterType=content"), "content-nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&clusterId=id2"), "application2-nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&application=tenant2.application2.instance2"), "application2-nodes.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/?recursive=true&parentHost=dockerhost1.yahoo.com"), "child-nodes.json");
    // POST restart command
    assertRestart(1, new Request("http://localhost:8080/nodes/v2/command/restart?hostname=host2.yahoo.com", new byte[0], Request.Method.POST));
    assertRestart(2, new Request("http://localhost:8080/nodes/v2/command/restart?application=tenant2.application2.instance2", new byte[0], Request.Method.POST));
    assertRestart(9, new Request("http://localhost:8080/nodes/v2/command/restart", new byte[0], Request.Method.POST));
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "\"restartGeneration\":3");
    // POST reboot command
    assertReboot(10, new Request("http://localhost:8080/nodes/v2/command/reboot?state=failed%20active", new byte[0], Request.Method.POST));
    assertReboot(2, new Request("http://localhost:8080/nodes/v2/command/reboot?application=tenant2.application2.instance2", new byte[0], Request.Method.POST));
    assertReboot(15, new Request("http://localhost:8080/nodes/v2/command/reboot", new byte[0], Request.Method.POST));
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "\"rebootGeneration\":4");
    // POST deactivation of a maintenance job
    assertResponse(new Request("http://localhost:8080/nodes/v2/maintenance/inactive/NodeFailer", new byte[0], Request.Method.POST), "{\"message\":\"Deactivated job 'NodeFailer'\"}");
    // GET a list of all maintenance jobs
    assertFile(new Request("http://localhost:8080/nodes/v2/maintenance/"), "maintenance.json");
    // DELETE deactivation of a maintenance job
    assertResponse(new Request("http://localhost:8080/nodes/v2/maintenance/inactive/NodeFailer", new byte[0], Request.Method.DELETE), "{\"message\":\"Re-activated job 'NodeFailer'\"}");
    // POST new nodes
    assertResponse(new Request("http://localhost:8080/nodes/v2/node", (// test with only 1 ip address
    "[" + asNodeJson("host8.yahoo.com", "default", "127.0.0.1") + "," + asNodeJson("host9.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + asHostJson("parent2.yahoo.com", "large-variant", "127.0.0.1", "::1") + "," + asDockerNodeJson("host11.yahoo.com", "parent.host.yahoo.com", 2, "127.0.0.1", "::1") + "]").getBytes(StandardCharsets.UTF_8), Request.Method.POST), "{\"message\":\"Added 4 nodes to the provisioned state\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com"), "node8.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host9.yahoo.com"), "node9.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host11.yahoo.com"), "node11.json");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/parent2.yahoo.com"), "parent2.json");
    // DELETE a provisioned node
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host9.yahoo.com", new byte[0], Request.Method.DELETE), "{\"message\":\"Removed host9.yahoo.com\"}");
    // PUT nodes ready
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/host8.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host8.yahoo.com to dirty\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host8.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host8.yahoo.com to ready\"}");
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com"), "\"state\":\"ready\"");
    // calling ready again is a noop:
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/ready/host8.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host8.yahoo.com to ready\"}");
    // PUT a node in failed ...
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/host2.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host2.yahoo.com to failed\"}");
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/host2.yahoo.com"), "\"state\":\"failed\"");
    // ... and put it back in active (after fixing). This is useful to restore data when multiple nodes fail.
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/active/host2.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host2.yahoo.com to active\"}");
    // PUT a node in parked ...
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/parked/host8.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved host8.yahoo.com to parked\"}");
    assertResponseContains(new Request("http://localhost:8080()/nodes/v2/node/host8.yahoo.com"), "\"state\":\"parked\"");
    // ... and delete it
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host8.yahoo.com", new byte[0], Request.Method.DELETE), "{\"message\":\"Removed host8.yahoo.com\"}");
    // or, PUT a node in failed ...
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/test-container-1", new byte[0], Request.Method.PUT), "{\"message\":\"Moved test-container-1 to failed\"}");
    assertResponseContains(new Request("http://localhost:8080/nodes/v2/node/test-container-1"), "\"state\":\"failed\"");
    // ... and deallocate it such that it moves to dirty and is recycled
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/dirty/test-container-1", new byte[0], Request.Method.PUT), "{\"message\":\"Moved test-container-1 to dirty\"}");
    // ... and set it back to ready as if this was from the node-admin with the temporary state rest api
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/availablefornewallocations/test-container-1", new byte[0], Request.Method.PUT), "{\"message\":\"Marked following nodes as available for new allocation: test-container-1\"}");
    // Put a host in failed and make sure it's children are also failed
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed/dockerhost1.yahoo.com", new byte[0], Request.Method.PUT), "{\"message\":\"Moved dockerhost1.yahoo.com, host4.yahoo.com to failed\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/state/failed"), "{\"nodes\":[" + "{\"url\":\"http://localhost:8080/nodes/v2/node/host5.yahoo.com\"}," + "{\"url\":\"http://localhost:8080/nodes/v2/node/host4.yahoo.com\"}," + "{\"url\":\"http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com\"}]}");
    // Update (PATCH) a node (multiple fields can also be sent in one request body)
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentRestartGeneration\": 1}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentRebootGeneration\": 1}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"flavor\": \"medium-disk\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentVespaVersion\": \"5.104.142\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"hardwareFailureDescription\": \"memory_mcelog\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"parentHostname\": \"parent.yahoo.com\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"ipAddresses\": [\"127.0.0.1\",\"::1\"]}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"wantToRetire\": true}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"wantToDeprovision\": true}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com", Utf8.toBytes("{\"currentDockerImage\": \"ignored-image-name:4443/vespa/ci:6.43.0\"}"), Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}");
    assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "node4-after-changes.json");
}
Also used : 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