public HostConfig withPortBindings(PortBinding... portBindings) { checkNotNull(portBindings, "portBindings was not specified"); withPortBindings(new Ports(portBindings)); return this; }
@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; } }
public HostConfig withPortBindings(PortBinding... portBindings) { checkNotNull(portBindings, "portBindings was not specified"); withPortBindings(new Ports(portBindings)); return this; }
Ports p = new Ports(); p.addPort("22/tcp"); ObjectMapper om = new ObjectMapper(); om.writeValue(System.out, p); //Produce {"ports":{"22/tcp":{}}}
@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; }
@Before public void setup() { HostConfig hostConfig = new HostConfig(); hostConfig.withPortBindings(new Ports()); when(inspectContainerResponse.getHostConfig()).thenReturn(hostConfig); when(inspectContainerCmd.exec()).thenReturn(inspectContainerResponse); when(dockerClient.inspectContainerCmd(anyString())).thenReturn(inspectContainerCmd); when(executor.getDockerClient()).thenReturn(dockerClient); CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setRemoveVolumes(false); cube = injectorInst.get().inject(new DockerCube(ID, cubeContainer, executor)); }
@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); }
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; }
List<ExposedPort> exposedPorts = getExposedPorts(); Map<Integer, Integer> portMappings = getPortsMapping(); Ports portBindings = new Ports(); for (ExposedPort exposedPort : exposedPorts) { Integer mappedPort = portMappings.get(exposedPort.getPort());
RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(10); Ports portBindings = new Ports(); List<ExposedPort> exposedPorts = new ArrayList<>(); if (microservice.getPortMappings() != null)
Ports ports = new Ports(port, Ports.Binding.bindPortRange(this.containerBindPortLow,this.containerBindPortHigh));
@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() { 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() { 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)); } 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; }
) throws InterruptedException, DockerException { final Ports ports = new Ports();