Search in sources :

Example 1 with NodeSpec

use of com.spotify.docker.client.messages.swarm.NodeSpec in project docker-client by spotify.

the class DefaultDockerClientTest method testListNodes.

@Test
public void testListNodes() throws Exception {
    requireDockerApiVersionAtLeast("1.24", "swarm support");
    List<Node> nodes = sut.listNodes();
    assertThat(nodes.size(), greaterThanOrEqualTo(1));
    Node nut = nodes.get(0);
    Date now = new Date();
    assertThat(nut.id(), allOf(notNullValue(), not("")));
    assertThat(nut.version().index(), allOf(notNullValue(), greaterThan(0L)));
    assertThat(nut.createdAt(), allOf(notNullValue(), lessThanOrEqualTo(now)));
    assertThat(nut.updatedAt(), allOf(notNullValue(), lessThanOrEqualTo(now)));
    NodeSpec specs = nut.spec();
    assertThat(specs, notNullValue());
    // Can be null if not set
    assertThat(specs.name(), is(anything()));
    // Can be null if not set
    assertThat(specs.labels(), is(anything()));
    assertThat(specs.role(), isIn(new String[] { "manager", "worker" }));
    assertThat(specs.availability(), isIn(new String[] { "active", "pause", "drain" }));
    NodeDescription desc = nut.description();
    assertThat(desc.hostname(), allOf(notNullValue(), not("")));
    assertThat(desc.platform(), notNullValue());
    assertThat(desc.platform().architecture(), allOf(notNullValue(), not("")));
    assertThat(desc.platform().os(), allOf(notNullValue(), not("")));
    assertThat(desc.resources(), notNullValue());
    assertThat(desc.resources().memoryBytes(), greaterThan(0L));
    assertThat(desc.resources().nanoCpus(), greaterThan(0L));
    EngineConfig engine = desc.engine();
    assertThat(engine, notNullValue());
    assertThat(engine.engineVersion(), allOf(notNullValue(), not("")));
    assertThat(engine.labels(), is(anything()));
    assertThat(engine.plugins().size(), greaterThanOrEqualTo(0));
    for (EnginePlugin plugin : engine.plugins()) {
        assertThat(plugin.type(), allOf(notNullValue(), not("")));
        assertThat(plugin.name(), allOf(notNullValue(), not("")));
    }
}
Also used : NodeDescription(com.spotify.docker.client.messages.swarm.NodeDescription) EnginePlugin(com.spotify.docker.client.messages.swarm.EnginePlugin) Node(com.spotify.docker.client.messages.swarm.Node) NodeSpec(com.spotify.docker.client.messages.swarm.NodeSpec) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) EngineConfig(com.spotify.docker.client.messages.swarm.EngineConfig) Date(java.util.Date) Test(org.junit.Test)

Example 2 with NodeSpec

use of com.spotify.docker.client.messages.swarm.NodeSpec in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testUpdateNonSwarmNode.

@Test(expected = NonSwarmNodeException.class)
public void testUpdateNonSwarmNode() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.28");
    enqueueServerApiError(503, "Error updating node: '24ifsmvkjbyhk'");
    final NodeSpec nodeSpec = NodeSpec.builder().name("foobar").addLabel("foo", "baz").availability("active").role("manager").build();
    dockerClient.updateNode("24ifsmvkjbyhk", 8L, nodeSpec);
}
Also used : NodeSpec(com.spotify.docker.client.messages.swarm.NodeSpec) Test(org.junit.Test)

Example 3 with NodeSpec

use of com.spotify.docker.client.messages.swarm.NodeSpec in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testUpdateMissingNode.

@Test(expected = NodeNotFoundException.class)
public void testUpdateMissingNode() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.28");
    enqueueServerApiError(404, "Error updating node: '24ifsmvkjbyhk'");
    final NodeSpec nodeSpec = NodeSpec.builder().addLabel("foo", "baz").name("foobar").availability("active").role("manager").build();
    dockerClient.updateNode("24ifsmvkjbyhk", 8L, nodeSpec);
}
Also used : NodeSpec(com.spotify.docker.client.messages.swarm.NodeSpec) Test(org.junit.Test)

Example 4 with NodeSpec

use of com.spotify.docker.client.messages.swarm.NodeSpec in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testUpdateNode.

@Test
public void testUpdateNode() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.28");
    enqueueServerApiResponse(200, "fixtures/1.28/listNodes.json");
    final List<Node> nodes = dockerClient.listNodes();
    assertThat(nodes.size(), is(1));
    final Node node = nodes.get(0);
    assertThat(node.id(), equalTo("24ifsmvkjbyhk"));
    assertThat(node.version().index(), equalTo(8L));
    assertThat(node.spec().name(), equalTo("my-node"));
    assertThat(node.spec().role(), equalTo("manager"));
    assertThat(node.spec().availability(), equalTo("active"));
    assertThat(node.spec().labels(), hasKey(equalTo("foo")));
    final NodeSpec updatedNodeSpec = NodeSpec.builder(node.spec()).addLabel("foobar", "foobar").build();
    enqueueServerApiVersion("1.28");
    enqueueServerApiEmptyResponse(200);
    dockerClient.updateNode(node.id(), node.version().index(), updatedNodeSpec);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Node(com.spotify.docker.client.messages.swarm.Node) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NodeSpec(com.spotify.docker.client.messages.swarm.NodeSpec) Test(org.junit.Test)

Example 5 with NodeSpec

use of com.spotify.docker.client.messages.swarm.NodeSpec in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testUpdateNodeWithInvalidVersion.

@Test(expected = DockerException.class)
public void testUpdateNodeWithInvalidVersion() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.28");
    final ObjectNode errorMessage = createObjectNode().put("message", "invalid node version: '7'");
    enqueueServerApiResponse(500, errorMessage);
    final NodeSpec nodeSpec = NodeSpec.builder().addLabel("foo", "baz").name("foobar").availability("active").role("manager").build();
    dockerClient.updateNode("24ifsmvkjbyhk", 7L, nodeSpec);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NodeSpec(com.spotify.docker.client.messages.swarm.NodeSpec) Test(org.junit.Test)

Aggregations

NodeSpec (com.spotify.docker.client.messages.swarm.NodeSpec)6 Test (org.junit.Test)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Node (com.spotify.docker.client.messages.swarm.Node)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 EngineConfig (com.spotify.docker.client.messages.swarm.EngineConfig)2 NodeDescription (com.spotify.docker.client.messages.swarm.NodeDescription)2 EnginePlugin (com.spotify.docker.client.messages.swarm.EnginePlugin)1 Long.toHexString (java.lang.Long.toHexString)1 Date (java.util.Date)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1