diff options
author | toby <smorgrav@yahoo-inc.com> | 2017-04-25 16:20:03 +0200 |
---|---|---|
committer | toby <smorgrav@yahoo-inc.com> | 2017-05-09 17:02:07 +0200 |
commit | 141643300d8c58d4dfb78944c425032090cfab9a (patch) | |
tree | e3dc17500f08bc1acfb1dfa932989cbcc9ab77de | |
parent | 8967f476ddbb8c52fb56b3afcc761860db4ea9ed (diff) |
Consistent formatting
7 files changed, 44 insertions, 37 deletions
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 66cd50ddb20..e94a2d9d118 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 @@ -93,7 +93,7 @@ public class DockerImpl implements Docker { true, /* fallback to 1.23 on errors */ metricReceiver); - if (! config.isRunningLocally()) { + if (!config.isRunningLocally()) { Duration minAgeToDelete = Duration.ofMinutes(config.imageGCMinTimeToLiveMinutes()); dockerImageGC = Optional.of(new DockerImageGarbageCollector(minAgeToDelete)); @@ -121,7 +121,7 @@ public class DockerImpl implements Docker { } private void setupDockerNetworkIfNeeded() throws IOException { - if (! dockerClient.listNetworksCmd().withNameFilter(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return; + if (!dockerClient.listNetworksCmd().withNameFilter(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return; // Use IPv6 address if there is a mix of IP4 and IPv6 by taking the longest address. List<InetAddress> hostAddresses = Arrays.asList(InetAddress.getAllByName(com.yahoo.net.HostName.getLocalhost())); @@ -426,7 +426,7 @@ public class DockerImpl implements Docker { @Override public void deleteUnusedDockerImages() { - if (! dockerImageGC.isPresent()) return; + if (!dockerImageGC.isPresent()) return; List<Image> images = listAllImages(); List<com.github.dockerjava.api.model.Container> containers = listAllContainers(); @@ -494,7 +494,7 @@ public class DockerImpl implements Docker { remoteApiVersion = RemoteApiVersion.parseConfig(DockerClientImpl.getInstance( buildDockerClientConfig(config).build()) .withDockerCmdExecFactory(dockerFactory).versionCmd().exec().getApiVersion()); - logger.info("Found version of remote docker API: "+ remoteApiVersion); + logger.info("Found version of remote docker API: " + remoteApiVersion); // From version 1.24 a field was removed which causes trouble with the current docker java code. // When this is fixed, we can remove this and do not specify version. if (remoteApiVersion.isGreaterOrEqual(RemoteApiVersion.VERSION_1_24)) { @@ -502,7 +502,7 @@ public class DockerImpl implements Docker { logger.info("Found version 1.24 or newer of remote API, using 1.23."); } } catch (Exception e) { - if (! fallbackTo123orErrors) { + 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/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java index 7dc29aaa200..fafbf3e2563 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImpl.java @@ -38,16 +38,17 @@ import static com.yahoo.vespa.defaults.Defaults.getDefaults; /** * Class that wraps the Docker class and have some tools related to running programs in docker. + * * @author dybis */ public class DockerOperationsImpl implements DockerOperations { public static final String NODE_PROGRAM = Defaults.getDefaults().underVespaHome("bin/vespa-nodectl"); private static final String[] GET_VESPA_VERSION_COMMAND = new String[]{NODE_PROGRAM, "vespa-version"}; - private static final String[] RESUME_NODE_COMMAND = new String[] {NODE_PROGRAM, "resume"}; - private static final String[] SUSPEND_NODE_COMMAND = new String[] {NODE_PROGRAM, "suspend"}; - private static final String[] RESTART_VESPA_ON_NODE_COMMAND = new String[] {NODE_PROGRAM, "restart-vespa"}; - private static final String[] STOP_NODE_COMMAND = new String[] {NODE_PROGRAM, "stop"}; + private static final String[] RESUME_NODE_COMMAND = new String[]{NODE_PROGRAM, "resume"}; + private static final String[] SUSPEND_NODE_COMMAND = new String[]{NODE_PROGRAM, "suspend"}; + private static final String[] RESTART_VESPA_ON_NODE_COMMAND = new String[]{NODE_PROGRAM, "restart-vespa"}; + private static final String[] STOP_NODE_COMMAND = new String[]{NODE_PROGRAM, "stop"}; private static final Pattern VESPA_VERSION_PATTERN = Pattern.compile("^(\\S*)$", Pattern.MULTILINE); @@ -55,6 +56,7 @@ public class DockerOperationsImpl implements DockerOperations { // Map of directories to mount and whether they should be writable by everyone private static final Map<String, Boolean> DIRECTORIES_TO_MOUNT = new HashMap<>(); + static { DIRECTORIES_TO_MOUNT.put("/etc/yamas-agent", true); DIRECTORIES_TO_MOUNT.put("/etc/filebeat", true); @@ -231,7 +233,7 @@ public class DockerOperationsImpl implements DockerOperations { * Try to suspend node. Suspending a node means the node should be taken offline, * such that maintenance can be done of the node (upgrading, rebooting, etc), * and such that we will start serving again as soon as possible afterwards. - * + * <p> * Any failures are logged and ignored. */ @Override @@ -244,7 +246,7 @@ public class DockerOperationsImpl implements DockerOperations { // It's bad to continue as-if nothing happened, but on the other hand if we do not proceed to // remove container, we will not be able to upgrade to fix any problems in the suspend logic! logger.warning("Failed trying to suspend container " + containerName.asString() + " with " - + Arrays.toString(SUSPEND_NODE_COMMAND), e); + + Arrays.toString(SUSPEND_NODE_COMMAND), e); } } @@ -371,7 +373,7 @@ public class DockerOperationsImpl implements DockerOperations { if (resultCode != 0) { throw new RuntimeException("Command " + Joiner.on(' ').join(command) + " failed: " + output); } - } catch (IOException|InterruptedException e) { + } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java index 0b44f526670..385e823dc3a 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/acl/AclMaintainer.java @@ -22,11 +22,11 @@ import java.util.stream.Collectors; * The responsibility of this class is to configure ACLs for all running containers. The ACLs are fetched from the Node * repository. Based on those ACLs, iptables commands are created and then executed in each of the containers network * namespace. - * + * <p> * If an ACL cannot be configured (e.g. iptables process execution fails), a rollback is attempted by setting the * default policy to ACCEPT which will allow any traffic. The configuration will be retried the next time the * maintainer runs. - * + * <p> * The ACL maintainer does not handle IPv4 addresses and is thus only intended to configure ACLs for IPv6-only * containers (e.g. any container, except node-admin). * @@ -43,7 +43,7 @@ public class AclMaintainer implements Runnable { private final Map<ContainerName, Acl> containerAcls; public AclMaintainer(DockerOperations dockerOperations, NodeRepository nodeRepository, - String nodeAdminHostname) { + String nodeAdminHostname) { this.dockerOperations = dockerOperations; this.nodeRepository = nodeRepository; this.nodeAdminHostname = nodeAdminHostname; diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 8e7892652e3..6ffe8bccf57 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -81,6 +81,7 @@ public class NodeAgentImpl implements NodeAgent { RUNNING_HOWEVER_RESUME_SCRIPT_NOT_RUN, RUNNING } + private ContainerState containerState = ABSENT; // The attributes of the last successful node repo attribute update for this node. Used to avoid redundant calls. @@ -173,7 +174,7 @@ public class NodeAgentImpl implements NodeAgent { } loopThread = new Thread(() -> { - while (! terminated.get()) tick(); + while (!terminated.get()) tick(); }); loopThread.setName("tick-" + hostname); loopThread.start(); @@ -200,7 +201,7 @@ public class NodeAgentImpl implements NodeAgent { try { FilebeatConfigProvider filebeatConfigProvider = new FilebeatConfigProvider(environment); Optional<String> config = filebeatConfigProvider.getConfig(nodeSpec); - if (! config.isPresent()) { + if (!config.isPresent()) { logger.error("Was not able to generate a config for filebeat, ignoring filebeat file creation." + nodeSpec.toString()); return; } @@ -251,16 +252,16 @@ public class NodeAgentImpl implements NodeAgent { // TODO: We should only update if the new current values do not match the node repo's current values if (!currentAttributes.equals(lastAttributesSet)) { logger.info("Publishing new set of attributes to node repo: " - + lastAttributesSet + " -> " + currentAttributes); + + lastAttributesSet + " -> " + currentAttributes); addDebugMessage("Publishing new set of attributes to node repo: {" + - lastAttributesSet + "} -> {" + currentAttributes + "}"); + lastAttributesSet + "} -> {" + currentAttributes + "}"); nodeRepository.updateNodeAttributes(hostname, currentAttributes); lastAttributesSet = currentAttributes; } } private void startContainerIfNeeded(final ContainerNodeSpec nodeSpec) { - if (! getContainer().isPresent()) { + if (!getContainer().isPresent()) { aclMaintainer.ifPresent(AclMaintainer::run); dockerOperations.startContainer(containerName, nodeSpec); metricReceiver.unsetMetricsForContainer(hostname); @@ -269,7 +270,7 @@ public class NodeAgentImpl implements NodeAgent { configureContainerMetrics(nodeSpec); addDebugMessage("startContainerIfNeeded: containerState " + containerState + " -> " + - RUNNING_HOWEVER_RESUME_SCRIPT_NOT_RUN); + RUNNING_HOWEVER_RESUME_SCRIPT_NOT_RUN); containerState = RUNNING_HOWEVER_RESUME_SCRIPT_NOT_RUN; logger.info("Container successfully started, new containerState is " + containerState); } @@ -280,13 +281,13 @@ public class NodeAgentImpl implements NodeAgent { shouldRestartServices(nodeSpec).ifPresent(restartReason -> { logger.info("Will restart services for container " + existingContainer + ": " + restartReason); restartServices(nodeSpec, existingContainer); - })); + })); } private Optional<String> shouldRestartServices(ContainerNodeSpec nodeSpec) { - if ( ! nodeSpec.wantedRestartGeneration.isPresent()) return Optional.empty(); + if (!nodeSpec.wantedRestartGeneration.isPresent()) return Optional.empty(); - if (! nodeSpec.currentRestartGeneration.isPresent() || + if (!nodeSpec.currentRestartGeneration.isPresent() || nodeSpec.currentRestartGeneration.get() < nodeSpec.wantedRestartGeneration.get()) { return Optional.of("Restart requested - wanted restart generation has been bumped: " + nodeSpec.currentRestartGeneration.get() + " -> " + nodeSpec.wantedRestartGeneration.get()); @@ -318,7 +319,7 @@ public class NodeAgentImpl implements NodeAgent { } if (nodeSpec.wantedDockerImage.isPresent() && !nodeSpec.wantedDockerImage.get().equals(existingContainer.image)) { return Optional.of("The node is supposed to run a new Docker image: " - + existingContainer + " -> " + nodeSpec.wantedDockerImage.get()); + + existingContainer + " -> " + nodeSpec.wantedDockerImage.get()); } if (!existingContainer.state.isRunning()) { return Optional.of("Container no longer running"); @@ -373,7 +374,7 @@ public class NodeAgentImpl implements NodeAgent { private void signalWorkToBeDone() { synchronized (monitor) { - if (! workToDoNow) { + if (!workToDoNow) { workToDoNow = true; addDebugMessage("Signaling work to be done"); monitor.notifyAll(); @@ -384,7 +385,7 @@ public class NodeAgentImpl implements NodeAgent { void tick() { boolean isFrozenCopy; synchronized (monitor) { - while (! workToDoNow) { + while (!workToDoNow) { long remainder = delaysBetweenEachConvergeMillis - Duration.between(lastConverge, clock.instant()).toMillis(); if (remainder > 0) { try { @@ -527,7 +528,7 @@ public class NodeAgentImpl implements NodeAgent { // The remaining metrics require container to exists and be running if (containerState == ABSENT) return; Optional<Docker.ContainerStats> containerStats = dockerOperations.getContainerStats(containerName); - if ( ! containerStats.isPresent()) return; + if (!containerStats.isPresent()) return; Docker.ContainerStats stats = containerStats.get(); @@ -579,7 +580,7 @@ public class NodeAgentImpl implements NodeAgent { if (metricsMap == null || !metricsMap.containsKey(metricName)) return; try { metricReceiver.declareGauge(MetricReceiverWrapper.APPLICATION_DOCKER, dimensions, yamasName) - .sample(((Number) metricsMap.get(metricName)).doubleValue()); + .sample(((Number) metricsMap.get(metricName)).doubleValue()); } catch (Throwable e) { logger.warning("Failed to update " + yamasName + " metric with value " + metricsMap.get(metricName), e); } @@ -608,7 +609,7 @@ public class NodeAgentImpl implements NodeAgent { } private void configureContainerMetrics(ContainerNodeSpec nodeSpec) { - if (! storageMaintainer.isPresent()) return; + if (!storageMaintainer.isPresent()) return; final Path yamasAgentFolder = environment.pathInNodeAdminFromPathInNode(containerName, "/etc/yamas-agent/"); Path vespaCheckPath = Paths.get(getDefaults().underVespaHome("libexec/yms/yms_check_vespa")); @@ -634,7 +635,7 @@ public class NodeAgentImpl implements NodeAgent { try { scheduleMaker.writeTo(yamasAgentFolder); - final String[] restartYamasAgent = new String[] {"service" , "yamas-agent", "restart"}; + final String[] restartYamasAgent = new String[]{"service", "yamas-agent", "restart"}; dockerOperations.executeCommandInContainerAsRoot(containerName, restartYamasAgent); } catch (IOException e) { throw new RuntimeException("Failed to write secret-agent schedules for " + containerName, e); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/provider/ComponentsProviderImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/provider/ComponentsProviderImpl.java index 39b479c8ce8..487d1845c62 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/provider/ComponentsProviderImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/provider/ComponentsProviderImpl.java @@ -83,7 +83,7 @@ public class ComponentsProviderImpl implements ComponentsProvider { public ComponentsProviderImpl(final NodeAdminConfig config, final Docker docker, final MetricReceiverWrapper metricReceiver) { this(docker, metricReceiver, new Environment(), config.isRunningLocally()); - if (! config.isRunningLocally()) { + if (!config.isRunningLocally()) { setCorePattern(docker); initializeNodeAgentSecretAgent(docker); } diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java index 8d867a16c05..2822926945b 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/DockerOperationsImplTest.java @@ -40,7 +40,7 @@ public class DockerOperationsImplTest { final ContainerName containerName = new ContainerName("container-name"); final ProcessResult actualResult = new ProcessResult(0, "output", "errors"); final String programPath = "/bin/command"; - final String[] command = new String[] {programPath, "arg"}; + final String[] command = new String[]{programPath, "arg"}; when(docker.executeInContainerAsRoot(any(), anyVararg())) .thenReturn(actualResult); // output from node program @@ -56,12 +56,12 @@ public class DockerOperationsImplTest { assertThat(result, is(actualResult)); } - @Test(expected=RuntimeException.class) + @Test(expected = RuntimeException.class) public void processResultFromNodeProgramWhenNonZeroExitCode() throws Exception { final ContainerName containerName = new ContainerName("container-name"); final ProcessResult actualResult = new ProcessResult(3, "output", "errors"); final String programPath = "/bin/command"; - final String[] command = new String[] {programPath, "arg"}; + final String[] command = new String[]{programPath, "arg"}; when(docker.executeInContainerAsRoot(any(), anyVararg())) .thenReturn(actualResult); // output from node program diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerMock.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerMock.java index 053ad921fef..67c2de924b3 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerMock.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/integrationTests/DockerMock.java @@ -220,10 +220,14 @@ public class DockerMock implements Docker { } @Override - public CreateContainerCommand withAddCapability(String capabilityName) {return this; } + public CreateContainerCommand withAddCapability(String capabilityName) { + return this; + } @Override - public CreateContainerCommand withDropCapability(String capabilityName) {return this; } + public CreateContainerCommand withDropCapability(String capabilityName) { + return this; + } @Override public void create() { |