Code style improvement

This commit is contained in:
Boaz Leskes 2014-08-29 09:01:05 +02:00
parent d5552a980f
commit 183ca37dfa
7 changed files with 256 additions and 246 deletions

465
pom.xml
View File

@ -183,7 +183,7 @@
<version>0.8.13</version> <version>0.8.13</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- Lucene spatial --> <!-- Lucene spatial -->
<!-- START: dependencies that are shaded --> <!-- START: dependencies that are shaded -->
@ -483,7 +483,8 @@
<haltOnFailure>${tests.failfast}</haltOnFailure> <haltOnFailure>${tests.failfast}</haltOnFailure>
<uniqueSuiteNames>false</uniqueSuiteNames> <uniqueSuiteNames>false</uniqueSuiteNames>
<systemProperties> <systemProperties>
<java.io.tmpdir>.</java.io.tmpdir> <!-- we use '.' since this is different per JVM--> <java.io.tmpdir>.</java.io.tmpdir>
<!-- we use '.' since this is different per JVM-->
<!-- RandomizedTesting library system properties --> <!-- RandomizedTesting library system properties -->
<tests.bwc>${tests.bwc}</tests.bwc> <tests.bwc>${tests.bwc}</tests.bwc>
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path> <tests.bwc.path>${tests.bwc.path}</tests.bwc.path>
@ -537,15 +538,15 @@
<version>1.7</version> <version>1.7</version>
<executions> <executions>
<execution> <execution>
<phase>validate</phase> <phase>validate</phase>
<goals> <goals>
<goal>run</goal> <goal>run</goal>
</goals> </goals>
<configuration> <configuration>
<target> <target>
<echo>Using ${java.runtime.name} ${java.runtime.version} ${java.vendor}</echo> <echo>Using ${java.runtime.name} ${java.runtime.version} ${java.vendor}</echo>
</target> </target>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>invalid-patterns</id> <id>invalid-patterns</id>
@ -573,7 +574,9 @@
</fileset> </fileset>
<map from="${basedir}${file.separator}" to="* "/> <map from="${basedir}${file.separator}" to="* "/>
</pathconvert> </pathconvert>
<fail if="validate.patternsFound">The following files contain tabs or nocommits:${line.separator}${validate.patternsFound}</fail> <fail if="validate.patternsFound">The following files contain tabs or
nocommits:${line.separator}${validate.patternsFound}
</fail>
</target> </target>
</configuration> </configuration>
</execution> </execution>
@ -581,7 +584,8 @@
<id>tests</id> <id>tests</id>
<phase>test</phase> <phase>test</phase>
<configuration> <configuration>
<skip>${skipTests}</skip> <!-- don't run if we skip the tests --> <skip>${skipTests}</skip>
<!-- don't run if we skip the tests -->
<failOnError>false</failOnError> <failOnError>false</failOnError>
<target> <target>
<property name="runtime_classpath" refid="maven.runtime.classpath"/> <property name="runtime_classpath" refid="maven.runtime.classpath"/>
@ -595,7 +599,7 @@
</classpath> </classpath>
</taskdef> </taskdef>
<tophints max="${tests.topn}"> <tophints max="${tests.topn}">
<file file="${basedir}/${execution.hint.file}" /> <file file="${basedir}/${execution.hint.file}"/>
</tophints> </tophints>
</target> </target>
</configuration> </configuration>
@ -708,7 +712,7 @@
<shadedPattern>org.elasticsearch.common.compress</shadedPattern> <shadedPattern>org.elasticsearch.common.compress</shadedPattern>
</relocation> </relocation>
<relocation> <relocation>
<pattern>com.github.mustachejava</pattern> <pattern>com.github.mustachejava</pattern>
<shadedPattern>org.elasticsearch.common.mustache</shadedPattern> <shadedPattern>org.elasticsearch.common.mustache</shadedPattern>
</relocation> </relocation>
<relocation> <relocation>
@ -1222,7 +1226,7 @@
<excludes> <excludes>
<!-- start exclude for test GC simulation using Thread.suspend --> <!-- start exclude for test GC simulation using Thread.suspend -->
<exclude>org/elasticsearch/test/disruption/LongGCDisruption.class</exclude> <exclude>org/elasticsearch/test/disruption/LongGCDisruption.class</exclude>
<!-- end exclude for Channels --> <!-- end exclude for GC simulation -->
</excludes> </excludes>
<signaturesFiles> <signaturesFiles>
<signaturesFile>test-signatures.txt</signaturesFile> <signaturesFile>test-signatures.txt</signaturesFile>
@ -1348,219 +1352,220 @@
</pluginManagement> </pluginManagement>
</build> </build>
<profiles> <profiles>
<!-- default profile, with randomization setting kicks in --> <!-- default profile, with randomization setting kicks in -->
<profile> <profile>
<id>default</id> <id>default</id>
<activation> <activation>
<activeByDefault>true</activeByDefault> <activeByDefault>true</activeByDefault>
</activation> </activation>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>com.carrotsearch.randomizedtesting</groupId> <groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>junit4-maven-plugin</artifactId> <artifactId>junit4-maven-plugin</artifactId>
<configuration> <configuration>
<argLine>${tests.jvm.argline}</argLine> <argLine>${tests.jvm.argline}</argLine>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.mycila</groupId> <groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId> <artifactId>license-maven-plugin</artifactId>
<version>2.5</version> <version>2.5</version>
<configuration> <configuration>
<header>dev-tools/elasticsearch_license_header.txt</header> <header>dev-tools/elasticsearch_license_header.txt</header>
<headerDefinitions> <headerDefinitions>
<headerDefinition>dev-tools/license_header_definition.xml</headerDefinition> <headerDefinition>dev-tools/license_header_definition.xml</headerDefinition>
</headerDefinitions> </headerDefinitions>
<includes> <includes>
<include>src/main/java/org/elasticsearch/**/*.java</include> <include>src/main/java/org/elasticsearch/**/*.java</include>
<include>src/test/java/org/elasticsearch/**/*.java</include> <include>src/test/java/org/elasticsearch/**/*.java</include>
</includes> </includes>
<excludes> <excludes>
<exclude>src/main/java/org/elasticsearch/common/inject/**</exclude> <exclude>src/main/java/org/elasticsearch/common/inject/**</exclude>
<!-- Guice --> <!-- Guice -->
<exclude>src/main/java/org/elasticsearch/common/geo/GeoHashUtils.java</exclude> <exclude>src/main/java/org/elasticsearch/common/geo/GeoHashUtils.java</exclude>
<exclude>src/main/java/org/elasticsearch/common/lucene/search/XBooleanFilter.java</exclude> <exclude>src/main/java/org/elasticsearch/common/lucene/search/XBooleanFilter.java</exclude>
<exclude>src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java</exclude> <exclude>src/main/java/org/elasticsearch/common/lucene/search/XFilteredQuery.java</exclude>
<exclude>src/main/java/org/apache/lucene/queryparser/XSimpleQueryParser.java</exclude> <exclude>src/main/java/org/apache/lucene/queryparser/XSimpleQueryParser.java</exclude>
<exclude>src/main/java/org/apache/lucene/**/X*.java</exclude> <exclude>src/main/java/org/apache/lucene/**/X*.java</exclude>
<!-- t-digest --> <!-- t-digest -->
<exclude>src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigestState.java</exclude> <exclude>src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigestState.java
<exclude>src/test/java/org/elasticsearch/search/aggregations/metrics/GroupTree.java</exclude> </exclude>
</excludes> <exclude>src/test/java/org/elasticsearch/search/aggregations/metrics/GroupTree.java</exclude>
</configuration> </excludes>
<executions> </configuration>
<execution> <executions>
<phase>compile</phase> <execution>
<goals> <phase>compile</phase>
<goal>check</goal> <goals>
</goals> <goal>check</goal>
</execution> </goals>
</executions> </execution>
</plugin> </executions>
</plugins> </plugin>
</build> </plugins>
</profile> </build>
<!-- profile for development that doesn't check forbidden-apis, no-commit validation or license headers run with mvn -Pdev --> </profile>
<profile> <!-- profile for development that doesn't check forbidden-apis, no-commit validation or license headers run with mvn -Pdev -->
<id>dev</id> <profile>
<properties> <id>dev</id>
<validate.skip>true</validate.skip> <properties>
</properties> <validate.skip>true</validate.skip>
<build> </properties>
<plugins> <build>
<plugin> <plugins>
<groupId>de.thetaphi</groupId> <plugin>
<artifactId>forbiddenapis</artifactId> <groupId>de.thetaphi</groupId>
<version>1.5.1</version> <artifactId>forbiddenapis</artifactId>
<executions> <version>1.5.1</version>
<execution> <executions>
<id>check-forbidden-apis</id> <execution>
<phase>none</phase> <id>check-forbidden-apis</id>
</execution> <phase>none</phase>
<execution> </execution>
<id>check-forbidden-test-apis</id> <execution>
<phase>none</phase> <id>check-forbidden-test-apis</id>
</execution> <phase>none</phase>
</executions> </execution>
</plugin> </executions>
</plugins> </plugin>
</build> </plugins>
</profile> </build>
<!-- license profile, to generate third party license file --> </profile>
<profile> <!-- license profile, to generate third party license file -->
<id>license</id> <profile>
<activation> <id>license</id>
<property> <activation>
<name>license.generation</name> <property>
<value>true</value> <name>license.generation</name>
</property> <value>true</value>
</activation> </property>
<!-- not including license-maven-plugin is sufficent to expose default license --> </activation>
</profile> <!-- not including license-maven-plugin is sufficent to expose default license -->
<!-- jacoco coverage profile. This will insert -jagent --> </profile>
<profile> <!-- jacoco coverage profile. This will insert -jagent -->
<id>coverage</id> <profile>
<activation> <id>coverage</id>
<property> <activation>
<name>tests.coverage</name> <property>
<value>true</value> <name>tests.coverage</name>
</property> <value>true</value>
</activation> </property>
<dependencies> </activation>
<dependency> <dependencies>
<!-- must be on the classpath --> <dependency>
<groupId>org.jacoco</groupId> <!-- must be on the classpath -->
<artifactId>org.jacoco.agent</artifactId> <groupId>org.jacoco</groupId>
<classifier>runtime</classifier> <artifactId>org.jacoco.agent</artifactId>
<version>0.6.4.201312101107</version> <classifier>runtime</classifier>
<scope>test</scope> <version>0.6.4.201312101107</version>
</dependency> <scope>test</scope>
</dependencies> </dependency>
<build> </dependencies>
<plugins> <build>
<plugin> <plugins>
<groupId>org.jacoco</groupId> <plugin>
<artifactId>jacoco-maven-plugin</artifactId> <groupId>org.jacoco</groupId>
<version>0.6.4.201312101107</version> <artifactId>jacoco-maven-plugin</artifactId>
<executions> <version>0.6.4.201312101107</version>
<execution> <executions>
<id>default-prepare-agent</id> <execution>
<goals> <id>default-prepare-agent</id>
<goal>prepare-agent</goal> <goals>
</goals> <goal>prepare-agent</goal>
</execution> </goals>
<execution> </execution>
<id>default-report</id> <execution>
<phase>prepare-package</phase> <id>default-report</id>
<goals> <phase>prepare-package</phase>
<goal>report</goal> <goals>
</goals> <goal>report</goal>
</execution> </goals>
<execution> </execution>
<id>default-check</id> <execution>
<goals> <id>default-check</id>
<goal>check</goal> <goals>
</goals> <goal>check</goal>
</execution> </goals>
</executions> </execution>
<configuration> </executions>
<excludes> <configuration>
<exclude>jsr166e/**</exclude> <excludes>
<exclude>org/apache/lucene/**</exclude> <exclude>jsr166e/**</exclude>
</excludes> <exclude>org/apache/lucene/**</exclude>
</configuration> </excludes>
</plugin> </configuration>
</plugins> </plugin>
</build> </plugins>
</profile> </build>
<profile> </profile>
<id>static</id> <profile>
<activation> <id>static</id>
<property> <activation>
<name>tests.static</name> <property>
<value>true</value> <name>tests.static</name>
</property> <value>true</value>
</activation> </property>
<build> </activation>
<plugins> <build>
<plugin> <plugins>
<groupId>org.codehaus.mojo</groupId> <plugin>
<artifactId>findbugs-maven-plugin</artifactId> <groupId>org.codehaus.mojo</groupId>
<version>2.5.3</version> <artifactId>findbugs-maven-plugin</artifactId>
</plugin> <version>2.5.3</version>
</plugins> </plugin>
</build> </plugins>
<reporting> </build>
<plugins> <reporting>
<plugin> <plugins>
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-jxr-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId>
<version>2.3</version> <artifactId>maven-jxr-plugin</artifactId>
</plugin> <version>2.3</version>
<plugin> </plugin>
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-pmd-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId>
<version>3.0.1</version> <artifactId>maven-pmd-plugin</artifactId>
<configuration> <version>3.0.1</version>
<rulesets> <configuration>
<ruleset>${basedir}/dev-tools/pmd/custom.xml</ruleset> <rulesets>
</rulesets> <ruleset>${basedir}/dev-tools/pmd/custom.xml</ruleset>
<targetJdk>1.7</targetJdk> </rulesets>
<excludes> <targetJdk>1.7</targetJdk>
<exclude>**/jsr166e/**</exclude> <excludes>
<exclude>**/org/apache/lucene/**</exclude> <exclude>**/jsr166e/**</exclude>
<exclude>**/org/apache/elasticsearch/common/Base64.java</exclude> <exclude>**/org/apache/lucene/**</exclude>
</excludes> <exclude>**/org/apache/elasticsearch/common/Base64.java</exclude>
</configuration> </excludes>
</plugin> </configuration>
<plugin> </plugin>
<groupId>org.codehaus.mojo</groupId> <plugin>
<artifactId>findbugs-maven-plugin</artifactId> <groupId>org.codehaus.mojo</groupId>
<version>2.5.3</version> <artifactId>findbugs-maven-plugin</artifactId>
<configuration> <version>2.5.3</version>
<xmlOutput>true</xmlOutput> <configuration>
<xmlOutputDirectory>target/site</xmlOutputDirectory> <xmlOutput>true</xmlOutput>
<fork>true</fork> <xmlOutputDirectory>target/site</xmlOutputDirectory>
<maxHeap>2048</maxHeap> <fork>true</fork>
<timeout>1800000</timeout> <maxHeap>2048</maxHeap>
<onlyAnalyze>org.elasticsearch.-</onlyAnalyze> <timeout>1800000</timeout>
</configuration> <onlyAnalyze>org.elasticsearch.-</onlyAnalyze>
</plugin> </configuration>
<plugin> </plugin>
<groupId>org.apache.maven.plugins</groupId> <plugin>
<artifactId>maven-project-info-reports-plugin</artifactId> <groupId>org.apache.maven.plugins</groupId>
<version>2.7</version> <artifactId>maven-project-info-reports-plugin</artifactId>
<reportSets> <version>2.7</version>
<reportSet> <reportSets>
<reports> <reportSet>
<report>index</report> <reports>
</reports> <report>index</report>
</reportSet> </reports>
</reportSets> </reportSet>
</plugin> </reportSets>
</plugins> </plugin>
</reporting> </plugins>
</profile> </reporting>
</profile>
</profiles> </profiles>
</project> </project>

View File

@ -118,7 +118,7 @@ public class ClusterBlocks {
} }
public boolean hasGlobalBlock(ClusterBlockLevel level) { public boolean hasGlobalBlock(ClusterBlockLevel level) {
return !global(level).isEmpty(); return global(level).size() > 0;
} }
/** /**

View File

@ -89,12 +89,13 @@ public class DiscoverySettings extends AbstractComponent {
} }
private ClusterBlock parseNoMasterBlock(String value) { private ClusterBlock parseNoMasterBlock(String value) {
if ("all".equals(value)) { switch (value) {
return NO_MASTER_BLOCK_ALL; case "all":
} else if ("write".equals(value)) { return NO_MASTER_BLOCK_ALL;
return NO_MASTER_BLOCK_WRITES; case "write":
} else { return NO_MASTER_BLOCK_WRITES;
throw new ElasticsearchIllegalArgumentException("invalid master block [" + value + "]"); default:
throw new ElasticsearchIllegalArgumentException("invalid master block [" + value + "]");
} }
} }
} }

View File

@ -939,13 +939,14 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
if (pingMasters.isEmpty()) { if (pingMasters.isEmpty()) {
// if we don't have enough master nodes, we bail, because there are not enough master to elect from // 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); logger.trace("not enough master nodes [{}]", possibleMasterNodes);
return null; return null;
} }
// lets tie break between discovered nodes
return electMaster.electMaster(possibleMasterNodes);
} else { } else {
// lets tie break between discovered nodes
return electMaster.electMaster(pingMasters); return electMaster.electMaster(pingMasters);
} }
} }

View File

@ -396,6 +396,7 @@ public class MasterFaultDetection extends AbstractComponent {
throw new NotMasterException(); 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)) { 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); 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 + "]"); throw new NotMasterException("master fault detection ping request is targeted for a different [" + request.clusterName + "] cluster then us [" + clusterName + "]");

View File

@ -321,6 +321,8 @@ public class NodesFaultDetection extends AbstractComponent {
if (!latestNodes.localNodeId().equals(request.nodeId)) { if (!latestNodes.localNodeId().equals(request.nodeId)) {
throw new ElasticsearchIllegalStateException("Got pinged as node [" + request.nodeId + "], but I am node [" + latestNodes.localNodeId() + "]"); 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)) { if (request.clusterName != null && !request.clusterName.equals(clusterName)) {
// Don't introduce new exception for bwc reasons // 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 + "]"); throw new ElasticsearchIllegalStateException("Got pinged with cluster name [" + request.clusterName + "], but I'm part of cluster [" + clusterName + "]");

View File

@ -71,7 +71,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
private final int concurrentConnects; private final int concurrentConnects;
private final DiscoveryNode[] nodes; private final DiscoveryNode[] configuredTargetNodes;
private volatile DiscoveryNodesProvider nodesProvider; private volatile DiscoveryNodesProvider nodesProvider;
@ -79,7 +79,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
private final Map<Integer, ConcurrentMap<DiscoveryNode, PingResponse>> receivedResponses = newConcurrentMap(); private final Map<Integer, ConcurrentMap<DiscoveryNode, PingResponse>> 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<PingResponse> temporalResponses = ConcurrentCollections.newQueue(); private final Queue<PingResponse> temporalResponses = ConcurrentCollections.newQueue();
private final CopyOnWriteArrayList<UnicastHostsProvider> hostsProviders = new CopyOnWriteArrayList<>(); private final CopyOnWriteArrayList<UnicastHostsProvider> hostsProviders = new CopyOnWriteArrayList<>();
@ -107,20 +107,20 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
List<String> hosts = Lists.newArrayList(hostArr); List<String> hosts = Lists.newArrayList(hostArr);
logger.debug("using initial hosts {}, with concurrent_connects [{}]", hosts, concurrentConnects); logger.debug("using initial hosts {}, with concurrent_connects [{}]", hosts, concurrentConnects);
List<DiscoveryNode> nodes = Lists.newArrayList(); List<DiscoveryNode> configuredTargetNodes = Lists.newArrayList();
int idCounter = 0; int idCounter = 0;
for (String host : hosts) { for (String host : hosts) {
try { try {
TransportAddress[] addresses = transportService.addressesFromString(host); TransportAddress[] addresses = transportService.addressesFromString(host);
// we only limit to 1 addresses, makes no sense to ping 100 ports // 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++) { 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) { } catch (Exception e) {
throw new ElasticsearchIllegalArgumentException("Failed to resolve address for [" + host + "]", 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()); transportService.registerHandler(ACTION_NAME, new UnicastPingRequestHandler());
} }
@ -273,7 +273,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
List<DiscoveryNode> sortedNodesToPing = electMasterService.sortByMasterLikelihood(nodesToPingSet); List<DiscoveryNode> sortedNodesToPing = electMasterService.sortByMasterLikelihood(nodesToPingSet);
// new add the the unicast targets first // new add the the unicast targets first
ArrayList<DiscoveryNode> nodesToPing = Lists.newArrayList(nodes); ArrayList<DiscoveryNode> nodesToPing = Lists.newArrayList(configuredTargetNodes);
nodesToPing.addAll(sortedNodesToPing); nodesToPing.addAll(sortedNodesToPing);
final CountDownLatch latch = new CountDownLatch(nodesToPing.size()); final CountDownLatch latch = new CountDownLatch(nodesToPing.size());