Search in sources :

Example 1 with DockerClient

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);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) DockerClient(com.spotify.docker.client.DockerClient) AbstractTestEnvironment(org.opennms.test.system.api.AbstractTestEnvironment) Logger(org.slf4j.Logger)

Example 2 with DockerClient

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);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) DockerClient(com.spotify.docker.client.DockerClient) OnmsMinion(org.opennms.netmgt.model.minion.OnmsMinion) InetSocketAddress(java.net.InetSocketAddress) Date(java.util.Date) RateLimiter(com.google.common.util.concurrent.RateLimiter) Timer(java.util.Timer) TimerTask(java.util.TimerTask) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 3 with DockerClient

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);
}
Also used : Path(java.nio.file.Path) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient)

Example 4 with DockerClient

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);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient)

Example 5 with DockerClient

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);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth)

Aggregations

DockerClient (com.spotify.docker.client.DockerClient)170 Test (org.junit.Test)102 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)75 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)23 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)20 JobId (com.spotify.helios.common.descriptors.JobId)19 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)18 LogStream (com.spotify.docker.client.LogStream)15 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)15 DockerException (com.spotify.docker.client.exceptions.DockerException)14 Path (java.nio.file.Path)12 DockerException (org.eclipse.linuxtools.docker.core.DockerException)12 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)12 Container (com.spotify.docker.client.messages.Container)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 HostConfig (com.spotify.docker.client.messages.HostConfig)10 HeliosClient (com.spotify.helios.client.HeliosClient)10 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)9 RunWithProject (org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)9 Deployment (com.spotify.helios.common.descriptors.Deployment)8