@Override public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { Ports out = new Ports(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> portNode = it.next(); JsonNode bindingsArray = portNode.getValue(); if (bindingsArray.equals(NullNode.getInstance())) { out.bind(ExposedPort.parse(portNode.getKey()), null); } else { for (int i = 0; i < bindingsArray.size(); i++) { JsonNode bindingNode = bindingsArray.get(i); if (!bindingNode.equals(NullNode.getInstance())) { String hostIp = bindingNode.get("HostIp").textValue(); String hostPort = bindingNode.get("HostPort").textValue(); out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort)); } } } } return out; } }
switch (parts.length) { case 2: { return new Binding(parts[0], parts[1]);
@Override public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { Ports out = new Ports(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> portNode = it.next(); JsonNode bindingsArray = portNode.getValue(); if (bindingsArray.equals(NullNode.getInstance())) { out.bind(ExposedPort.parse(portNode.getKey()), null); } else { for (int i = 0; i < bindingsArray.size(); i++) { JsonNode bindingNode = bindingsArray.get(i); if (!bindingNode.equals(NullNode.getInstance())) { String hostIp = bindingNode.get("HostIp").textValue(); String hostPort = bindingNode.get("HostPort").textValue(); out.bind(ExposedPort.parse(portNode.getKey()), new Binding(hostIp, hostPort)); } } } } return out; } }
switch (parts.length) { case 2: { return new Binding(parts[0], parts[1]);
public String run(String image, int... ports) { String containerId = docker.createContainerCmd(image).exec().getId(); List<PortBinding> portBindings = new ArrayList<>(); if (ports != null) { for (int port : ports) { portBindings.add(new PortBinding(new Ports.Binding(port), new ExposedPort(port))); } } docker.startContainerCmd(containerId).withPortBindings(portBindings.toArray(new PortBinding[portBindings.size()])).exec(); startedContainers.add(containerId); registerShutdown(containerId); return containerId; }
/** * Creates an empty {@link Binding}. */ public static Binding empty() { return new Binding(null, null); }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address} and port range. */ public static Binding bindIpAndPortRange(String hostIp, int lowPort, int highPort) { return new Binding(hostIp, lowPort + "-" + highPort); }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address} and port number. */ public static Binding bindIpAndPort(String hostIp, int port) { return new Binding(hostIp, "" + port); }
/** * Creates a {@link Binding} for the given {@link #getHostPortSpec() port spec}, leaving the {@link #getHostIp() IP address} * undefined. * * @see Ports#bind(ExposedPort, Binding) * @see ExposedPort */ public static Binding bindPortSpec(String portSpec) { return new Binding(null, portSpec); }
private Ports toPortBindings(Collection<PortBinding> portBindings) { Ports ports = new Ports(); for (PortBinding portBinding : portBindings) { ports.bind( new ExposedPort( portBinding.getExposedPort().getExposed(), InternetProtocol.parse(portBinding.getExposedPort().getType())), new Binding(portBinding.getHost(), Integer.toString(portBinding.getBound()))); } return ports; }
private Ports toPortBindings(Collection<PortBinding> portBindings) { Ports ports = new Ports(); for (PortBinding portBinding : portBindings) { ports.bind( new ExposedPort( portBinding.getExposedPort().getExposed(), InternetProtocol.parse(portBinding.getExposedPort().getType())), new Binding(portBinding.getHost(), Integer.toString(portBinding.getBound()))); } return ports; }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address}, leaving the {@link #getHostPortSpec() port spec} * undefined. */ public static Binding bindIp(String hostIp) { return new Binding(hostIp, null); }
/** * Creates an empty {@link Binding}. */ public static Binding empty() { return new Binding(null, null); }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address} and port number. */ public static Binding bindIpAndPort(String hostIp, int port) { return new Binding(hostIp, "" + port); }
/** * Creates a {@link Binding} for the given {@link #getHostPortSpec() port spec}, leaving the {@link #getHostIp() IP address} * undefined. * * @see Ports#bind(ExposedPort, Binding) * @see ExposedPort */ public static Binding bindPortSpec(String portSpec) { return new Binding(null, portSpec); }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address} and port range. */ public static Binding bindIpAndPortRange(String hostIp, int lowPort, int highPort) { return new Binding(hostIp, lowPort + "-" + highPort); }
/** * Creates a {@link Binding} for the given {@link #getHostIp() IP address}, leaving the {@link #getHostPortSpec() port spec} * undefined. */ public static Binding bindIp(String hostIp) { return new Binding(hostIp, null); }