summaryrefslogtreecommitdiffstats
path: root/docker-api
diff options
context:
space:
mode:
authorHarald Musum <musum@yahoo-inc.com>2017-12-19 21:30:41 +0100
committerGitHub <noreply@github.com>2017-12-19 21:30:41 +0100
commiteef3b73f9cd69c2d120642b32a1aa7d950b959cd (patch)
tree83ac9d6d219c4a6e3cee62521c1d4716a2e58305 /docker-api
parenta5760e9537aee7fd123e1455424b1083d6881ee8 (diff)
Revert "Prepare for making node admin components optional"
Diffstat (limited to 'docker-api')
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/Docker.java5
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java79
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java6
3 files changed, 29 insertions, 61 deletions
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/Docker.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/Docker.java
index bc94c39d135..2bf3f0f8d84 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/Docker.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/Docker.java
@@ -12,11 +12,6 @@ import java.util.Optional;
* and to avoid OSGi exporting those classes.
*/
public interface Docker {
- /**
- * Must be called before any other method. May be called more than once.
- */
- void start();
-
interface CreateContainerCommand {
CreateContainerCommand withLabel(String name, String value);
CreateContainerCommand withEnvironment(String name, String value);
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
index 054f466657f..9de2cae604f 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
@@ -59,10 +59,7 @@ public class DockerImpl implements Docker {
static final String LABEL_NAME_MANAGEDBY = "com.yahoo.vespa.managedby";
private final int SECONDS_TO_WAIT_BEFORE_KILLING;
- private final boolean fallbackTo123OnErrors;
private static final String FRAMEWORK_CONTAINER_PREFIX = "/";
- private final DockerConfig config;
- private final boolean inProduction;
private Optional<DockerImageGarbageCollector> dockerImageGC = Optional.empty();
private CounterWrapper numberOfDockerDaemonFails;
@@ -71,61 +68,39 @@ public class DockerImpl implements Docker {
private final Set<DockerImage> scheduledPulls = new HashSet<>();
// Exposed for testing.
- DockerClient dockerClient;
-
- @Inject
- public DockerImpl(final DockerConfig config, MetricReceiverWrapper metricReceiver) {
- this(config,
- true, /* fallback to 1.23 on errors */
- metricReceiver,
- !config.isRunningLocally());
- }
-
- private DockerImpl(final DockerConfig config,
- boolean fallbackTo123OnErrors,
- MetricReceiverWrapper metricReceiverWrapper,
- boolean inProduction) {
- this.config = config;
- this.fallbackTo123OnErrors = fallbackTo123OnErrors;
- this.inProduction = inProduction;
- if (config == null) {
- this.SECONDS_TO_WAIT_BEFORE_KILLING = 10;
- } else {
- SECONDS_TO_WAIT_BEFORE_KILLING = config.secondsToWaitBeforeKillingContainer();
- }
- if (metricReceiverWrapper != null) {
- setMetrics(metricReceiverWrapper);
- }
- }
+ final DockerClient dockerClient;
// For testing
DockerImpl(final DockerClient dockerClient) {
- this(null, false, null, false);
this.dockerClient = dockerClient;
+ this.SECONDS_TO_WAIT_BEFORE_KILLING = 10;
}
- // For testing
- DockerImpl(final DockerConfig config,
- boolean fallbackTo123OnErrors,
- MetricReceiverWrapper metricReceiverWrapper) {
- this(config, fallbackTo123OnErrors, metricReceiverWrapper, false);
+ DockerImpl(
+ final DockerConfig config,
+ boolean fallbackTo123OnErrors,
+ MetricReceiverWrapper metricReceiverWrapper) {
+ SECONDS_TO_WAIT_BEFORE_KILLING = config.secondsToWaitBeforeKillingContainer();
+
+ dockerClient = initDockerConnection(config, fallbackTo123OnErrors);
+ setMetrics(metricReceiverWrapper);
}
- @Override
- public void start() {
- if (config != null) {
- if (dockerClient == null) {
- dockerClient = initDockerConnection();
- }
- if (inProduction) {
- Duration minAgeToDelete = Duration.ofMinutes(config.imageGCMinTimeToLiveMinutes());
- dockerImageGC = Optional.of(new DockerImageGarbageCollector(minAgeToDelete));
-
- try {
- setupDockerNetworkIfNeeded();
- } catch (Exception e) {
- throw new DockerException("Could not setup docker network", e);
- }
+ @Inject
+ public DockerImpl(final DockerConfig config, MetricReceiverWrapper metricReceiver) {
+ this(
+ config,
+ true, /* fallback to 1.23 on errors */
+ metricReceiver);
+
+ if (!config.isRunningLocally()) {
+ Duration minAgeToDelete = Duration.ofMinutes(config.imageGCMinTimeToLiveMinutes());
+ dockerImageGC = Optional.of(new DockerImageGarbageCollector(minAgeToDelete));
+
+ try {
+ setupDockerNetworkIfNeeded();
+ } catch (Exception e) {
+ throw new DockerException("Could not setup docker network", e);
}
}
}
@@ -514,7 +489,7 @@ public class DockerImpl implements Docker {
}
}
- private DockerClient initDockerConnection() {
+ private DockerClient initDockerConnection(final DockerConfig config, boolean fallbackTo123orErrors) {
JerseyDockerCmdExecFactory dockerFactory = new JerseyDockerCmdExecFactory()
.withMaxPerRouteConnections(config.maxPerRouteConnections())
.withMaxTotalConnections(config.maxTotalConnections())
@@ -533,7 +508,7 @@ public class DockerImpl implements Docker {
logger.info("Found version 1.24 or newer of remote API, using 1.23.");
}
} catch (Exception e) {
- if (!fallbackTo123OnErrors) {
+ if (!fallbackTo123orErrors) {
throw e;
}
logger.log(LogLevel.ERROR, "Failed when trying to figure out remote API version of docker, using 1.23", e);
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
index 549af0d85cb..079d6876043 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
@@ -46,13 +46,11 @@ public class DockerTestUtils {
public static DockerImpl getDocker() {
if (docker == null) {
- DockerImpl tmpDocker = new DockerImpl(
+ docker = new DockerImpl(
dockerConfig,
false, /* fallback to 1.23 on errors */
new MetricReceiverWrapper(MetricReceiver.nullImplementation));
- tmpDocker.start();
- createDockerTestNetworkIfNeeded(tmpDocker);
- docker = tmpDocker;
+ createDockerTestNetworkIfNeeded(docker);
}
return docker;