use of com.spotify.docker.client.DockerClient in project helios by spotify.
the class TerminationTest method testNoIntOnExit.
@Test
public void testNoIntOnExit() throws Exception {
startDefaultMaster();
final String host = testHost();
startDefaultAgent(host);
final HeliosClient client = defaultClient();
awaitHostStatus(client, host, UP, LONG_WAIT_SECONDS, SECONDS);
// Note: signal 2 is SIGINT
final Job jobToInterrupt = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(asList("/bin/sh", "-c", "trap handle 2; handle() { echo int; exit 0; }; " + "while true; do sleep 1; done")).build();
final JobId jobId = createJob(jobToInterrupt);
deployJob(jobId, host);
awaitTaskState(jobId, host, RUNNING);
client.setGoal(new Deployment(jobId, Goal.STOP, Deployment.EMTPY_DEPLOYER_USER, Deployment.EMPTY_DEPLOYER_MASTER, Deployment.EMPTY_DEPLOYMENT_GROUP_NAME), host);
final TaskStatus taskStatus = awaitTaskState(jobId, host, STOPPED);
final String log;
try (final DockerClient dockerClient = getNewDockerClient();
LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout())) {
log = logs.readFully();
}
// No message expected, since SIGINT should not be sent
assertEquals("", log);
}
use of com.spotify.docker.client.DockerClient in project helios by spotify.
the class TerminationTest method setup.
@Before
public void setup() throws Exception {
// LXC has a bug where the TERM signal isn't sent to containers, so we can only run this test
// if docker runs with the native driver.
// See: https://github.com/docker/docker/issues/2436
final DockerClient dockerClient = getNewDockerClient();
assumeThat(dockerClient.info().executionDriver(), startsWith("native"));
}
use of com.spotify.docker.client.DockerClient in project helios by spotify.
the class NamespaceTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
final String id = "test-" + Integer.toHexString(new SecureRandom().nextInt());
final String namespace = "helios-" + id;
final HeliosClient client = defaultClient();
startDefaultAgent(testHost(), "--id=" + id);
// Create a job
final Job job = Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setCommand(IDLE_COMMAND).build();
final JobId jobId = job.getId();
final CreateJobResponse created = client.createJob(job).get();
assertEquals(CreateJobResponse.Status.OK, created.getStatus());
// Wait for agent to come up
awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS);
awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Deploy the job on the agent
final Deployment deployment = Deployment.of(jobId, START);
final JobDeployResponse deployed = client.deploy(deployment, testHost()).get();
assertEquals(JobDeployResponse.Status.OK, deployed.getStatus());
awaitJobState(client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS);
try (final DockerClient docker = getNewDockerClient()) {
final List<Container> containers = docker.listContainers();
Container jobContainer = null;
for (final Container container : containers) {
for (final String name : container.names()) {
if (name.startsWith("/" + namespace)) {
jobContainer = container;
}
}
}
assertNotNull(jobContainer);
}
}
use of com.spotify.docker.client.DockerClient in project helios by spotify.
the class EnvironmentVariableTest method test.
@Test
public void test() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost(), "--env", "SPOTIFY_POD=PODNAME", "SPOTIFY_ROLE=ROLENAME", "BAR=badfood");
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
// Wait for the agent to report environment vars
Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() {
@Override
public Object call() throws Exception {
final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() {
});
return status.get(testHost()).getEnvironment();
}
});
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<String> command = asList("sh", "-c", "echo pod: $SPOTIFY_POD; " + "echo role: $SPOTIFY_ROLE; " + "echo foo: $FOO; " + "echo bar: $BAR");
// Create job
final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command, ImmutableMap.of("FOO", "4711", "BAR", "deadbeef"));
// deploy
deployJob(jobId, testHost());
final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr());
final String log = logs.readFully();
assertThat(log, containsString("pod: PODNAME"));
assertThat(log, containsString("role: ROLENAME"));
assertThat(log, containsString("foo: 4711"));
// Verify that the the BAR environment variable in the job overrode the agent config
assertThat(log, containsString("bar: deadbeef"));
final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() {
});
assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "badfood"), status.get(testHost()).getEnvironment());
assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "deadbeef", "FOO", "4711"), status.get(testHost()).getStatuses().get(jobId).getEnv());
}
}
use of com.spotify.docker.client.DockerClient in project helios by spotify.
the class ContainerHostNameTest method testValidHostname.
@Test
public void testValidHostname() throws Exception {
startDefaultMaster();
startDefaultAgent(testHost());
awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
try (final DockerClient dockerClient = getNewDockerClient()) {
final List<String> command = asList("hostname", "-f");
// Create job
final JobId jobId = createJob(Job.newBuilder().setName(testJobName).setVersion(testJobVersion).setImage(BUSYBOX).setHostname(testHost()).setCommand(command).build());
// deploy
deployJob(jobId, testHost());
final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
final String log;
try (final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr())) {
log = logs.readFully();
}
assertThat(log, containsString(testHost()));
}
}
Aggregations