com.github.dockerjava.api.model.Version Java Examples

The following examples show how to use com.github.dockerjava.api.model.Version. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDockerComponentForUnixSocket() throws Exception {
    File dockerSocket = new File("/var/run/docker.sock");

    Assume.assumeTrue("Docker socket /var/run/docker.sock does not exist or is not writable", dockerSocket.exists() && dockerSocket.canWrite());

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("docker:version?socket=true&host=%s", dockerSocket.getPath());
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Version dockerVersion = template.requestBody("direct:start", null, Version.class);
        Assert.assertNotNull("Docker version not null", dockerVersion);
        Assert.assertFalse("Docker version was empty", dockerVersion.getVersion().isEmpty());
    } finally {
        camelctx.close();
    }
}
 
Example #2
Source File: DockerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testDockerComponentForHostnameAndPort() throws Exception {
    Assume.assumeNotNull("DOCKER_HOST environment variable is not set", System.getenv("DOCKER_HOST"));

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .toF("docker:version?host=%s&port=%d", TestUtils.getDockerHost(), TestUtils.getDockerPort());
        }
    });

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        Version dockerVersion = template.requestBody("direct:start", null, Version.class);
        Assert.assertNotNull("Docker version not null", dockerVersion);
        Assert.assertFalse("Docker version was empty", dockerVersion.getVersion().isEmpty());
    } finally {
        camelctx.close();
    }
}
 
Example #3
Source File: VersionCmdExec.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Override
protected Version execute(VersionCmd command) {
    WebTarget webResource = getBaseResource().path("/version");

    LOGGER.trace("GET: {}", webResource);
    return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<Version>() {
    });
}
 
Example #4
Source File: DockerCloud.java    From docker-plugin with MIT License 5 votes vote down vote up
public boolean isTriton() {
    if( _isTriton == null ) {
        final Version remoteVersion;
        try(final DockerClient client = dockerApi.getClient()) {
            remoteVersion = client.versionCmd().exec();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        _isTriton = remoteVersion.getOperatingSystem().equals("solaris");
    }
    return _isTriton;
}
 
Example #5
Source File: DockerAPI.java    From docker-plugin with MIT License 5 votes vote down vote up
public boolean isSwarm() {
    if (_isSwarm == null) {
        try(final DockerClient client = getClient()) {
            Version remoteVersion = client.versionCmd().exec();
            // Cache the return.
            _isSwarm = remoteVersion.getVersion().startsWith("swarm");
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
    return _isSwarm;
}
 
Example #6
Source File: DockerAPI.java    From docker-plugin with MIT License 5 votes vote down vote up
@RequirePOST
public FormValidation doTestConnection(
        @AncestorInPath Item context,
        @QueryParameter String uri,
        @QueryParameter String credentialsId,
        @QueryParameter String apiVersion,
        @QueryParameter int connectTimeout,
        @QueryParameter int readTimeout
) {
    throwIfNoPermission(context);
    final FormValidation credentialsIdCheckResult = doCheckCredentialsId(context, uri, credentialsId);
    if (credentialsIdCheckResult != FormValidation.ok()) {
        return FormValidation.error("Invalid credentials");
    }
    try {
        final DockerServerEndpoint dsep = new DockerServerEndpoint(uri, credentialsId);
        final DockerAPI dapi = new DockerAPI(dsep, connectTimeout, readTimeout, apiVersion, null);
        try(final DockerClient dc = dapi.getClient()) {
            final VersionCmd vc = dc.versionCmd();
            final Version v = vc.exec();
            final String actualVersion = v.getVersion();
            final String actualApiVersion = v.getApiVersion();
            return FormValidation.ok("Version = " + actualVersion + ", API Version = " + actualApiVersion);
        }
    } catch (Exception e) {
        return FormValidation.error(e, e.getMessage());
    }
}