use of com.spotify.docker.client.messages.Container in project linuxtools by eclipse.
the class DockerConnectionTest method shouldLoadContainers.
@Test
public void shouldLoadContainers() throws DockerException {
// given
final Container fooContainer = MockContainerFactory.id("foo").build();
final Container barContainer = MockContainerFactory.id("bar").build();
final DockerClient client = MockDockerClientFactory.container(fooContainer).container(barContainer).build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
dockerConnection.open(false);
// when
final List<IDockerContainer> containers = dockerConnection.getContainers();
// then
assertThat(containers).hasSize(2);
}
use of com.spotify.docker.client.messages.Container in project helios by spotify.
the class ZooKeeperClusterIdTest method testAgent.
@Test
public void testAgent() throws Exception {
startDefaultMaster("--zk-cluster-id=" + zkClusterId);
startDefaultAgent(testHost(), "--zk-cluster-id=" + zkClusterId);
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Create job and deploy it
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, IDLE_COMMAND);
deployJob(jobId, testHost());
final TaskStatus runningStatus = awaitTaskState(jobId, testHost(), RUNNING);
final String containerId = runningStatus.getContainerId();
// Delete the config node which contains the cluster ID and all the job definitions
zk().curatorWithSuperAuth().delete().deletingChildrenIfNeeded().forPath("/config");
// Sleep for a second so agent has a chance to react to deletion
Thread.sleep(1000);
// Make sure the agent didn't stop the job
try (final DockerClient docker = getNewDockerClient()) {
final List<Container> containers = docker.listContainers();
final CustomTypeSafeMatcher<Container> containerIdMatcher = new CustomTypeSafeMatcher<Container>("Container with id " + containerId) {
@Override
protected boolean matchesSafely(Container container) {
return container.id().equals(containerId);
}
};
assertContainersMatch(containers, containerIdMatcher);
}
}
use of com.spotify.docker.client.messages.Container in project helios by spotify.
the class SystemTestBase method listContainers.
protected List<Container> listContainers(final DockerClient dockerClient, final String needle) throws DockerException, InterruptedException {
final List<Container> containers = dockerClient.listContainers();
final List<Container> matches = Lists.newArrayList();
for (final Container container : containers) {
if (container.names() != null) {
for (final String name : container.names()) {
if (name.contains(needle)) {
matches.add(container);
break;
}
}
}
}
return matches;
}
use of com.spotify.docker.client.messages.Container in project helios by spotify.
the class SystemTestBase method baseTeardown.
@After
public void baseTeardown() throws Exception {
for (final HeliosClient client : clients) {
client.close();
}
clients.clear();
for (final Service service : services) {
try {
service.stopAsync();
} catch (Exception e) {
log.error("Uncaught exception", e);
}
}
for (final Service service : services) {
try {
service.awaitTerminated();
} catch (Exception e) {
log.error("Service failed", e);
}
}
services.clear();
// Clean up docker
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<Container> containers = dockerClient.listContainers();
for (final Container container : containers) {
for (final String name : container.names()) {
if (name.contains(testTag)) {
try {
dockerClient.killContainer(container.id());
} catch (DockerException e) {
e.printStackTrace();
}
break;
}
}
}
} catch (Exception e) {
log.error("Docker client exception", e);
}
if (zk != null) {
zk.close();
}
listThreads();
}
use of com.spotify.docker.client.messages.Container in project helios by spotify.
the class DeploymentTest method testLotsOfConcurrentJobs.
@Test
public void testLotsOfConcurrentJobs() throws Exception {
startDefaultMaster();
final HeliosClient client = defaultClient();
startDefaultAgent(testHost());
awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
final int numberOfJobs = 40;
final List<JobId> jobIds = Lists.newArrayListWithCapacity(numberOfJobs);
final String jobName = testJobName + "_" + toHexString(ThreadLocalRandom.current().nextInt());
// create and deploy a bunch of jobs
for (Integer i = 0; i < numberOfJobs; i++) {
final Job job = Job.newBuilder().setName(jobName).setVersion(i.toString()).setImage(BUSYBOX).setCommand(IDLE_COMMAND).setCreatingUser(TEST_USER).build();
final JobId jobId = job.getId();
final CreateJobResponse created = client.createJob(job).get();
assertEquals(CreateJobResponse.Status.OK, created.getStatus());
final Deployment deployment = Deployment.of(jobId, START, TEST_USER);
final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
jobIds.add(jobId);
}
// get the container ID's for the jobs
final Set<String> containerIds = Sets.newHashSetWithExpectedSize(numberOfJobs);
for (final JobId jobId : jobIds) {
final TaskStatus taskStatus = awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
containerIds.add(taskStatus.getContainerId());
}
try (final DockerClient dockerClient = getNewDockerClient()) {
// kill all the containers for the jobs
for (final String containerId : containerIds) {
dockerClient.killContainer(containerId);
}
// make sure all the containers come back up
final int restartedContainers = Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
int matchingContainerCount = 0;
for (final Container c : dockerClient.listContainers()) {
for (final String name : c.names()) {
if (name.contains(jobName)) {
matchingContainerCount++;
}
}
}
if (matchingContainerCount < containerIds.size()) {
return null;
} else {
return matchingContainerCount;
}
}
});
assertEquals(numberOfJobs, restartedContainers);
}
}
Aggregations