-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathAerospikeWaitStrategy.java
More file actions
52 lines (43 loc) · 2.13 KB
/
AerospikeWaitStrategy.java
File metadata and controls
52 lines (43 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.playtika.testcontainer.aerospike;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.NetworkSettings;
import com.github.dockerjava.api.model.Ports;
import com.playtika.testcontainer.common.checks.AbstractRetryingWaitStrategy;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.DockerClientFactory;
import java.util.Map;
@Slf4j
@AllArgsConstructor
public class AerospikeWaitStrategy extends AbstractRetryingWaitStrategy {
private final AerospikeProperties properties;
@Override
protected boolean isReady() {
String containerId = waitStrategyTarget.getContainerId();
log.debug("Check Aerospike container {} status", containerId);
InspectContainerResponse containerInfo = waitStrategyTarget.getContainerInfo();
if (containerInfo == null) {
log.debug("Aerospike container[{}] doesn't contain info. Abnormal situation, should not happen.", containerId);
return false;
}
int port = getMappedPort(containerInfo.getNetworkSettings(), properties.port);
String host = DockerClientFactory.instance().dockerHostIpAddress();
//TODO: Remove dependency to client https://www.aerospike.com/docs/tools/asmonitor/common_tasks.html
try (AerospikeClient client = new AerospikeClient(host, port)) {
return client.isConnected();
} catch (AerospikeException.Connection e) {
log.debug("Aerospike container: {} not yet started. {}", containerId, e.getMessage());
}
return false;
}
private int getMappedPort(NetworkSettings networkSettings, int originalPort) {
ExposedPort exposedPort = new ExposedPort(originalPort);
Ports ports = networkSettings.getPorts();
Map<ExposedPort, Ports.Binding[]> bindings = ports.getBindings();
Ports.Binding[] binding = bindings.get(exposedPort);
return Integer.parseInt(binding[0].getHostPortSpec());
}
}