Search in sources :

Example 1 with NodeDescription

use of com.spotify.docker.client.messages.swarm.NodeDescription 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 NodeDescription

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

the class DefaultDockerClientUnitTest method testListNodes.

@Test
public void testListNodes() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.28");
    server.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/json").setBody(fixture("fixtures/1.28/listNodes.json")));
    final List<Node> nodes = dockerClient.listNodes();
    assertThat(nodes.size(), equalTo(1));
    final Node node = nodes.get(0);
    assertThat(node, notNullValue());
    assertThat(node.id(), is("24ifsmvkjbyhk"));
    assertThat(node.version().index(), is(8L));
    final NodeSpec nodeSpec = node.spec();
    assertThat(nodeSpec.name(), is("my-node"));
    assertThat(nodeSpec.role(), is("manager"));
    assertThat(nodeSpec.availability(), is("active"));
    assertThat(nodeSpec.labels().keySet(), contains("foo"));
    final NodeDescription desc = node.description();
    assertThat(desc.hostname(), is("bf3067039e47"));
    assertThat(desc.platform().architecture(), is("x86_64"));
    assertThat(desc.platform().os(), is("linux"));
    assertThat(desc.resources().memoryBytes(), is(8272408576L));
    assertThat(desc.resources().nanoCpus(), is(4000000000L));
    final EngineConfig engine = desc.engine();
    assertThat(engine.engineVersion(), is("17.04.0"));
    assertThat(engine.labels().keySet(), contains("foo"));
    assertThat(engine.plugins().size(), equalTo(4));
    assertThat(node.status(), notNullValue());
    assertThat(node.status().addr(), is("172.17.0.2"));
    assertThat(node.managerStatus(), notNullValue());
    assertThat(node.managerStatus().addr(), is("172.17.0.2:2377"));
    assertThat(node.managerStatus().leader(), is(true));
    assertThat(node.managerStatus().reachability(), is("reachable"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NodeDescription(com.spotify.docker.client.messages.swarm.NodeDescription) 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) EngineConfig(com.spotify.docker.client.messages.swarm.EngineConfig) Test(org.junit.Test)

Aggregations

EngineConfig (com.spotify.docker.client.messages.swarm.EngineConfig)2 Node (com.spotify.docker.client.messages.swarm.Node)2 NodeDescription (com.spotify.docker.client.messages.swarm.NodeDescription)2 NodeSpec (com.spotify.docker.client.messages.swarm.NodeSpec)2 Test (org.junit.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 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