Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7acb32a5b54792b03e7232054bfc2cc37a945915 (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*******************************************************************************
 * Copyright (c) 2014 Red Hat.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - Initial Contribution
 *******************************************************************************/
package org.eclipse.linuxtools.internal.docker.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.linuxtools.docker.core.IDockerConfParameter;
import org.eclipse.linuxtools.docker.core.IDockerHostConfig;
import org.eclipse.linuxtools.docker.core.IDockerPortBinding;

import com.spotify.docker.client.messages.HostConfig;
import com.spotify.docker.client.messages.HostConfig.LxcConfParameter;
import com.spotify.docker.client.messages.PortBinding;

public class DockerHostConfig implements IDockerHostConfig {

	private final List<String> binds;
	private final String containerIDFile;
	private final List<IDockerConfParameter> lxcConf;
	private final boolean privileged;
	private final boolean readonlyRootfs;
	private final Map<String, String> tmpfs;
	private final Map<String, List<IDockerPortBinding>> portBindings;
	private final List<String> links;
	private final boolean publishAllPorts;
	private final List<String> dns;
	private final List<String> dnsSearch;
	private final List<String> volumesFrom;
	private final List<String> securityOpt;
	private final List<String> capAdd;
	private final List<String> capDrop;
	private final String networkMode;
	private final Long memory;
	private final Long cpuShares;

	public DockerHostConfig(final HostConfig hostConfig) {
		this.binds = hostConfig.binds();
		this.containerIDFile = hostConfig.containerIdFile();
		this.lxcConf = new ArrayList<>();
		if(hostConfig.lxcConf() != null) {
			for (LxcConfParameter lxcConfParameter : hostConfig.lxcConf()) {
				this.lxcConf.add(new DockerConfParameter(lxcConfParameter));
			}
		}
		this.privileged = hostConfig.privileged() != null
				? hostConfig.privileged() : false;
		this.readonlyRootfs = hostConfig.readonlyRootfs() != null
				? hostConfig.readonlyRootfs()
				: false;
		this.tmpfs = hostConfig.tmpfs();
		this.portBindings = new HashMap<>();
		if(hostConfig != null && hostConfig.portBindings() != null) {
			for(Entry<String, List<PortBinding>> entry : hostConfig.portBindings().entrySet()) {
				final List<IDockerPortBinding> portBindings = new ArrayList<>();
				for (PortBinding portBinding : entry.getValue()) {
					portBindings.add(new DockerPortBinding(portBinding));
				}
				this.portBindings.put(entry.getKey(), portBindings);
			}
		}
		this.links = hostConfig.links();
		this.publishAllPorts = hostConfig.publishAllPorts() != null
				? hostConfig.publishAllPorts() : false;
		this.dns = hostConfig.dns();
		this.dnsSearch = hostConfig.dnsSearch();
		this.volumesFrom = hostConfig.volumesFrom();
		this.networkMode = hostConfig.networkMode();
		this.memory = hostConfig.memory();
		this.cpuShares = hostConfig.cpuShares();
		this.securityOpt = hostConfig.securityOpt();
		this.capAdd = hostConfig.capAdd();
		this.capDrop = hostConfig.capDrop();
	}

	private DockerHostConfig(final Builder builder) {
		this.binds = builder.binds;
		this.containerIDFile = builder.containerIDFile;
		this.lxcConf = builder.lxcConf;
		this.privileged = builder.privileged != null ? builder.privileged
				: false;
		this.readonlyRootfs = builder.readonlyRootfs != null
				? builder.readonlyRootfs
				: false;
		this.tmpfs = builder.tmpfs;
		this.portBindings = builder.portBindings;
		this.links = builder.links;
		this.publishAllPorts = builder.publishAllPorts != null
				? builder.publishAllPorts : false;
		this.dns = builder.dns;
		this.dnsSearch = builder.dnsSearch;
		this.volumesFrom = builder.volumesFrom;
		this.networkMode = builder.networkMode;
		this.memory = builder.memory;
		this.cpuShares = builder.cpuShares;
		this.securityOpt = builder.securityOpt;
		this.capAdd = builder.capAdd;
		this.capDrop = builder.capDrop;

	}

	@Override
	public List<String> binds() {
		return binds;
	}

	@Override
	public String containerIDFile() {
		return containerIDFile;
	}

	@Override
	public List<IDockerConfParameter> lxcConf() {
		return lxcConf;
	}

	@Override
	public boolean privileged() {
		return privileged;
	}

	public boolean readonlyRootfs() {
		return readonlyRootfs;
	}

	public Map<String, String> tmpfs() {
		return tmpfs;
	}

	@Override
	public Map<String, List<IDockerPortBinding>> portBindings() {
		return portBindings;
	}

	@Override
	public List<String> links() {
		return links;
	}

	@Override
	public boolean publishAllPorts() {
		return publishAllPorts;
	}

	@Override
	public List<String> dns() {
		return dns;
	}

	@Override
	public List<String> dnsSearch() {
		return dnsSearch;
	}

	@Override
	public List<String> volumesFrom() {
		return volumesFrom;
	}

	@Override
	public List<String> securityOpt() {
		return securityOpt;
	}

	public List<String> capAdd() {
		return capAdd;
	}

	public List<String> capDrop() {
		return capDrop;
	}

	@Override
	public String networkMode() {
		return networkMode;
	}

	public Long memory() {
		return memory;
	}

	public Long cpuShares() {
		return cpuShares;
	}

	public static Builder builder() {
		return new Builder();
	}

	public static class Builder {

		private List<String> binds;
		private String containerIDFile;
		private List<IDockerConfParameter> lxcConf;
		private Boolean privileged;
		private Boolean readonlyRootfs;
		private Map<String, String> tmpfs;
		private Map<String, List<IDockerPortBinding>> portBindings;
		private List<String> links;
		private Boolean publishAllPorts;
		private List<String> dns;
		private List<String> dnsSearch;
		private List<String> volumesFrom;
		private List<String> securityOpt;
		private List<String> capAdd;
		private List<String> capDrop;
		private String networkMode;
		private Long memory;
		private Long cpuShares;

		public Builder binds(final List<String> binds) {
			this.binds = new ArrayList<>(binds);
			return this;
		}

		public Builder binds(final String... binds) {
			this.binds = Arrays.asList(binds);
			return this;
		}

		public List<String> binds() {
			return binds;
		}

		public Builder containerIDFile(final String containerIDFile) {
			this.containerIDFile = containerIDFile;
			return this;
		}

		public Builder lxcConf(final List<IDockerConfParameter> lxcConf) {
			this.lxcConf = new ArrayList<>(lxcConf);
			return this;
		}

		public Builder lxcConf(final IDockerConfParameter... lxcConf) {
			this.lxcConf = Arrays.asList(lxcConf);
			return this;
		}

		public Builder privileged(final Boolean privileged) {
			this.privileged = privileged;
			return this;
		}

		public Builder readonlyRootfs(final Boolean readonlyRootfs) {
			this.readonlyRootfs = readonlyRootfs;
			return this;
		}

		public Builder tmpfs(Map<String, String> tmpfs) {
			this.tmpfs = tmpfs;
			return this;
		}

		public Map<String, String> tmpfs() {
			return tmpfs;
		}

		public Builder portBindings(
				final Map<String, List<IDockerPortBinding>> portBindings) {
			this.portBindings = portBindings;
			return this;
		}

		public Builder links(final List<String> links) {
			this.links = new ArrayList<>(links);
			return this;
		}

		public Builder links(final String... links) {
			this.links = Arrays.asList(links);
			return this;
		}

		public Builder publishAllPorts(final Boolean publishAllPorts) {
			this.publishAllPorts = publishAllPorts;
			return this;
		}

		public Builder dns(final List<String> dns) {
			this.dns = new ArrayList<>(dns);
			return this;
		}

		public Builder dns(final String... dns) {
			this.dns = Arrays.asList(dns);
			return this;
		}

		public Builder dnsSearch(final List<String> dnsSearch) {
			this.dnsSearch = new ArrayList<>(dnsSearch);
			return this;
		}

		public Builder dnsSearch(final String... dnsSearch) {
			this.dnsSearch = Arrays.asList(dnsSearch);
			return this;
		}

		public Builder volumesFrom(final List<String> volumesFrom) {
			this.volumesFrom = new ArrayList<>(volumesFrom);
			return this;
		}

		public Builder volumesFrom(final String... volumesFrom) {
			this.volumesFrom = Arrays.asList(volumesFrom);
			return this;
		}

		public Builder securityOpt(final List<String> securityOpt) {
			this.securityOpt = new ArrayList<>(securityOpt);
			return this;
		}

		public Builder securityOpt(final String... securityOpt) {
			this.securityOpt = Arrays.asList(securityOpt);
			return this;
		}

		public Builder capAdd(final List<String> capAdd) {
			this.capAdd = new ArrayList<>(capAdd);
			return this;
		}

		public Builder capAdd(final String... capAdd) {
			this.capAdd = Arrays.asList(capAdd);
			return this;
		}

		public Builder capDrop(final List<String> capDrop) {
			this.capDrop = new ArrayList<>(capDrop);
			return this;
		}

		public Builder capDrop(final String... capDrop) {
			this.capDrop = Arrays.asList(capDrop);
			return this;
		}

		public Builder networkMode(final String networkMode) {
			this.networkMode = networkMode;
			return this;
		}

		public Builder memory(final Long memory) {
			this.memory = memory;
			return this;
		}
		
		public Builder cpuShares(final Long cpuShares) {
			this.cpuShares = cpuShares;
			return this;
		}

		public IDockerHostConfig build() {
			return new DockerHostConfig(this);
		}

	}
}

Back to the top