/** * Parses a textual port specification (as used by the Docker CLI) to an {@link ExposedPort}. * * @param serialized * the specification, e.g. <code>80/tcp</code> * @return an {@link ExposedPort} matching the specification * @throws IllegalArgumentException * if the specification cannot be parsed */ public static ExposedPort parse(String serialized) throws IllegalArgumentException { try { String[] parts = serialized.split("/"); switch (parts.length) { case 1: return new ExposedPort(Integer.parseInt(parts[0])); case 2: return new ExposedPort(Integer.parseInt(parts[0]), InternetProtocol.parse(parts[1])); default: throw new IllegalArgumentException(); } } catch (Exception e) { throw new IllegalArgumentException("Error parsing ExposedPort '" + serialized + "'"); } }
/** * Returns a string representation of this {@link ExposedPort} suitable for inclusion in a JSON message. The format is * <code>port/protocol</code>, like the argument in {@link #parse(String)}. * * @return a string representation of this {@link ExposedPort} */ @Override public String toString() { return port + "/" + protocol.toString(); }
/** * Creates an {@link ExposedPort} for the given parameters. * * @param scheme * the {@link #getScheme() scheme}, <code>tcp</code> or <code>udp</code> * @param port * the {@link #getPort() port number} * @deprecated use {@link #ExposedPort(int, InternetProtocol)} */ @Deprecated public ExposedPort(String scheme, int port) { this(port, InternetProtocol.valueOf(scheme)); }
private void exportPortBindings(EnvVars envs, Map<ExposedPort, Binding[]> bindings) { StringBuilder ports = new StringBuilder(); for (ExposedPort exposedPort : bindings.keySet()) { ports.append(exposedPort.toString()).append(ID_SEPARATOR); Binding[] exposedPortBinding = bindings.get(exposedPort); if (exposedPortBinding == null) { continue; } envs.put(PORT_BINDING_PREFIX + exposedPort.getProtocol().name() + "_" + exposedPort.getPort(), exposedPortBinding[0].getHostPortSpec()); StringBuilder portBinding = new StringBuilder(); String hostIp = exposedPortBinding[0].getHostIp(); if (hostIp != null && hostIp.length() > 0) { portBinding.append(hostIp).append(":"); portBinding.append(exposedPortBinding[0].getHostPortSpec()); envs.put(HOST_SOCKET_PREFIX + exposedPort.getProtocol().name() + "_" + exposedPort.getPort(), portBinding.toString()); } } String bindPorts = ports.substring(0, ports.length() - 1).toString(); envs.put(PORT_BINDINGS_ENV_VAR, bindPorts); }
/** * Parses a textual port specification (as used by the Docker CLI) to an {@link ExposedPort}. * * @param serialized * the specification, e.g. <code>80/tcp</code> * @return an {@link ExposedPort} matching the specification * @throws IllegalArgumentException * if the specification cannot be parsed */ public static ExposedPort parse(String serialized) throws IllegalArgumentException { try { String[] parts = serialized.split("/"); switch (parts.length) { case 1: return new ExposedPort(Integer.parseInt(parts[0])); case 2: return new ExposedPort(Integer.parseInt(parts[0]), InternetProtocol.parse(parts[1])); default: throw new IllegalArgumentException(); } } catch (Exception e) { throw new IllegalArgumentException("Error parsing ExposedPort '" + serialized + "'"); } }
/** * @return the scheme (internet protocol), <code>tcp</code> or <code>udp</code> * @deprecated use {@link #getProtocol()} */ @Deprecated public String getScheme() { return protocol.toString(); }
/** * Parses a string to an {@link InternetProtocol}. * * @param serialized * the protocol, e.g. <code>tcp</code> or <code>TCP</code> * @return an {@link InternetProtocol} described by the string * @throws IllegalArgumentException * if the argument cannot be parsed */ public static InternetProtocol parse(String serialized) throws IllegalArgumentException { try { return valueOf(serialized.toUpperCase()); } catch (Exception e) { throw new IllegalArgumentException("Error parsing Protocol '" + serialized + "'"); } }
private Set<ExposedPort> resolveExposedPorts(CubeContainer containerConfiguration, CreateContainerCmd createContainerCmd) { Set<ExposedPort> allExposedPorts = new HashSet<>(); if (containerConfiguration.getPortBindings() != null) { for (PortBinding binding : containerConfiguration.getPortBindings()) { allExposedPorts.add(new ExposedPort(binding.getExposedPort().getExposed(), InternetProtocol.parse(binding.getExposedPort().getType()))); } } if (containerConfiguration.getExposedPorts() != null) { for (org.arquillian.cube.docker.impl.client.config.ExposedPort port : containerConfiguration.getExposedPorts()) { allExposedPorts.add(new ExposedPort(port.getExposed(), InternetProtocol.parse(port.getType()))); } } return allExposedPorts; }
/** * Returns a string representation of this {@link ExposedPort} suitable for inclusion in a JSON message. The format is * <code>port/protocol</code>, like the argument in {@link #parse(String)}. * * @return a string representation of this {@link ExposedPort} */ @Override public String toString() { return port + "/" + protocol.toString(); }
/** * Creates an {@link ExposedPort} for the given parameters. * * @param scheme * the {@link #getScheme() scheme}, <code>tcp</code> or <code>udp</code> * @param port * the {@link #getPort() port number} * @deprecated use {@link #ExposedPort(int, InternetProtocol)} */ @Deprecated public ExposedPort(String scheme, int port) { this(port, InternetProtocol.valueOf(scheme)); }
private Set<ExposedPort> resolveExposedPorts(CubeContainer containerConfiguration, CreateContainerCmd createContainerCmd) { Set<ExposedPort> allExposedPorts = new HashSet<>(); if (containerConfiguration.getPortBindings() != null) { for (PortBinding binding : containerConfiguration.getPortBindings()) { allExposedPorts.add(new ExposedPort(binding.getExposedPort().getExposed(), InternetProtocol.parse(binding.getExposedPort().getType()))); } } if (containerConfiguration.getExposedPorts() != null) { for (org.arquillian.cube.docker.impl.client.config.ExposedPort port : containerConfiguration.getExposedPorts()) { allExposedPorts.add(new ExposedPort(port.getExposed(), InternetProtocol.parse(port.getType()))); } } return allExposedPorts; }
/** * @return the scheme (internet protocol), <code>tcp</code> or <code>udp</code> * @deprecated use {@link #getProtocol()} */ @Deprecated public String getScheme() { return protocol.toString(); }
/** * Parses a string to an {@link InternetProtocol}. * * @param serialized * the protocol, e.g. <code>tcp</code> or <code>TCP</code> * @return an {@link InternetProtocol} described by the string * @throws IllegalArgumentException * if the argument cannot be parsed */ public static InternetProtocol parse(String serialized) throws IllegalArgumentException { try { return valueOf(serialized.toUpperCase()); } catch (Exception e) { throw new IllegalArgumentException("Error parsing Protocol '" + serialized + "'"); } }
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; }