forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerClientBuilder.java
More file actions
110 lines (95 loc) · 3.64 KB
/
Copy pathDockerClientBuilder.java
File metadata and controls
110 lines (95 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.github.dockerjava.core;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.DockerCmdExecFactory;
import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory;
import com.github.dockerjava.jaxrs.JerseyDockerHttpClient;
import com.github.dockerjava.transport.DockerHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DockerClientBuilder {
private final DockerClientConfig dockerClientConfig;
private DockerCmdExecFactory dockerCmdExecFactory = null;
private DockerHttpClient dockerHttpClient = null;
private DockerClientBuilder(DockerClientConfig dockerClientConfig) {
this.dockerClientConfig = dockerClientConfig;
}
public static DockerClientBuilder getInstance() {
return new DockerClientBuilder(
DefaultDockerClientConfig.createDefaultConfigBuilder().build()
);
}
/**
*
* @deprecated use {@link #getInstance(DockerClientConfig)}
*/
@Deprecated
public static DockerClientBuilder getInstance(DefaultDockerClientConfig.Builder dockerClientConfigBuilder) {
return getInstance(dockerClientConfigBuilder.build());
}
public static DockerClientBuilder getInstance(DockerClientConfig dockerClientConfig) {
return new DockerClientBuilder(dockerClientConfig);
}
/**
*
* @deprecated use {@link DefaultDockerClientConfig.Builder#withDockerHost(String)}
*/
@Deprecated
public static DockerClientBuilder getInstance(String serverUrl) {
return new DockerClientBuilder(
DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost(serverUrl)
.build()
);
}
/**
*
* @deprecated no replacement, use one of {@link DockerHttpClient}
*/
@Deprecated
public static DockerCmdExecFactory getDefaultDockerCmdExecFactory() {
return new JerseyDockerCmdExecFactory();
}
/**
* Note that this method overrides {@link DockerHttpClient} if it was previously set
*
* @deprecated use {@link #withDockerHttpClient(DockerHttpClient)}
*/
@Deprecated
public DockerClientBuilder withDockerCmdExecFactory(DockerCmdExecFactory dockerCmdExecFactory) {
this.dockerCmdExecFactory = dockerCmdExecFactory;
this.dockerHttpClient = null;
return this;
}
/**
* Note that this method overrides {@link DockerCmdExecFactory} if it was previously set
*/
public DockerClientBuilder withDockerHttpClient(DockerHttpClient dockerHttpClient) {
this.dockerCmdExecFactory = null;
this.dockerHttpClient = dockerHttpClient;
return this;
}
public DockerClient build() {
if (dockerHttpClient != null) {
return DockerClientImpl.getInstance(
dockerClientConfig,
dockerHttpClient
);
} else if (dockerCmdExecFactory != null) {
return DockerClientImpl.getInstance(dockerClientConfig)
.withDockerCmdExecFactory(dockerCmdExecFactory);
} else {
Logger log = LoggerFactory.getLogger(DockerClientBuilder.class);
log.warn(
"'dockerHttpClient' should be set." +
"Falling back to Jersey, will be an error in future releases."
);
return DockerClientImpl.getInstance(
dockerClientConfig,
new JerseyDockerHttpClient.Builder()
.dockerHost(dockerClientConfig.getDockerHost())
.sslConfig(dockerClientConfig.getSSLConfig())
.build()
);
}
}
}