/** * Creates a {@link Ports} object with an initial {@link PortBinding} for the specified {@link ExposedPort} and {@link Binding}. Use * {@link #bind(ExposedPort, Binding)} or {@link #add(PortBinding...)} to add more {@link PortBinding}s. */ public Ports(ExposedPort exposedPort, Binding host) { bind(exposedPort, host); }
/** * Adds the specified {@link PortBinding}(s) to the list of {@link PortBinding}s. */ public void add(PortBinding... portBindings) { for (PortBinding binding : portBindings) { bind(binding.getExposedPort(), binding.getBinding()); } }
@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; } }
/** * Creates a {@link Ports} object with an initial {@link PortBinding} for the specified {@link ExposedPort} and {@link Binding}. Use * {@link #bind(ExposedPort, Binding)} or {@link #add(PortBinding...)} to add more {@link PortBinding}s. */ public Ports(ExposedPort exposedPort, Binding host) { bind(exposedPort, host); }
/** * Adds the specified {@link PortBinding}(s) to the list of {@link PortBinding}s. */ public void add(PortBinding... portBindings) { for (PortBinding binding : portBindings) { bind(binding.getExposedPort(), binding.getBinding()); } }
@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; } }
private Ports createPortBindings(PortBinding... portBinding) { Ports bindings = new Ports(); for (PortBinding binding : portBinding) { ExposedPort inner = tcp(binding.inner); bindings.bind(inner, bindPort(binding.exposed)); } return bindings; }
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; }
@Override public CreateContainerCmd build(ServiceDescriptor sd, CreateContainerCmd cmd, PortBinding pb) { List<ExposedPort> ports = new ArrayList<>(Arrays.asList(cmd.getExposedPorts())); ExposedPort containerPort = pb.protocol() .equals(Protocol.TCP) ? ExposedPort.tcp(pb.exposedPort()) : ExposedPort.udp(pb.exposedPort()); ports.add(containerPort); Ports bindings = cmd.getPortBindings(); if (bindings == null) { bindings = new Ports(); } bindings.bind(containerPort, pb.hostIp() .isEmpty() ? Binding.bindPort(pb.hostPort()) : Binding.bindIpAndPort(pb.hostIp(), pb.hostPort())); return cmd.withExposedPorts(ports) .withPortBindings(bindings); }
Integer mappedPort = portMappings.get(exposedPort.getPort()); if (mappedPort != null) { portBindings.bind(exposedPort, Ports.Binding.bindPort(mappedPort));
ExposedPort internal = ExposedPort.tcp(mapping.getInside()); Binding external = Binding.bindPort(mapping.getOutside()); portBindings.bind(internal, external); exposedPorts.add(internal); });
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExposedPorts(new ExposedPort(ZooKeeperConfig.DEFAULT_ZOOKEEPER_PORT), new ExposedPort(2888), new ExposedPort(3888)) .withPortBindings(portBindings); }
@Override protected CreateContainerCmd dockerCommand() { ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT)); } return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress()) .withCmd(CollectionsUtils.splitCmd(config.getCmd())) .withExposedPorts(exposedPort) .withPortBindings(portBindings); }
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } ExposedPort consulHTTPPort = ExposedPort.tcp(ConsulConfig.CONSUL_HTTP_PORT); ExposedPort consulDNSPort = ExposedPort.udp(ConsulConfig.CONSUL_DNS_PORT); return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withName(getName()) .withCmd("agent", "-server", "-bootstrap", "-client", "0.0.0.0") .withExposedPorts(consulHTTPPort, consulDNSPort) .withPortBindings(portBindings); }
@Override protected CreateContainerCmd dockerCommand() { int port = getServicePort(); ExposedPort exposedPort = ExposedPort.tcp(port); Ports portBindings = new Ports(); if (getCluster().isMapPortsToHost()) { portBindings.bind(exposedPort, Ports.Binding.bindPort(port)); } CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag()) .withName(getName()) .withExposedPorts(new ExposedPort(getServicePort())) .withEnv(newEnvironment() .withValues(getMesosMasterEnvVars()) .withValues(getSharedEnvVars()) .createEnvironment()) .withPortBindings(portBindings); MesosDns mesosDns = getCluster().getMesosDns(); if (mesosDns != null) { cmd.withDns(mesosDns.getIpAddress()); } return cmd; }