From 183ca37dfad453e7eb26cf5ae9c3337495541334 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Fri, 29 Aug 2014 09:01:05 +0200 Subject: [PATCH] Code style improvement --- pom.xml | 465 +++++++++--------- .../cluster/block/ClusterBlocks.java | 2 +- .../discovery/DiscoverySettings.java | 13 +- .../discovery/zen/ZenDiscovery.java | 7 +- .../zen/fd/MasterFaultDetection.java | 1 + .../discovery/zen/fd/NodesFaultDetection.java | 2 + .../zen/ping/unicast/UnicastZenPing.java | 12 +- 7 files changed, 256 insertions(+), 246 deletions(-) diff --git a/pom.xml b/pom.xml index e01f6b8e689..d6bcaeb42cd 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ 0.8.13 true - + @@ -483,7 +483,8 @@ ${tests.failfast} false - . + . + ${tests.bwc} ${tests.bwc.path} @@ -537,15 +538,15 @@ 1.7 - validate - - run - - - - Using ${java.runtime.name} ${java.runtime.version} ${java.vendor} - - + validate + + run + + + + Using ${java.runtime.name} ${java.runtime.version} ${java.vendor} + + invalid-patterns @@ -573,7 +574,9 @@ - The following files contain tabs or nocommits:${line.separator}${validate.patternsFound} + The following files contain tabs or + nocommits:${line.separator}${validate.patternsFound} + @@ -581,7 +584,8 @@ tests test - ${skipTests} + ${skipTests} + false @@ -595,7 +599,7 @@ - + @@ -708,7 +712,7 @@ org.elasticsearch.common.compress - com.github.mustachejava + com.github.mustachejava org.elasticsearch.common.mustache @@ -1222,7 +1226,7 @@ org/elasticsearch/test/disruption/LongGCDisruption.class - + test-signatures.txt @@ -1348,219 +1352,220 @@ - - - default - - true - - - - - com.carrotsearch.randomizedtesting - junit4-maven-plugin - - ${tests.jvm.argline} - - - - com.mycila - license-maven-plugin - 2.5 - -
dev-tools/elasticsearch_license_header.txt
- - dev-tools/license_header_definition.xml - - - src/main/java/org/elasticsearch/**/*.java - src/test/java/org/elasticsearch/**/*.java - - - src/main/java/org/elasticsearch/common/inject/** - - src/main/java/org/elasticsearch/common/geo/GeoHashUtils.java - src/main/java/org/elasticsearch/common/lucene/search/XBooleanFilter.java - src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java - src/main/java/org/apache/lucene/queryparser/XSimpleQueryParser.java - src/main/java/org/apache/lucene/**/X*.java - - src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigestState.java - src/test/java/org/elasticsearch/search/aggregations/metrics/GroupTree.java - -
- - - compile - - check - - - -
-
-
-
- - - dev - - true - - - - - de.thetaphi - forbiddenapis - 1.5.1 - - - check-forbidden-apis - none - - - check-forbidden-test-apis - none - - - - - - - - - license - - - license.generation - true - - - - - - - coverage - - - tests.coverage - true - - - - - - org.jacoco - org.jacoco.agent - runtime - 0.6.4.201312101107 - test - - - - - - org.jacoco - jacoco-maven-plugin - 0.6.4.201312101107 - - - default-prepare-agent - - prepare-agent - - - - default-report - prepare-package - - report - - - - default-check - - check - - - - - - jsr166e/** - org/apache/lucene/** - - - - - - - - static - - - tests.static - true - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 2.5.3 - - - - - - - org.apache.maven.plugins - maven-jxr-plugin - 2.3 - - - org.apache.maven.plugins - maven-pmd-plugin - 3.0.1 - - - ${basedir}/dev-tools/pmd/custom.xml - - 1.7 - - **/jsr166e/** - **/org/apache/lucene/** - **/org/apache/elasticsearch/common/Base64.java - - - - - org.codehaus.mojo - findbugs-maven-plugin - 2.5.3 - - true - target/site - true - 2048 - 1800000 - org.elasticsearch.- - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.7 - - - - index - - - - - - - + + + default + + true + + + + + com.carrotsearch.randomizedtesting + junit4-maven-plugin + + ${tests.jvm.argline} + + + + com.mycila + license-maven-plugin + 2.5 + +
dev-tools/elasticsearch_license_header.txt
+ + dev-tools/license_header_definition.xml + + + src/main/java/org/elasticsearch/**/*.java + src/test/java/org/elasticsearch/**/*.java + + + src/main/java/org/elasticsearch/common/inject/** + + src/main/java/org/elasticsearch/common/geo/GeoHashUtils.java + src/main/java/org/elasticsearch/common/lucene/search/XBooleanFilter.java + src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java + src/main/java/org/apache/lucene/queryparser/XSimpleQueryParser.java + src/main/java/org/apache/lucene/**/X*.java + + src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigestState.java + + src/test/java/org/elasticsearch/search/aggregations/metrics/GroupTree.java + +
+ + + compile + + check + + + +
+
+
+
+ + + dev + + true + + + + + de.thetaphi + forbiddenapis + 1.5.1 + + + check-forbidden-apis + none + + + check-forbidden-test-apis + none + + + + + + + + + license + + + license.generation + true + + + + + + + coverage + + + tests.coverage + true + + + + + + org.jacoco + org.jacoco.agent + runtime + 0.6.4.201312101107 + test + + + + + + org.jacoco + jacoco-maven-plugin + 0.6.4.201312101107 + + + default-prepare-agent + + prepare-agent + + + + default-report + prepare-package + + report + + + + default-check + + check + + + + + + jsr166e/** + org/apache/lucene/** + + + + + + + + static + + + tests.static + true + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 2.5.3 + + + + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.3 + + + org.apache.maven.plugins + maven-pmd-plugin + 3.0.1 + + + ${basedir}/dev-tools/pmd/custom.xml + + 1.7 + + **/jsr166e/** + **/org/apache/lucene/** + **/org/apache/elasticsearch/common/Base64.java + + + + + org.codehaus.mojo + findbugs-maven-plugin + 2.5.3 + + true + target/site + true + 2048 + 1800000 + org.elasticsearch.- + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.7 + + + + index + + + + + + +
diff --git a/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 2aa6e4e014b..bb7d332de4f 100644 --- a/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -118,7 +118,7 @@ public class ClusterBlocks { } public boolean hasGlobalBlock(ClusterBlockLevel level) { - return !global(level).isEmpty(); + return global(level).size() > 0; } /** diff --git a/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java b/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java index dda300424ad..b8d48b16129 100644 --- a/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java +++ b/src/main/java/org/elasticsearch/discovery/DiscoverySettings.java @@ -89,12 +89,13 @@ public class DiscoverySettings extends AbstractComponent { } private ClusterBlock parseNoMasterBlock(String value) { - if ("all".equals(value)) { - return NO_MASTER_BLOCK_ALL; - } else if ("write".equals(value)) { - return NO_MASTER_BLOCK_WRITES; - } else { - throw new ElasticsearchIllegalArgumentException("invalid master block [" + value + "]"); + switch (value) { + case "all": + return NO_MASTER_BLOCK_ALL; + case "write": + return NO_MASTER_BLOCK_WRITES; + default: + throw new ElasticsearchIllegalArgumentException("invalid master block [" + value + "]"); } } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 8bfcb5bdb14..5662492d4d5 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -939,13 +939,14 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen if (pingMasters.isEmpty()) { // if we don't have enough master nodes, we bail, because there are not enough master to elect from - if (!electMaster.hasEnoughMasterNodes(possibleMasterNodes)) { + if (electMaster.hasEnoughMasterNodes(possibleMasterNodes)) { + return electMaster.electMaster(possibleMasterNodes); + } else { logger.trace("not enough master nodes [{}]", possibleMasterNodes); return null; } - // lets tie break between discovered nodes - return electMaster.electMaster(possibleMasterNodes); } else { + // lets tie break between discovered nodes return electMaster.electMaster(pingMasters); } } diff --git a/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java b/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java index b4f635184e7..c4b385572a2 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java +++ b/src/main/java/org/elasticsearch/discovery/zen/fd/MasterFaultDetection.java @@ -396,6 +396,7 @@ public class MasterFaultDetection extends AbstractComponent { throw new NotMasterException(); } + // ping from nodes of version < 1.4.0 will have the clustername set to null if (request.clusterName != null && !request.clusterName.equals(clusterName)) { logger.trace("master fault detection ping request is targeted for a different [{}] cluster then us [{}]", request.clusterName, clusterName); throw new NotMasterException("master fault detection ping request is targeted for a different [" + request.clusterName + "] cluster then us [" + clusterName + "]"); diff --git a/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java b/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java index bd485b927e3..b21cab0bc43 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java +++ b/src/main/java/org/elasticsearch/discovery/zen/fd/NodesFaultDetection.java @@ -321,6 +321,8 @@ public class NodesFaultDetection extends AbstractComponent { if (!latestNodes.localNodeId().equals(request.nodeId)) { throw new ElasticsearchIllegalStateException("Got pinged as node [" + request.nodeId + "], but I am node [" + latestNodes.localNodeId() + "]"); } + + // PingRequest will have clusterName set to null if it came from a node of version <1.4.0 if (request.clusterName != null && !request.clusterName.equals(clusterName)) { // Don't introduce new exception for bwc reasons throw new ElasticsearchIllegalStateException("Got pinged with cluster name [" + request.clusterName + "], but I'm part of cluster [" + clusterName + "]"); diff --git a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index ee9526f6d5f..123f2d7fc7f 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -71,7 +71,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen private final int concurrentConnects; - private final DiscoveryNode[] nodes; + private final DiscoveryNode[] configuredTargetNodes; private volatile DiscoveryNodesProvider nodesProvider; @@ -79,7 +79,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen private final Map> receivedResponses = newConcurrentMap(); - // a list of temporal responses a node will return for a request (holds requests from other nodes) + // a list of temporal responses a node will return for a request (holds requests from other configuredTargetNodes) private final Queue temporalResponses = ConcurrentCollections.newQueue(); private final CopyOnWriteArrayList hostsProviders = new CopyOnWriteArrayList<>(); @@ -107,20 +107,20 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen List hosts = Lists.newArrayList(hostArr); logger.debug("using initial hosts {}, with concurrent_connects [{}]", hosts, concurrentConnects); - List nodes = Lists.newArrayList(); + List configuredTargetNodes = Lists.newArrayList(); int idCounter = 0; for (String host : hosts) { try { TransportAddress[] addresses = transportService.addressesFromString(host); // we only limit to 1 addresses, makes no sense to ping 100 ports for (int i = 0; (i < addresses.length && i < LIMIT_PORTS_COUNT); i++) { - nodes.add(new DiscoveryNode("#zen_unicast_" + (++idCounter) + "#", addresses[i], version.minimumCompatibilityVersion())); + configuredTargetNodes.add(new DiscoveryNode("#zen_unicast_" + (++idCounter) + "#", addresses[i], version.minimumCompatibilityVersion())); } } catch (Exception e) { throw new ElasticsearchIllegalArgumentException("Failed to resolve address for [" + host + "]", e); } } - this.nodes = nodes.toArray(new DiscoveryNode[nodes.size()]); + this.configuredTargetNodes = configuredTargetNodes.toArray(new DiscoveryNode[configuredTargetNodes.size()]); transportService.registerHandler(ACTION_NAME, new UnicastPingRequestHandler()); } @@ -273,7 +273,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen List sortedNodesToPing = electMasterService.sortByMasterLikelihood(nodesToPingSet); // new add the the unicast targets first - ArrayList nodesToPing = Lists.newArrayList(nodes); + ArrayList nodesToPing = Lists.newArrayList(configuredTargetNodes); nodesToPing.addAll(sortedNodesToPing); final CountDownLatch latch = new CountDownLatch(nodesToPing.size());