merged master

This commit is contained in:
Peter 2012-02-08 08:31:41 +01:00
commit 93134bd89e
805 changed files with 20612 additions and 15027 deletions

View File

@ -36,7 +36,7 @@ First of all, DON'T PANIC. It will take 5 minutes to get the gist of what Elasti
h3. Installation
* Download and unzip the ElasticSearch installation.
* "Download":http://www.elasticsearch.org/download and unzip the ElasticSearch official distribution.
* Run @bin/elasticsearch -f@ on unix, or @bin/elasticsearch.bat@ on windows.
* Run @curl -X GET http://localhost:9200/@.
* Start more servers ...
@ -198,7 +198,7 @@ h3. Building from Source
ElasticSearch uses "Maven":http://maven.apache.org for its build system.
In order to create a distribution, simply run the @mvn assembly:assembly -DskipTests@ command in the cloned directory.
In order to create a distribution, simply run the @mvn package -DskipTests@ command in the cloned directory.
The distribution will be created under @target/releases@.

View File

@ -17,8 +17,7 @@
# Optionally, exact memory values can be set using the following values, note,
# they can still be set using the `ES_JAVA_OPTS`. Sample format include "512m", and "10g".
#
# ES_MIN_MEM -- The minimum number of memory to allocate.
# ES_MAX_MEM -- The maximum number of memory to allocate.
# ES_HEAP_SIZE -- Sets both the minimum and maximum memory to allocate (recommended)
#
# As a convenience, a fragment of shell is sourced in order to set one or
# more of these variables. This so-called `include' can be placed in a
@ -114,20 +113,20 @@ launch_service()
es_parms="-Delasticsearch"
if [ "x$pidpath" != "x" ]; then
es_parms="$es_parms -Des-pidfile=$pidpath"
es_parms="$es_parms -Des.pidfile=$pidpath"
fi
# The es-daemon option will tell ElasticSearch to close stdout/stderr,
# but it's up to us not to background.
# The es-foreground option will tell ElasticSearch not to close stdout/stderr, but it's up to us not to background.
if [ "x$foreground" != "x" ]; then
es_parms="$es_parms -Des-foreground=yes"
es_parms="$es_parms -Des.foreground=yes"
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
org.elasticsearch.bootstrap.ElasticSearch
else
# Startup ElasticSearch, background it, and write the pid.
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
org.elasticsearch.bootstrap.ElasticSearch <&- &
[ ! -z "$pidpath" ] && printf '%d' $! > "$pidpath"
# no longer need to write the pid, the elasticsearch process will do it
# [ ! -z "$pidpath" ] && printf '%d' $! > "$pidpath"
fi
return $?

View File

@ -18,7 +18,17 @@ if "%ES_MAX_MEM%" == "" (
set ES_MAX_MEM=1g
)
if NOT "%ES_HEAP_SIZE%" == "" (
set ES_MIN_MEM=%ES_HEAP_SIZE%
set ES_MAX_MEM=%ES_HEAP_SIZE%
)
set JAVA_OPTS=%JAVA_OPTS% -Xms%ES_MIN_MEM% -Xmx%ES_MAX_MEM%
if NOT "%ES_HEAP_NEWSIZE%" == "" (
set JAVA_OPTS=%JAVA_OPTS% -Xmn%ES_HEAP_NEWSIZE%
)
set JAVA_OPTS=%JAVA_OPTS% -Xss128k
REM Enable aggressive optimizations in the JVM
@ -27,12 +37,13 @@ REM set JAVA_OPTS=%JAVA_OPTS% -XX:+AggressiveOpts
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseParNewGC
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseConcMarkSweepGC
set JAVA_OPTS=%JAVA_OPTS% -XX:+CMSParallelRemarkEnabled
set JAVA_OPTS=%JAVA_OPTS% -XX:SurvivorRatio=8
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxTenuringThreshold=1
set JAVA_OPTS=%JAVA_OPTS% -XX:CMSInitiatingOccupancyFraction=75
set JAVA_OPTS=%JAVA_OPTS% -XX:+UseCMSInitiatingOccupancyOnly
REM When running under Java 7
REM JAVA_OPTS=%JAVA_OPTS% -XX:+UseCondCardMark
REM GC logging options -- uncomment to enable
REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDetails
REM JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCTimeStamps

View File

@ -6,6 +6,10 @@ fi
if [ "x$ES_MAX_MEM" = "x" ]; then
ES_MAX_MEM=1g
fi
if [ "x$ES_HEAP_SIZE" != "x" ]; then
ES_MIN_MEM=$ES_HEAP_SIZE
ES_MAX_MEM=$ES_HEAP_SIZE
fi
# min and max heap sizes should be set to the same value to avoid
# stop-the-world GC pauses during resize, and so that we can lock the
@ -14,6 +18,11 @@ fi
JAVA_OPTS="$JAVA_OPTS -Xms${ES_MIN_MEM}"
JAVA_OPTS="$JAVA_OPTS -Xmx${ES_MAX_MEM}"
# new generation
if [ "x$ES_HEAP_NEWSIZE" != "x" ]; then
JAVA_OPTS="$JAVA_OPTS -Xmn${ES_HEAP_NEWSIZE}"
fi
# reduce the per-thread stack size
JAVA_OPTS="$JAVA_OPTS -Xss128k"
@ -26,12 +35,13 @@ JAVA_OPTS="$JAVA_OPTS -Xss128k"
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled"
JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=8"
JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=1"
JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
# When running under Java 7
#JAVA_OPTS="$JAVA_OPTS -XX:+UseCondCardMark"
# GC logging options -- uncomment to enable
# JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
# JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"

View File

@ -28,4 +28,4 @@ else
JAVA=`which java`
fi
exec $JAVA -Delasticsearch -Des.path.home="$ES_HOME" -cp "$ES_HOME/lib/*" org.elasticsearch.plugins.PluginManager $*
exec $JAVA -Xmx64m -Xms16m -Delasticsearch -Des.path.home="$ES_HOME" -cp "$ES_HOME/lib/*" org.elasticsearch.plugins.PluginManager $*

View File

@ -8,7 +8,7 @@ set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI
"%JAVA_HOME%\bin\java" -Des.path.home="%ES_HOME%" -cp "%ES_HOME%/lib/*" "org.elasticsearch.plugins.PluginManager" %*
"%JAVA_HOME%\bin\java" -Xmx64m -Xms16m -Des.path.home="%ES_HOME%" -cp "%ES_HOME%/lib/*" "org.elasticsearch.plugins.PluginManager" %*
goto finally
@ -19,4 +19,4 @@ pause
:finally
ENDLOCAL
ENDLOCAL

View File

@ -83,6 +83,10 @@
# node.rack: rack314
# By default, multiple nodes are allowed to start from the same installation location
# to disable it, set the following:
# node.max_local_storage_nodes: 1
#################################### Index ####################################
# You can set a number of options (such as shard/replica options, mapping
@ -234,7 +238,8 @@
# gateway.type: local
# Settings below control how and when to start the initial recovery process on
# a full cluster restart (to reuse as much local data as possible).
# a full cluster restart (to reuse as much local data as possible when using shared
# gateway).
# Allow recovery process after N nodes in a cluster are up:
#
@ -246,7 +251,8 @@
# gateway.recover_after_time: 5m
# Set how many nodes are expected in this cluster. Once these N nodes
# are up, begin recovery process immediately:
# are up (and recover_after_nodes is met), begin recovery process immediately
# (without waiting for recover_after_time to expire):
#
# gateway.expected_nodes: 2
@ -284,7 +290,7 @@
# Set to ensure a node sees N other master eligible nodes to be considered
# operational within the cluster. Set this option to a higher value (2-4)
# for large clusters:
# for large clusters (>3 nodes):
#
# discovery.zen.minimum_master_nodes: 1
@ -335,3 +341,13 @@
#index.search.slowlog.threshold.fetch.info: 800ms
#index.search.slowlog.threshold.fetch.debug: 500ms
#index.search.slowlog.threshold.fetch.trace: 200ms
################################## GC Logging ################################
#monitor.jvm.gc.ParNew.warn: 1000ms
#monitor.jvm.gc.ParNew.info: 700ms
#monitor.jvm.gc.ParNew.debug: 400ms
#monitor.jvm.gc.ConcurrentMarkSweep.warn: 10s
#monitor.jvm.gc.ConcurrentMarkSweep.info: 5s
#monitor.jvm.gc.ConcurrentMarkSweep.debug: 2s

138
pom.xml
View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.19.0-SNAPSHOT</version>
<version>0.19.0.RC2-SNAPSHOT</version>
<packaging>jar</packaging>
<description>ElasticSearch - Open Source, Distributed, RESTful Search Engine</description>
<inceptionYear>2009</inceptionYear>
@ -81,17 +81,10 @@
</dependency>
<!-- START: dependencies that are shaded -->
<dependency>
<groupId>com.googlecode.concurrentlinkedhashmap</groupId>
<artifactId>concurrentlinkedhashmap-lru</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
<version>11.0.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
@ -110,21 +103,14 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>es-jsr166y</artifactId>
<version>20110918</version>
<version>20120131</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>es-jsr166e</artifactId>
<version>20110918</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>
<version>20120131</version>
<scope>compile</scope>
</dependency>
@ -139,21 +125,21 @@
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.1.Beta7</version>
<version>2.1.Beta8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
<version>1.9.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-smile</artifactId>
<version>1.9.2</version>
<version>1.9.3</version>
<scope>compile</scope>
</dependency>
@ -165,9 +151,9 @@
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.7.Final</version>
<version>3.3.1.Final</version>
<scope>compile</scope>
</dependency>
<!-- END: dependencies that are shaded -->
@ -196,20 +182,13 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>1.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>sigar</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sigar/sigar-1.6.4.jar</systemPath>
<optional>true</optional>
</dependency>
<dependency>
@ -322,25 +301,19 @@
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru</include>
<include>com.google.guava:guava</include>
<include>net.sf.trove4j:trove4j</include>
<include>org.elasticsearch:es-jsr166y</include>
<include>org.elasticsearch:es-jsr166e</include>
<include>commons-codec:commons-codec</include>
<include>org.mvel:mvel2</include>
<include>org.codehaus.jackson:jackson-core-asl</include>
<include>org.codehaus.jackson:jackson-smile</include>
<include>org.yaml:snakeyaml</include>
<include>joda-time:joda-time</include>
<include>org.jboss.netty:netty</include>
<include>io.netty:netty</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.googlecode.concurrentlinkedhashmap</pattern>
<shadedPattern>org.elasticsearch.common.concurrentlinkedhashmap</shadedPattern>
</relocation>
<relocation>
<pattern>com.google.common</pattern>
<shadedPattern>org.elasticsearch.common</shadedPattern>
@ -357,10 +330,6 @@
<pattern>jsr166e</pattern>
<shadedPattern>org.elasticsearch.common.util.concurrent.jsr166e</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.codec</pattern>
<shadedPattern>org.elasticsearch.common.codec</shadedPattern>
</relocation>
<relocation>
<pattern>org.mvel2</pattern>
<shadedPattern>org.elasticsearch.common.mvel2</shadedPattern>
@ -406,14 +375,14 @@
</descriptors>
</configuration>
<executions>
<execution>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
@ -424,19 +393,19 @@
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- some infos https://github.com/tcurdt/jdeb/blob/master/docs/maven.md
-->
<plugin>
<!-- some infos https://github.com/tcurdt/jdeb/blob/master/docs/maven.md
-->
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
<version>0.8</version>
<configuration>
<deb>${project.build.directory}/releases/${artifactId}-${version}.deb</deb>
</configuration>
<deb>${project.build.directory}/releases/${project.artifactId}-${project.version}.deb</deb>
</configuration>
<executions>
<execution>
<phase>package</phase>
@ -444,44 +413,33 @@
<goal>jdeb</goal>
</goals>
<configuration>
<dataSet>
<data>
<dataSet>
<data>
<src>${project.basedir}/</src>
<includes>*.txt, *.textile</includes>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/usr/share/elasticsearch</prefix>
<prefix>/usr/share/elasticsearch</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
<data>
</data>
<data>
<src>${project.basedir}/bin</src>
<type>directory</type>
<excludes>*.bat</excludes>
<mapper>
<type>perm</type>
<prefix>/usr/share/elasticsearch/bin</prefix>
<prefix>/usr/share/elasticsearch/bin</prefix>
<filemode>755</filemode>
<user>root</user>
<group>root</group>
</mapper>
</data>
<data>
<src>${project.build.directory}/</src>
<includes>${project.build.finalName}.jar, ${project.basedir}/lib/sigar/*</includes>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/usr/share/elasticsearch/lib</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
</data>
<data>
<src>${project.build.directory}/lib</src>
<includes>lucene*, log4j*, jline*, jna*</includes>
<src>${project.build.directory}/</src>
<includes>${project.build.finalName}.jar</includes>
<type>directory</type>
<mapper>
<type>perm</type>
@ -490,17 +448,39 @@
<group>root</group>
</mapper>
</data>
<data>
<data>
<src>${project.basedir}/lib/sigar/</src>
<includes>sigar-*.jar, libsigar-*-linux.*</includes>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/usr/share/elasticsearch/lib/sigar</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
<data>
<src>${project.build.directory}/lib</src>
<includes>lucene*, log4j*, jna*</includes>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/usr/share/elasticsearch/lib</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
<data>
<src>${project.basedir}/src/deb/default/</src>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/etc/default</prefix>
<prefix>/etc/default</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
<data>
<data>
<src>${project.basedir}/src/deb/init.d/</src>
<type>directory</type>
<mapper>
@ -511,22 +491,22 @@
<group>root</group>
</mapper>
</data>
<data>
<data>
<src>${project.basedir}/config</src>
<type>directory</type>
<mapper>
<type>perm</type>
<prefix>/etc/elasticsearch</prefix>
<prefix>/etc/elasticsearch</prefix>
<user>root</user>
<group>root</group>
</mapper>
</data>
</dataSet>
</data>
</dataSet>
</configuration>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>
</project>

View File

@ -6,7 +6,6 @@
<includes>
<include>org.apache.lucene:lucene*</include>
<include>log4j:log4j</include>
<include>jline:jline</include>
<include>net.java.dev.jna:jna</include>
</includes>
</dependencySet>
@ -28,6 +27,10 @@
</fileSet>
</fileSets>
<files>
<file>
<source>README.textile</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>LICENSE.txt</source>
<outputDirectory>/</outputDirectory>

View File

@ -11,8 +11,22 @@
<fileSet>
<directory>bin</directory>
<outputDirectory>bin</outputDirectory>
<lineEnding>dos</lineEnding>
<includes>
<include>*</include>
<include>elasticsearch.bat</include>
<include>plugin.bat</include>
</includes>
</fileSet>
<fileSet>
<directory>bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<lineEnding>unix</lineEnding>
<includes>
<include>elasticsearch.in.sh</include>
<include>elasticsearch</include>
<include>plugin</include>
</includes>
</fileSet>

View File

@ -86,8 +86,10 @@ public class TrackingConcurrentMergeScheduler extends ConcurrentMergeScheduler {
logger.trace("merge [{}] starting...", merge.info.name);
}
try {
TrackingMergeScheduler.setCurrentMerge(merge);
super.doMerge(merge);
} finally {
TrackingMergeScheduler.removeCurrentMerge();
long took = System.currentTimeMillis() - time;
currentMerges.dec();

View File

@ -0,0 +1,24 @@
package org.apache.lucene.index;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import java.util.concurrent.ConcurrentMap;
/**
*/
public class TrackingMergeScheduler {
private static final ConcurrentMap<Thread, MergePolicy.OneMerge> merges = ConcurrentCollections.newConcurrentMap();
public static void setCurrentMerge(MergePolicy.OneMerge merge) {
merges.put(Thread.currentThread(), merge);
}
public static void removeCurrentMerge() {
merges.remove(Thread.currentThread());
}
public static MergePolicy.OneMerge getCurrentMerge() {
return merges.get(Thread.currentThread());
}
}

View File

@ -93,8 +93,10 @@ public class TrackingSerialMergeScheduler extends MergeScheduler {
currentMergesNumDocs.inc(totalNumDocs);
currentMergesSizeInBytes.inc(totalSizeInBytes);
try {
TrackingMergeScheduler.setCurrentMerge(merge);
writer.merge(merge);
} finally {
TrackingMergeScheduler.removeCurrentMerge();
long took = System.currentTimeMillis() - time;
currentMerges.dec();

View File

@ -50,8 +50,6 @@ import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQu
* <p/>
* <p>Also breaks fields with [type].[name] into a boolean query that must include the type
* as well as the query on the name.
*
*
*/
public class MapperQueryParser extends QueryParser {
@ -66,6 +64,8 @@ public class MapperQueryParser extends QueryParser {
private final QueryParseContext parseContext;
private boolean forcedAnalyzer;
private FieldMapper currentMapper;
private boolean analyzeWildcard;
@ -76,14 +76,15 @@ public class MapperQueryParser extends QueryParser {
}
public MapperQueryParser(QueryParserSettings settings, QueryParseContext parseContext) {
super(Lucene.QUERYPARSER_VERSION, settings.defaultField(), settings.analyzer());
super(Lucene.QUERYPARSER_VERSION, settings.defaultField(), settings.defaultAnalyzer());
this.parseContext = parseContext;
reset(settings);
}
public void reset(QueryParserSettings settings) {
this.field = settings.defaultField();
this.analyzer = settings.analyzer();
this.forcedAnalyzer = settings.forcedAnalyzer() != null;
this.analyzer = forcedAnalyzer ? settings.forcedAnalyzer() : settings.defaultAnalyzer();
setMultiTermRewriteMethod(settings.rewriteMethod());
setEnablePositionIncrements(settings.enablePositionIncrements());
setAutoGeneratePhraseQueries(settings.autoGeneratePhraseQueries());
@ -123,12 +124,23 @@ public class MapperQueryParser extends QueryParser {
try {
MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
analyzer = fieldMappers.searchAnalyzer();
if (!forcedAnalyzer) {
analyzer = fieldMappers.searchAnalyzer();
}
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
Query query = null;
if (currentMapper.useFieldQueryWithQueryString()) {
query = currentMapper.fieldQuery(queryText, parseContext);
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.fieldQuery(queryText, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = currentMapper.fieldQuery(queryText, parseContext);
}
}
if (query == null) {
query = super.getFieldQuery(currentMapper.names().indexName(), queryText, quoted);
@ -178,20 +190,36 @@ public class MapperQueryParser extends QueryParser {
@Override
protected Query getPrefixQuery(String field, String termStr) throws ParseException {
String indexedNameField = field;
currentMapper = null;
Analyzer oldAnalyzer = analyzer;
try {
MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
analyzer = fieldMappers.searchAnalyzer();
if (!forcedAnalyzer) {
analyzer = fieldMappers.searchAnalyzer();
}
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
indexedNameField = currentMapper.names().indexName();
Query query = null;
if (currentMapper.useFieldQueryWithQueryString()) {
if (fieldMappers.explicitTypeInNameWithDocMapper()) {
String[] previousTypes = QueryParseContext.setTypesWithPrevious(new String[]{fieldMappers.docMapper().type()});
try {
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
} finally {
QueryParseContext.setTypes(previousTypes);
}
} else {
query = currentMapper.prefixQuery(termStr, multiTermRewriteMethod, parseContext);
}
}
if (query == null) {
query = getPossiblyAnalyzedPrefixQuery(currentMapper.names().indexName(), termStr);
}
return wrapSmartNameQuery(query, fieldMappers, parseContext);
}
return wrapSmartNameQuery(getPossiblyAnalyzedPrefixQuery(indexedNameField, termStr), fieldMappers, parseContext);
}
return getPossiblyAnalyzedPrefixQuery(indexedNameField, termStr);
return getPossiblyAnalyzedPrefixQuery(field, termStr);
} finally {
analyzer = oldAnalyzer;
}
@ -229,7 +257,15 @@ public class MapperQueryParser extends QueryParser {
if (tlist.size() == 1) {
return super.getPrefixQuery(field, tlist.get(0));
} else {
return super.getPrefixQuery(field, termStr);
// build a boolean query with prefix on each one...
List<BooleanClause> clauses = new ArrayList<BooleanClause>();
for (String token : tlist) {
clauses.add(new BooleanClause(super.getPrefixQuery(field, token), BooleanClause.Occur.SHOULD));
}
return getBooleanQuery(clauses, true);
//return super.getPrefixQuery(field, termStr);
/* this means that the analyzer used either added or consumed
* (common for a stemmer) tokens, and we can't build a PrefixQuery */
// throw new ParseException("Cannot build PrefixQuery with analyzer "
@ -250,7 +286,9 @@ public class MapperQueryParser extends QueryParser {
try {
MapperService.SmartNameFieldMappers fieldMappers = parseContext.smartFieldMappers(field);
if (fieldMappers != null) {
analyzer = fieldMappers.searchAnalyzer();
if (!forcedAnalyzer) {
analyzer = fieldMappers.searchAnalyzer();
}
currentMapper = fieldMappers.fieldMappers().mapper();
if (currentMapper != null) {
indexedNameField = currentMapper.names().indexName();

View File

@ -28,20 +28,24 @@ import org.apache.lucene.search.MultiTermQuery;
*/
public class QueryParserSettings {
public static final boolean DEFAULT_ALLOW_LEADING_WILDCARD = true;
public static final boolean DEFAULT_ANALYZE_WILDCARD = false;
private String queryString;
private String defaultField;
private float boost = 1.0f;
private MapperQueryParser.Operator defaultOperator = QueryParser.Operator.OR;
private boolean autoGeneratePhraseQueries = false;
private boolean allowLeadingWildcard = true;
private boolean allowLeadingWildcard = DEFAULT_ALLOW_LEADING_WILDCARD;
private boolean lowercaseExpandedTerms = true;
private boolean enablePositionIncrements = true;
private int phraseSlop = 0;
private float fuzzyMinSim = FuzzyQuery.defaultMinSimilarity;
private int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;
private boolean analyzeWildcard = false;
private boolean analyzeWildcard = DEFAULT_ANALYZE_WILDCARD;
private boolean escape = false;
private Analyzer analyzer = null;
private Analyzer defaultAnalyzer = null;
private Analyzer forcedAnalyzer = null;
private MultiTermQuery.RewriteMethod rewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
private String minimumShouldMatch;
@ -141,12 +145,20 @@ public class QueryParserSettings {
this.escape = escape;
}
public Analyzer analyzer() {
return analyzer;
public Analyzer defaultAnalyzer() {
return defaultAnalyzer;
}
public void analyzer(Analyzer analyzer) {
this.analyzer = analyzer;
public void defaultAnalyzer(Analyzer defaultAnalyzer) {
this.defaultAnalyzer = defaultAnalyzer;
}
public Analyzer forcedAnalyzer() {
return forcedAnalyzer;
}
public void forcedAnalyzer(Analyzer forcedAnalyzer) {
this.forcedAnalyzer = forcedAnalyzer;
}
public boolean analyzeWildcard() {
@ -190,7 +202,10 @@ public class QueryParserSettings {
if (fuzzyPrefixLength != that.fuzzyPrefixLength) return false;
if (lowercaseExpandedTerms != that.lowercaseExpandedTerms) return false;
if (phraseSlop != that.phraseSlop) return false;
if (analyzer != null ? !analyzer.equals(that.analyzer) : that.analyzer != null) return false;
if (defaultAnalyzer != null ? !defaultAnalyzer.equals(that.defaultAnalyzer) : that.defaultAnalyzer != null)
return false;
if (forcedAnalyzer != null ? !forcedAnalyzer.equals(that.forcedAnalyzer) : that.forcedAnalyzer != null)
return false;
if (defaultField != null ? !defaultField.equals(that.defaultField) : that.defaultField != null) return false;
if (defaultOperator != that.defaultOperator) return false;
if (queryString != null ? !queryString.equals(that.queryString) : that.queryString != null) return false;
@ -216,7 +231,8 @@ public class QueryParserSettings {
result = 31 * result + (fuzzyMinSim != +0.0f ? Float.floatToIntBits(fuzzyMinSim) : 0);
result = 31 * result + fuzzyPrefixLength;
result = 31 * result + (escape ? 1 : 0);
result = 31 * result + (analyzer != null ? analyzer.hashCode() : 0);
result = 31 * result + (defaultAnalyzer != null ? defaultAnalyzer.hashCode() : 0);
result = 31 * result + (forcedAnalyzer != null ? forcedAnalyzer.hashCode() : 0);
result = 31 * result + (analyzeWildcard ? 1 : 0);
return result;
}

View File

@ -0,0 +1,151 @@
package org.apache.lucene.store;
import java.io.IOException;
/**
* Exactly the same as Lucene {@link BufferedIndexOutput} but with the ability to set the buffer size
*/
// LUCENE MONITOR
public abstract class OpenBufferedIndexOutput extends IndexOutput {
public static final int DEFAULT_BUFFER_SIZE = BufferedIndexOutput.BUFFER_SIZE;
final int BUFFER_SIZE;
private final byte[] buffer;
private long bufferStart = 0; // position in file of buffer
private int bufferPosition = 0; // position in buffer
protected OpenBufferedIndexOutput(int BUFFER_SIZE) {
this.BUFFER_SIZE = BUFFER_SIZE;
this.buffer = new byte[BUFFER_SIZE];
}
/**
* Writes a single byte.
*
* @see IndexInput#readByte()
*/
@Override
public void writeByte(byte b) throws IOException {
if (bufferPosition >= BUFFER_SIZE)
flush();
buffer[bufferPosition++] = b;
}
/**
* Writes an array of bytes.
*
* @param b the bytes to write
* @param length the number of bytes to write
* @see IndexInput#readBytes(byte[], int, int)
*/
@Override
public void writeBytes(byte[] b, int offset, int length) throws IOException {
int bytesLeft = BUFFER_SIZE - bufferPosition;
// is there enough space in the buffer?
if (bytesLeft >= length) {
// we add the data to the end of the buffer
System.arraycopy(b, offset, buffer, bufferPosition, length);
bufferPosition += length;
// if the buffer is full, flush it
if (BUFFER_SIZE - bufferPosition == 0)
flush();
} else {
// is data larger then buffer?
if (length > BUFFER_SIZE) {
// we flush the buffer
if (bufferPosition > 0)
flush();
// and write data at once
flushBuffer(b, offset, length);
bufferStart += length;
} else {
// we fill/flush the buffer (until the input is written)
int pos = 0; // position in the input data
int pieceLength;
while (pos < length) {
pieceLength = (length - pos < bytesLeft) ? length - pos : bytesLeft;
System.arraycopy(b, pos + offset, buffer, bufferPosition, pieceLength);
pos += pieceLength;
bufferPosition += pieceLength;
// if the buffer is full, flush it
bytesLeft = BUFFER_SIZE - bufferPosition;
if (bytesLeft == 0) {
flush();
bytesLeft = BUFFER_SIZE;
}
}
}
}
}
/**
* Forces any buffered output to be written.
*/
@Override
public void flush() throws IOException {
flushBuffer(buffer, bufferPosition);
bufferStart += bufferPosition;
bufferPosition = 0;
}
/**
* Expert: implements buffer write. Writes bytes at the current position in
* the output.
*
* @param b the bytes to write
* @param len the number of bytes to write
*/
private void flushBuffer(byte[] b, int len) throws IOException {
flushBuffer(b, 0, len);
}
/**
* Expert: implements buffer write. Writes bytes at the current position in
* the output.
*
* @param b the bytes to write
* @param offset the offset in the byte array
* @param len the number of bytes to write
*/
protected abstract void flushBuffer(byte[] b, int offset, int len) throws IOException;
/**
* Closes this stream to further operations.
*/
@Override
public void close() throws IOException {
flush();
}
/**
* Returns the current position in this file, where the next write will
* occur.
*
* @see #seek(long)
*/
@Override
public long getFilePointer() {
return bufferStart + bufferPosition;
}
/**
* Sets current position in this file, where the next write will occur.
*
* @see #getFilePointer()
*/
@Override
public void seek(long pos) throws IOException {
flush();
bufferStart = pos;
}
/**
* The number of bytes in the file.
*/
@Override
public abstract long length() throws IOException;
}

View File

@ -1,24 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;

View File

@ -1,24 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
@ -30,6 +28,7 @@ import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
/**
* A memory based directory that uses {@link java.nio.ByteBuffer} in order to store the directory content.
@ -41,8 +40,6 @@ import java.util.concurrent.ConcurrentHashMap;
* <p/>
* <p>If constructed with {@link ByteBufferAllocator}, it allows to control the allocation and release of
* byte buffer. For example, custom implementations can include caching of byte buffers.
*
*
*/
public class ByteBufferDirectory extends Directory {
@ -52,6 +49,8 @@ public class ByteBufferDirectory extends Directory {
private final boolean internalAllocator;
final AtomicLong sizeInBytes = new AtomicLong();
/**
* Constructs a new directory using {@link PlainByteBufferAllocator}.
*/
@ -78,6 +77,13 @@ public class ByteBufferDirectory extends Directory {
}
}
/**
* Returns the size in bytes of the directory, chunk by buffer size.
*/
public long sizeInBytes() {
return sizeInBytes.get();
}
public void sync(Collection<String> names) throws IOException {
// nothing to do here
}
@ -110,7 +116,7 @@ public class ByteBufferDirectory extends Directory {
do {
try {
Thread.sleep(0, 1);
} catch (InterruptedException ie) {
} catch (java.lang.InterruptedException ie) {
// In 3.0 we will change this to throw
// InterruptedException instead
Thread.currentThread().interrupt();
@ -127,7 +133,8 @@ public class ByteBufferDirectory extends Directory {
ByteBufferFile file = files.remove(name);
if (file == null)
throw new FileNotFoundException(name);
file.clean();
sizeInBytes.addAndGet(-file.sizeInBytes.get());
file.delete();
}
@Override
@ -147,9 +154,10 @@ public class ByteBufferDirectory extends Directory {
ByteBufferFile file = new ByteBufferFile(this, allocator.sizeInBytes(allocatorType));
ByteBufferFile existing = files.put(name, file);
if (existing != null) {
existing.clean();
sizeInBytes.addAndGet(-existing.sizeInBytes.get());
existing.delete();
}
return new ByteBufferIndexOutput(allocator, allocatorType, file);
return new ByteBufferIndexOutput(name, allocator, allocatorType, file);
}
@Override
@ -157,7 +165,7 @@ public class ByteBufferDirectory extends Directory {
ByteBufferFile file = files.get(name);
if (file == null)
throw new FileNotFoundException(name);
return new ByteBufferIndexInput(file);
return new ByteBufferIndexInput(name, file);
}
@Override

View File

@ -1,29 +1,28 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.nio.ByteBuffer;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
*
*/
public class ByteBufferFile {
@ -35,6 +34,10 @@ public class ByteBufferFile {
// This is publicly modifiable via Directory.touchFile(), so direct access not supported
private volatile long lastModified = System.currentTimeMillis();
private final AtomicInteger refCount = new AtomicInteger(1);
final AtomicLong sizeInBytes = new AtomicLong();
public ByteBufferFile(ByteBufferDirectory dir, int bufferSize) {
this.dir = dir;
this.bufferSize = bufferSize;
@ -60,6 +63,8 @@ public class ByteBufferFile {
protected final void addBuffer(ByteBuffer buffer) {
buffers.add(buffer);
sizeInBytes.addAndGet(buffer.remaining());
dir.sizeInBytes.addAndGet(buffer.remaining());
}
protected final ByteBuffer getBuffer(int index) {
@ -70,8 +75,17 @@ public class ByteBufferFile {
return buffers.size();
}
void clean() {
if (buffers != null) {
void delete() {
decRef();
}
void incRef() {
refCount.incrementAndGet();
}
void decRef() {
if (refCount.decrementAndGet() == 0) {
length = 0;
for (ByteBuffer buffer : buffers) {
dir.releaseBuffer(buffer);
}

View File

@ -19,11 +19,12 @@ package org.apache.lucene.store.bytebuffer;
import org.apache.lucene.store.IndexInput;
import java.io.EOFException;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
/**
*
*/
public class ByteBufferIndexInput extends IndexInput {
@ -38,8 +39,12 @@ public class ByteBufferIndexInput extends IndexInput {
private long bufferStart;
private final int BUFFER_SIZE;
public ByteBufferIndexInput(ByteBufferFile file) throws IOException {
private volatile boolean closed = false;
public ByteBufferIndexInput(String name, ByteBufferFile file) throws IOException {
super("BBIndexInput(name=" + name + ")");
this.file = file;
this.file.incRef();
this.length = file.getLength();
this.BUFFER_SIZE = file.bufferSize;
@ -51,7 +56,13 @@ public class ByteBufferIndexInput extends IndexInput {
@Override
public void close() {
// nothing to do here
// we protected from double closing the index input since
// some tests do that...
if (closed) {
return;
}
closed = true;
file.decRef();
}
@Override
@ -59,32 +70,38 @@ public class ByteBufferIndexInput extends IndexInput {
return length;
}
// @Override
// public short readShort() throws IOException {
// try {
// return currentBuffer.getShort();
// } catch (BufferUnderflowException e) {
// return super.readShort();
// }
// }
//
// @Override
// public int readInt() throws IOException {
// try {
// return currentBuffer.getInt();
// } catch (BufferUnderflowException e) {
// return super.readInt();
// }
// }
//
// @Override
// public long readLong() throws IOException {
// try {
// return currentBuffer.getLong();
// } catch (BufferUnderflowException e) {
// return super.readLong();
// }
// }
@Override
public short readShort() throws IOException {
try {
currentBuffer.mark();
return currentBuffer.getShort();
} catch (BufferUnderflowException e) {
currentBuffer.reset();
return super.readShort();
}
}
@Override
public int readInt() throws IOException {
try {
currentBuffer.mark();
return currentBuffer.getInt();
} catch (BufferUnderflowException e) {
currentBuffer.reset();
return super.readInt();
}
}
@Override
public long readLong() throws IOException {
try {
currentBuffer.mark();
return currentBuffer.getLong();
} catch (BufferUnderflowException e) {
currentBuffer.reset();
return super.readLong();
}
}
@Override
public byte readByte() throws IOException {
@ -120,27 +137,28 @@ public class ByteBufferIndexInput extends IndexInput {
public void seek(long pos) throws IOException {
if (currentBuffer == EMPTY_BUFFER || pos < bufferStart || pos >= bufferStart + BUFFER_SIZE) {
currentBufferIndex = (int) (pos / BUFFER_SIZE);
if (currentBufferIndex >= file.numBuffers()) {
// if we are past EOF, don't throw one here, instead, move it to the last position in the last buffer
currentBufferIndex = file.numBuffers() - 1;
currentBuffer = currentBufferIndex == -1 ? EMPTY_BUFFER : file.getBuffer(currentBufferIndex);
currentBuffer.position(currentBuffer.limit());
return;
} else {
switchCurrentBuffer(false);
}
switchCurrentBuffer(false);
}
try {
currentBuffer.position((int) (pos % BUFFER_SIZE));
// Grrr, need to wrap in IllegalArgumentException since tests (if not other places)
// expect an IOException...
} catch (IllegalArgumentException e) {
currentBuffer.position(currentBuffer.limit());
IOException ioException = new IOException("seeking past position");
ioException.initCause(e);
throw ioException;
}
}
private void switchCurrentBuffer(boolean enforceEOF) throws IOException {
if (currentBufferIndex >= file.numBuffers()) {
// end of file reached, no more buffers left
if (enforceEOF) {
throw new IOException("Read past EOF");
throw new EOFException("Read past EOF (resource: " + this + ")");
} else {
// Force EOF if a read takes place at this position
currentBufferIndex--;
currentBuffer.position(currentBuffer.limit());
}
} else {
ByteBuffer buffer = file.getBuffer(currentBufferIndex);
@ -152,8 +170,16 @@ public class ByteBufferIndexInput extends IndexInput {
long buflen = length - bufferStart;
if (buflen < BUFFER_SIZE) {
currentBuffer.limit((int) buflen);
if (enforceEOF && buflen == 0) {
throw new IOException("Read past EOF");
}
// we need to enforce EOF here as well...
if (!currentBuffer.hasRemaining()) {
if (enforceEOF) {
throw new EOFException("Read past EOF (resource: " + this + ")");
} else {
// Force EOF if a read takes place at this position
currentBufferIndex--;
currentBuffer.position(currentBuffer.limit());
}
}
}
@ -162,6 +188,7 @@ public class ByteBufferIndexInput extends IndexInput {
@Override
public Object clone() {
ByteBufferIndexInput cloned = (ByteBufferIndexInput) super.clone();
cloned.file.incRef(); // inc ref on cloned one
if (currentBuffer != EMPTY_BUFFER) {
cloned.currentBuffer = currentBuffer.asReadOnlyBuffer();
cloned.currentBuffer.position(currentBuffer.position());

View File

@ -1,23 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.lucene.store.bytebuffer;
import org.apache.lucene.store.IndexOutput;
@ -28,6 +27,9 @@ import java.nio.ByteBuffer;
*/
public class ByteBufferIndexOutput extends IndexOutput {
private final static ByteBuffer EMPTY_BUFFER = ByteBuffer.allocate(0).asReadOnlyBuffer();
private final String name;
private final ByteBufferAllocator allocator;
private final ByteBufferAllocator.Type allocatorType;
private final int BUFFER_SIZE;
@ -38,13 +40,15 @@ public class ByteBufferIndexOutput extends IndexOutput {
private long bufferStart;
public ByteBufferIndexOutput(ByteBufferAllocator allocator, ByteBufferAllocator.Type allocatorType, ByteBufferFile file) throws IOException {
public ByteBufferIndexOutput(String name, ByteBufferAllocator allocator, ByteBufferAllocator.Type allocatorType, ByteBufferFile file) throws IOException {
this.name = name;
this.allocator = allocator;
this.allocatorType = allocatorType;
this.BUFFER_SIZE = file.bufferSize;
this.file = file;
// create the first buffer we write to
switchCurrentBuffer();
currentBufferIndex = -1;
currentBuffer = EMPTY_BUFFER;
}
@Override

View File

@ -1,24 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.ArrayBlockingQueue;

View File

@ -1,24 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.lucene.store.bytebuffer;
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.IOException;
import java.nio.ByteBuffer;

View File

@ -25,10 +25,11 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.monitor.jvm.JvmInfo;
import java.io.IOException;
import java.io.Serializable;
/**
*/
public class Version {
public class Version implements Serializable {
// The logic for ID is: XXYYZZAA, where XX is major version, YY is minor version, ZZ is revision, and AA is Beta/RC indicator
// AA values below 50 are beta builds, and below 99 are RC builds, with 99 indicating a release
@ -48,17 +49,24 @@ public class Version {
public static final Version V_0_18_5 = new Version(V_0_18_5_ID, false);
public static final int V_0_18_6_ID = /*00*/180699;
public static final Version V_0_18_6 = new Version(V_0_18_6_ID, false);
public static final int V_0_18_7_ID = /*00*/180799;
public static final Version V_0_18_7 = new Version(V_0_18_7_ID, false);
public static final int V_0_18_8_ID = /*00*/180899;
public static final Version V_0_18_8 = new Version(V_0_18_8_ID, false);
public static final int V_0_19_0_ID = /*00*/190099;
public static final Version V_0_19_0 = new Version(V_0_19_0_ID, true);
public static final int V_0_19_0_RC1_ID = /*00*/190051;
public static final Version V_0_19_0_RC1 = new Version(V_0_19_0_RC1_ID, false);
public static final Version CURRENT = V_0_19_0;
public static final int V_0_19_0_RC2_ID = /*00*/190052;
public static final Version V_0_19_0_RC2 = new Version(V_0_19_0_RC2_ID, true);
public static final Version CURRENT = V_0_19_0_RC2;
public static Version readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
}
private static Version fromId(int id) {
public static Version fromId(int id) {
switch (id) {
case V_0_18_0_ID:
return V_0_18_0;
@ -74,8 +82,15 @@ public class Version {
return V_0_18_5;
case V_0_18_6_ID:
return V_0_18_6;
case V_0_19_0_ID:
return V_0_19_0;
case V_0_18_7_ID:
return V_0_18_7;
case V_0_18_8_ID:
return V_0_18_8;
case V_0_19_0_RC1_ID:
return V_0_19_0_RC1;
case V_0_19_0_RC2_ID:
return V_0_19_0_RC2;
default:
return new Version(id, null);
}

View File

@ -19,14 +19,17 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.client.Client;
/**
*
* Main action (used with {@link Client} API.
*/
public interface Action<Request extends ActionRequest, Response extends ActionResponse> {
public abstract class Action<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response>>
extends GenericAction<Request, Response> {
ActionFuture<Response> execute(Request request) throws ElasticSearchException;
protected Action(String name) {
super(name);
}
void execute(Request request, ActionListener<Response> listener);
public abstract RequestBuilder newRequestBuilder(Client client);
}

View File

@ -0,0 +1,240 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action;
import com.google.common.collect.Maps;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartAction;
import org.elasticsearch.action.admin.cluster.node.restart.TransportNodesRestartAction;
import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownAction;
import org.elasticsearch.action.admin.cluster.node.shutdown.TransportNodesShutdownAction;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction;
import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction;
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction;
import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction;
import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction;
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction;
import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction;
import org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction;
import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesCacheAction;
import org.elasticsearch.action.admin.indices.close.CloseIndexAction;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.exists.IndicesExistsAction;
import org.elasticsearch.action.admin.indices.exists.TransportIndicesExistsAction;
import org.elasticsearch.action.admin.indices.flush.FlushAction;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotAction;
import org.elasticsearch.action.admin.indices.gateway.snapshot.TransportGatewaySnapshotAction;
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingAction;
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction;
import org.elasticsearch.action.admin.indices.open.OpenIndexAction;
import org.elasticsearch.action.admin.indices.open.TransportOpenIndexAction;
import org.elasticsearch.action.admin.indices.optimize.OptimizeAction;
import org.elasticsearch.action.admin.indices.optimize.TransportOptimizeAction;
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction;
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction;
import org.elasticsearch.action.admin.indices.segments.TransportIndicesSegmentsAction;
import org.elasticsearch.action.admin.indices.settings.TransportUpdateSettingsAction;
import org.elasticsearch.action.admin.indices.settings.UpdateSettingsAction;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
import org.elasticsearch.action.admin.indices.status.IndicesStatusAction;
import org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.validate.query.TransportValidateQueryAction;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction;
import org.elasticsearch.action.bulk.BulkAction;
import org.elasticsearch.action.bulk.TransportBulkAction;
import org.elasticsearch.action.bulk.TransportShardBulkAction;
import org.elasticsearch.action.count.CountAction;
import org.elasticsearch.action.count.TransportCountAction;
import org.elasticsearch.action.delete.DeleteAction;
import org.elasticsearch.action.delete.TransportDeleteAction;
import org.elasticsearch.action.delete.index.TransportIndexDeleteAction;
import org.elasticsearch.action.delete.index.TransportShardDeleteAction;
import org.elasticsearch.action.deletebyquery.DeleteByQueryAction;
import org.elasticsearch.action.deletebyquery.TransportDeleteByQueryAction;
import org.elasticsearch.action.deletebyquery.TransportIndexDeleteByQueryAction;
import org.elasticsearch.action.deletebyquery.TransportShardDeleteByQueryAction;
import org.elasticsearch.action.get.*;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.TransportIndexAction;
import org.elasticsearch.action.mlt.MoreLikeThisAction;
import org.elasticsearch.action.mlt.TransportMoreLikeThisAction;
import org.elasticsearch.action.percolate.PercolateAction;
import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.SearchAction;
import org.elasticsearch.action.search.SearchScrollAction;
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.search.TransportSearchScrollAction;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.update.TransportUpdateAction;
import org.elasticsearch.action.update.UpdateAction;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
import java.util.Map;
/**
*
*/
public class ActionModule extends AbstractModule {
private final Map<String, ActionEntry> actions = Maps.newHashMap();
static class ActionEntry<Request extends ActionRequest, Response extends ActionResponse> {
public final GenericAction<Request, Response> action;
public final Class<? extends TransportAction<Request, Response>> transportAction;
public final Class[] supportTransportActions;
ActionEntry(GenericAction<Request, Response> action, Class<? extends TransportAction<Request, Response>> transportAction, Class... supportTransportActions) {
this.action = action;
this.transportAction = transportAction;
this.supportTransportActions = supportTransportActions;
}
}
private final boolean proxy;
public ActionModule(boolean proxy) {
this.proxy = proxy;
}
/**
* Registers an action.
*
* @param action The action type.
* @param transportAction The transport action implementing the actual action.
* @param supportTransportActions Any support actions that are needed by the transport action.
* @param <Request> The request type.
* @param <Response> The response type.
*/
public <Request extends ActionRequest, Response extends ActionResponse> void registerAction(GenericAction<Request, Response> action, Class<? extends TransportAction<Request, Response>> transportAction, Class... supportTransportActions) {
actions.put(action.name(), new ActionEntry<Request, Response>(action, transportAction, supportTransportActions));
}
@Override
protected void configure() {
registerAction(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class);
registerAction(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class);
registerAction(NodesShutdownAction.INSTANCE, TransportNodesShutdownAction.class);
registerAction(NodesRestartAction.INSTANCE, TransportNodesRestartAction.class);
registerAction(ClusterStateAction.INSTANCE, TransportClusterStateAction.class);
registerAction(ClusterHealthAction.INSTANCE, TransportClusterHealthAction.class);
registerAction(ClusterUpdateSettingsAction.INSTANCE, TransportClusterUpdateSettingsAction.class);
registerAction(ClusterRerouteAction.INSTANCE, TransportClusterRerouteAction.class);
registerAction(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class);
registerAction(IndicesStatusAction.INSTANCE, TransportIndicesStatusAction.class);
registerAction(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
registerAction(CreateIndexAction.INSTANCE, TransportCreateIndexAction.class);
registerAction(DeleteIndexAction.INSTANCE, TransportDeleteIndexAction.class);
registerAction(OpenIndexAction.INSTANCE, TransportOpenIndexAction.class);
registerAction(CloseIndexAction.INSTANCE, TransportCloseIndexAction.class);
registerAction(IndicesExistsAction.INSTANCE, TransportIndicesExistsAction.class);
registerAction(PutMappingAction.INSTANCE, TransportPutMappingAction.class);
registerAction(DeleteMappingAction.INSTANCE, TransportDeleteMappingAction.class);
registerAction(IndicesAliasesAction.INSTANCE, TransportIndicesAliasesAction.class);
registerAction(UpdateSettingsAction.INSTANCE, TransportUpdateSettingsAction.class);
registerAction(AnalyzeAction.INSTANCE, TransportAnalyzeAction.class);
registerAction(PutIndexTemplateAction.INSTANCE, TransportPutIndexTemplateAction.class);
registerAction(DeleteIndexTemplateAction.INSTANCE, TransportDeleteIndexTemplateAction.class);
registerAction(ValidateQueryAction.INSTANCE, TransportValidateQueryAction.class);
registerAction(GatewaySnapshotAction.INSTANCE, TransportGatewaySnapshotAction.class);
registerAction(RefreshAction.INSTANCE, TransportRefreshAction.class);
registerAction(FlushAction.INSTANCE, TransportFlushAction.class);
registerAction(OptimizeAction.INSTANCE, TransportOptimizeAction.class);
registerAction(ClearIndicesCacheAction.INSTANCE, TransportClearIndicesCacheAction.class);
registerAction(IndexAction.INSTANCE, TransportIndexAction.class);
registerAction(GetAction.INSTANCE, TransportGetAction.class);
registerAction(DeleteAction.INSTANCE, TransportDeleteAction.class,
TransportIndexDeleteAction.class, TransportShardDeleteAction.class);
registerAction(CountAction.INSTANCE, TransportCountAction.class);
registerAction(UpdateAction.INSTANCE, TransportUpdateAction.class);
registerAction(MultiGetAction.INSTANCE, TransportMultiGetAction.class,
TransportShardMultiGetAction.class);
registerAction(BulkAction.INSTANCE, TransportBulkAction.class,
TransportShardBulkAction.class);
registerAction(DeleteByQueryAction.INSTANCE, TransportDeleteByQueryAction.class,
TransportIndexDeleteByQueryAction.class, TransportShardDeleteByQueryAction.class);
registerAction(SearchAction.INSTANCE, TransportSearchAction.class,
TransportSearchCache.class,
TransportSearchDfsQueryThenFetchAction.class,
TransportSearchQueryThenFetchAction.class,
TransportSearchDfsQueryAndFetchAction.class,
TransportSearchQueryAndFetchAction.class,
TransportSearchScanAction.class
);
registerAction(SearchScrollAction.INSTANCE, TransportSearchScrollAction.class,
TransportSearchScrollScanAction.class,
TransportSearchScrollQueryThenFetchAction.class,
TransportSearchScrollQueryAndFetchAction.class
);
registerAction(MoreLikeThisAction.INSTANCE, TransportMoreLikeThisAction.class);
registerAction(PercolateAction.INSTANCE, TransportPercolateAction.class);
// register Name -> GenericAction Map that can be injected to instances.
MapBinder<String, GenericAction> actionsBinder
= MapBinder.newMapBinder(binder(), String.class, GenericAction.class);
for (Map.Entry<String, ActionEntry> entry : actions.entrySet()) {
actionsBinder.addBinding(entry.getKey()).toInstance(entry.getValue().action);
}
// register GenericAction -> transportAction Map that can be injected to instances.
// also register any supporting classes
if (!proxy) {
MapBinder<GenericAction, TransportAction> transportActionsBinder
= MapBinder.newMapBinder(binder(), GenericAction.class, TransportAction.class);
for (Map.Entry<String, ActionEntry> entry : actions.entrySet()) {
// bind the action as eager singleton, so the map binder one will reuse it
bind(entry.getValue().transportAction).asEagerSingleton();
transportActionsBinder.addBinding(entry.getValue().action).to(entry.getValue().transportAction).asEagerSingleton();
for (Class supportAction : entry.getValue().supportTransportActions) {
bind(supportAction).asEagerSingleton();
}
}
}
}
}

View File

@ -17,17 +17,14 @@
* under the License.
*/
package org.elasticsearch.client.action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ListenableActionFuture;
package org.elasticsearch.action;
/**
*
*/
public interface RequestBuilder<Request extends ActionRequest, Response extends ActionResponse> {
public interface ActionRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> {
Request request();
ListenableActionFuture<Response> execute();

View File

@ -0,0 +1,66 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action;
import org.elasticsearch.transport.TransportRequestOptions;
/**
* A generic action. Should strive to make it a singleton.
*/
public abstract class GenericAction<Request extends ActionRequest, Response extends ActionResponse> {
private final String name;
/**
* @param name The name of the action, must be unique across actions.
*/
protected GenericAction(String name) {
this.name = name;
}
/**
* The name of the action. Must be unique across actions.
*/
public String name() {
return this.name;
}
/**
* Creates a new response instance.
*/
public abstract Response newResponse();
/**
* Optional request options for the action.
*/
public TransportRequestOptions options() {
return TransportRequestOptions.EMPTY;
}
@Override
public boolean equals(Object o) {
return name.equals(((GenericAction) o).name());
}
@Override
public int hashCode() {
return name.hashCode();
}
}

View File

@ -1,156 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action;
import org.elasticsearch.action.admin.cluster.health.TransportClusterHealthAction;
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.restart.TransportNodesRestartAction;
import org.elasticsearch.action.admin.cluster.node.shutdown.TransportNodesShutdownAction;
import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction;
import org.elasticsearch.action.admin.cluster.ping.broadcast.TransportBroadcastPingAction;
import org.elasticsearch.action.admin.cluster.ping.replication.TransportIndexReplicationPingAction;
import org.elasticsearch.action.admin.cluster.ping.replication.TransportReplicationPingAction;
import org.elasticsearch.action.admin.cluster.ping.replication.TransportShardReplicationPingAction;
import org.elasticsearch.action.admin.cluster.ping.single.TransportSinglePingAction;
import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction;
import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction;
import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction;
import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction;
import org.elasticsearch.action.admin.indices.analyze.TransportAnalyzeAction;
import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesCacheAction;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.exists.TransportIndicesExistsAction;
import org.elasticsearch.action.admin.indices.flush.TransportFlushAction;
import org.elasticsearch.action.admin.indices.gateway.snapshot.TransportGatewaySnapshotAction;
import org.elasticsearch.action.admin.indices.mapping.delete.TransportDeleteMappingAction;
import org.elasticsearch.action.admin.indices.mapping.put.TransportPutMappingAction;
import org.elasticsearch.action.admin.indices.open.TransportOpenIndexAction;
import org.elasticsearch.action.admin.indices.optimize.TransportOptimizeAction;
import org.elasticsearch.action.admin.indices.refresh.TransportRefreshAction;
import org.elasticsearch.action.admin.indices.segments.TransportIndicesSegmentsAction;
import org.elasticsearch.action.admin.indices.settings.TransportUpdateSettingsAction;
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
import org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
import org.elasticsearch.action.bulk.TransportBulkAction;
import org.elasticsearch.action.bulk.TransportShardBulkAction;
import org.elasticsearch.action.count.TransportCountAction;
import org.elasticsearch.action.delete.TransportDeleteAction;
import org.elasticsearch.action.delete.index.TransportIndexDeleteAction;
import org.elasticsearch.action.delete.index.TransportShardDeleteAction;
import org.elasticsearch.action.deletebyquery.TransportDeleteByQueryAction;
import org.elasticsearch.action.deletebyquery.TransportIndexDeleteByQueryAction;
import org.elasticsearch.action.deletebyquery.TransportShardDeleteByQueryAction;
import org.elasticsearch.action.get.TransportGetAction;
import org.elasticsearch.action.get.TransportMultiGetAction;
import org.elasticsearch.action.get.TransportShardMultiGetAction;
import org.elasticsearch.action.index.TransportIndexAction;
import org.elasticsearch.action.mlt.TransportMoreLikeThisAction;
import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.search.TransportSearchScrollAction;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.common.inject.AbstractModule;
/**
*
*/
public class TransportActionModule extends AbstractModule {
@Override
protected void configure() {
bind(TransportNodesInfoAction.class).asEagerSingleton();
bind(TransportNodesStatsAction.class).asEagerSingleton();
bind(TransportNodesShutdownAction.class).asEagerSingleton();
bind(TransportNodesRestartAction.class).asEagerSingleton();
bind(TransportClusterStateAction.class).asEagerSingleton();
bind(TransportClusterHealthAction.class).asEagerSingleton();
bind(TransportClusterUpdateSettingsAction.class).asEagerSingleton();
bind(TransportClusterRerouteAction.class).asEagerSingleton();
bind(TransportSinglePingAction.class).asEagerSingleton();
bind(TransportBroadcastPingAction.class).asEagerSingleton();
bind(TransportShardReplicationPingAction.class).asEagerSingleton();
bind(TransportIndexReplicationPingAction.class).asEagerSingleton();
bind(TransportReplicationPingAction.class).asEagerSingleton();
bind(TransportIndicesStatsAction.class).asEagerSingleton();
bind(TransportIndicesStatusAction.class).asEagerSingleton();
bind(TransportIndicesSegmentsAction.class).asEagerSingleton();
bind(TransportCreateIndexAction.class).asEagerSingleton();
bind(TransportDeleteIndexAction.class).asEagerSingleton();
bind(TransportOpenIndexAction.class).asEagerSingleton();
bind(TransportCloseIndexAction.class).asEagerSingleton();
bind(TransportIndicesExistsAction.class).asEagerSingleton();
bind(TransportPutMappingAction.class).asEagerSingleton();
bind(TransportDeleteMappingAction.class).asEagerSingleton();
bind(TransportIndicesAliasesAction.class).asEagerSingleton();
bind(TransportUpdateSettingsAction.class).asEagerSingleton();
bind(TransportAnalyzeAction.class).asEagerSingleton();
bind(TransportPutIndexTemplateAction.class).asEagerSingleton();
bind(TransportDeleteIndexTemplateAction.class).asEagerSingleton();
bind(TransportGatewaySnapshotAction.class).asEagerSingleton();
bind(TransportRefreshAction.class).asEagerSingleton();
bind(TransportFlushAction.class).asEagerSingleton();
bind(TransportOptimizeAction.class).asEagerSingleton();
bind(TransportClearIndicesCacheAction.class).asEagerSingleton();
bind(TransportIndexAction.class).asEagerSingleton();
bind(TransportGetAction.class).asEagerSingleton();
bind(TransportDeleteAction.class).asEagerSingleton();
bind(TransportIndexDeleteAction.class).asEagerSingleton();
bind(TransportShardDeleteAction.class).asEagerSingleton();
bind(TransportCountAction.class).asEagerSingleton();
bind(TransportMultiGetAction.class).asEagerSingleton();
bind(TransportShardMultiGetAction.class).asEagerSingleton();
bind(TransportBulkAction.class).asEagerSingleton();
bind(TransportShardBulkAction.class).asEagerSingleton();
bind(TransportShardDeleteByQueryAction.class).asEagerSingleton();
bind(TransportIndexDeleteByQueryAction.class).asEagerSingleton();
bind(TransportDeleteByQueryAction.class).asEagerSingleton();
bind(TransportSearchCache.class).asEagerSingleton();
bind(TransportSearchDfsQueryThenFetchAction.class).asEagerSingleton();
bind(TransportSearchQueryThenFetchAction.class).asEagerSingleton();
bind(TransportSearchDfsQueryAndFetchAction.class).asEagerSingleton();
bind(TransportSearchQueryAndFetchAction.class).asEagerSingleton();
bind(TransportSearchScanAction.class).asEagerSingleton();
bind(TransportSearchAction.class).asEagerSingleton();
bind(TransportSearchScrollScanAction.class).asEagerSingleton();
bind(TransportSearchScrollQueryThenFetchAction.class).asEagerSingleton();
bind(TransportSearchScrollQueryAndFetchAction.class).asEagerSingleton();
bind(TransportSearchScrollAction.class).asEagerSingleton();
bind(TransportMoreLikeThisAction.class).asEagerSingleton();
bind(TransportPercolateAction.class).asEagerSingleton();
}
}

View File

@ -17,51 +17,34 @@
* under the License.
*/
package org.elasticsearch.client.transport.action.support;
package org.elasticsearch.action;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.transport.action.ClientTransportAction;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.BaseTransportResponseHandler;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequestOptions;
import org.elasticsearch.transport.TransportService;
import java.lang.reflect.Constructor;
import static org.elasticsearch.action.support.PlainActionFuture.newFuture;
/**
*
* A generic proxy that will execute the given action against a specific node.
*/
public abstract class BaseClientTransportAction<Request extends ActionRequest, Response extends ActionResponse> extends AbstractComponent implements ClientTransportAction<Request, Response> {
public class TransportActionNodeProxy<Request extends ActionRequest, Response extends ActionResponse> {
protected final TransportService transportService;
private final Constructor<Response> responseConstructor;
private final GenericAction<Request, Response> action;
protected BaseClientTransportAction(Settings settings, TransportService transportService, Class<Response> type) {
super(settings);
@Inject
public TransportActionNodeProxy(GenericAction<Request, Response> action, TransportService transportService) {
this.action = action;
this.transportService = transportService;
try {
this.responseConstructor = type.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
throw new ElasticSearchIllegalArgumentException("No default constructor is declared for [" + type.getName() + "]");
}
responseConstructor.setAccessible(true);
}
@Override
public ActionFuture<Response> execute(DiscoveryNode node, Request request) throws ElasticSearchException {
PlainActionFuture<Response> future = newFuture();
request.listenerThreaded(false);
@ -69,12 +52,11 @@ public abstract class BaseClientTransportAction<Request extends ActionRequest, R
return future;
}
@Override
public void execute(DiscoveryNode node, final Request request, final ActionListener<Response> listener) {
transportService.sendRequest(node, action(), request, options(), new BaseTransportResponseHandler<Response>() {
transportService.sendRequest(node, action.name(), request, action.options(), new BaseTransportResponseHandler<Response>() {
@Override
public Response newInstance() {
return BaseClientTransportAction.this.newInstance();
return action.newResponse();
}
@Override
@ -97,17 +79,4 @@ public abstract class BaseClientTransportAction<Request extends ActionRequest, R
});
}
protected TransportRequestOptions options() {
return TransportRequestOptions.EMPTY;
}
protected abstract String action();
protected Response newInstance() {
try {
return responseConstructor.newInstance();
} catch (Exception e) {
throw new ElasticSearchIllegalStateException("Failed to create a new instance");
}
}
}

View File

@ -1,106 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action;
/**
*
*/
public class TransportActions {
public static final String BULK = "indices/bulk";
public static final String INDEX = "indices/index/shard/index";
public static final String COUNT = "indices/count";
public static final String DELETE = "indices/index/shard/delete";
public static final String DELETE_BY_QUERY = "indices/deleteByQuery";
public static final String GET = "indices/get";
public static final String MULTI_GET = "indices/mget";
public static final String SEARCH = "indices/search";
public static final String SEARCH_SCROLL = "indices/searchScroll";
public static final String TERMS = "indices/terms";
public static final String MORE_LIKE_THIS = "indices/moreLikeThis";
public static final String PERCOLATE = "indices/percolate";
public static class Admin {
public static class Indices {
public static final String CREATE = "indices/createIndex";
public static final String DELETE = "indices/deleteIndex";
public static final String OPEN = "indices/openIndex";
public static final String CLOSE = "indices/closeIndex";
public static final String FLUSH = "indices/flush";
public static final String REFRESH = "indices/refresh";
public static final String OPTIMIZE = "indices/optimize";
public static final String STATUS = "indices/status";
public static final String STATS = "indices/stats";
public static final String SEGMENTS = "indices/segments";
public static final String EXISTS = "indices/exists";
public static final String ALIASES = "indices/aliases";
public static final String UPDATE_SETTINGS = "indices/updateSettings";
public static final String ANALYZE = "indices/analyze";
public static final String PUT_INDEX_TEMPLATE = "indices/putIndexTemplate";
public static final String DELETE_INDEX_TEMPLATE = "indices/deleteIndexTemplate";
public static class Gateway {
public static final String SNAPSHOT = "indices/gateway/snapshot";
}
public static class Mapping {
public static final String PUT = "indices/mapping/put";
public static final String DELETE = "indices/mapping/delete";
}
public static class Cache {
public static final String CLEAR = "indices/cache/clear";
}
}
public static class Cluster {
public static final String STATE = "/cluster/state";
public static final String HEALTH = "/cluster/health";
public static final String UPDATE_SETTINGS = "/cluster/updateSettings";
public static final String REROUTE = "/cluster/reroute";
public static class Node {
public static final String INFO = "/cluster/nodes/info";
public static final String STATS = "/cluster/nodes/stats";
public static final String SHUTDOWN = "/cluster/nodes/shutdown";
public static final String RESTART = "/cluster/nodes/restart";
}
public static class Ping {
public static final String SINGLE = "/cluster/ping/single";
public static final String REPLICATION = "/cluster/ping/replication";
public static final String BROADCAST = "/cluster/ping/broadcast";
}
}
}
}

View File

@ -20,14 +20,16 @@
package org.elasticsearch.action;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.rest.RestStatus;
/**
*
*/
public class UnavailableShardsException extends ElasticSearchException {
public UnavailableShardsException(ShardId shardId, String message) {
public UnavailableShardsException(@Nullable ShardId shardId, String message) {
super(buildMessage(shardId, message));
}
@ -37,4 +39,9 @@ public class UnavailableShardsException extends ElasticSearchException {
}
return "[" + shardId.index().name() + "][" + shardId.id() + "] " + message;
}
@Override
public RestStatus status() {
return RestStatus.SERVICE_UNAVAILABLE;
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.action;
/**
*
*/
public class Actions {
public class ValidateActions {
public static ActionRequestValidationException addValidationError(String error, ActionRequestValidationException validationException) {
if (validationException == null) {

View File

@ -17,21 +17,23 @@
* under the License.
*/
package org.elasticsearch.client.transport.action;
package org.elasticsearch.action.admin.cluster;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.action.GenericAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*
* Cluster action (used with {@link ClusterAdminClient} API.
*/
public interface ClientTransportAction<Request extends ActionRequest, Response extends ActionResponse> {
public abstract class ClusterAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response>>
extends GenericAction<Request, Response> {
ActionFuture<Response> execute(DiscoveryNode node, Request request) throws ElasticSearchException;
protected ClusterAction(String name) {
super(name);
}
void execute(DiscoveryNode node, Request request, ActionListener<Response> listener);
public abstract RequestBuilder newRequestBuilder(ClusterAdminClient client);
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.health;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class ClusterHealthAction extends ClusterAction<ClusterHealthRequest, ClusterHealthResponse, ClusterHealthRequestBuilder> {
public static final ClusterHealthAction INSTANCE = new ClusterHealthAction();
public static final String NAME = "cluster/health";
private ClusterHealthAction() {
super(NAME);
}
@Override
public ClusterHealthResponse newResponse() {
return new ClusterHealthResponse();
}
@Override
public ClusterHealthRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new ClusterHealthRequestBuilder(client);
}
}

View File

@ -70,6 +70,9 @@ public class ClusterHealthRequest extends MasterNodeOperationRequest {
public ClusterHealthRequest timeout(TimeValue timeout) {
this.timeout = timeout;
if (masterNodeTimeout == DEFAULT_MASTER_NODE_TIMEOUT) {
masterNodeTimeout = timeout;
}
return this;
}

View File

@ -17,14 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.health;
package org.elasticsearch.action.admin.cluster.health;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.admin.cluster.health;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
@ -32,8 +31,8 @@ import org.elasticsearch.cluster.routing.RoutingTableValidation;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -58,7 +57,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.HEALTH;
return ClusterHealthAction.NAME;
}
@Override
@ -267,7 +266,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeOperationAc
response.status = ClusterHealthStatus.GREEN;
if (!response.validationFailures().isEmpty()) {
response.status = ClusterHealthStatus.RED;
} else if (clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
} else if (clusterState.blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) {
response.status = ClusterHealthStatus.RED;
} else {
for (ClusterIndexHealth indexHealth : response) {

View File

@ -32,6 +32,7 @@ import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.monitor.network.NetworkInfo;
import org.elasticsearch.monitor.os.OsInfo;
import org.elasticsearch.monitor.process.ProcessInfo;
import org.elasticsearch.threadpool.ThreadPoolInfo;
import org.elasticsearch.transport.TransportInfo;
import java.io.IOException;
@ -39,61 +40,94 @@ import java.util.Map;
/**
* Node information (static, does not change over time).
*
*
*/
public class NodeInfo extends NodeOperationResponse {
private ImmutableMap<String, String> attributes;
@Nullable
private ImmutableMap<String, String> serviceAttributes;
@Nullable
private String hostname;
@Nullable
private Settings settings;
@Nullable
private OsInfo os;
@Nullable
private ProcessInfo process;
@Nullable
private JvmInfo jvm;
@Nullable
private ThreadPoolInfo threadPool;
@Nullable
private NetworkInfo network;
@Nullable
private TransportInfo transport;
@Nullable
private HttpInfo http;
NodeInfo() {
}
public NodeInfo(DiscoveryNode node, ImmutableMap<String, String> attributes, Settings settings,
OsInfo os, ProcessInfo process, JvmInfo jvm, NetworkInfo network,
TransportInfo transport, @Nullable HttpInfo http) {
public NodeInfo(@Nullable String hostname, DiscoveryNode node, @Nullable ImmutableMap<String, String> serviceAttributes, @Nullable Settings settings,
@Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool, @Nullable NetworkInfo network,
@Nullable TransportInfo transport, @Nullable HttpInfo http) {
super(node);
this.attributes = attributes;
this.hostname = hostname;
this.serviceAttributes = serviceAttributes;
this.settings = settings;
this.os = os;
this.process = process;
this.jvm = jvm;
this.threadPool = threadPool;
this.network = network;
this.transport = transport;
this.http = http;
}
/**
* The attributes of the node.
* System's hostname. <code>null</code> in case of UnknownHostException
*/
public ImmutableMap<String, String> attributes() {
return this.attributes;
@Nullable
public String hostname() {
return this.hostname;
}
/**
* System's hostname. <code>null</code> in case of UnknownHostException
*/
@Nullable
public String getHostname() {
return hostname();
}
/**
* The service attributes of the node.
*/
@Nullable
public ImmutableMap<String, String> serviceAttributes() {
return this.serviceAttributes;
}
/**
* The attributes of the node.
*/
public ImmutableMap<String, String> getAttributes() {
return attributes();
@Nullable
public ImmutableMap<String, String> getServiceAttributes() {
return serviceAttributes();
}
/**
* The settings of the node.
*/
@Nullable
public Settings settings() {
return this.settings;
}
@ -101,6 +135,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* The settings of the node.
*/
@Nullable
public Settings getSettings() {
return settings();
}
@ -108,6 +143,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* Operating System level information.
*/
@Nullable
public OsInfo os() {
return this.os;
}
@ -115,6 +151,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* Operating System level information.
*/
@Nullable
public OsInfo getOs() {
return os();
}
@ -122,6 +159,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* Process level information.
*/
@Nullable
public ProcessInfo process() {
return process;
}
@ -129,6 +167,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* Process level information.
*/
@Nullable
public ProcessInfo getProcess() {
return process();
}
@ -136,6 +175,7 @@ public class NodeInfo extends NodeOperationResponse {
/**
* JVM level information.
*/
@Nullable
public JvmInfo jvm() {
return jvm;
}
@ -143,13 +183,25 @@ public class NodeInfo extends NodeOperationResponse {
/**
* JVM level information.
*/
@Nullable
public JvmInfo getJvm() {
return jvm();
}
@Nullable
public ThreadPoolInfo threadPool() {
return this.threadPool;
}
@Nullable
public ThreadPoolInfo getThreadPool() {
return threadPool();
}
/**
* Network level information.
*/
@Nullable
public NetworkInfo network() {
return network;
}
@ -157,22 +209,27 @@ public class NodeInfo extends NodeOperationResponse {
/**
* Network level information.
*/
@Nullable
public NetworkInfo getNetwork() {
return network();
}
@Nullable
public TransportInfo transport() {
return transport;
}
@Nullable
public TransportInfo getTransport() {
return transport();
}
@Nullable
public HttpInfo http() {
return http;
}
@Nullable
public HttpInfo getHttp() {
return http();
}
@ -186,13 +243,20 @@ public class NodeInfo extends NodeOperationResponse {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
int size = in.readVInt();
for (int i = 0; i < size; i++) {
builder.put(in.readUTF(), in.readUTF());
if (in.readBoolean()) {
hostname = in.readUTF();
}
if (in.readBoolean()) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
int size = in.readVInt();
for (int i = 0; i < size; i++) {
builder.put(in.readUTF(), in.readUTF());
}
serviceAttributes = builder.build();
}
if (in.readBoolean()) {
settings = ImmutableSettings.readSettingsFromStream(in);
}
attributes = builder.build();
settings = ImmutableSettings.readSettingsFromStream(in);
if (in.readBoolean()) {
os = OsInfo.readOsInfo(in);
}
@ -202,6 +266,9 @@ public class NodeInfo extends NodeOperationResponse {
if (in.readBoolean()) {
jvm = JvmInfo.readJvmInfo(in);
}
if (in.readBoolean()) {
threadPool = ThreadPoolInfo.readThreadPoolInfo(in);
}
if (in.readBoolean()) {
network = NetworkInfo.readNetworkInfo(in);
}
@ -216,12 +283,28 @@ public class NodeInfo extends NodeOperationResponse {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(attributes.size());
for (Map.Entry<String, String> entry : attributes.entrySet()) {
out.writeUTF(entry.getKey());
out.writeUTF(entry.getValue());
if (hostname == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(hostname);
}
if (serviceAttributes() == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeVInt(serviceAttributes.size());
for (Map.Entry<String, String> entry : serviceAttributes.entrySet()) {
out.writeUTF(entry.getKey());
out.writeUTF(entry.getValue());
}
}
if (settings == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
ImmutableSettings.writeSettingsToStream(settings, out);
}
ImmutableSettings.writeSettingsToStream(settings, out);
if (os == null) {
out.writeBoolean(false);
} else {
@ -240,6 +323,12 @@ public class NodeInfo extends NodeOperationResponse {
out.writeBoolean(true);
jvm.writeTo(out);
}
if (threadPool == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
threadPool.writeTo(out);
}
if (network == null) {
out.writeBoolean(false);
} else {

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.info;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class NodesInfoAction extends ClusterAction<NodesInfoRequest, NodesInfoResponse, NodesInfoRequestBuilder> {
public static final NodesInfoAction INSTANCE = new NodesInfoAction();
public static final String NAME = "cluster/nodes/info";
private NodesInfoAction() {
super(NAME);
}
@Override
public NodesInfoResponse newResponse() {
return new NodesInfoResponse();
}
@Override
public NodesInfoRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new NodesInfoRequestBuilder(client);
}
}

View File

@ -20,14 +20,25 @@
package org.elasticsearch.action.admin.cluster.node.info;
import org.elasticsearch.action.support.nodes.NodesOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
* A request to get node (cluster) level information.
*
*
*/
public class NodesInfoRequest extends NodesOperationRequest {
private boolean settings = false;
private boolean os = false;
private boolean process = false;
private boolean jvm = false;
private boolean threadPool = false;
private boolean network = false;
private boolean transport = false;
private boolean http = false;
public NodesInfoRequest() {
}
@ -38,4 +49,180 @@ public class NodesInfoRequest extends NodesOperationRequest {
public NodesInfoRequest(String... nodesIds) {
super(nodesIds);
}
/**
* Clears all info flags.
*/
public NodesInfoRequest clear() {
settings = false;
os = false;
process = false;
jvm = false;
threadPool = false;
network = false;
transport = false;
http = false;
return this;
}
/**
* Sets to return all the data.
*/
public NodesInfoRequest all() {
settings = true;
os = true;
process = true;
jvm = true;
threadPool = true;
network = true;
transport = true;
http = true;
return this;
}
/**
* Should the node settings be returned.
*/
public boolean settings() {
return this.settings;
}
/**
* Should the node settings be returned.
*/
public NodesInfoRequest settings(boolean settings) {
this.settings = settings;
return this;
}
/**
* Should the node OS be returned.
*/
public boolean os() {
return this.os;
}
/**
* Should the node OS be returned.
*/
public NodesInfoRequest os(boolean os) {
this.os = os;
return this;
}
/**
* Should the node Process be returned.
*/
public boolean process() {
return this.process;
}
/**
* Should the node Process be returned.
*/
public NodesInfoRequest process(boolean process) {
this.process = process;
return this;
}
/**
* Should the node JVM be returned.
*/
public boolean jvm() {
return this.jvm;
}
/**
* Should the node JVM be returned.
*/
public NodesInfoRequest jvm(boolean jvm) {
this.jvm = jvm;
return this;
}
/**
* Should the node Thread Pool info be returned.
*/
public boolean threadPool() {
return this.threadPool;
}
/**
* Should the node Thread Pool info be returned.
*/
public NodesInfoRequest threadPool(boolean threadPool) {
this.threadPool = threadPool;
return this;
}
/**
* Should the node Network be returned.
*/
public boolean network() {
return this.network;
}
/**
* Should the node Network be returned.
*/
public NodesInfoRequest network(boolean network) {
this.network = network;
return this;
}
/**
* Should the node Transport be returned.
*/
public boolean transport() {
return this.transport;
}
/**
* Should the node Transport be returned.
*/
public NodesInfoRequest transport(boolean transport) {
this.transport = transport;
return this;
}
/**
* Should the node HTTP be returned.
*/
public boolean http() {
return this.http;
}
/**
* Should the node HTTP be returned.
*/
public NodesInfoRequest http(boolean http) {
this.http = http;
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
settings = in.readBoolean();
os = in.readBoolean();
process = in.readBoolean();
jvm = in.readBoolean();
threadPool = in.readBoolean();
network = in.readBoolean();
transport = in.readBoolean();
http = in.readBoolean();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(settings);
out.writeBoolean(os);
out.writeBoolean(process);
out.writeBoolean(jvm);
out.writeBoolean(threadPool);
out.writeBoolean(network);
out.writeBoolean(transport);
out.writeBoolean(http);
}
}

View File

@ -0,0 +1,125 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.info;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
/**
*
*/
public class NodesInfoRequestBuilder extends BaseClusterRequestBuilder<NodesInfoRequest, NodesInfoResponse> {
public NodesInfoRequestBuilder(ClusterAdminClient clusterClient) {
super(clusterClient, new NodesInfoRequest());
}
public NodesInfoRequestBuilder setNodesIds(String... nodesIds) {
request.nodesIds(nodesIds);
return this;
}
/**
* Clears all info flags.
*/
public NodesInfoRequestBuilder clear() {
request.clear();
return this;
}
/**
* Sets to reutrn all the data.
*/
public NodesInfoRequestBuilder all() {
request.all();
return this;
}
/**
* Should the node settings be returned.
*/
public NodesInfoRequestBuilder setSettings(boolean settings) {
request.settings(settings);
return this;
}
/**
* Should the node OS info be returned.
*/
public NodesInfoRequestBuilder setOs(boolean os) {
request.os(os);
return this;
}
/**
* Should the node OS process be returned.
*/
public NodesInfoRequestBuilder setProcess(boolean process) {
request.process(process);
return this;
}
/**
* Should the node JVM info be returned.
*/
public NodesInfoRequestBuilder setJvm(boolean jvm) {
request.jvm(jvm);
return this;
}
/**
* Should the node thread pool info be returned.
*/
public NodesInfoRequestBuilder setThreadPool(boolean threadPool) {
request.threadPool(threadPool);
return this;
}
/**
* Should the node Network info be returned.
*/
public NodesInfoRequestBuilder setNetwork(boolean network) {
request.network(network);
return this;
}
/**
* Should the node Transport info be returned.
*/
public NodesInfoRequestBuilder setTransport(boolean transport) {
request.transport(transport);
return this;
}
/**
* Should the node HTTP info be returned.
*/
public NodesInfoRequestBuilder setHttp(boolean http) {
request.http(http);
return this;
}
@Override
protected void doExecute(ActionListener<NodesInfoResponse> listener) {
client.nodesInfo(request, listener);
}
}

View File

@ -23,13 +23,20 @@ import org.elasticsearch.action.support.nodes.NodesOperationResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
/**
*
*/
public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> {
public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> implements ToXContent {
private SettingsFilter settingsFilter;
public NodesInfoResponse() {
}
@ -55,4 +62,76 @@ public class NodesInfoResponse extends NodesOperationResponse<NodeInfo> {
node.writeTo(out);
}
}
public NodesInfoResponse settingsFilter(SettingsFilter settingsFilter) {
this.settingsFilter = settingsFilter;
return this;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("cluster_name", clusterName().value());
builder.startObject("nodes");
for (NodeInfo nodeInfo : this) {
builder.startObject(nodeInfo.node().id(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("name", nodeInfo.node().name(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("transport_address", nodeInfo.node().address().toString());
if (nodeInfo.hostname() != null) {
builder.field("hostname", nodeInfo.hostname(), XContentBuilder.FieldCaseConversion.NONE);
}
if (nodeInfo.serviceAttributes() != null) {
for (Map.Entry<String, String> nodeAttribute : nodeInfo.serviceAttributes().entrySet()) {
builder.field(nodeAttribute.getKey(), nodeAttribute.getValue());
}
}
if (!nodeInfo.node().attributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attr : nodeInfo.node().attributes().entrySet()) {
builder.field(attr.getKey(), attr.getValue());
}
builder.endObject();
}
if (nodeInfo.settings() != null) {
builder.startObject("settings");
Settings settings = settingsFilter.filterSettings(nodeInfo.settings());
for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
builder.endObject();
}
if (nodeInfo.os() != null) {
nodeInfo.os().toXContent(builder, params);
}
if (nodeInfo.process() != null) {
nodeInfo.process().toXContent(builder, params);
}
if (nodeInfo.jvm() != null) {
nodeInfo.jvm().toXContent(builder, params);
}
if (nodeInfo.threadPool() != null) {
nodeInfo.threadPool().toXContent(builder, params);
}
if (nodeInfo.network() != null) {
nodeInfo.network().toXContent(builder, params);
}
if (nodeInfo.transport() != null) {
nodeInfo.transport().toXContent(builder, params);
}
if (nodeInfo.http() != null) {
nodeInfo.http().toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}
}

View File

@ -20,17 +20,19 @@
package org.elasticsearch.action.admin.cluster.node.info;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.nodes.NodeOperationRequest;
import org.elasticsearch.action.support.nodes.TransportNodesOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;
@ -57,12 +59,7 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Node.INFO;
}
@Override
protected String transportNodeAction() {
return "/cluster/nodes/info/node";
return NodesInfoAction.NAME;
}
@Override
@ -89,7 +86,7 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
@Override
protected NodeInfoRequest newNodeRequest(String nodeId, NodesInfoRequest request) {
return new NodeInfoRequest(nodeId);
return new NodeInfoRequest(nodeId, request);
}
@Override
@ -98,8 +95,9 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
}
@Override
protected NodeInfo nodeOperation(NodeInfoRequest nodeInfoRequest) throws ElasticSearchException {
return nodeService.info();
protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest) throws ElasticSearchException {
NodesInfoRequest request = nodeRequest.request;
return nodeService.info(request.settings(), request.os(), request.process(), request.jvm(), request.threadPool(), request.network(), request.transport(), request.http());
}
@Override
@ -107,13 +105,29 @@ public class TransportNodesInfoAction extends TransportNodesOperationAction<Node
return false;
}
protected static class NodeInfoRequest extends NodeOperationRequest {
static class NodeInfoRequest extends NodeOperationRequest {
private NodeInfoRequest() {
NodesInfoRequest request;
NodeInfoRequest() {
}
private NodeInfoRequest(String nodeId) {
NodeInfoRequest(String nodeId, NodesInfoRequest request) {
super(nodeId);
this.request = request;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
request = new NodesInfoRequest();
request.readFrom(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
request.writeTo(out);
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.restart;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class NodesRestartAction extends ClusterAction<NodesRestartRequest, NodesRestartResponse, NodesRestartRequestBuilder> {
public static final NodesRestartAction INSTANCE = new NodesRestartAction();
public static final String NAME = "cluster/nodes/restart";
private NodesRestartAction() {
super(NAME);
}
@Override
public NodesRestartResponse newResponse() {
return new NodesRestartResponse();
}
@Override
public NodesRestartRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new NodesRestartRequestBuilder(client);
}
}

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.node.restart;
package org.elasticsearch.action.admin.cluster.node.restart;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartRequest;
import org.elasticsearch.action.admin.cluster.node.restart.NodesRestartResponse;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**

View File

@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.cluster.node.restart;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.nodes.NodeOperationRequest;
import org.elasticsearch.action.support.nodes.TransportNodesOperationAction;
import org.elasticsearch.cluster.ClusterName;
@ -76,12 +75,7 @@ public class TransportNodesRestartAction extends TransportNodesOperationAction<N
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Node.RESTART;
}
@Override
protected String transportNodeAction() {
return "/cluster/nodes/restart/node";
return NodesRestartAction.NAME;
}
@Override

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.shutdown;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class NodesShutdownAction extends ClusterAction<NodesShutdownRequest, NodesShutdownResponse, NodesShutdownRequestBuilder> {
public static final NodesShutdownAction INSTANCE = new NodesShutdownAction();
public static final String NAME = "cluster/nodes/shutdown";
private NodesShutdownAction() {
super(NAME);
}
@Override
public NodesShutdownResponse newResponse() {
return new NodesShutdownResponse();
}
@Override
public NodesShutdownRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new NodesShutdownRequestBuilder(client);
}
}

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.node.shutdown;
package org.elasticsearch.action.admin.cluster.node.shutdown;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest;
import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownResponse;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**

View File

@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.cluster.node.shutdown;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
@ -62,7 +61,7 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc
super(settings, transportService, clusterService, threadPool);
this.node = node;
this.clusterName = clusterName;
this.disabled = componentSettings.getAsBoolean("disabled", false);
this.disabled = settings.getAsBoolean("action.disable_shutdown", componentSettings.getAsBoolean("disabled", false));
this.delay = componentSettings.getAsTime("delay", TimeValue.timeValueMillis(200));
this.transportService.registerHandler(NodeShutdownRequestHandler.ACTION, new NodeShutdownRequestHandler());
@ -75,7 +74,7 @@ public class TransportNodesShutdownAction extends TransportMasterNodeOperationAc
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Node.SHUTDOWN;
return NodesShutdownAction.NAME;
}
@Override

View File

@ -26,54 +26,84 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.http.HttpStats;
import org.elasticsearch.indices.NodeIndicesStats;
import org.elasticsearch.monitor.fs.FsStats;
import org.elasticsearch.monitor.jvm.JvmStats;
import org.elasticsearch.monitor.network.NetworkStats;
import org.elasticsearch.monitor.os.OsStats;
import org.elasticsearch.monitor.process.ProcessStats;
import org.elasticsearch.threadpool.ThreadPoolStats;
import org.elasticsearch.transport.TransportStats;
import java.io.IOException;
/**
* Node statistics (static, does not change over time).
*
*
*/
public class NodeStats extends NodeOperationResponse {
@Nullable
private String hostname;
@Nullable
private NodeIndicesStats indices;
@Nullable
private OsStats os;
@Nullable
private ProcessStats process;
@Nullable
private JvmStats jvm;
@Nullable
private ThreadPoolStats threadPool;
@Nullable
private NetworkStats network;
@Nullable
private FsStats fs;
@Nullable
private TransportStats transport;
@Nullable
private HttpStats http;
NodeStats() {
}
public NodeStats(DiscoveryNode node, NodeIndicesStats indices,
OsStats os, ProcessStats process, JvmStats jvm, NetworkStats network,
TransportStats transport, @Nullable HttpStats http) {
public NodeStats(DiscoveryNode node, @Nullable String hostname, @Nullable NodeIndicesStats indices,
@Nullable OsStats os, @Nullable ProcessStats process, @Nullable JvmStats jvm, @Nullable ThreadPoolStats threadPool, @Nullable NetworkStats network,
@Nullable FsStats fs, @Nullable TransportStats transport, @Nullable HttpStats http) {
super(node);
this.hostname = hostname;
this.indices = indices;
this.os = os;
this.process = process;
this.jvm = jvm;
this.threadPool = threadPool;
this.network = network;
this.fs = fs;
this.transport = transport;
this.http = http;
}
@Nullable
public String hostname() {
return this.hostname;
}
@Nullable
public String getHostname() {
return this.hostname;
}
/**
* Indices level stats.
*/
@Nullable
public NodeIndicesStats indices() {
return this.indices;
}
@ -81,6 +111,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* Indices level stats.
*/
@Nullable
public NodeIndicesStats getIndices() {
return indices();
}
@ -88,6 +119,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* Operating System level statistics.
*/
@Nullable
public OsStats os() {
return this.os;
}
@ -95,6 +127,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* Operating System level statistics.
*/
@Nullable
public OsStats getOs() {
return os();
}
@ -102,6 +135,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* Process level statistics.
*/
@Nullable
public ProcessStats process() {
return process;
}
@ -109,6 +143,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* Process level statistics.
*/
@Nullable
public ProcessStats getProcess() {
return process();
}
@ -116,6 +151,7 @@ public class NodeStats extends NodeOperationResponse {
/**
* JVM level statistics.
*/
@Nullable
public JvmStats jvm() {
return jvm;
}
@ -123,13 +159,31 @@ public class NodeStats extends NodeOperationResponse {
/**
* JVM level statistics.
*/
@Nullable
public JvmStats getJvm() {
return jvm();
}
/**
* Thread Pool level statistics.
*/
@Nullable
public ThreadPoolStats threadPool() {
return this.threadPool;
}
/**
* Thread Pool level statistics.
*/
@Nullable
public ThreadPoolStats getThreadPool() {
return threadPool();
}
/**
* Network level statistics.
*/
@Nullable
public NetworkStats network() {
return network;
}
@ -137,22 +191,43 @@ public class NodeStats extends NodeOperationResponse {
/**
* Network level statistics.
*/
@Nullable
public NetworkStats getNetwork() {
return network();
}
/**
* File system level stats.
*/
@Nullable
FsStats fs() {
return fs;
}
/**
* File system level stats.
*/
@Nullable
FsStats getFs() {
return fs();
}
@Nullable
public TransportStats transport() {
return this.transport;
}
@Nullable
public TransportStats getTransport() {
return transport();
}
@Nullable
public HttpStats http() {
return this.http;
}
@Nullable
public HttpStats getHttp() {
return http();
}
@ -166,6 +241,9 @@ public class NodeStats extends NodeOperationResponse {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
hostname = in.readUTF();
}
if (in.readBoolean()) {
indices = NodeIndicesStats.readIndicesStats(in);
}
@ -178,9 +256,15 @@ public class NodeStats extends NodeOperationResponse {
if (in.readBoolean()) {
jvm = JvmStats.readJvmStats(in);
}
if (in.readBoolean()) {
threadPool = ThreadPoolStats.readThreadPoolStats(in);
}
if (in.readBoolean()) {
network = NetworkStats.readNetworkStats(in);
}
if (in.readBoolean()) {
fs = FsStats.readFsStats(in);
}
if (in.readBoolean()) {
transport = TransportStats.readTransportStats(in);
}
@ -192,6 +276,12 @@ public class NodeStats extends NodeOperationResponse {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (hostname == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(hostname);
}
if (indices == null) {
out.writeBoolean(false);
} else {
@ -216,12 +306,24 @@ public class NodeStats extends NodeOperationResponse {
out.writeBoolean(true);
jvm.writeTo(out);
}
if (threadPool == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
threadPool.writeTo(out);
}
if (network == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
network.writeTo(out);
}
if (fs == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
fs.writeTo(out);
}
if (transport == null) {
out.writeBoolean(false);
} else {

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.stats;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class NodesStatsAction extends ClusterAction<NodesStatsRequest, NodesStatsResponse, NodesStatsRequestBuilder> {
public static final NodesStatsAction INSTANCE = new NodesStatsAction();
public static final String NAME = "cluster/nodes/stats";
private NodesStatsAction() {
super(NAME);
}
@Override
public NodesStatsResponse newResponse() {
return new NodesStatsResponse();
}
@Override
public NodesStatsRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new NodesStatsRequestBuilder(client);
}
}

View File

@ -20,14 +20,26 @@
package org.elasticsearch.action.admin.cluster.node.stats;
import org.elasticsearch.action.support.nodes.NodesOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
* A request to get node (cluster) level stats.
*
*
*/
public class NodesStatsRequest extends NodesOperationRequest {
private boolean indices = true;
private boolean os;
private boolean process;
private boolean jvm;
private boolean threadPool;
private boolean network;
private boolean fs;
private boolean transport;
private boolean http;
protected NodesStatsRequest() {
}
@ -38,4 +50,200 @@ public class NodesStatsRequest extends NodesOperationRequest {
public NodesStatsRequest(String... nodesIds) {
super(nodesIds);
}
/**
* Sets all the request flags.
*/
public NodesStatsRequest all() {
this.indices = true;
this.os = true;
this.process = true;
this.jvm = true;
this.threadPool = true;
this.network = true;
this.fs = true;
this.transport = true;
this.http = true;
return this;
}
/**
* Clears all the request flags.
*/
public NodesStatsRequest clear() {
this.indices = false;
this.os = false;
this.process = false;
this.jvm = false;
this.threadPool = false;
this.network = false;
this.fs = false;
this.transport = false;
this.http = false;
return this;
}
/**
* Should indices stats be returned.
*/
public boolean indices() {
return this.indices;
}
/**
* Should indices stats be returned.
*/
public NodesStatsRequest indices(boolean indices) {
this.indices = indices;
return this;
}
/**
* Should the node OS be returned.
*/
public boolean os() {
return this.os;
}
/**
* Should the node OS be returned.
*/
public NodesStatsRequest os(boolean os) {
this.os = os;
return this;
}
/**
* Should the node Process be returned.
*/
public boolean process() {
return this.process;
}
/**
* Should the node Process be returned.
*/
public NodesStatsRequest process(boolean process) {
this.process = process;
return this;
}
/**
* Should the node JVM be returned.
*/
public boolean jvm() {
return this.jvm;
}
/**
* Should the node JVM be returned.
*/
public NodesStatsRequest jvm(boolean jvm) {
this.jvm = jvm;
return this;
}
/**
* Should the node Thread Pool be returned.
*/
public boolean threadPool() {
return this.threadPool;
}
/**
* Should the node Thread Pool be returned.
*/
public NodesStatsRequest threadPool(boolean threadPool) {
this.threadPool = threadPool;
return this;
}
/**
* Should the node Network be returned.
*/
public boolean network() {
return this.network;
}
/**
* Should the node Network be returned.
*/
public NodesStatsRequest network(boolean network) {
this.network = network;
return this;
}
/**
* Should the node file system stats be returned.
*/
public boolean fs() {
return this.fs;
}
/**
* Should the node file system stats be returned.
*/
public NodesStatsRequest fs(boolean fs) {
this.fs = fs;
return this;
}
/**
* Should the node Transport be returned.
*/
public boolean transport() {
return this.transport;
}
/**
* Should the node Transport be returned.
*/
public NodesStatsRequest transport(boolean transport) {
this.transport = transport;
return this;
}
/**
* Should the node HTTP be returned.
*/
public boolean http() {
return this.http;
}
/**
* Should the node HTTP be returned.
*/
public NodesStatsRequest http(boolean http) {
this.http = http;
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readBoolean();
os = in.readBoolean();
process = in.readBoolean();
jvm = in.readBoolean();
threadPool = in.readBoolean();
network = in.readBoolean();
fs = in.readBoolean();
transport = in.readBoolean();
http = in.readBoolean();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeBoolean(indices);
out.writeBoolean(os);
out.writeBoolean(process);
out.writeBoolean(jvm);
out.writeBoolean(threadPool);
out.writeBoolean(network);
out.writeBoolean(fs);
out.writeBoolean(transport);
out.writeBoolean(http);
}
}

View File

@ -0,0 +1,132 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.node.stats;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
/**
*
*/
public class NodesStatsRequestBuilder extends BaseClusterRequestBuilder<NodesStatsRequest, NodesStatsResponse> {
public NodesStatsRequestBuilder(ClusterAdminClient clusterClient) {
super(clusterClient, new NodesStatsRequest());
}
public NodesStatsRequestBuilder setNodesIds(String... nodesIds) {
request.nodesIds(nodesIds);
return this;
}
/**
* Sets all the request flags.
*/
public NodesStatsRequestBuilder all() {
request.all();
return this;
}
/**
* Clears all stats flags.
*/
public NodesStatsRequestBuilder clear() {
request.clear();
return this;
}
/**
* Should the node indices stats be returned.
*/
public NodesStatsRequestBuilder setIndices(boolean indices) {
request.indices(indices);
return this;
}
/**
* Should the node OS stats be returned.
*/
public NodesStatsRequestBuilder setOs(boolean os) {
request.os(os);
return this;
}
/**
* Should the node OS stats be returned.
*/
public NodesStatsRequestBuilder setProcess(boolean process) {
request.process(process);
return this;
}
/**
* Should the node JVM stats be returned.
*/
public NodesStatsRequestBuilder setJvm(boolean jvm) {
request.jvm(jvm);
return this;
}
/**
* Should the node thread pool stats be returned.
*/
public NodesStatsRequestBuilder setThreadPool(boolean threadPool) {
request.threadPool(threadPool);
return this;
}
/**
* Should the node Network stats be returned.
*/
public NodesStatsRequestBuilder setNetwork(boolean network) {
request.network(network);
return this;
}
/**
* Should the node file system stats be returned.
*/
public NodesStatsRequestBuilder setFs(boolean fs) {
request.fs(fs);
return this;
}
/**
* Should the node Transport stats be returned.
*/
public NodesStatsRequestBuilder setTransport(boolean transport) {
request.transport(transport);
return this;
}
/**
* Should the node HTTP stats be returned.
*/
public NodesStatsRequestBuilder setHttp(boolean http) {
request.http(http);
return this;
}
@Override
protected void doExecute(ActionListener<NodesStatsResponse> listener) {
client.nodesStats(request, listener);
}
}

View File

@ -23,13 +23,16 @@ import org.elasticsearch.action.support.nodes.NodesOperationResponse;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
/**
*
*/
public class NodesStatsResponse extends NodesOperationResponse<NodeStats> {
public class NodesStatsResponse extends NodesOperationResponse<NodeStats> implements ToXContent {
NodesStatsResponse() {
}
@ -55,4 +58,63 @@ public class NodesStatsResponse extends NodesOperationResponse<NodeStats> {
node.writeTo(out);
}
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("cluster_name", clusterName().value());
builder.startObject("nodes");
for (NodeStats nodeStats : this) {
builder.startObject(nodeStats.node().id(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("name", nodeStats.node().name(), XContentBuilder.FieldCaseConversion.NONE);
builder.field("transport_address", nodeStats.node().address().toString());
if (nodeStats.hostname() != null) {
builder.field("hostname", nodeStats.hostname(), XContentBuilder.FieldCaseConversion.NONE);
}
if (!nodeStats.node().attributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attr : nodeStats.node().attributes().entrySet()) {
builder.field(attr.getKey(), attr.getValue());
}
builder.endObject();
}
if (nodeStats.indices() != null) {
nodeStats.indices().toXContent(builder, params);
}
if (nodeStats.os() != null) {
nodeStats.os().toXContent(builder, params);
}
if (nodeStats.process() != null) {
nodeStats.process().toXContent(builder, params);
}
if (nodeStats.jvm() != null) {
nodeStats.jvm().toXContent(builder, params);
}
if (nodeStats.threadPool() != null) {
nodeStats.threadPool().toXContent(builder, params);
}
if (nodeStats.network() != null) {
nodeStats.network().toXContent(builder, params);
}
if (nodeStats.fs() != null) {
nodeStats.fs().toXContent(builder, params);
}
if (nodeStats.transport() != null) {
nodeStats.transport().toXContent(builder, params);
}
if (nodeStats.http() != null) {
nodeStats.http().toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}
}

View File

@ -21,17 +21,19 @@ package org.elasticsearch.action.admin.cluster.node.stats;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.nodes.NodeOperationRequest;
import org.elasticsearch.action.support.nodes.TransportNodesOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;
@ -57,12 +59,7 @@ public class TransportNodesStatsAction extends TransportNodesOperationAction<Nod
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Node.STATS;
}
@Override
protected String transportNodeAction() {
return "/cluster/nodes/stats/node";
return NodesStatsAction.NAME;
}
@Override
@ -89,7 +86,7 @@ public class TransportNodesStatsAction extends TransportNodesOperationAction<Nod
@Override
protected NodeStatsRequest newNodeRequest(String nodeId, NodesStatsRequest request) {
return new NodeStatsRequest(nodeId);
return new NodeStatsRequest(nodeId, request);
}
@Override
@ -98,8 +95,9 @@ public class TransportNodesStatsAction extends TransportNodesOperationAction<Nod
}
@Override
protected NodeStats nodeOperation(NodeStatsRequest request) throws ElasticSearchException {
return nodeService.stats();
protected NodeStats nodeOperation(NodeStatsRequest nodeStatsRequest) throws ElasticSearchException {
NodesStatsRequest request = nodeStatsRequest.request;
return nodeService.stats(request.indices(), request.os(), request.process(), request.jvm(), request.threadPool(), request.network(), request.fs(), request.transport(), request.http());
}
@Override
@ -107,13 +105,29 @@ public class TransportNodesStatsAction extends TransportNodesOperationAction<Nod
return false;
}
protected static class NodeStatsRequest extends NodeOperationRequest {
static class NodeStatsRequest extends NodeOperationRequest {
private NodeStatsRequest() {
NodesStatsRequest request;
NodeStatsRequest() {
}
private NodeStatsRequest(String nodeId) {
NodeStatsRequest(String nodeId, NodesStatsRequest request) {
super(nodeId);
this.request = request;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
request = new NodesStatsRequest();
request.readFrom(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
request.writeTo(out);
}
}
}

View File

@ -1,85 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.broadcast;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
*
*/
public class BroadcastPingRequest extends BroadcastOperationRequest {
@Nullable
protected String queryHint;
BroadcastPingRequest() {
}
public BroadcastPingRequest(String... indices) {
super(indices);
this.queryHint = null;
}
@Override
public BroadcastPingRequest operationThreading(BroadcastOperationThreading operationThreading) {
super.operationThreading(operationThreading);
return this;
}
@Override
public BroadcastPingRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
public String queryHint() {
return this.queryHint;
}
public BroadcastPingRequest queryHint(String queryHint) {
this.queryHint = queryHint;
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.readBoolean()) {
queryHint = in.readUTF();
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (queryHint == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(queryHint);
}
}
}

View File

@ -1,118 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.broadcast;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;
import static com.google.common.collect.Lists.newArrayList;
/**
*
*/
public class TransportBroadcastPingAction extends TransportBroadcastOperationAction<BroadcastPingRequest, BroadcastPingResponse, BroadcastShardPingRequest, BroadcastShardPingResponse> {
@Inject
public TransportBroadcastPingAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) {
super(settings, threadPool, clusterService, transportService);
}
@Override
protected String executor() {
return ThreadPool.Names.CACHED;
}
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Ping.BROADCAST;
}
@Override
protected String transportShardAction() {
return "/cluster/ping/broadcast/shard";
}
@Override
protected BroadcastPingRequest newRequest() {
return new BroadcastPingRequest();
}
@Override
protected GroupShardsIterator shards(BroadcastPingRequest request, String[] concreteIndices, ClusterState clusterState) {
return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, request.queryHint(), null, null);
}
@Override
protected BroadcastPingResponse newResponse(BroadcastPingRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
int successfulShards = 0;
int failedShards = 0;
List<ShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.length(); i++) {
Object shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
failedShards++;
} else if (shardResponse instanceof BroadcastShardOperationFailedException) {
failedShards++;
if (shardFailures == null) {
shardFailures = newArrayList();
}
shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
} else {
successfulShards++;
}
}
return new BroadcastPingResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
@Override
protected BroadcastShardPingRequest newShardRequest() {
return new BroadcastShardPingRequest();
}
@Override
protected BroadcastShardPingRequest newShardRequest(ShardRouting shard, BroadcastPingRequest request) {
return new BroadcastShardPingRequest(shard.index(), shard.id());
}
@Override
protected BroadcastShardPingResponse newShardResponse() {
return new BroadcastShardPingResponse();
}
@Override
protected BroadcastShardPingResponse shardOperation(BroadcastShardPingRequest broadcastShardPingRequest) throws ElasticSearchException {
return new BroadcastShardPingResponse();
}
}

View File

@ -1,69 +0,0 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.support.replication.IndexReplicationOperationRequest;
import org.elasticsearch.action.support.replication.ReplicationType;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;
import java.io.IOException;
/**
*
*/
public class IndexReplicationPingRequest extends IndexReplicationOperationRequest {
public IndexReplicationPingRequest(String index) {
this.index = index;
}
IndexReplicationPingRequest(ReplicationPingRequest request, String index) {
this.index = index;
this.timeout = request.timeout();
this.replicationType = request.replicationType();
}
IndexReplicationPingRequest() {
}
public IndexReplicationPingRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
}
/**
* The replication type to use with this operation.
*/
public IndexReplicationPingRequest replicationType(ReplicationType replicationType) {
this.replicationType = replicationType;
return this;
}
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
}
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
}
}

View File

@ -1,79 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
/**
*
*/
public class IndexReplicationPingResponse implements ActionResponse, Streamable {
private String index;
private int successfulShards;
private int failedShards;
IndexReplicationPingResponse(String index, int successfulShards, int failedShards) {
this.index = index;
this.successfulShards = successfulShards;
this.failedShards = failedShards;
}
IndexReplicationPingResponse() {
}
public String index() {
return index;
}
public int successfulShards() {
return successfulShards;
}
public int failedShards() {
return failedShards;
}
public int totalShards() {
return successfulShards + failedShards;
}
@Override
public void readFrom(StreamInput in) throws IOException {
index = in.readUTF();
successfulShards = in.readVInt();
failedShards = in.readVInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(index);
out.writeVInt(successfulShards);
out.writeVInt(failedShards);
}
}

View File

@ -1,58 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.support.replication.IndicesReplicationOperationRequest;
import org.elasticsearch.action.support.replication.ReplicationType;
import org.elasticsearch.common.unit.TimeValue;
/**
*
*/
public class ReplicationPingRequest extends IndicesReplicationOperationRequest {
public ReplicationPingRequest(String... indices) {
this.indices = indices;
}
public ReplicationPingRequest() {
}
@Override
public ReplicationPingRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
public ReplicationPingRequest replicationType(ReplicationType replicationType) {
this.replicationType = replicationType;
return this;
}
public ReplicationPingRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
}
public ReplicationPingRequest timeout(String timeout) {
return timeout(TimeValue.parseTimeValue(timeout, null));
}
}

View File

@ -1,67 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class ReplicationPingResponse implements ActionResponse, Streamable {
private Map<String, IndexReplicationPingResponse> responses = new HashMap<String, IndexReplicationPingResponse>();
ReplicationPingResponse() {
}
public Map<String, IndexReplicationPingResponse> indices() {
return responses;
}
public IndexReplicationPingResponse index(String index) {
return responses.get(index);
}
@Override
public void readFrom(StreamInput in) throws IOException {
int size = in.readVInt();
for (int i = 0; i < size; i++) {
IndexReplicationPingResponse response = new IndexReplicationPingResponse();
response.readFrom(in);
responses.put(response.index(), response);
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(responses.size());
for (IndexReplicationPingResponse response : responses.values()) {
response.writeTo(out);
}
}
}

View File

@ -1,88 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.support.replication.ReplicationType;
import org.elasticsearch.action.support.replication.ShardReplicationOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
*
*/
public class ShardReplicationPingRequest extends ShardReplicationOperationRequest {
private int shardId;
public ShardReplicationPingRequest(IndexReplicationPingRequest request, int shardId) {
this(request.index(), shardId);
timeout = request.timeout();
replicationType(request.replicationType());
}
public ShardReplicationPingRequest(String index, int shardId) {
this.index = index;
this.shardId = shardId;
}
ShardReplicationPingRequest() {
}
public int shardId() {
return this.shardId;
}
@Override
public ShardReplicationPingRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
@Override
public ShardReplicationPingRequest operationThreaded(boolean threadedOperation) {
super.operationThreaded(threadedOperation);
return this;
}
@Override
public ShardReplicationPingRequest replicationType(ReplicationType replicationType) {
super.replicationType(replicationType);
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
shardId = in.readVInt();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVInt(shardId);
}
@Override
public String toString() {
return "replication_ping {[" + index + "][" + shardId + "]}";
}
}

View File

@ -1,88 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.support.replication.TransportIndexReplicationOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.concurrent.atomic.AtomicReferenceArray;
/**
*/
public class TransportIndexReplicationPingAction extends TransportIndexReplicationOperationAction<IndexReplicationPingRequest, IndexReplicationPingResponse, ShardReplicationPingRequest, ShardReplicationPingRequest, ShardReplicationPingResponse> {
@Inject
public TransportIndexReplicationPingAction(Settings settings, ClusterService clusterService,
TransportService transportService, ThreadPool threadPool,
TransportShardReplicationPingAction shardReplicationPingAction) {
super(settings, transportService, clusterService, threadPool, shardReplicationPingAction);
}
@Override
protected IndexReplicationPingRequest newRequestInstance() {
return new IndexReplicationPingRequest();
}
@Override
protected IndexReplicationPingResponse newResponseInstance(IndexReplicationPingRequest request, AtomicReferenceArray shardsResponses) {
int successfulShards = 0;
int failedShards = 0;
for (int i = 0; i < shardsResponses.length(); i++) {
if (shardsResponses.get(i) == null) {
failedShards++;
} else {
successfulShards++;
}
}
return new IndexReplicationPingResponse(request.index(), successfulShards, failedShards);
}
@Override
protected boolean accumulateExceptions() {
return false;
}
@Override
protected String transportAction() {
return "ping/replication/index";
}
@Override
protected GroupShardsIterator shards(IndexReplicationPingRequest indexRequest) {
IndexRoutingTable indexRouting = clusterService.state().routingTable().index(indexRequest.index());
if (indexRouting == null) {
throw new IndexMissingException(new Index(indexRequest.index()));
}
return indexRouting.groupByShardsIt();
}
@Override
protected ShardReplicationPingRequest newShardRequestInstance(IndexReplicationPingRequest indexRequest, int shardId) {
return new ShardReplicationPingRequest(indexRequest, shardId);
}
}

View File

@ -1,73 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.replication.TransportIndicesReplicationOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReferenceArray;
/**
*/
public class TransportReplicationPingAction extends TransportIndicesReplicationOperationAction<ReplicationPingRequest, ReplicationPingResponse, IndexReplicationPingRequest, IndexReplicationPingResponse, ShardReplicationPingRequest, ShardReplicationPingRequest, ShardReplicationPingResponse> {
@Inject
public TransportReplicationPingAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, TransportIndexReplicationPingAction indexAction) {
super(settings, transportService, clusterService, threadPool, indexAction);
}
@Override
protected ReplicationPingRequest newRequestInstance() {
return new ReplicationPingRequest();
}
@Override
protected ReplicationPingResponse newResponseInstance(ReplicationPingRequest request, AtomicReferenceArray indexResponses) {
ReplicationPingResponse response = new ReplicationPingResponse();
for (int i = 0; i < indexResponses.length(); i++) {
IndexReplicationPingResponse indexResponse = (IndexReplicationPingResponse) indexResponses.get(i);
if (indexResponse != null) {
response.indices().put(indexResponse.index(), indexResponse);
}
}
return response;
}
@Override
protected boolean accumulateExceptions() {
return false;
}
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Ping.REPLICATION;
}
@Override
protected IndexReplicationPingRequest newIndexRequestInstance(ReplicationPingRequest request, String index, Set<String> routing) {
return new IndexReplicationPingRequest(request, index);
}
}

View File

@ -1,88 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.replication;
import org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.action.shard.ShardStateAction;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
/**
*
*/
public class TransportShardReplicationPingAction extends TransportShardReplicationOperationAction<ShardReplicationPingRequest, ShardReplicationPingRequest, ShardReplicationPingResponse> {
@Inject
public TransportShardReplicationPingAction(Settings settings, TransportService transportService,
ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool,
ShardStateAction shardStateAction) {
super(settings, transportService, clusterService, indicesService, threadPool, shardStateAction);
}
@Override
protected String executor() {
return ThreadPool.Names.CACHED;
}
@Override
protected boolean checkWriteConsistency() {
return true;
}
@Override
protected ShardReplicationPingRequest newRequestInstance() {
return new ShardReplicationPingRequest();
}
@Override
protected ShardReplicationPingRequest newReplicaRequestInstance() {
return new ShardReplicationPingRequest();
}
@Override
protected ShardReplicationPingResponse newResponseInstance() {
return new ShardReplicationPingResponse();
}
@Override
protected String transportAction() {
return "ping/replication/shard";
}
@Override
protected PrimaryResponse<ShardReplicationPingResponse, ShardReplicationPingRequest> shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) {
return new PrimaryResponse<ShardReplicationPingResponse, ShardReplicationPingRequest>(shardRequest.request, new ShardReplicationPingResponse(), null);
}
@Override
protected void shardOperationOnReplica(ReplicaOperationRequest shardRequest) {
}
@Override
protected ShardIterator shards(ClusterState clusterState, ShardReplicationPingRequest request) {
return clusterService.state().routingTable().index(request.index()).shard(request.shardId()).shardsIt();
}
}

View File

@ -1,89 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.single;
import org.elasticsearch.action.support.single.shard.SingleShardOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
/**
*
*/
public class SinglePingRequest extends SingleShardOperationRequest {
protected String type;
protected String id;
public SinglePingRequest(String index) {
super(index);
}
public SinglePingRequest(String index, String type, String id) {
super(index);
this.type = type;
this.id = id;
}
public SinglePingRequest() {
}
public SinglePingRequest index(String index) {
this.index = index;
return this;
}
public SinglePingRequest type(String type) {
this.type = type;
return this;
}
public SinglePingRequest id(String id) {
this.id = id;
return this;
}
@Override
public SinglePingRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
@Override
public SinglePingRequest operationThreaded(boolean threadedOperation) {
super.operationThreaded(threadedOperation);
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
type = in.readUTF();
id = in.readUTF();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeUTF(type);
out.writeUTF(id);
}
}

View File

@ -1,78 +0,0 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.single;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
/**
*
*/
public class TransportSinglePingAction extends TransportShardSingleOperationAction<SinglePingRequest, SinglePingResponse> {
@Inject
public TransportSinglePingAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService) {
super(settings, threadPool, clusterService, transportService);
}
@Override
protected String executor() {
return ThreadPool.Names.CACHED;
}
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.Ping.SINGLE;
}
@Override
protected String transportShardAction() {
return "/cluster/ping/single/shard";
}
@Override
protected ShardIterator shards(ClusterState clusterState, SinglePingRequest request) throws ElasticSearchException {
return clusterService.operationRouting()
.getShards(clusterService.state(), request.index(), request.type, request.id, null, null);
}
@Override
protected SinglePingResponse shardOperation(SinglePingRequest request, int shardId) throws ElasticSearchException {
return new SinglePingResponse();
}
@Override
protected SinglePingRequest newRequest() {
return new SinglePingRequest();
}
@Override
protected SinglePingResponse newResponse() {
return new SinglePingResponse();
}
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.reroute;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class ClusterRerouteAction extends ClusterAction<ClusterRerouteRequest, ClusterRerouteResponse, ClusterRerouteRequestBuilder> {
public static final ClusterRerouteAction INSTANCE = new ClusterRerouteAction();
public static final String NAME = "cluster/reroute";
private ClusterRerouteAction() {
super(NAME);
}
@Override
public ClusterRerouteResponse newResponse() {
return new ClusterRerouteResponse();
}
@Override
public ClusterRerouteRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new ClusterRerouteRequestBuilder(client);
}
}

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.reroute;
package org.elasticsearch.action.admin.cluster.reroute;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest;
import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.admin.cluster.reroute;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -57,7 +56,7 @@ public class TransportClusterRerouteAction extends TransportMasterNodeOperationA
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.REROUTE;
return ClusterRerouteAction.NAME;
}
@Override

View File

@ -17,30 +17,29 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.node.info;
package org.elasticsearch.action.admin.cluster.settings;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
/**
*
*/
public class NodesInfoRequestBuilder extends BaseClusterRequestBuilder<NodesInfoRequest, NodesInfoResponse> {
public class ClusterUpdateSettingsAction extends ClusterAction<ClusterUpdateSettingsRequest, ClusterUpdateSettingsResponse, ClusterUpdateSettingsRequestBuilder> {
public NodesInfoRequestBuilder(ClusterAdminClient clusterClient) {
super(clusterClient, new NodesInfoRequest());
}
public static final ClusterUpdateSettingsAction INSTANCE = new ClusterUpdateSettingsAction();
public static final String NAME = "cluster/settings/update";
public NodesInfoRequestBuilder setNodesIds(String... nodesIds) {
request.nodesIds(nodesIds);
return this;
private ClusterUpdateSettingsAction() {
super(NAME);
}
@Override
protected void doExecute(ActionListener<NodesInfoResponse> listener) {
client.nodesInfo(request, listener);
public ClusterUpdateSettingsResponse newResponse() {
return new ClusterUpdateSettingsResponse();
}
@Override
public ClusterUpdateSettingsRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new ClusterUpdateSettingsRequestBuilder(client);
}
}

View File

@ -33,7 +33,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.action.Actions.addValidationError;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.readSettingsFromStream;
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.settings;
package org.elasticsearch.action.admin.cluster.settings;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;

View File

@ -20,12 +20,12 @@
package org.elasticsearch.action.admin.cluster.settings;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.ProcessedClusterStateUpdateTask;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
@ -62,7 +62,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.UPDATE_SETTINGS;
return ClusterUpdateSettingsAction.NAME;
}
@Override
@ -108,6 +108,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
}
if (!changed) {
latch.countDown();
return currentState;
}
@ -115,8 +116,15 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeOpe
.persistentSettings(persistentSettings.build())
.transientSettings(transientSettings.build());
ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
boolean updatedReadOnly = metaData.persistentSettings().getAsBoolean(MetaData.SETTING_READ_ONLY, false) || metaData.transientSettings().getAsBoolean(MetaData.SETTING_READ_ONLY, false);
if (updatedReadOnly) {
blocks.addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
} else {
blocks.removeGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK);
}
return ClusterState.builder().state(currentState).metaData(metaData).build();
return ClusterState.builder().state(currentState).metaData(metaData).blocks(blocks).build();
} catch (Exception e) {
latch.countDown();
logger.warn("failed to update cluster settings", e);

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.cluster.state;
import org.elasticsearch.action.admin.cluster.ClusterAction;
import org.elasticsearch.client.ClusterAdminClient;
/**
*/
public class ClusterStateAction extends ClusterAction<ClusterStateRequest, ClusterStateResponse, ClusterStateRequestBuilder> {
public static final ClusterStateAction INSTANCE = new ClusterStateAction();
public static final String NAME = "cluster/state";
private ClusterStateAction() {
super(NAME);
}
@Override
public ClusterStateResponse newResponse() {
return new ClusterStateResponse();
}
@Override
public ClusterStateRequestBuilder newRequestBuilder(ClusterAdminClient client) {
return new ClusterStateRequestBuilder(client);
}
}

View File

@ -54,6 +54,16 @@ public class ClusterStateRequest extends MasterNodeOperationRequest {
return null;
}
public ClusterStateRequest filterAll() {
filterRoutingTable = true;
filterNodes = true;
filterMetaData = true;
filterBlocks = true;
filteredIndices = Strings.EMPTY_ARRAY;
filteredIndexTemplates = Strings.EMPTY_ARRAY;
return this;
}
public boolean filterRoutingTable() {
return filterRoutingTable;
}

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.state;
package org.elasticsearch.action.admin.cluster.state;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**
@ -35,6 +33,19 @@ public class ClusterStateRequestBuilder extends BaseClusterRequestBuilder<Cluste
super(clusterClient, new ClusterStateRequest());
}
/**
* Filters all data responses.
*/
public ClusterStateRequestBuilder setFilterAll() {
request.filterAll();
return this;
}
public ClusterStateRequestBuilder setFilterBlocks(boolean filter) {
request.filterBlocks(filter);
return this;
}
/**
* Should the cluster state result include the {@link org.elasticsearch.cluster.metadata.MetaData}. Defaults
* to <tt>false</tt>.
@ -71,6 +82,11 @@ public class ClusterStateRequestBuilder extends BaseClusterRequestBuilder<Cluste
return this;
}
public ClusterStateRequestBuilder setFilterIndexTemplates(String... templates) {
request.filteredIndexTemplates(templates);
return this;
}
/**
* Sets the master node timeout in case the master has not yet been discovered.
*/

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.admin.cluster.state;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
@ -57,7 +56,7 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
@Override
protected String transportAction() {
return TransportActions.Admin.Cluster.STATE;
return ClusterStateAction.NAME;
}
@Override
@ -100,7 +99,7 @@ public class TransportClusterStateAction extends TransportMasterNodeOperationAct
for (String filteredIndex : indices) {
IndexMetaData indexMetaData = currentState.metaData().index(filteredIndex);
if (indexMetaData != null) {
mdBuilder.put(indexMetaData);
mdBuilder.put(indexMetaData, false);
}
}
}

View File

@ -17,21 +17,17 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.cluster.support;
package org.elasticsearch.action.admin.cluster.support;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.action.*;
import org.elasticsearch.action.support.PlainListenableActionFuture;
import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.client.action.RequestBuilder;
import org.elasticsearch.client.internal.InternalClusterAdminClient;
/**
*
*/
public abstract class BaseClusterRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> implements RequestBuilder<Request, Response> {
public abstract class BaseClusterRequestBuilder<Request extends ActionRequest, Response extends ActionResponse> implements ActionRequestBuilder<Request, Response> {
protected final InternalClusterAdminClient client;
@ -42,6 +38,11 @@ public abstract class BaseClusterRequestBuilder<Request extends ActionRequest, R
this.request = request;
}
@Override
public Request request() {
return request;
}
@Override
public ListenableActionFuture<Response> execute() {
PlainListenableActionFuture<Response> future = new PlainListenableActionFuture<Response>(request.listenerThreaded(), client.threadPool());

View File

@ -0,0 +1,39 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.GenericAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
* Indices action (used with {@link IndicesAdminClient} API.
*/
public abstract class IndicesAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response>>
extends GenericAction<Request, Response> {
protected IndicesAction(String name) {
super(name);
}
public abstract RequestBuilder newRequestBuilder(IndicesAdminClient client);
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.alias;
import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
*/
public class IndicesAliasesAction extends IndicesAction<IndicesAliasesRequest, IndicesAliasesResponse, IndicesAliasesRequestBuilder> {
public static final IndicesAliasesAction INSTANCE = new IndicesAliasesAction();
public static final String NAME = "indices/aliases";
private IndicesAliasesAction() {
super(NAME);
}
@Override
public IndicesAliasesResponse newResponse() {
return new IndicesAliasesResponse();
}
@Override
public IndicesAliasesRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new IndicesAliasesRequestBuilder(client);
}
}

View File

@ -37,14 +37,12 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.action.Actions.addValidationError;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.cluster.metadata.AliasAction.readAliasAction;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
/**
* A request to add/remove aliases for one or more indices.
*
*
*/
public class IndicesAliasesRequest extends MasterNodeOperationRequest {

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.alias;
package org.elasticsearch.action.admin.indices.alias;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.cluster.metadata.AliasAction;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.FilterBuilder;

View File

@ -21,7 +21,6 @@ package org.elasticsearch.action.admin.indices.alias;
import com.google.common.collect.Sets;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -59,7 +58,7 @@ public class TransportIndicesAliasesAction extends TransportMasterNodeOperationA
@Override
protected String transportAction() {
return TransportActions.Admin.Indices.ALIASES;
return IndicesAliasesAction.NAME;
}
@Override

View File

@ -17,34 +17,29 @@
* under the License.
*/
package org.elasticsearch.action.admin.cluster.ping.broadcast;
package org.elasticsearch.action.admin.indices.analyze;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
*
*/
public class BroadcastShardPingRequest extends BroadcastShardOperationRequest {
public class AnalyzeAction extends IndicesAction<AnalyzeRequest, AnalyzeResponse, AnalyzeRequestBuilder> {
BroadcastShardPingRequest() {
public static final AnalyzeAction INSTANCE = new AnalyzeAction();
public static final String NAME = "indices/analyze";
}
public BroadcastShardPingRequest(String index, int shardId) {
super(index, shardId);
private AnalyzeAction() {
super(NAME);
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
public AnalyzeResponse newResponse() {
return new AnalyzeResponse();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
public AnalyzeRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new AnalyzeRequestBuilder(client);
}
}
}

View File

@ -21,12 +21,13 @@ package org.elasticsearch.action.admin.indices.analyze;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.single.custom.SingleCustomOperationRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import static org.elasticsearch.action.Actions.addValidationError;
import static org.elasticsearch.action.ValidateActions.addValidationError;
/**
* A request to analyze a text associated with a specific index. Allow to provide
@ -40,19 +41,32 @@ public class AnalyzeRequest extends SingleCustomOperationRequest {
private String analyzer;
private String tokenizer;
private String[] tokenFilters;
private String field;
AnalyzeRequest() {
}
/**
* Constructs a new analyzer request for the provided text.
*
* @param text The text to analyze
*/
public AnalyzeRequest(String text) {
this.text = text;
}
/**
* Constructs a new analyzer request for the provided index and text.
*
* @param index The index name
* @param text The text to analyze
*/
public AnalyzeRequest(String index, String text) {
public AnalyzeRequest(@Nullable String index, String text) {
this.index = index;
this.text = text;
}
@ -79,6 +93,24 @@ public class AnalyzeRequest extends SingleCustomOperationRequest {
return this.analyzer;
}
public AnalyzeRequest tokenizer(String tokenizer) {
this.tokenizer = tokenizer;
return this;
}
public String tokenizer() {
return this.tokenizer;
}
public AnalyzeRequest tokenFilters(String... tokenFilters) {
this.tokenFilters = tokenFilters;
return this;
}
public String[] tokenFilters() {
return this.tokenFilters;
}
public AnalyzeRequest field(String field) {
this.field = field;
return this;
@ -101,9 +133,6 @@ public class AnalyzeRequest extends SingleCustomOperationRequest {
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
if (index == null) {
validationException = addValidationError("index is missing", validationException);
}
if (text == null) {
validationException = addValidationError("text is missing", validationException);
}
@ -113,11 +142,23 @@ public class AnalyzeRequest extends SingleCustomOperationRequest {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
index = in.readUTF();
if (in.readBoolean()) {
index = in.readUTF();
}
text = in.readUTF();
if (in.readBoolean()) {
analyzer = in.readUTF();
}
if (in.readBoolean()) {
tokenizer = in.readUTF();
}
int size = in.readVInt();
if (size > 0) {
tokenFilters = new String[size];
for (int i = 0; i < size; i++) {
tokenFilters[i] = in.readUTF();
}
}
if (in.readBoolean()) {
field = in.readUTF();
}
@ -126,9 +167,23 @@ public class AnalyzeRequest extends SingleCustomOperationRequest {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeUTF(index);
if (index == null) {
out.writeBoolean(false);
out.writeUTF(index);
} else {
out.writeUTF(index);
}
out.writeUTF(text);
writeOption(out, analyzer);
writeOption(out, tokenizer);
if (tokenFilters == null) {
out.writeVInt(0);
} else {
out.writeVInt(tokenFilters.length);
for (String tokenFilter : tokenFilters) {
out.writeUTF(tokenFilter);
}
}
writeOption(out, field);
}

View File

@ -17,23 +17,34 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.analyze;
package org.elasticsearch.action.admin.indices.analyze;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
/**
*
*/
public class AnalyzeRequestBuilder extends BaseIndicesRequestBuilder<AnalyzeRequest, AnalyzeResponse> {
public AnalyzeRequestBuilder(IndicesAdminClient indicesClient) {
super(indicesClient, new AnalyzeRequest());
}
public AnalyzeRequestBuilder(IndicesAdminClient indicesClient, String index, String text) {
super(indicesClient, new AnalyzeRequest(index, text));
}
/**
* Sets the index to use to analyzer the text (for example, if it holds specific analyzers
* registered).
*/
public AnalyzeRequestBuilder setIndex(String index) {
request.index(index);
return this;
}
/**
* Sets the analyzer name to use in order to analyze the text.
*
@ -44,6 +55,32 @@ public class AnalyzeRequestBuilder extends BaseIndicesRequestBuilder<AnalyzeRequ
return this;
}
/**
* Sets the field that its analyzer will be used to analyze the text. Note, requires an index
* to be set.
*/
public AnalyzeRequestBuilder setField(String field) {
request.field(field);
return this;
}
/**
* Instead of setting the analyzer, sets the tokenizer that will be used as part of a custom
* analyzer.
*/
public AnalyzeRequestBuilder setTokenizer(String tokenizer) {
request.tokenizer(tokenizer);
return this;
}
/**
* Sets token filters that will be used on top of a tokenizer provided.
*/
public AnalyzeRequestBuilder setTokenFilters(String... tokenFilters) {
request.tokenFilters(tokenFilters);
return this;
}
/**
* if this operation hits a node with a local relevant shard, should it be preferred
* to be executed on, or just do plain round robin. Defaults to <tt>true</tt>
@ -57,9 +94,4 @@ public class AnalyzeRequestBuilder extends BaseIndicesRequestBuilder<AnalyzeRequ
protected void doExecute(ActionListener<AnalyzeResponse> listener) {
client.analyze(request, listener);
}
public AnalyzeRequestBuilder setField(String field) {
request.field(field);
return this;
}
}

View File

@ -28,17 +28,23 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TypeAttribute;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.single.custom.TransportSingleCustomOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.*;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.internal.AllFieldMapper;
import org.elasticsearch.index.service.IndexService;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -52,11 +58,14 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction
private final IndicesService indicesService;
private final IndicesAnalysisService indicesAnalysisService;
@Inject
public TransportAnalyzeAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService,
IndicesService indicesService) {
IndicesService indicesService, IndicesAnalysisService indicesAnalysisService) {
super(settings, threadPool, clusterService, transportService);
this.indicesService = indicesService;
this.indicesAnalysisService = indicesAnalysisService;
}
@Override
@ -76,26 +85,45 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction
@Override
protected String transportAction() {
return TransportActions.Admin.Indices.ANALYZE;
return AnalyzeAction.NAME;
}
@Override
protected String transportShardAction() {
return "indices/analyze/shard";
protected ClusterBlockException checkGlobalBlock(ClusterState state, AnalyzeRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.READ);
}
@Override
protected ShardsIterator shards(ClusterState clusterState, AnalyzeRequest request) {
request.index(clusterState.metaData().concreteIndex(request.index()));
return clusterState.routingTable().index(request.index()).randomAllActiveShardsIt();
protected ClusterBlockException checkRequestBlock(ClusterState state, AnalyzeRequest request) {
if (request.index() != null) {
request.index(state.metaData().concreteIndex(request.index()));
return state.blocks().indexBlockedException(ClusterBlockLevel.READ, request.index());
}
return null;
}
@Override
protected ShardsIterator shards(ClusterState state, AnalyzeRequest request) {
if (request.index() == null) {
// just execute locally....
return null;
}
return state.routingTable().index(request.index()).randomAllActiveShardsIt();
}
@Override
protected AnalyzeResponse shardOperation(AnalyzeRequest request, int shardId) throws ElasticSearchException {
IndexService indexService = indicesService.indexServiceSafe(request.index());
IndexService indexService = null;
if (request.index() != null) {
indexService = indicesService.indexServiceSafe(request.index());
}
Analyzer analyzer = null;
boolean closeAnalyzer = false;
String field = null;
if (request.field() != null) {
if (indexService == null) {
throw new ElasticSearchIllegalArgumentException("No index provided, and trying to analyzer based on a specific field which requires the index parameter");
}
FieldMapper fieldMapper = indexService.mapperService().smartNameFieldMapper(request.field());
if (fieldMapper != null) {
analyzer = fieldMapper.indexAnalyzer();
@ -103,12 +131,65 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction
}
}
if (field == null) {
field = "_all";
if (indexService != null) {
field = indexService.queryParserService().defaultField();
} else {
field = AllFieldMapper.NAME;
}
}
if (analyzer == null && request.analyzer() != null) {
analyzer = indexService.analysisService().analyzer(request.analyzer());
if (indexService == null) {
analyzer = indicesAnalysisService.analyzer(request.analyzer());
} else {
analyzer = indexService.analysisService().analyzer(request.analyzer());
}
if (analyzer == null) {
throw new ElasticSearchIllegalArgumentException("failed to find analyzer [" + request.analyzer() + "]");
}
} else if (request.tokenizer() != null) {
TokenizerFactory tokenizerFactory;
if (indexService == null) {
TokenizerFactoryFactory tokenizerFactoryFactory = indicesAnalysisService.tokenizerFactoryFactory(request.tokenizer());
if (tokenizerFactoryFactory == null) {
throw new ElasticSearchIllegalArgumentException("failed to find global tokenizer under [" + request.tokenizer() + "]");
}
tokenizerFactory = tokenizerFactoryFactory.create(request.tokenizer(), ImmutableSettings.Builder.EMPTY_SETTINGS);
} else {
tokenizerFactory = indexService.analysisService().tokenizer(request.tokenizer());
if (tokenizerFactory == null) {
throw new ElasticSearchIllegalArgumentException("failed to find tokenizer under [" + request.tokenizer() + "]");
}
}
TokenFilterFactory[] tokenFilterFactories = new TokenFilterFactory[0];
if (request.tokenFilters() != null && request.tokenFilters().length > 0) {
tokenFilterFactories = new TokenFilterFactory[request.tokenFilters().length];
for (int i = 0; i < request.tokenFilters().length; i++) {
String tokenFilterName = request.tokenFilters()[i];
if (indexService == null) {
TokenFilterFactoryFactory tokenFilterFactoryFactory = indicesAnalysisService.tokenFilterFactoryFactory(tokenFilterName);
if (tokenFilterFactoryFactory == null) {
throw new ElasticSearchIllegalArgumentException("failed to find global token filter under [" + request.tokenizer() + "]");
}
tokenFilterFactories[i] = tokenFilterFactoryFactory.create(tokenFilterName, ImmutableSettings.Builder.EMPTY_SETTINGS);
} else {
tokenFilterFactories[i] = indexService.analysisService().tokenFilter(tokenFilterName);
if (tokenFilterFactories[i] == null) {
throw new ElasticSearchIllegalArgumentException("failed to find token filter under [" + request.tokenizer() + "]");
}
}
if (tokenFilterFactories[i] == null) {
throw new ElasticSearchIllegalArgumentException("failed to find token filter under [" + request.tokenizer() + "]");
}
}
}
analyzer = new CustomAnalyzer(tokenizerFactory, new CharFilterFactory[0], tokenFilterFactories);
closeAnalyzer = true;
} else if (analyzer == null) {
analyzer = indexService.analysisService().defaultIndexAnalyzer();
if (indexService == null) {
analyzer = Lucene.STANDARD_ANALYZER;
} else {
analyzer = indexService.analysisService().defaultIndexAnalyzer();
}
}
if (analyzer == null) {
throw new ElasticSearchIllegalArgumentException("failed to find analyzer");
@ -143,6 +224,9 @@ public class TransportAnalyzeAction extends TransportSingleCustomOperationAction
// ignore
}
}
if (closeAnalyzer) {
analyzer.close();
}
}
return new AnalyzeResponse(tokens);

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.cache.clear;
import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
*/
public class ClearIndicesCacheAction extends IndicesAction<ClearIndicesCacheRequest, ClearIndicesCacheResponse, ClearIndicesCacheRequestBuilder> {
public static final ClearIndicesCacheAction INSTANCE = new ClearIndicesCacheAction();
public static final String NAME = "indices/cache/clear";
private ClearIndicesCacheAction() {
super(NAME);
}
@Override
public ClearIndicesCacheResponse newResponse() {
return new ClearIndicesCacheResponse();
}
@Override
public ClearIndicesCacheRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new ClearIndicesCacheRequestBuilder(client);
}
}

View File

@ -17,14 +17,12 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.cache.clear;
package org.elasticsearch.action.admin.indices.cache.clear;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
/**
*

View File

@ -21,12 +21,13 @@ package org.elasticsearch.action.admin.indices.cache.clear;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
@ -43,8 +44,6 @@ import static com.google.common.collect.Lists.newArrayList;
/**
* Indices clear cache action.
*
*
*/
public class TransportClearIndicesCacheAction extends TransportBroadcastOperationAction<ClearIndicesCacheRequest, ClearIndicesCacheResponse, ShardClearIndicesCacheRequest, ShardClearIndicesCacheResponse> {
@ -64,15 +63,9 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
@Override
protected String transportAction() {
return TransportActions.Admin.Indices.Cache.CLEAR;
return ClearIndicesCacheAction.NAME;
}
@Override
protected String transportShardAction() {
return "indices/cache/clear/shard";
}
@Override
protected ClearIndicesCacheRequest newRequest() {
return new ClearIndicesCacheRequest();
@ -168,7 +161,18 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastOperatio
* The refresh request works against *all* shards.
*/
@Override
protected GroupShardsIterator shards(ClearIndicesCacheRequest request, String[] concreteIndices, ClusterState clusterState) {
protected GroupShardsIterator shards(ClusterState clusterState, ClearIndicesCacheRequest request, String[] concreteIndices) {
return clusterState.routingTable().allActiveShardsGrouped(concreteIndices, true);
}
@Override
protected ClusterBlockException checkGlobalBlock(ClusterState state, ClearIndicesCacheRequest request) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
}
@Override
protected ClusterBlockException checkRequestBlock(ClusterState state, ClearIndicesCacheRequest request, String[] concreteIndices) {
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA, concreteIndices);
}
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.close;
import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
*/
public class CloseIndexAction extends IndicesAction<CloseIndexRequest, CloseIndexResponse, CloseIndexRequestBuilder> {
public static final CloseIndexAction INSTANCE = new CloseIndexAction();
public static final String NAME = "indices/close";
private CloseIndexAction() {
super(NAME);
}
@Override
public CloseIndexResponse newResponse() {
return new CloseIndexResponse();
}
@Override
public CloseIndexRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new CloseIndexRequestBuilder(client);
}
}

View File

@ -27,14 +27,12 @@ import org.elasticsearch.common.unit.TimeValue;
import java.io.IOException;
import static org.elasticsearch.action.Actions.addValidationError;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
/**
* A request to close an index.
*
*
*/
public class CloseIndexRequest extends MasterNodeOperationRequest {
@ -68,6 +66,11 @@ public class CloseIndexRequest extends MasterNodeOperationRequest {
return index;
}
public CloseIndexRequest index(String index) {
this.index = index;
return this;
}
/**
* Timeout to wait for the index deletion to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.close;
package org.elasticsearch.action.admin.indices.close;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
/**
@ -31,10 +29,19 @@ import org.elasticsearch.common.unit.TimeValue;
*/
public class CloseIndexRequestBuilder extends BaseIndicesRequestBuilder<CloseIndexRequest, CloseIndexResponse> {
public CloseIndexRequestBuilder(IndicesAdminClient indicesClient) {
super(indicesClient, new CloseIndexRequest());
}
public CloseIndexRequestBuilder(IndicesAdminClient indicesClient, String index) {
super(indicesClient, new CloseIndexRequest(index));
}
public CloseIndexRequestBuilder setIndex(String index) {
request.index(index);
return this;
}
/**
* Timeout to wait for the operation to be acknowledged by current cluster nodes. Defaults
* to <tt>10s</tt>.

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.admin.indices.close;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -37,8 +36,6 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* Delete index action.
*
*
*/
public class TransportCloseIndexAction extends TransportMasterNodeOperationAction<CloseIndexRequest, CloseIndexResponse> {
@ -58,7 +55,7 @@ public class TransportCloseIndexAction extends TransportMasterNodeOperationActio
@Override
protected String transportAction() {
return TransportActions.Admin.Indices.CLOSE;
return CloseIndexAction.NAME;
}
@Override
@ -73,6 +70,7 @@ public class TransportCloseIndexAction extends TransportMasterNodeOperationActio
@Override
protected ClusterBlockException checkBlock(CloseIndexRequest request, ClusterState state) {
request.index(clusterService.state().metaData().concreteIndex(request.index()));
return state.blocks().indexBlockedException(ClusterBlockLevel.METADATA, request.index());
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.create;
import org.elasticsearch.action.admin.indices.IndicesAction;
import org.elasticsearch.client.IndicesAdminClient;
/**
*/
public class CreateIndexAction extends IndicesAction<CreateIndexRequest, CreateIndexResponse, CreateIndexRequestBuilder> {
public static final CreateIndexAction INSTANCE = new CreateIndexAction();
public static final String NAME = "indices/create";
private CreateIndexAction() {
super(NAME);
}
@Override
public CreateIndexResponse newResponse() {
return new CreateIndexResponse();
}
@Override
public CreateIndexRequestBuilder newRequestBuilder(IndicesAdminClient client) {
return new CreateIndexRequestBuilder(client);
}
}

View File

@ -38,7 +38,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.google.common.collect.Maps.newHashMap;
import static org.elasticsearch.action.Actions.addValidationError;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
import static org.elasticsearch.common.settings.ImmutableSettings.readSettingsFromStream;
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;
@ -49,7 +49,6 @@ import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
* <p/>
* <p>The index created can optionally be created with {@link #settings(org.elasticsearch.common.settings.Settings)}.
*
*
* @see org.elasticsearch.client.IndicesAdminClient#create(CreateIndexRequest)
* @see org.elasticsearch.client.Requests#createIndexRequest(String)
* @see CreateIndexResponse
@ -100,6 +99,11 @@ public class CreateIndexRequest extends MasterNodeOperationRequest {
return index;
}
public CreateIndexRequest index(String index) {
this.index = index;
return this;
}
/**
* The settings to created the index with.
*/
@ -247,6 +251,15 @@ public class CreateIndexRequest extends MasterNodeOperationRequest {
return timeout(TimeValue.parseTimeValue(timeout, null));
}
/**
* A timeout value in case the master has not been discovered yet or disconnected.
*/
@Override
public CreateIndexRequest masterNodeTimeout(TimeValue timeout) {
this.masterNodeTimeout = timeout;
return this;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);

View File

@ -17,13 +17,11 @@
* under the License.
*/
package org.elasticsearch.client.action.admin.indices.create;
package org.elasticsearch.action.admin.indices.create;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -35,10 +33,19 @@ import java.util.Map;
*/
public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder<CreateIndexRequest, CreateIndexResponse> {
public CreateIndexRequestBuilder(IndicesAdminClient indicesClient) {
super(indicesClient, new CreateIndexRequest());
}
public CreateIndexRequestBuilder(IndicesAdminClient indicesClient, String index) {
super(indicesClient, new CreateIndexRequest(index));
}
public CreateIndexRequestBuilder setIndex(String index) {
request.index(index);
return this;
}
/**
* The settings to created the index with.
*/

View File

@ -20,7 +20,6 @@
package org.elasticsearch.action.admin.indices.create;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -37,8 +36,6 @@ import java.util.concurrent.atomic.AtomicReference;
/**
* Create index action.
*
*
*/
public class TransportCreateIndexAction extends TransportMasterNodeOperationAction<CreateIndexRequest, CreateIndexResponse> {
@ -58,7 +55,7 @@ public class TransportCreateIndexAction extends TransportMasterNodeOperationActi
@Override
protected String transportAction() {
return TransportActions.Admin.Indices.CREATE;
return CreateIndexAction.NAME;
}
@Override

Some files were not shown because too many files have changed in this diff Show More