use of com.spotify.docker.client.DockerClient in project opennms by OpenNMS.
the class MinionHeartbeatOutageIT method restartContainer.
private void restartContainer(ContainerAlias alias) {
final DockerClient docker = ((AbstractTestEnvironment) testEnvironment).getDockerClient();
final String id = testEnvironment.getContainerInfo(alias).id();
final Logger logger = getLogger();
try {
logger.info("Restarting container: {} -> {}", alias, id);
docker.restartContainer(id);
logger.info("Container restarted: {} -> {}", alias, id);
} catch (DockerException | InterruptedException e) {
logger.warn("Unexpected exception while restarting container {}", id, e);
}
}
use of com.spotify.docker.client.DockerClient in project opennms by OpenNMS.
the class SyslogKafkaElasticsearch5OutageIT method testMinionSyslogsOverKafkaToEsRest.
@Test
public void testMinionSyslogsOverKafkaToEsRest() throws Exception {
Date startOfTest = new Date();
int numMessages = 10000;
int packetsPerSecond = 250;
InetSocketAddress minionSshAddr = testEnvironment.getServiceAddress(ContainerAlias.MINION, 8201);
InetSocketAddress opennmsSshAddr = testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 8101);
InetSocketAddress kafkaAddress = testEnvironment.getServiceAddress(ContainerAlias.KAFKA, 9092);
InetSocketAddress zookeeperAddress = testEnvironment.getServiceAddress(ContainerAlias.KAFKA, 2181);
// Install the Kafka syslog and trap handlers on the Minion system
installFeaturesOnMinion(minionSshAddr, kafkaAddress);
// Install the Kafka and Elasticsearch features on the OpenNMS system
installFeaturesOnOpenNMS(opennmsSshAddr, kafkaAddress, zookeeperAddress);
final String sender = testEnvironment.getContainerInfo(ContainerAlias.SNMPD).networkSettings().ipAddress();
// Wait for the minion to show up
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
LOG.info("Warming up syslog routes by sending 100 packets");
// Warm up the routes
sendMessage(ContainerAlias.MINION, sender, 100);
for (int i = 0; i < 10; i++) {
LOG.info("Slept for " + i + " seconds");
Thread.sleep(1000);
}
LOG.info("Resetting statistics");
resetRouteStatistics(opennmsSshAddr, minionSshAddr);
for (int i = 0; i < 20; i++) {
LOG.info("Slept for " + i + " seconds");
Thread.sleep(1000);
}
// Make sure that this evenly divides into the numMessages
final int chunk = 250;
// Make sure that this is an even multiple of chunk
final int logEvery = 1000;
int count = 0;
long start = System.currentTimeMillis();
AtomicInteger restartCounter = new AtomicInteger();
// Start a timer that occasionally restarts Elasticsearch
Timer restarter = new Timer("Elasticsearch-Restarter", true);
restarter.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final DockerClient docker = ((AbstractTestEnvironment) testEnvironment).getDockerClient();
final String id = testEnvironment.getContainerInfo(ContainerAlias.ELASTICSEARCH_5).id();
try {
LOG.info("Restarting container: {}", id);
docker.restartContainer(id);
restartCounter.incrementAndGet();
LOG.info("Container restarted: {}", id);
} catch (DockerException | InterruptedException e) {
LOG.warn("Unexpected exception while restarting container {}", id, e);
}
}
}, 0L, TimeUnit.SECONDS.toMillis(29));
// Send ${numMessages} syslog messages
RateLimiter limiter = RateLimiter.create(packetsPerSecond);
for (int i = 0; i < (numMessages / chunk); i++) {
limiter.acquire(chunk);
sendMessage(ContainerAlias.MINION, sender, chunk);
count += chunk;
if (count % logEvery == 0) {
long mid = System.currentTimeMillis();
LOG.info(String.format("Sent %d packets in %d milliseconds", logEvery, mid - start));
start = System.currentTimeMillis();
}
}
// Stop restarting Elasticsearch
restarter.cancel();
// 100 warm-up messages plus ${numMessages} messages
pollForElasticsearchEventsUsingJest(this::getEs5Address, 100 + numMessages);
assertTrue("Elasticsearch was never restarted", restartCounter.get() > 0);
}
use of com.spotify.docker.client.DockerClient in project TOSCAna by StuPro-TOSCAna.
the class ImageBuilder method buildImage.
/**
* This Command Builds the DockerImage using the Dockerfile in the (previously specified) dockerWorkDir
*
* @throws Exception gets thrown if something during the Build Procedure fails
*/
public void buildImage() throws Exception {
DockerClient client = getDockerClient();
Path abs = Paths.get(access.getAbsolutePath(dockerWorkDir));
// Build the image
String result = client.build(abs, getTag(), this);
logger.info("Image build was successful. Image ID: {}", result);
}
use of com.spotify.docker.client.DockerClient in project TOSCAna by StuPro-TOSCAna.
the class PushingImageBuilder method storeImage.
@Override
public void storeImage() throws Exception {
DockerClient client = getDockerClient();
client.push(getTag(), this);
}
use of com.spotify.docker.client.DockerClient in project TOSCAna by StuPro-TOSCAna.
the class PushingImageBuilderIT method validate.
@Override
public void validate(String tag) throws Exception {
RegistryAuth auth = credentials.toRegistryAuth();
DockerClient client = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(auth, RegistryConfigs.create(Collections.singletonMap(credentials.getRegistryURL(), auth)))).build();
client.removeImage(tag);
// Pull the image from the registry
client.pull(tag);
}
Aggregations