Skip to content

Commit

Permalink
Extend common container locator to return a POJO
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Najda committed Jun 26, 2021
1 parent f22562c commit 24563b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.devservices.common;

public class ContainerAddress {
private final String ipAddress;
private final int port;

public ContainerAddress(String ipAddress, Integer port) {
this.ipAddress = ipAddress;
this.port = port;
}

public String getIpAddress() {
return ipAddress;
}

public int getPort() {
return port;
}

public String getUrl() {
return String.format("%s:%d", ipAddress, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ private ContainerPort getMappedPort(Container container, int port) {
return null;
}

public String locateContainer(String serviceName) {
public ContainerAddress locateContainer(String serviceName) {
Container container = lookup(serviceName);
if (container != null) {
ContainerPort containerPort = getMappedPort(container, port);
if (containerPort != null) {
String url = containerPort.getIp() + ":" + containerPort.getPublicPort();
final ContainerAddress containerAddress = new ContainerAddress(containerPort.getIp(),
containerPort.getPublicPort());
log.infof("Dev Services container locator found: %s (%s). "
+ "Connecting to: %s.",
container.getId(),
container.getImage(), url);
return url;
container.getImage(), containerAddress.getUrl());
return containerAddress;
}
}
return null;
Expand Down

0 comments on commit 24563b4

Please sign in to comment.