Node json should be optional

The Node element of the container json is optional
as well as nullable.
This commit is contained in:
Duncan Grant 2016-06-09 09:04:56 +01:00 committed by Ignasi Barrera
parent ebc8f7568f
commit 91339b200e
7 changed files with 53 additions and 8 deletions

View File

@ -36,7 +36,6 @@ import org.jclouds.domain.Location;
import org.jclouds.providers.ProviderMetadata;
import com.google.common.base.Function;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@ -113,8 +112,8 @@ public class ContainerToNodeMetadata implements Function<Container, NodeMetadata
private List<String> getPublicIpAddresses(Container container) {
String dockerIpAddress;
if (container.node() != null && !Strings.isNullOrEmpty(container.node().ip())) {
dockerIpAddress = container.node().ip();
if (container.node().isPresent()) {
dockerIpAddress = container.node().get().ip();
} else {
dockerIpAddress = URI.create(providerMetadata.getEndpoint()).getHost();
}

View File

@ -26,6 +26,7 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@ -77,7 +78,7 @@ public abstract class Container {
@Nullable public abstract String processLabel();
@Nullable public abstract Node node();
public abstract Optional<Node> node();
Container() {
}
@ -93,7 +94,7 @@ public abstract class Container {
String resolvConfPath, Map<String, String> volumes, HostConfig hostConfig,
String driver, String execDriver, Map<String, Boolean> volumesRW, String command,
String status, List<Port> ports, String hostnamePath, String hostsPath,
String mountLabel, String processLabel, Node node) {
String mountLabel, String processLabel, Optional<Node> node) {
return new AutoValue_Container(id, created, path, name, copyOf(args), config, state, image, networkSettings,
sysInitPath, resolvConfPath, copyOf(volumes), hostConfig, driver, execDriver, copyOf(volumesRW), command,
status, copyOf(ports), hostnamePath, hostsPath, mountLabel, processLabel, node);
@ -132,7 +133,7 @@ public abstract class Container {
private String hostsPath;
private String mountLabel;
private String processLabel;
private Node node;
private Optional<Node> node = Optional.absent();
public Builder id(String id) {
this.id = id;
@ -250,7 +251,7 @@ public abstract class Container {
}
public Builder node(Node node) {
this.node = node;
this.node = Optional.fromNullable(node);
return this;
}
@ -266,7 +267,7 @@ public abstract class Container {
.sysInitPath(in.sysInitPath()).resolvConfPath(in.resolvConfPath()).driver(in.driver())
.execDriver(in.execDriver()).volumes(in.volumes()).hostConfig(in.hostConfig()).volumesRW(in.volumesRW())
.command(in.command()).status(in.status()).ports(in.ports()).hostnamePath(in.hostnamePath())
.hostsPath(in.hostsPath()).mountLabel(in.mountLabel()).processLabel(in.processLabel()).node(in.node());
.hostsPath(in.hostsPath()).mountLabel(in.mountLabel()).processLabel(in.processLabel()).node(in.node().orNull());
}
}
}

View File

@ -128,6 +128,7 @@ public class ContainerToNodeMetadataTest {
.status("")
.hostConfig(HostConfig.builder().publishAllPorts(true).build())
.ports(ImmutableList.<Port>of())
.node(null)
.build();
ProviderMetadata providerMetadata = EasyMock.createMock(ProviderMetadata.class);
expect(providerMetadata.getEndpoint()).andReturn("http://127.0.0.1:4243");

View File

@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.docker.domain;
import static org.assertj.core.api.Assertions.assertThat;
import org.testng.annotations.Test;
@Test(groups = "unit", testName = "ContainerTest")
public class ContainerTest {
@Test
public void testFromContainer() {
Container testContainer = Container.builder()
.id("testcontainer")
.build();
Container newTestContainer = testContainer.toBuilder().build();
assertThat(newTestContainer).isEqualTo(testContainer);
}
}

View File

@ -27,6 +27,7 @@ import org.jclouds.docker.domain.Config;
import org.jclouds.docker.domain.Container;
import org.jclouds.docker.domain.HostConfig;
import org.jclouds.docker.domain.NetworkSettings;
import org.jclouds.docker.domain.Node;
import org.jclouds.docker.domain.State;
import org.jclouds.docker.internal.BaseDockerParseTest;
import org.testng.annotations.Test;
@ -125,6 +126,8 @@ public class ContainerParseTest extends BaseDockerParseTest<Container> {
.hostsPath("/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/hosts")
.mountLabel("")
.processLabel("")
.node(Node.builder().
ip("10.10.10.10").build())
.build();
}
}

View File

@ -239,6 +239,7 @@ public class ContainerVersionMajor1Minor21 {
"bridge", NetworkSettings.Details.create("", "", "", 0, "", "", 0, "")))
.build())
.path("/bin/sh")
.node(null)
.processLabel("")
.resolvConfPath("/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf")
// "RestartCount": 1,

View File

@ -134,6 +134,9 @@
}
}
},
"Node": {
"IP": "10.10.10.10"
},
"Path": "/home/weave/weaver",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/resolv.conf",