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

View File

@ -118,7 +118,7 @@ public class ClusterBlocks {
}
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) {
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 + "]");
}
}
}

View File

@ -939,13 +939,14 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> 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);
}
}

View File

@ -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 + "]");

View File

@ -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 + "]");

View File

@ -71,7 +71,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> 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<ZenPing> implemen
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 CopyOnWriteArrayList<UnicastHostsProvider> hostsProviders = new CopyOnWriteArrayList<>();
@ -107,20 +107,20 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
List<String> hosts = Lists.newArrayList(hostArr);
logger.debug("using initial hosts {}, with concurrent_connects [{}]", hosts, concurrentConnects);
List<DiscoveryNode> nodes = Lists.newArrayList();
List<DiscoveryNode> 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<ZenPing> implemen
List<DiscoveryNode> sortedNodesToPing = electMasterService.sortByMasterLikelihood(nodesToPingSet);
// new add the the unicast targets first
ArrayList<DiscoveryNode> nodesToPing = Lists.newArrayList(nodes);
ArrayList<DiscoveryNode> nodesToPing = Lists.newArrayList(configuredTargetNodes);
nodesToPing.addAll(sortedNodesToPing);
final CountDownLatch latch = new CountDownLatch(nodesToPing.size());