Search in sources :

Example 1 with Version

use of com.spotify.docker.client.messages.Version in project linuxtools by eclipse.

the class DockerConnection method getInfo.

@Override
public IDockerConnectionInfo getInfo() throws DockerException {
    if (this.client == null) {
        return null;
    }
    try {
        final Info info = this.client.info();
        final Version version = this.client.version();
        return new DockerConnectionInfo(info, version);
    } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
        throw new DockerException(e.message());
    } catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
        throw new DockerException(Messages.Docker_General_Info_Failure, e);
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IDockerVersion(org.eclipse.linuxtools.docker.core.IDockerVersion) Version(com.spotify.docker.client.messages.Version) Info(com.spotify.docker.client.messages.Info) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) ImageInfo(com.spotify.docker.client.messages.ImageInfo) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo)

Example 2 with Version

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

the class DefaultDockerClientTest method testVersion.

@Test
public void testVersion() throws Exception {
    final Version version = sut.version();
    assertThat(version.apiVersion(), not(isEmptyOrNullString()));
    assertThat(version.arch(), not(isEmptyOrNullString()));
    assertThat(version.gitCommit(), not(isEmptyOrNullString()));
    assertThat(version.goVersion(), not(isEmptyOrNullString()));
    assertThat(version.kernelVersion(), not(isEmptyOrNullString()));
    assertThat(version.os(), not(isEmptyOrNullString()));
    assertThat(version.version(), not(isEmptyOrNullString()));
    if (dockerApiVersionAtLeast("1.22")) {
        assertThat(version.buildTime(), not(isEmptyOrNullString()));
    }
}
Also used : VersionCompare.compareVersion(com.spotify.docker.client.VersionCompare.compareVersion) Version(com.spotify.docker.client.messages.Version) Test(org.junit.Test)

Example 3 with Version

use of com.spotify.docker.client.messages.Version in project helios by spotify.

the class TaskRunnerTest method arePullsConcurrent.

private boolean arePullsConcurrent(final String dockerVersion) throws DockerException, InterruptedException, ExecutionException {
    final Version version = mock(Version.class);
    doReturn(dockerVersion).when(version).version();
    doReturn(version).when(mockDocker).version();
    final AtomicInteger pullers = new AtomicInteger();
    final AtomicBoolean concurrentPullsIssued = new AtomicBoolean(false);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            try {
                if (pullers.incrementAndGet() > 1) {
                    concurrentPullsIssued.set(true);
                }
                Thread.sleep(5000);
            } finally {
                pullers.decrementAndGet();
            }
            return null;
        }
    }).when(mockDocker).pull(any());
    final TaskRunner tr = TaskRunner.builder().delayMillis(0).config(TaskConfig.builder().namespace("test").host(HOST).job(JOB).containerDecorators(ImmutableList.of(containerDecorator)).build()).docker(mockDocker).listener(new TaskRunner.NopListener()).build();
    final TaskRunner tr2 = TaskRunner.builder().delayMillis(0).config(TaskConfig.builder().namespace("test").host(HOST).job(JOB).containerDecorators(ImmutableList.of(containerDecorator)).build()).docker(mockDocker).listener(new TaskRunner.NopListener()).build();
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    final Future<?> future = executor.submit(new Runnable() {

        @Override
        public void run() {
            tr.run();
        }
    });
    final Future<?> future2 = executor.submit(new Runnable() {

        @Override
        public void run() {
            tr2.run();
        }
    });
    future.get();
    future2.get();
    return concurrentPullsIssued.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Version(com.spotify.docker.client.messages.Version) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ExecutorService(java.util.concurrent.ExecutorService)

Example 4 with Version

use of com.spotify.docker.client.messages.Version in project helios by spotify.

the class HealthCheckTest method execCompatibleDockerVersion.

private static Matcher<Version> execCompatibleDockerVersion() {
    return new CustomTypeSafeMatcher<Version>("apiVersion >= 1.18") {

        @Override
        protected boolean matchesSafely(final Version version) {
            try {
                final Iterator<String> versionParts = Splitter.on('.').split(version.apiVersion()).iterator();
                final int apiVersionMajor = Integer.parseInt(versionParts.next());
                final int apiVersionMinor = Integer.parseInt(versionParts.next());
                return apiVersionMajor == 1 && apiVersionMinor >= 18;
            } catch (Exception e) {
                return false;
            }
        }
    };
}
Also used : CustomTypeSafeMatcher(org.hamcrest.CustomTypeSafeMatcher) Version(com.spotify.docker.client.messages.Version) ServiceEndpoint(com.spotify.helios.common.descriptors.ServiceEndpoint) Endpoint(com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint) IOException(java.io.IOException)

Example 5 with Version

use of com.spotify.docker.client.messages.Version in project helios by spotify.

the class ExecHealthCheckerTest method setUp.

@Before
public void setUp() throws Exception {
    final ExecHealthCheck healthCheck = ExecHealthCheck.of("exit 0");
    final Info info = mock(Info.class);
    when(info.executionDriver()).thenReturn("native-0.2");
    final Version version = mock(Version.class);
    when(version.apiVersion()).thenReturn("1.18");
    final ExecState execState = mock(ExecState.class);
    when(execState.exitCode()).thenReturn(0L);
    final LogStream log = mock(LogStream.class);
    when(log.readFully()).thenReturn("");
    docker = mock(DockerClient.class);
    when(docker.info()).thenReturn(info);
    when(docker.version()).thenReturn(version);
    when(docker.execCreate(eq(CONTAINER_ID), any(String[].class), (DockerClient.ExecCreateParam) anyVararg())).thenReturn(ExecCreation.create(EXEC_ID, emptyList()));
    when(docker.execStart(eq(EXEC_ID), (ExecStartParameter) anyVararg())).thenReturn(log);
    when(docker.execInspect(EXEC_ID)).thenReturn(execState);
    checker = new ExecHealthChecker(healthCheck, docker);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Version(com.spotify.docker.client.messages.Version) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck) ExecState(com.spotify.docker.client.messages.ExecState) LogStream(com.spotify.docker.client.LogStream) Info(com.spotify.docker.client.messages.Info) ExecHealthChecker(com.spotify.helios.agent.HealthCheckerFactory.ExecHealthChecker) Before(org.junit.Before)

Aggregations

Version (com.spotify.docker.client.messages.Version)6 Info (com.spotify.docker.client.messages.Info)2 Test (org.junit.Test)2 DockerClient (com.spotify.docker.client.DockerClient)1 LogStream (com.spotify.docker.client.LogStream)1 VersionCompare.compareVersion (com.spotify.docker.client.VersionCompare.compareVersion)1 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 ExecState (com.spotify.docker.client.messages.ExecState)1 ImageInfo (com.spotify.docker.client.messages.ImageInfo)1 ExecHealthChecker (com.spotify.helios.agent.HealthCheckerFactory.ExecHealthChecker)1 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)1 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)1 Endpoint (com.spotify.helios.serviceregistration.ServiceRegistration.Endpoint)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DockerException (org.eclipse.linuxtools.docker.core.DockerException)1 IDockerConnectionInfo (org.eclipse.linuxtools.docker.core.IDockerConnectionInfo)1 IDockerContainerInfo (org.eclipse.linuxtools.docker.core.IDockerContainerInfo)1