Java Code Examples for com.spotify.docker.client.DefaultDockerClient#ping()

The following examples show how to use com.spotify.docker.client.DefaultDockerClient#ping() . 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: DockerClientFactory.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 6 votes vote down vote up
private static DefaultDockerClient createClient(ClusterProfileProperties clusterProfileProperties) throws Exception {
    DefaultDockerClient.Builder builder = DefaultDockerClient.builder();

    builder.uri(clusterProfileProperties.getDockerURI());
    if (clusterProfileProperties.getDockerURI().startsWith("https://")) {
        setupCerts(clusterProfileProperties, builder);
    }

    if (clusterProfileProperties.useDockerAuthInfo()) {
        final RegistryAuth registryAuth = clusterProfileProperties.registryAuth();
        LOG.info(format("Using private docker registry server `{0}`.", registryAuth.serverAddress()));
        builder.registryAuth(registryAuth);
    }

    DefaultDockerClient docker = builder.build();
    String ping = docker.ping();
    if (!"OK".equals(ping)) {
        throw new RuntimeException("Could not ping the docker server, the server said '" + ping + "' instead of 'OK'.");
    }
    return docker;
}
 
Example 2
Source File: DockerClientFactory.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
private static DefaultDockerClient createClient(ArtifactStoreConfig artifactStoreConfig) throws DockerCertificateException, DockerException, InterruptedException {
    final RegistryAuthSupplierChain registryAuthSupplier = new RegistryAuthSupplierChain(artifactStoreConfig, new AWSTokenRequestGenerator());
    DefaultDockerClient docker = DefaultDockerClient.fromEnv().registryAuthSupplier(registryAuthSupplier).build();

    LOG.info(format("Using docker registry server `{0}`.", artifactStoreConfig.getRegistryUrl()));

    final String result = docker.ping();
    if (!result.equalsIgnoreCase("OK")) {
        throw new RuntimeException("Could not ping the docker server.");
    }
    return docker;
}
 
Example 3
Source File: DockerClientFactory.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
private static DefaultDockerClient createClient(PluginSettings pluginSettings) throws Exception {
    DefaultDockerClient.Builder builder = DefaultDockerClient.builder();

    builder.uri(pluginSettings.getDockerURI());
    if (pluginSettings.getDockerURI().startsWith("https://")) {
        setupCerts(pluginSettings, builder);
    }

    if (pluginSettings.useDockerAuthInfo()) {
        RegistryAuth auth;
        if (pluginSettings.useCustomRegistryCredentials()) {
            auth = RegistryAuth.builder()
                    .password(pluginSettings.getPrivateRegistryPassword())
                    .serverAddress(pluginSettings.getPrivateRegistryServer())
                    .username(pluginSettings.getPrivateRegistryUsername())
                    .build();
        } else {
            auth = RegistryAuth.fromDockerConfig(pluginSettings.getPrivateRegistryServer()).build();
        }
        builder.registryAuth(auth);
    }

    DefaultDockerClient docker = builder.build();
    String ping = docker.ping();
    if (!"OK".equals(ping)) {
        throw new RuntimeException("Could not ping the docker server, the server said '" + ping + "' instead of 'OK'.");
    }
    return docker;
}