// Generated by delombok at Sun Sep 08 08:37:39 UTC 2019
package org.testcontainers.containers;
import com.github.dockerjava.api.exception.
DockerException;
import com.github.dockerjava.api.model.
Container;
import org.testcontainers.containers.traits.
LinkableContainer;
import org.testcontainers.utility.
TestcontainersConfiguration;
import java.util.
List;
import static java.util.
Arrays.asList;
/**
* An ambassador container is used as a TCP proxy, enabling any TCP port of another linked container to be exposed
* publicly, even if that container does not make the port public itself. The <code>richnorth/ambassador:latest</code>
* container is used (based on HAProxy).
*
* @deprecated use {@link SocatContainer}
*/
@
Deprecated
public class
AmbassadorContainer<SELF extends
AmbassadorContainer<SELF>> extends
GenericContainer<SELF> {
private final
String otherContainerName;
private final
String serviceName;
private final int
servicePort;
public
AmbassadorContainer(
LinkableContainer otherContainer,
String serviceName, int
servicePort) {
super(
TestcontainersConfiguration.
getInstance().
getAmbassadorContainerImage());
/*
Use the unique 'identifierPrefix' (random compose project name) so that the ambassador can see
the container it's supposed to be proxying.
*/
this.
otherContainerName =
otherContainer.
getContainerName();
this.
serviceName =
serviceName;
this.
servicePort =
servicePort;
// Link
addLink(
otherContainer,
serviceName);
// Expose ambassador's port
addExposedPort(
servicePort);
// Tell the proxy what to connect to within the docker network
addEnv("SERVICE_NAME",
serviceName);
addEnv("SERVICE_PORT",
String.
format("%d",
servicePort));
}
public boolean
isServiceReady() {
try {
List<
Container>
allContainers =
dockerClient.
listContainersCmd().
withShowAll(true).
exec();
for (
Container container :
allContainers) {
if (
asList(
container.
getNames()).
contains("/" +
otherContainerName) && !
container.
getStatus().
contains("Exited")) {
return true;
}
}
} catch (
DockerException e) {
return false;
}
return false;
}
@java.lang.
Override
@java.lang.
SuppressWarnings("all")
public boolean
equals(final java.lang.
Object o) {
if (
o == this) return true;
if (!(
o instanceof
AmbassadorContainer)) return false;
final
AmbassadorContainer<?>
other = (
AmbassadorContainer<?>)
o;
if (!
other.
canEqual((java.lang.
Object) this)) return false;
final java.lang.
Object this$otherContainerName = this.
getOtherContainerName();
final java.lang.
Object other$otherContainerName =
other.
getOtherContainerName();
if (
this$otherContainerName == null ?
other$otherContainerName != null : !
this$otherContainerName.
equals(
other$otherContainerName)) return false;
final java.lang.
Object this$serviceName = this.
getServiceName();
final java.lang.
Object other$serviceName =
other.
getServiceName();
if (
this$serviceName == null ?
other$serviceName != null : !
this$serviceName.
equals(
other$serviceName)) return false;
if (this.
getServicePort() !=
other.
getServicePort()) return false;
return true;
}
@java.lang.
SuppressWarnings("all")
protected boolean
canEqual(final java.lang.
Object other) {
return
other instanceof
AmbassadorContainer;
}
@java.lang.
Override
@java.lang.
SuppressWarnings("all")
public int
hashCode() {
final int
PRIME = 59;
int
result = 1;
final java.lang.
Object $otherContainerName = this.
getOtherContainerName();
result =
result *
PRIME + (
$otherContainerName == null ? 43 :
$otherContainerName.
hashCode());
final java.lang.
Object $serviceName = this.
getServiceName();
result =
result *
PRIME + (
$serviceName == null ? 43 :
$serviceName.
hashCode());
result =
result *
PRIME + this.
getServicePort();
return
result;
}
@java.lang.
SuppressWarnings("all")
public
String getOtherContainerName() {
return this.
otherContainerName;
}
@java.lang.
SuppressWarnings("all")
public
String getServiceName() {
return this.
serviceName;
}
@java.lang.
SuppressWarnings("all")
public int
getServicePort() {
return this.
servicePort;
}
@java.lang.
Override
@java.lang.
SuppressWarnings("all")
public java.lang.
String toString() {
return "AmbassadorContainer(otherContainerName=" + this.
getOtherContainerName() + ", serviceName=" + this.
getServiceName() + ", servicePort=" + this.
getServicePort() + ")";
}
}