Search in sources :

Example 1 with RestartPolicy

use of com.spotify.docker.client.messages.swarm.RestartPolicy in project docker-client by spotify.

the class DefaultDockerClientTest method testCreateServiceWithDefaults.

@Test
public void testCreateServiceWithDefaults() throws Exception {
    requireDockerApiVersionAtLeast("1.24", "swarm support");
    final String serviceName = randomName();
    final TaskSpec taskSpec = TaskSpec.builder().containerSpec(ContainerSpec.builder().image("alpine").command(new String[] { "ping", "-c1000", "localhost" }).mounts(Mount.builder().volumeOptions(VolumeOptions.builder().driverConfig(com.spotify.docker.client.messages.mount.Driver.builder().build()).build()).bindOptions(BindOptions.builder().build()).tmpfsOptions(TmpfsOptions.builder().build()).build()).build()).resources(ResourceRequirements.builder().build()).restartPolicy(RestartPolicy.builder().build()).placement(Placement.create(null)).networks(NetworkAttachmentConfig.builder().build()).logDriver(Driver.builder().build()).build();
    final ServiceMode serviceMode = ServiceMode.builder().replicated(ReplicatedService.builder().build()).build();
    final ServiceSpec serviceSpec = ServiceSpec.builder().name(serviceName).taskTemplate(taskSpec).mode(serviceMode).updateConfig(UpdateConfig.create(null, null, null)).networks(Collections.<NetworkAttachmentConfig>emptyList()).endpointSpec(EndpointSpec.builder().addPort(PortConfig.builder().build()).build()).build();
    final ServiceCreateResponse response = sut.createService(serviceSpec);
    assertThat(response.id(), is(notNullValue()));
    sut.listTasks();
    final Service service = sut.inspectService(serviceName);
    final ServiceSpec actualServiceSpec = service.spec();
    assertThat(actualServiceSpec.mode().replicated().replicas(), equalTo(1L));
    assertThat(actualServiceSpec.taskTemplate().logDriver().options(), equalTo(Collections.<String, String>emptyMap()));
    assertThat(actualServiceSpec.endpointSpec().mode(), equalTo(EndpointSpec.Mode.RESOLUTION_MODE_VIP));
    assertThat(actualServiceSpec.updateConfig().failureAction(), equalTo("pause"));
    final PortConfig.Builder portConfigBuilder = PortConfig.builder().protocol(PROTOCOL_TCP);
    if (dockerApiVersionAtLeast("1.25")) {
        // Ingress publish mode is the default for ports in API versions >= 1.25
        portConfigBuilder.publishMode(PortConfigPublishMode.INGRESS);
    }
    final PortConfig expectedPortConfig = portConfigBuilder.build();
    assertThat(actualServiceSpec.endpointSpec().ports(), contains(expectedPortConfig));
    assertThat(service.endpoint().spec().ports(), contains(expectedPortConfig));
    final ContainerSpec containerSpec = actualServiceSpec.taskTemplate().containerSpec();
    assertThat(containerSpec.labels(), equalTo(Collections.<String, String>emptyMap()));
    assertThat(containerSpec.mounts().size(), equalTo(1));
    final Mount mount = containerSpec.mounts().get(0);
    assertThat(mount.type(), equalTo("bind"));
    final VolumeOptions volumeOptions = mount.volumeOptions();
    assertThat(volumeOptions.noCopy(), nullValue());
    assertThat(volumeOptions.labels(), nullValue());
    final com.spotify.docker.client.messages.mount.Driver driver = volumeOptions.driverConfig();
    assertThat(driver.name(), nullValue());
    assertThat(driver.options(), nullValue());
    final RestartPolicy restartPolicy = actualServiceSpec.taskTemplate().restartPolicy();
    assertThat(restartPolicy.condition(), equalTo(RESTART_POLICY_ANY));
    assertThat(restartPolicy.maxAttempts(), equalTo(0));
}
Also used : TaskSpec(com.spotify.docker.client.messages.swarm.TaskSpec) ContainerSpec(com.spotify.docker.client.messages.swarm.ContainerSpec) ServiceSpec(com.spotify.docker.client.messages.swarm.ServiceSpec) ContainerMount(com.spotify.docker.client.messages.ContainerMount) Mount(com.spotify.docker.client.messages.mount.Mount) ReplicatedService(com.spotify.docker.client.messages.swarm.ReplicatedService) CompletionService(java.util.concurrent.CompletionService) Service(com.spotify.docker.client.messages.swarm.Service) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ExecutorService(java.util.concurrent.ExecutorService) RestartPolicy(com.spotify.docker.client.messages.swarm.RestartPolicy) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) ServiceMode(com.spotify.docker.client.messages.swarm.ServiceMode) VolumeOptions(com.spotify.docker.client.messages.mount.VolumeOptions) ServiceCreateResponse(com.spotify.docker.client.messages.ServiceCreateResponse) PortConfig(com.spotify.docker.client.messages.swarm.PortConfig) Test(org.junit.Test)

Aggregations

ContainerMount (com.spotify.docker.client.messages.ContainerMount)1 ServiceCreateResponse (com.spotify.docker.client.messages.ServiceCreateResponse)1 Mount (com.spotify.docker.client.messages.mount.Mount)1 VolumeOptions (com.spotify.docker.client.messages.mount.VolumeOptions)1 ContainerSpec (com.spotify.docker.client.messages.swarm.ContainerSpec)1 PortConfig (com.spotify.docker.client.messages.swarm.PortConfig)1 ReplicatedService (com.spotify.docker.client.messages.swarm.ReplicatedService)1 RestartPolicy (com.spotify.docker.client.messages.swarm.RestartPolicy)1 Service (com.spotify.docker.client.messages.swarm.Service)1 ServiceMode (com.spotify.docker.client.messages.swarm.ServiceMode)1 ServiceSpec (com.spotify.docker.client.messages.swarm.ServiceSpec)1 TaskSpec (com.spotify.docker.client.messages.swarm.TaskSpec)1 Long.toHexString (java.lang.Long.toHexString)1 CompletionService (java.util.concurrent.CompletionService)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 Test (org.junit.Test)1