From e3ae1df6f0896bf3b835042525e1531c143cba93 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 1 May 2015 16:04:55 -0400 Subject: [PATCH 01/22] [DOCS] Restructure Aggs documentation --- .../{search => }/aggregations.asciidoc | 153 ++--------------- docs/reference/aggregations/bucket.asciidoc | 49 ++++++ .../bucket/children-aggregation.asciidoc | 0 .../bucket/datehistogram-aggregation.asciidoc | 0 .../bucket/daterange-aggregation.asciidoc | 0 .../bucket/filter-aggregation.asciidoc | 0 .../bucket/filters-aggregation.asciidoc | 0 .../bucket/geodistance-aggregation.asciidoc | 0 .../bucket/geohashgrid-aggregation.asciidoc | 0 .../bucket/global-aggregation.asciidoc | 0 .../bucket/histogram-aggregation.asciidoc | 0 .../bucket/iprange-aggregation.asciidoc | 0 .../bucket/missing-aggregation.asciidoc | 0 .../bucket/nested-aggregation.asciidoc | 0 .../bucket/range-aggregation.asciidoc | 0 .../reverse-nested-aggregation.asciidoc | 0 .../bucket/sampler-aggregation.asciidoc | 0 .../significantterms-aggregation.asciidoc | 0 .../bucket/terms-aggregation.asciidoc | 0 docs/reference/aggregations/metrics.asciidoc | 48 ++++++ .../metrics/avg-aggregation.asciidoc | 0 .../metrics/cardinality-aggregation.asciidoc | 0 .../extendedstats-aggregation.asciidoc | 0 .../metrics/geobounds-aggregation.asciidoc | 0 .../metrics/max-aggregation.asciidoc | 0 .../metrics/min-aggregation.asciidoc | 0 .../metrics/percentile-aggregation.asciidoc | 0 .../percentile-rank-aggregation.asciidoc | 0 .../scripted-metric-aggregation.asciidoc | 0 .../metrics/stats-aggregation.asciidoc | 0 .../metrics/sum-aggregation.asciidoc | 0 .../metrics/tophits-aggregation.asciidoc | 0 .../metrics/valuecount-aggregation.asciidoc | 0 docs/reference/aggregations/misc.asciidoc | 76 +++++++++ docs/reference/aggregations/reducer.asciidoc | 160 ++++++++++++++++++ .../reducer/derivative-aggregation.asciidoc | 44 ++--- .../reducer/max-bucket-aggregation.asciidoc | 21 ++- .../reducer/min-bucket-aggregation.asciidoc | 20 +++ .../reducer/movavg-aggregation.asciidoc | 30 +--- docs/reference/index.asciidoc | 2 + docs/reference/search.asciidoc | 2 - .../search/aggregations/bucket.asciidoc | 33 ---- .../search/aggregations/metrics.asciidoc | 27 --- .../search/aggregations/reducer.asciidoc | 6 - 44 files changed, 415 insertions(+), 256 deletions(-) rename docs/reference/{search => }/aggregations.asciidoc (51%) create mode 100644 docs/reference/aggregations/bucket.asciidoc rename docs/reference/{search => }/aggregations/bucket/children-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/datehistogram-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/daterange-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/filter-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/filters-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/geodistance-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/geohashgrid-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/global-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/histogram-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/iprange-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/missing-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/nested-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/range-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/reverse-nested-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/sampler-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/significantterms-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/bucket/terms-aggregation.asciidoc (100%) create mode 100644 docs/reference/aggregations/metrics.asciidoc rename docs/reference/{search => }/aggregations/metrics/avg-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/cardinality-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/extendedstats-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/geobounds-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/max-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/min-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/percentile-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/percentile-rank-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/scripted-metric-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/stats-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/sum-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/tophits-aggregation.asciidoc (100%) rename docs/reference/{search => }/aggregations/metrics/valuecount-aggregation.asciidoc (100%) create mode 100644 docs/reference/aggregations/misc.asciidoc create mode 100644 docs/reference/aggregations/reducer.asciidoc rename docs/reference/{search => }/aggregations/reducer/derivative-aggregation.asciidoc (83%) rename docs/reference/{search => }/aggregations/reducer/max-bucket-aggregation.asciidoc (83%) rename docs/reference/{search => }/aggregations/reducer/min-bucket-aggregation.asciidoc (83%) rename docs/reference/{search => }/aggregations/reducer/movavg-aggregation.asciidoc (93%) delete mode 100644 docs/reference/search/aggregations/bucket.asciidoc delete mode 100644 docs/reference/search/aggregations/metrics.asciidoc delete mode 100644 docs/reference/search/aggregations/reducer.asciidoc diff --git a/docs/reference/search/aggregations.asciidoc b/docs/reference/aggregations.asciidoc similarity index 51% rename from docs/reference/search/aggregations.asciidoc rename to docs/reference/aggregations.asciidoc index cf4b4348eda..c6fb674834e 100644 --- a/docs/reference/search/aggregations.asciidoc +++ b/docs/reference/aggregations.asciidoc @@ -1,6 +1,8 @@ [[search-aggregations]] -== Aggregations += Aggregations +[partintro] +-- The aggregations framework helps provide aggregated data based on a search query. It is based on simple building blocks called aggregations, that can be composed in order to build complex summaries of the data. @@ -11,16 +13,19 @@ query/filters of the search request). There are many different types of aggregations, each with its own purpose and output. To better understand these types, it is often easier to break them into two main families: -_Bucketing_:: +<>:: A family of aggregations that build buckets, where each bucket is associated with a _key_ and a document criterion. When the aggregation is executed, all the buckets criteria are evaluated on every document in the context and when a criterion matches, the document is considered to "fall in" the relevant bucket. By the end of the aggregation process, we'll end up with a list of buckets - each one with a set of documents that "belong" to it. -_Metric_:: +<>:: Aggregations that keep track and compute metrics over a set of documents. +<>:: + Aggregations that aggregate the output of other aggregations and their associated metrics + The interesting part comes next. Since each bucket effectively defines a document set (all documents belonging to the bucket), one can potentially associate aggregations on the bucket level, and those will execute within the context of that bucket. This is where the real power of aggregations kicks in: *aggregations can be nested!* @@ -31,7 +36,7 @@ NOTE: Bucketing aggregations can have sub-aggregations (bucketing or metric). Th another higher-level aggregation). [float] -=== Structuring Aggregations +== Structuring Aggregations The following snippet captures the basic structure of aggregations: @@ -62,7 +67,7 @@ bucketing aggregation. For example, if you define a set of aggregations under th sub-aggregations will be computed for the range buckets that are defined. [float] -==== Values Source +=== Values Source Some aggregations work on values extracted from the aggregated documents. Typically, the values will be extracted from a specific document field which is set using the `field` key for the aggregations. It is also possible to define a @@ -89,142 +94,7 @@ perform optimizations when dealing with sorted values (for example, with the `mi sorted, Elasticsearch will skip the iterations over all the values and rely on the first value in the list to be the minimum value among all other values associated with the same document). -[float] -=== Metrics Aggregations - -The aggregations in this family compute metrics based on values extracted in one way or another from the documents that -are being aggregated. The values are typically extracted from the fields of the document (using the field data), but -can also be generated using scripts. - -Numeric metrics aggregations are a special type of metrics aggregation which output numeric values. Some aggregations output -a single numeric metric (e.g. `avg`) and are called `single-value numeric metrics aggregation`, others generate multiple -metrics (e.g. `stats`) and are called `multi-value numeric metrics aggregation`. The distinction between single-value and -multi-value numeric metrics aggregations plays a role when these aggregations serve as direct sub-aggregations of some -bucket aggregations (some bucket aggregations enable you to sort the returned buckets based on the numeric metrics in each bucket). - - -[float] -=== Bucket Aggregations - -Bucket aggregations don't calculate metrics over fields like the metrics aggregations do, but instead, they create -buckets of documents. Each bucket is associated with a criterion (depending on the aggregation type) which determines -whether or not a document in the current context "falls" into it. In other words, the buckets effectively define document -sets. In addition to the buckets themselves, the `bucket` aggregations also compute and return the number of documents -that "fell in" to each bucket. - -Bucket aggregations, as opposed to `metrics` aggregations, can hold sub-aggregations. These sub-aggregations will be -aggregated for the buckets created by their "parent" bucket aggregation. - -There are different bucket aggregators, each with a different "bucketing" strategy. Some define a single bucket, some -define fixed number of multiple buckets, and others dynamically create the buckets during the aggregation process. - -[float] -=== Reducer Aggregations - -coming[2.0.0] - -experimental[] - -Reducer aggregations work on the outputs produced from other aggregations rather than from document sets, adding -information to the output tree. There are many different types of reducer, each computing different information from -other aggregations, but these types can broken down into two families: - -_Parent_:: - A family of reducer aggregations that is provided with the output of its parent aggregation and is able - to compute new buckets or new aggregations to add to existing buckets. - -_Sibling_:: - Reducer aggregations that are provided with the output of a sibling aggregation and are able to compute a - new aggregation which will be at the same level as the sibling aggregation. - -Reducer aggregations can reference the aggregations they need to perform their computation by using the `buckets_paths` -parameter to indicate the paths to the required metrics. The syntax for defining these paths can be found in the -<> section. - -?????? SHOULD THE SECTION ABOUT DEFINING AGGREGATION PATHS -BE IN THIS PAGE AND REFERENCED FROM THE TERMS AGGREGATION DOCUMENTATION ??????? - -Reducer aggregations cannot have sub-aggregations but depending on the type it can reference another reducer in the `buckets_path` -allowing reducers to be chained. - -NOTE: Because reducer aggregations only add to the output, when chaining reducer aggregations the output of each reducer will be -included in the final output. - -[float] -=== Caching heavy aggregations - -Frequently used aggregations (e.g. for display on the home page of a website) -can be cached for faster responses. These cached results are the same results -that would be returned by an uncached aggregation -- you will never get stale -results. - -See <> for more details. - -[float] -=== Returning only aggregation results - -There are many occasions when aggregations are required but search hits are not. For these cases the hits can be ignored by -setting `size=0`. For example: - -[source,js] --------------------------------------------------- -$ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{ - "size": 0, - "aggregations": { - "my_agg": { - "terms": { - "field": "text" - } - } - } -} -' --------------------------------------------------- - -Setting `size` to `0` avoids executing the fetch phase of the search making the request more efficient. - -[float] -=== Metadata - -You can associate a piece of metadata with individual aggregations at request time that will be returned in place -at response time. - -Consider this example where we want to associate the color blue with our `terms` aggregation. - -[source,js] --------------------------------------------------- -{ - ... - aggs": { - "titles": { - "terms": { - "field": "title" - }, - "meta": { - "color": "blue" - }, - } - } -} --------------------------------------------------- - -Then that piece of metadata will be returned in place for our `titles` terms aggregation - -[source,js] --------------------------------------------------- -{ - ... - "aggregations": { - "titles": { - "meta": { - "color" : "blue" - }, - "buckets": [ - ] - } - } -} --------------------------------------------------- +-- include::aggregations/metrics.asciidoc[] @@ -232,3 +102,4 @@ include::aggregations/bucket.asciidoc[] include::aggregations/reducer.asciidoc[] +include::aggregations/misc.asciidoc[] diff --git a/docs/reference/aggregations/bucket.asciidoc b/docs/reference/aggregations/bucket.asciidoc new file mode 100644 index 00000000000..2d185dd49a0 --- /dev/null +++ b/docs/reference/aggregations/bucket.asciidoc @@ -0,0 +1,49 @@ +[[search-aggregations-bucket]] +== Bucket Aggregations + +Bucket aggregations don't calculate metrics over fields like the metrics aggregations do, but instead, they create +buckets of documents. Each bucket is associated with a criterion (depending on the aggregation type) which determines +whether or not a document in the current context "falls" into it. In other words, the buckets effectively define document +sets. In addition to the buckets themselves, the `bucket` aggregations also compute and return the number of documents +that "fell in" to each bucket. + +Bucket aggregations, as opposed to `metrics` aggregations, can hold sub-aggregations. These sub-aggregations will be +aggregated for the buckets created by their "parent" bucket aggregation. + +There are different bucket aggregators, each with a different "bucketing" strategy. Some define a single bucket, some +define fixed number of multiple buckets, and others dynamically create the buckets during the aggregation process. + +include::bucket/children-aggregation.asciidoc[] + +include::bucket/datehistogram-aggregation.asciidoc[] + +include::bucket/daterange-aggregation.asciidoc[] + +include::bucket/filter-aggregation.asciidoc[] + +include::bucket/filters-aggregation.asciidoc[] + +include::bucket/geodistance-aggregation.asciidoc[] + +include::bucket/geohashgrid-aggregation.asciidoc[] + +include::bucket/global-aggregation.asciidoc[] + +include::bucket/histogram-aggregation.asciidoc[] + +include::bucket/iprange-aggregation.asciidoc[] + +include::bucket/missing-aggregation.asciidoc[] + +include::bucket/nested-aggregation.asciidoc[] + +include::bucket/range-aggregation.asciidoc[] + +include::bucket/reverse-nested-aggregation.asciidoc[] + +include::bucket/sampler-aggregation.asciidoc[] + +include::bucket/significantterms-aggregation.asciidoc[] + +include::bucket/terms-aggregation.asciidoc[] + diff --git a/docs/reference/search/aggregations/bucket/children-aggregation.asciidoc b/docs/reference/aggregations/bucket/children-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/children-aggregation.asciidoc rename to docs/reference/aggregations/bucket/children-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc rename to docs/reference/aggregations/bucket/datehistogram-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc rename to docs/reference/aggregations/bucket/daterange-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/filter-aggregation.asciidoc b/docs/reference/aggregations/bucket/filter-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/filter-aggregation.asciidoc rename to docs/reference/aggregations/bucket/filter-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/filters-aggregation.asciidoc b/docs/reference/aggregations/bucket/filters-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/filters-aggregation.asciidoc rename to docs/reference/aggregations/bucket/filters-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc b/docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc rename to docs/reference/aggregations/bucket/geodistance-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/geohashgrid-aggregation.asciidoc b/docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/geohashgrid-aggregation.asciidoc rename to docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/global-aggregation.asciidoc b/docs/reference/aggregations/bucket/global-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/global-aggregation.asciidoc rename to docs/reference/aggregations/bucket/global-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc rename to docs/reference/aggregations/bucket/histogram-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc b/docs/reference/aggregations/bucket/iprange-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc rename to docs/reference/aggregations/bucket/iprange-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/missing-aggregation.asciidoc b/docs/reference/aggregations/bucket/missing-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/missing-aggregation.asciidoc rename to docs/reference/aggregations/bucket/missing-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/nested-aggregation.asciidoc b/docs/reference/aggregations/bucket/nested-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/nested-aggregation.asciidoc rename to docs/reference/aggregations/bucket/nested-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/range-aggregation.asciidoc b/docs/reference/aggregations/bucket/range-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/range-aggregation.asciidoc rename to docs/reference/aggregations/bucket/range-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/reverse-nested-aggregation.asciidoc b/docs/reference/aggregations/bucket/reverse-nested-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/reverse-nested-aggregation.asciidoc rename to docs/reference/aggregations/bucket/reverse-nested-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/sampler-aggregation.asciidoc b/docs/reference/aggregations/bucket/sampler-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/sampler-aggregation.asciidoc rename to docs/reference/aggregations/bucket/sampler-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/significantterms-aggregation.asciidoc b/docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/significantterms-aggregation.asciidoc rename to docs/reference/aggregations/bucket/significantterms-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/aggregations/bucket/terms-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc rename to docs/reference/aggregations/bucket/terms-aggregation.asciidoc diff --git a/docs/reference/aggregations/metrics.asciidoc b/docs/reference/aggregations/metrics.asciidoc new file mode 100644 index 00000000000..f80c36f2ebe --- /dev/null +++ b/docs/reference/aggregations/metrics.asciidoc @@ -0,0 +1,48 @@ +[[search-aggregations-metrics]] +== Metrics Aggregations + +The aggregations in this family compute metrics based on values extracted in one way or another from the documents that +are being aggregated. The values are typically extracted from the fields of the document (using the field data), but +can also be generated using scripts. + +Numeric metrics aggregations are a special type of metrics aggregation which output numeric values. Some aggregations output +a single numeric metric (e.g. `avg`) and are called `single-value numeric metrics aggregation`, others generate multiple +metrics (e.g. `stats`) and are called `multi-value numeric metrics aggregation`. The distinction between single-value and +multi-value numeric metrics aggregations plays a role when these aggregations serve as direct sub-aggregations of some +bucket aggregations (some bucket aggregations enable you to sort the returned buckets based on the numeric metrics in each bucket). + +include::metrics/avg-aggregation.asciidoc[] + +include::metrics/cardinality-aggregation.asciidoc[] + +include::metrics/extendedstats-aggregation.asciidoc[] + +include::metrics/geobounds-aggregation.asciidoc[] + +include::metrics/max-aggregation.asciidoc[] + +include::metrics/min-aggregation.asciidoc[] + +include::metrics/percentile-aggregation.asciidoc[] + +include::metrics/percentile-rank-aggregation.asciidoc[] + +include::metrics/scripted-metric-aggregation.asciidoc[] + +include::metrics/stats-aggregation.asciidoc[] + +include::metrics/sum-aggregation.asciidoc[] + +include::metrics/tophits-aggregation.asciidoc[] + +include::metrics/valuecount-aggregation.asciidoc[] + + + + + + + + + + diff --git a/docs/reference/search/aggregations/metrics/avg-aggregation.asciidoc b/docs/reference/aggregations/metrics/avg-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/avg-aggregation.asciidoc rename to docs/reference/aggregations/metrics/avg-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/cardinality-aggregation.asciidoc b/docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/cardinality-aggregation.asciidoc rename to docs/reference/aggregations/metrics/cardinality-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/extendedstats-aggregation.asciidoc b/docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/extendedstats-aggregation.asciidoc rename to docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/geobounds-aggregation.asciidoc b/docs/reference/aggregations/metrics/geobounds-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/geobounds-aggregation.asciidoc rename to docs/reference/aggregations/metrics/geobounds-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/max-aggregation.asciidoc b/docs/reference/aggregations/metrics/max-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/max-aggregation.asciidoc rename to docs/reference/aggregations/metrics/max-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/min-aggregation.asciidoc b/docs/reference/aggregations/metrics/min-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/min-aggregation.asciidoc rename to docs/reference/aggregations/metrics/min-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/percentile-aggregation.asciidoc rename to docs/reference/aggregations/metrics/percentile-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/percentile-rank-aggregation.asciidoc rename to docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/scripted-metric-aggregation.asciidoc b/docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/scripted-metric-aggregation.asciidoc rename to docs/reference/aggregations/metrics/scripted-metric-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/stats-aggregation.asciidoc b/docs/reference/aggregations/metrics/stats-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/stats-aggregation.asciidoc rename to docs/reference/aggregations/metrics/stats-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/sum-aggregation.asciidoc b/docs/reference/aggregations/metrics/sum-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/sum-aggregation.asciidoc rename to docs/reference/aggregations/metrics/sum-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/tophits-aggregation.asciidoc rename to docs/reference/aggregations/metrics/tophits-aggregation.asciidoc diff --git a/docs/reference/search/aggregations/metrics/valuecount-aggregation.asciidoc b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc similarity index 100% rename from docs/reference/search/aggregations/metrics/valuecount-aggregation.asciidoc rename to docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc diff --git a/docs/reference/aggregations/misc.asciidoc b/docs/reference/aggregations/misc.asciidoc new file mode 100644 index 00000000000..f494d5291c0 --- /dev/null +++ b/docs/reference/aggregations/misc.asciidoc @@ -0,0 +1,76 @@ + +[[caching-heavy-aggregations]] +== Caching heavy aggregations + +Frequently used aggregations (e.g. for display on the home page of a website) +can be cached for faster responses. These cached results are the same results +that would be returned by an uncached aggregation -- you will never get stale +results. + +See <> for more details. + +[[returning-only-agg-results]] +== Returning only aggregation results + +There are many occasions when aggregations are required but search hits are not. For these cases the hits can be ignored by +setting `size=0`. For example: + +[source,js] +-------------------------------------------------- +$ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{ + "size": 0, + "aggregations": { + "my_agg": { + "terms": { + "field": "text" + } + } + } +} +' +-------------------------------------------------- + +Setting `size` to `0` avoids executing the fetch phase of the search making the request more efficient. + +[[agg-metadata]] +== Aggregation Metadata + +You can associate a piece of metadata with individual aggregations at request time that will be returned in place +at response time. + +Consider this example where we want to associate the color blue with our `terms` aggregation. + +[source,js] +-------------------------------------------------- +{ + ... + aggs": { + "titles": { + "terms": { + "field": "title" + }, + "meta": { + "color": "blue" + }, + } + } +} +-------------------------------------------------- + +Then that piece of metadata will be returned in place for our `titles` terms aggregation + +[source,js] +-------------------------------------------------- +{ + ... + "aggregations": { + "titles": { + "meta": { + "color" : "blue" + }, + "buckets": [ + ] + } + } +} +-------------------------------------------------- \ No newline at end of file diff --git a/docs/reference/aggregations/reducer.asciidoc b/docs/reference/aggregations/reducer.asciidoc new file mode 100644 index 00000000000..2ce379cd583 --- /dev/null +++ b/docs/reference/aggregations/reducer.asciidoc @@ -0,0 +1,160 @@ +[[search-aggregations-reducer]] + +== Reducer Aggregations + +coming[2.0.0] + +experimental[] + +Reducer aggregations work on the outputs produced from other aggregations rather than from document sets, adding +information to the output tree. There are many different types of reducer, each computing different information from +other aggregations, but these types can broken down into two families: + +_Parent_:: + A family of reducer aggregations that is provided with the output of its parent aggregation and is able + to compute new buckets or new aggregations to add to existing buckets. + +_Sibling_:: + Reducer aggregations that are provided with the output of a sibling aggregation and are able to compute a + new aggregation which will be at the same level as the sibling aggregation. + +Reducer aggregations can reference the aggregations they need to perform their computation by using the `buckets_paths` +parameter to indicate the paths to the required metrics. The syntax for defining these paths can be found in the +<> section below. + +Reducer aggregations cannot have sub-aggregations but depending on the type it can reference another reducer in the `buckets_path` +allowing reducers to be chained. For example, you can chain together two derivatives to calculate the second derivative +(e.g. a derivative of a derivative). + +NOTE: Because reducer aggregations only add to the output, when chaining reducer aggregations the output of each reducer will be +included in the final output. + +[[bucket-path-syntax]] +[float] +=== `buckets_path` Syntax + +Most reducers require another aggregation as their input. The input aggregation is defined via the `buckets_path` +parameter, which follows a specific format: + +-------------------------------------------------- +AGG_SEPARATOR := '>' +METRIC_SEPARATOR := '.' +AGG_NAME := +METRIC := +PATH := []*[] +-------------------------------------------------- + +For example, the path `"my_bucket>my_stats.avg"` will path to the `avg` value in the `"my_stats"` metric, which is +contained in the `"my_bucket"` bucket aggregation. + +Paths are relative from the position of the reducer; they are not absolute paths, and the path cannot go back "up" the +aggregation tree. For example, this moving average is embedded inside a date_histogram and refers to a "sibling" +metric `"the_sum"`: + +[source,js] +-------------------------------------------------- +{ + "my_date_histo":{ + "date_histogram":{ + "field":"timestamp", + "interval":"day" + }, + "aggs":{ + "the_sum":{ + "sum":{ "field": "lemmings" } <1> + }, + "the_movavg":{ + "moving_avg":{ "buckets_path": "the_sum" } <2> + } + } + } +} +-------------------------------------------------- +<1> The metric is called `"the_sum"` +<2> The `buckets_path` refers to the metric via a relative path `"the_sum"` + +`buckets_path` is also used for Sibling reducer aggregations, where the aggregation is "next" to a series of buckets +instead of embedded "inside" them. For example, the `max_bucket` aggregation uses the `buckets_path` to specify +a metric embedded inside a sibling aggregation: + +[source,js] +-------------------------------------------------- +{ + "aggs" : { + "sales_per_month" : { + "date_histogram" : { + "field" : "date", + "interval" : "month" + }, + "aggs": { + "sales": { + "sum": { + "field": "price" + } + } + } + }, + "max_monthly_sales": { + "max_bucket": { + "buckets_paths": "sales_per_month>sales" <1> + } + } + } +} +-------------------------------------------------- +<1> `bucket_paths` instructs this max_bucket aggregation that we want the maximum value of the `sales` aggregation in the +`sales_per_month` date histogram. + +[float] +==== Special Paths + +Instead of pathing to a metric, `buckets_path` can use a special `"_count"` path. This instructs +the reducer to use the document count as it's input. For example, a moving average can be calculated on the document +count of each bucket, instead of a specific metric: + +[source,js] +-------------------------------------------------- +{ + "my_date_histo":{ + "date_histogram":{ + "field":"timestamp", + "interval":"day" + }, + "aggs":{ + "the_movavg":{ + "moving_avg":{ "buckets_path": "_count" } <1> + } + } + } +} +-------------------------------------------------- +<1> By using `_count` instead of a metric name, we can calculate the moving average of document counts in the histogram + + +[float] +=== Dealing with gaps in the data + +There are a couple of reasons why the data output by the enclosing histogram may have gaps: + +* There are no documents matching the query for some buckets +* The data for a metric is missing in all of the documents falling into a bucket (this is most likely with either a small interval +on the enclosing histogram or with a query matching only a small number of documents) + +Where there is no data available in a bucket for a given metric it presents a problem for calculating the derivative value for both +the current bucket and the next bucket. In the derivative reducer aggregation has a `gap policy` parameter to define what the behavior +should be when a gap in the data is found. There are currently two options for controlling the gap policy: + +_ignore_:: + This option will not produce a derivative value for any buckets where the value in the current or previous bucket is + missing + +_insert_zeros_:: + This option will assume the missing value is `0` and calculate the derivative with the value `0`. + + + + +include::reducer/derivative-aggregation.asciidoc[] +include::reducer/max-bucket-aggregation.asciidoc[] +include::reducer/min-bucket-aggregation.asciidoc[] +include::reducer/movavg-aggregation.asciidoc[] diff --git a/docs/reference/search/aggregations/reducer/derivative-aggregation.asciidoc b/docs/reference/aggregations/reducer/derivative-aggregation.asciidoc similarity index 83% rename from docs/reference/search/aggregations/reducer/derivative-aggregation.asciidoc rename to docs/reference/aggregations/reducer/derivative-aggregation.asciidoc index be644091b51..17801055418 100644 --- a/docs/reference/search/aggregations/reducer/derivative-aggregation.asciidoc +++ b/docs/reference/aggregations/reducer/derivative-aggregation.asciidoc @@ -5,6 +5,28 @@ A parent reducer aggregation which calculates the derivative of a specified metr aggregation. The specified metric must be numeric and the enclosing histogram must have `min_doc_count` set to `0` (default for `histogram` aggregations). +==== Syntax + +A `derivative` aggregation looks like this in isolation: + +[source,js] +-------------------------------------------------- +{ + "derivative": { + "buckets_path": "the_sum" + } +} +-------------------------------------------------- + +.`derivative` Parameters +|=== +|Parameter Name |Description |Required |Default Value +|`buckets_path` |Path to the metric of interest (see <> for more details |Required | +|=== + + +==== First Order Derivative + The following snippet calculates the derivative of the total monthly `sales`: [source,js] @@ -82,7 +104,7 @@ And the following may be the response: <1> No derivative for the first bucket since we need at least 2 data points to calculate the derivative <2> Derivative value units are implicitly defined by the `sales` aggregation and the parent histogram so in this case the units would be $/month assuming the `price` field has units of $. -<3> The number of documents in the bucket are represented by the `doc_count` value +<3> The number of documents in the bucket are represented by the `doc_count` f ==== Second Order Derivative @@ -172,23 +194,3 @@ And the following may be the response: <1> No second derivative for the first two buckets since we need at least 2 data points from the first derivative to calculate the second derivative -==== Dealing with gaps in the data - -There are a couple of reasons why the data output by the enclosing histogram may have gaps: - -* There are no documents matching the query for some buckets -* The data for a metric is missing in all of the documents falling into a bucket (this is most likely with either a small interval -on the enclosing histogram or with a query matching only a small number of documents) - -Where there is no data available in a bucket for a given metric it presents a problem for calculating the derivative value for both -the current bucket and the next bucket. In the derivative reducer aggregation has a `gap_policy` parameter to define what the behavior -should be when a gap in the data is found. There are currently two options for controlling the gap policy: - -_ignore_:: - This option will not produce a derivative value for any buckets where the value in the current or previous bucket is - missing - -_insert_zeros_:: - This option will assume the missing value is `0` and calculate the derivative with the value `0`. - - diff --git a/docs/reference/search/aggregations/reducer/max-bucket-aggregation.asciidoc b/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc similarity index 83% rename from docs/reference/search/aggregations/reducer/max-bucket-aggregation.asciidoc rename to docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc index a93c7ed8036..e1a5e9aa389 100644 --- a/docs/reference/search/aggregations/reducer/max-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc @@ -5,6 +5,26 @@ A sibling reducer aggregation which identifies the bucket(s) with the maximum va and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. +==== Syntax + +A `max_bucket` aggregation looks like this in isolation: + +[source,js] +-------------------------------------------------- +{ + "max_bucket": { + "buckets_path": "the_sum" + } +} +-------------------------------------------------- + +.`max_bucket` Parameters +|=== +|Parameter Name |Description |Required |Default Value +|`buckets_path` |The path to the buckets we wish to find the maximum for (see <> for more + details |Required | +|=== + The following snippet calculates the maximum of the total monthly `sales`: [source,js] @@ -32,7 +52,6 @@ The following snippet calculates the maximum of the total monthly `sales`: } } -------------------------------------------------- - <1> `bucket_paths` instructs this max_bucket aggregation that we want the maximum value of the `sales` aggregation in the `sales_per_month` date histogram. diff --git a/docs/reference/search/aggregations/reducer/min-bucket-aggregation.asciidoc b/docs/reference/aggregations/reducer/min-bucket-aggregation.asciidoc similarity index 83% rename from docs/reference/search/aggregations/reducer/min-bucket-aggregation.asciidoc rename to docs/reference/aggregations/reducer/min-bucket-aggregation.asciidoc index 558d0c19983..1ea26c17a2e 100644 --- a/docs/reference/search/aggregations/reducer/min-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/reducer/min-bucket-aggregation.asciidoc @@ -5,6 +5,26 @@ A sibling reducer aggregation which identifies the bucket(s) with the minimum va and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. +==== Syntax + +A `max_bucket` aggregation looks like this in isolation: + +[source,js] +-------------------------------------------------- +{ + "min_bucket": { + "buckets_path": "the_sum" + } +} +-------------------------------------------------- + +.`min_bucket` Parameters +|=== +|Parameter Name |Description |Required |Default Value +|`buckets_path` |Path to the metric of interest (see <> for more details |Required | +|=== + + The following snippet calculates the minimum of the total monthly `sales`: [source,js] diff --git a/docs/reference/search/aggregations/reducer/movavg-aggregation.asciidoc b/docs/reference/aggregations/reducer/movavg-aggregation.asciidoc similarity index 93% rename from docs/reference/search/aggregations/reducer/movavg-aggregation.asciidoc rename to docs/reference/aggregations/reducer/movavg-aggregation.asciidoc index 03f6b7e9fa1..18cf98d263d 100644 --- a/docs/reference/search/aggregations/reducer/movavg-aggregation.asciidoc +++ b/docs/reference/aggregations/reducer/movavg-aggregation.asciidoc @@ -35,16 +35,14 @@ A `moving_avg` aggregation looks like this in isolation: .`moving_avg` Parameters |=== -|Parameter Name |Description |Required |Default - -|`buckets_path` |The path to the metric that we wish to calculate a moving average for |Required | +|Parameter Name |Description |Required |Default Value +|`buckets_path` |Path to the metric of interest (see <> for more details |Required | |`model` |The moving average weighting model that we wish to use |Optional |`simple` |`gap_policy` |Determines what should happen when a gap in the data is encountered. |Optional |`insert_zero` |`window` |The size of window to "slide" across the histogram. |Optional |`5` |`settings` |Model-specific settings, contents which differ depending on the model specified. |Optional | |=== - `moving_avg` aggregations must be embedded inside of a `histogram` or `date_histogram` aggregation. They can be embedded like any other metric aggregation: @@ -73,27 +71,9 @@ embedded like any other metric aggregation: Moving averages are built by first specifying a `histogram` or `date_histogram` over a field. You can then optionally add normal metrics, such as a `sum`, inside of that histogram. Finally, the `moving_avg` is embedded inside the histogram. -The `buckets_path` parameter is then used to "point" at one of the sibling metrics inside of the histogram. +The `buckets_path` parameter is then used to "point" at one of the sibling metrics inside of the histogram (see +<> for a description of the syntax for `buckets_path`. -A moving average can also be calculated on the document count of each bucket, instead of a metric: - -[source,js] --------------------------------------------------- -{ - "my_date_histo":{ - "date_histogram":{ - "field":"timestamp", - "interval":"day" - }, - "aggs":{ - "the_movavg":{ - "moving_avg":{ "buckets_path": "_count" } <1> - } - } - } -} --------------------------------------------------- -<1> By using `_count` instead of a metric name, we can calculate the moving average of document counts in the histogram ==== Models @@ -250,7 +230,7 @@ image::images/reducers_movavg/double_0.2beta.png[] .Double Exponential moving average with window of size 100, alpha = 0.5, beta = 0.7 image::images/reducers_movavg/double_0.7beta.png[] -=== Prediction +==== Prediction All the moving average model support a "prediction" mode, which will attempt to extrapolate into the future given the current smoothed, moving average. Depending on the model and parameter, these predictions may or may not be accurate. diff --git a/docs/reference/index.asciidoc b/docs/reference/index.asciidoc index 1e63d18a4d2..696fbaa3bca 100644 --- a/docs/reference/index.asciidoc +++ b/docs/reference/index.asciidoc @@ -18,6 +18,8 @@ include::docs.asciidoc[] include::search.asciidoc[] +include::aggregations.asciidoc[] + include::indices.asciidoc[] include::cat.asciidoc[] diff --git a/docs/reference/search.asciidoc b/docs/reference/search.asciidoc index 79d3c7a93fd..b71a0dfe466 100644 --- a/docs/reference/search.asciidoc +++ b/docs/reference/search.asciidoc @@ -85,8 +85,6 @@ include::search/search-template.asciidoc[] include::search/search-shards.asciidoc[] -include::search/aggregations.asciidoc[] - include::search/facets.asciidoc[] include::search/suggesters.asciidoc[] diff --git a/docs/reference/search/aggregations/bucket.asciidoc b/docs/reference/search/aggregations/bucket.asciidoc deleted file mode 100644 index 7d7848fa1a2..00000000000 --- a/docs/reference/search/aggregations/bucket.asciidoc +++ /dev/null @@ -1,33 +0,0 @@ -[[search-aggregations-bucket]] - -include::bucket/global-aggregation.asciidoc[] - -include::bucket/filter-aggregation.asciidoc[] - -include::bucket/filters-aggregation.asciidoc[] - -include::bucket/missing-aggregation.asciidoc[] - -include::bucket/nested-aggregation.asciidoc[] - -include::bucket/reverse-nested-aggregation.asciidoc[] - -include::bucket/children-aggregation.asciidoc[] - -include::bucket/terms-aggregation.asciidoc[] - -include::bucket/significantterms-aggregation.asciidoc[] - -include::bucket/range-aggregation.asciidoc[] - -include::bucket/daterange-aggregation.asciidoc[] - -include::bucket/iprange-aggregation.asciidoc[] - -include::bucket/histogram-aggregation.asciidoc[] - -include::bucket/datehistogram-aggregation.asciidoc[] - -include::bucket/geodistance-aggregation.asciidoc[] - -include::bucket/geohashgrid-aggregation.asciidoc[] diff --git a/docs/reference/search/aggregations/metrics.asciidoc b/docs/reference/search/aggregations/metrics.asciidoc deleted file mode 100644 index 7dbbd090bbd..00000000000 --- a/docs/reference/search/aggregations/metrics.asciidoc +++ /dev/null @@ -1,27 +0,0 @@ -[[search-aggregations-metrics]] - -include::metrics/min-aggregation.asciidoc[] - -include::metrics/max-aggregation.asciidoc[] - -include::metrics/sum-aggregation.asciidoc[] - -include::metrics/avg-aggregation.asciidoc[] - -include::metrics/stats-aggregation.asciidoc[] - -include::metrics/extendedstats-aggregation.asciidoc[] - -include::metrics/valuecount-aggregation.asciidoc[] - -include::metrics/percentile-aggregation.asciidoc[] - -include::metrics/percentile-rank-aggregation.asciidoc[] - -include::metrics/cardinality-aggregation.asciidoc[] - -include::metrics/geobounds-aggregation.asciidoc[] - -include::metrics/tophits-aggregation.asciidoc[] - -include::metrics/scripted-metric-aggregation.asciidoc[] diff --git a/docs/reference/search/aggregations/reducer.asciidoc b/docs/reference/search/aggregations/reducer.asciidoc deleted file mode 100644 index a725bc77e38..00000000000 --- a/docs/reference/search/aggregations/reducer.asciidoc +++ /dev/null @@ -1,6 +0,0 @@ -[[search-aggregations-reducer]] - -include::reducer/derivative-aggregation.asciidoc[] -include::reducer/max-bucket-aggregation.asciidoc[] -include::reducer/min-bucket-aggregation.asciidoc[] -include::reducer/movavg-aggregation.asciidoc[] From 967e05ea76fb2b2a134917c9d2eec9c67b60319b Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 4 May 2015 09:18:24 -0400 Subject: [PATCH 02/22] [DOCS] Fix section levels for Sampler agg --- .../aggregations/bucket/sampler-aggregation.asciidoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/reference/aggregations/bucket/sampler-aggregation.asciidoc b/docs/reference/aggregations/bucket/sampler-aggregation.asciidoc index 5ad9dbc0194..29742709ea0 100644 --- a/docs/reference/aggregations/bucket/sampler-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/sampler-aggregation.asciidoc @@ -72,7 +72,7 @@ Response: The `shard_size` parameter limits how many top-scoring documents are collected in the sample processed on each shard. The default value is 100. -=== Controlling diversity +==== Controlling diversity Optionally, you can use the `field` or `script` and `max_docs_per_value` settings to control the maximum number of documents collected on any one shard which share a common value. The choice of value (e.g. `author`) is loaded from a regular `field` or derived dynamically by a `script`. @@ -139,16 +139,16 @@ The default setting is to use `global_ordinals` if this information is available The `bytes_hash` setting may prove faster in some cases but introduces the possibility of false positives in de-duplication logic due to the possibility of hash collisions. Please note that Elasticsearch will ignore the choice of execution hint if it is not applicable and that there is no backward compatibility guarantee on these hints. -=== Limitations +==== Limitations -==== Cannot be nested under `breadth_first` aggregations +===== Cannot be nested under `breadth_first` aggregations Being a quality-based filter the sampler aggregation needs access to the relevance score produced for each document. It therefore cannot be nested under a `terms` aggregation which has the `collect_mode` switched from the default `depth_first` mode to `breadth_first` as this discards scores. In this situation an error will be thrown. -==== Limited de-dup logic. +===== Limited de-dup logic. The de-duplication logic in the diversify settings applies only at a shard level so will not apply across shards. -==== No specialized syntax for geo/date fields +===== No specialized syntax for geo/date fields Currently the syntax for defining the diversifying values is defined by a choice of `field` or `script` - there is no added syntactical sugar for expressing geo or date units such as "1w" (1 week). This support may be added in a later release and users will currently have to create these sorts of values using a script. \ No newline at end of file From c0659ce4d4ac0d5da46f4aa8b96363bbf0ca5ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Sala=C3=BCn?= Date: Mon, 4 May 2015 16:29:37 +0200 Subject: [PATCH 03/22] Docs: Update geo-distance-range-filter.asciidoc missing comma Closes #10957 --- .../query-dsl/filters/geo-distance-range-filter.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/query-dsl/filters/geo-distance-range-filter.asciidoc b/docs/reference/query-dsl/filters/geo-distance-range-filter.asciidoc index 1bc4197e5b3..6da05947023 100644 --- a/docs/reference/query-dsl/filters/geo-distance-range-filter.asciidoc +++ b/docs/reference/query-dsl/filters/geo-distance-range-filter.asciidoc @@ -13,7 +13,7 @@ Filters documents that exists within a range from a specific point: "filter" : { "geo_distance_range" : { "from" : "200km", - "to" : "400km" + "to" : "400km", "pin.location" : { "lat" : 40, "lon" : -70 From 63c4a214db3a9d30dde9d255e0887c47b2f6ee3e Mon Sep 17 00:00:00 2001 From: Matt Weber Date: Fri, 1 May 2015 21:36:27 -0700 Subject: [PATCH 04/22] document and test custom analyzer position offset gap --- docs/reference/analysis/analyzers/custom-analyzer.asciidoc | 4 ++++ .../elasticsearch/index/analysis/AnalysisModuleTests.java | 6 ++++++ src/test/java/org/elasticsearch/index/analysis/test1.json | 4 ++++ src/test/java/org/elasticsearch/index/analysis/test1.yml | 5 +++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/reference/analysis/analyzers/custom-analyzer.asciidoc b/docs/reference/analysis/analyzers/custom-analyzer.asciidoc index 5c778a6c83d..a7cf7136a83 100644 --- a/docs/reference/analysis/analyzers/custom-analyzer.asciidoc +++ b/docs/reference/analysis/analyzers/custom-analyzer.asciidoc @@ -18,6 +18,9 @@ filters. |`char_filter` |An optional list of logical / registered name of char filters. + +|`position_offset_gap` |An optional number of positions to increment +between each field value of a field using this analyzer. |======================================================================= Here is an example: @@ -32,6 +35,7 @@ index : tokenizer : myTokenizer1 filter : [myTokenFilter1, myTokenFilter2] char_filter : [my_html] + position_offset_gap: 256 tokenizer : myTokenizer1 : type : standard diff --git a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index 81f06ad79d7..0ce7ed466ff 100644 --- a/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -152,6 +152,12 @@ public class AnalysisModuleTests extends ElasticsearchTestCase { // html = (HtmlStripCharFilterFactory) custom2.charFilters()[1]; // assertThat(html.readAheadLimit(), equalTo(1024)); + // verify position offset gap + analyzer = analysisService.analyzer("custom6").analyzer(); + assertThat(analyzer, instanceOf(CustomAnalyzer.class)); + CustomAnalyzer custom6 = (CustomAnalyzer) analyzer; + assertThat(custom6.getPositionIncrementGap("any_string"), equalTo(256)); + // verify characters mapping analyzer = analysisService.analyzer("custom5").analyzer(); assertThat(analyzer, instanceOf(CustomAnalyzer.class)); diff --git a/src/test/java/org/elasticsearch/index/analysis/test1.json b/src/test/java/org/elasticsearch/index/analysis/test1.json index 3b503d1da76..69be6db8f82 100644 --- a/src/test/java/org/elasticsearch/index/analysis/test1.json +++ b/src/test/java/org/elasticsearch/index/analysis/test1.json @@ -66,6 +66,10 @@ "tokenizer":"standard", "char_filter":["my_mapping"] }, + "custom6":{ + "tokenizer":"standard", + "position_offset_gap": 256 + }, "czechAnalyzerWithStemmer":{ "tokenizer":"standard", "filter":["standard", "lowercase", "stop", "czech_stem"] diff --git a/src/test/java/org/elasticsearch/index/analysis/test1.yml b/src/test/java/org/elasticsearch/index/analysis/test1.yml index 9c4aac6a6cb..81ef2353103 100644 --- a/src/test/java/org/elasticsearch/index/analysis/test1.yml +++ b/src/test/java/org/elasticsearch/index/analysis/test1.yml @@ -49,7 +49,8 @@ index : tokenizer : standard char_filter : [my_mapping] custom6 : - type : standard + tokenizer : standard + position_offset_gap: 256 custom7 : type : standard version: 3.6 @@ -58,4 +59,4 @@ index : filter : [standard, lowercase, stop, czech_stem] decompoundingAnalyzer : tokenizer : standard - filter : [dict_dec] \ No newline at end of file + filter : [dict_dec] From 7bf83ff924bf7a3102aeb66780800035954e3d01 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Fri, 24 Apr 2015 16:23:51 +0200 Subject: [PATCH 05/22] ref count write operations on IndexShard This commit adds a counter for IndexShard that keeps track of how many write operations are currently in flight on a shard. The counter is incremented whenever a write request is submitted in TransportShardReplicationOperationAction and decremented when it is finished. On a primary it stays incremented while replicas are being processed. The counter is an instance of AbstractRefCounted. Once this counter reaches 0 each write operation will be rejected with an IndexClosedException. closes #10610 --- ...nsportShardReplicationOperationAction.java | 110 +++++-- .../util/concurrent/AbstractRefCounted.java | 6 +- .../elasticsearch/index/shard/IndexShard.java | 75 ++++- .../ShardReplicationOperationTests.java | 300 +++++++++++++++++- .../index/shard/IndexShardTests.java | 56 +++- .../test/ElasticsearchIntegrationTest.java | 1 + .../test/InternalTestCluster.java | 52 +-- .../org/elasticsearch/test/TestCluster.java | 6 + 8 files changed, 516 insertions(+), 90 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java index efdc5ab0d4c..c45a3798318 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java +++ b/src/main/java/org/elasticsearch/action/support/replication/TransportShardReplicationOperationAction.java @@ -19,7 +19,7 @@ package org.elasticsearch.action.support.replication; -import org.elasticsearch.ElasticsearchException; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionWriteResponse; @@ -36,17 +36,16 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.IndexRoutingTable; -import org.elasticsearch.cluster.routing.IndexShardRoutingTable; -import org.elasticsearch.cluster.routing.ShardIterator; -import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingState; +import org.elasticsearch.cluster.routing.*; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.lease.Releasable; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; +import org.elasticsearch.common.util.concurrent.RefCounted; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.DocumentAlreadyExistsException; import org.elasticsearch.index.engine.VersionConflictEngineException; @@ -57,21 +56,15 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.node.NodeClosedException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.BaseTransportResponseHandler; -import org.elasticsearch.transport.ConnectTransportException; -import org.elasticsearch.transport.EmptyTransportResponseHandler; -import org.elasticsearch.transport.TransportChannel; -import org.elasticsearch.transport.TransportException; -import org.elasticsearch.transport.TransportRequestHandler; -import org.elasticsearch.transport.TransportRequestOptions; -import org.elasticsearch.transport.TransportResponse; -import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.*; +import java.io.Closeable; import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; /** */ @@ -103,7 +96,7 @@ public abstract class TransportShardReplicationOperationAction listener) { @@ -394,7 +393,9 @@ public abstract class TransportShardReplicationOperationAction primaryResponse = shardOperationOnPrimary(observer.observedState(), por); logger.trace("operation completed on primary [{}]", primary); - replicationPhase = new ReplicationPhase(shardsIt, primaryResponse.v2(), primaryResponse.v1(), observer, primary, internalRequest, listener); + replicationPhase = new ReplicationPhase(shardsIt, primaryResponse.v2(), primaryResponse.v1(), observer, primary, internalRequest, listener, indexShardReference); } catch (Throwable e) { internalRequest.request.setCanHaveDuplicates(); // shard has not been allocated yet, retry it here if (retryPrimaryException(e)) { logger.trace("had an error while performing operation on primary ({}), scheduling a retry.", e.getMessage()); + // We have to close here because when we retry we will increment get a new reference on index shard again and we do not want to + // increment twice. + Releasables.close(indexShardReference); + // We have to reset to null here because whe we retry it might be that we never get to the point where we assign a new reference + // (for example, in case the operation was rejected because queue is full). In this case we would release again once one of the finish methods is called. + indexShardReference = null; retry(e); return; } @@ -614,6 +628,12 @@ public abstract class TransportShardReplicationOperationAction listener) { + InternalRequest internalRequest, ActionListener listener, Releasable indexShardReference) { this.replicaRequest = replicaRequest; this.listener = listener; this.finalResponse = finalResponse; this.originalPrimaryShard = originalPrimaryShard; this.observer = observer; indexMetaData = observer.observedState().metaData().index(internalRequest.concreteIndex()); + this.indexShardReference = indexShardReference; ShardRouting shard; // we double check on the state, if it got changed we need to make sure we take the latest one cause @@ -742,17 +766,23 @@ public abstract class TransportShardReplicationOperationAction recoveredTypes = internalPerformTranslogRecovery(true); - assert recoveredTypes.isEmpty(); - assert recoveryState.getTranslog().recoveredOperations() == 0; + assert engineUnsafe() == null : "engine was already created"; + Map recoveredTypes = internalPerformTranslogRecovery(true); + assert recoveredTypes.isEmpty(); + assert recoveryState.getTranslog().recoveredOperations() == 0; } - /** called if recovery has to be restarted after network error / delay ** */ + /** + * called if recovery has to be restarted after network error / delay ** + */ public void performRecoveryRestart() throws IOException { synchronized (mutex) { if (state != IndexShardState.RECOVERING) { @@ -850,7 +863,9 @@ public class IndexShard extends AbstractIndexShardComponent { } } - /** returns stats about ongoing recoveries, both source and target */ + /** + * returns stats about ongoing recoveries, both source and target + */ public RecoveryStats recoveryStats() { return recoveryStats; } @@ -999,6 +1014,7 @@ public class IndexShard extends AbstractIndexShardComponent { } MetaDataStateFormat.deleteMetaState(shardPath().getDataPath()); } + public ShardPath shardPath() { return path; } @@ -1098,7 +1114,9 @@ public class IndexShard extends AbstractIndexShardComponent { }); } - /** Schedules another (future) refresh, if refresh_interval is still enabled. */ + /** + * Schedules another (future) refresh, if refresh_interval is still enabled. + */ private void reschedule() { synchronized (mutex) { if (state != IndexShardState.CLOSED && refreshInterval.millis() > 0) { @@ -1293,4 +1311,37 @@ public class IndexShard extends AbstractIndexShardComponent { threadPool, indexingService, indexSettingsService, warmer, store, deletionPolicy, translog, mergePolicyProvider, mergeScheduler, mapperAnalyzer, similarityService.similarity(), codecService, failedEngineListener, translogRecoveryPerformer, indexCache.filter(), indexCache.filterPolicy()); } + + private static class IndexShardOperationCounter extends AbstractRefCounted { + final private ESLogger logger; + private final ShardId shardId; + + public IndexShardOperationCounter(ESLogger logger, ShardId shardId) { + super("index-shard-operations-counter"); + this.logger = logger; + this.shardId = shardId; + } + + @Override + protected void closeInternal() { + logger.debug("operations counter reached 0, will not accept any further writes"); + } + + @Override + protected void alreadyClosed() { + throw new IndexShardClosedException(shardId, "could not increment operation counter. shard is closed."); + } + } + + public void incrementOperationCounter() { + indexShardOperationCounter.incRef(); + } + + public void decrementOperationCounter() { + indexShardOperationCounter.decRef(); + } + + public int getOperationsCount() { + return indexShardOperationCounter.refCount(); + } } diff --git a/src/test/java/org/elasticsearch/action/support/replication/ShardReplicationOperationTests.java b/src/test/java/org/elasticsearch/action/support/replication/ShardReplicationOperationTests.java index a28c78ccd34..7bd0cf373a5 100644 --- a/src/test/java/org/elasticsearch/action/support/replication/ShardReplicationOperationTests.java +++ b/src/test/java/org/elasticsearch/action/support/replication/ShardReplicationOperationTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.action.support.replication; +import com.google.common.base.Predicate; import org.apache.lucene.index.CorruptIndexException; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; @@ -41,9 +42,11 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.*; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; @@ -55,7 +58,9 @@ import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.cluster.TestClusterService; import org.elasticsearch.test.transport.CapturingTransport; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportResponse; +import org.elasticsearch.transport.TransportResponseOptions; import org.elasticsearch.transport.TransportService; import org.junit.AfterClass; import org.junit.Before; @@ -66,6 +71,7 @@ import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -82,7 +88,10 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { private TransportService transportService; private CapturingTransport transport; private Action action; - + /* * + * TransportShardReplicationOperationAction needs an instance of IndexShard to count operations. + * indexShards is reset to null before each test and will be initialized upon request in the tests. + */ @BeforeClass public static void beforeClass() { @@ -97,6 +106,7 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { transportService = new TransportService(transport, threadPool); transportService.start(); action = new Action(ImmutableSettings.EMPTY, "testAction", transportService, clusterService, threadPool); + count.set(1); } @AfterClass @@ -105,7 +115,6 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { threadPool = null; } - void assertListenerThrows(String msg, PlainActionFuture listener, Class klass) throws InterruptedException { try { listener.get(); @@ -113,7 +122,6 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { } catch (ExecutionException ex) { assertThat(ex.getCause(), instanceOf(klass)); } - } @Test @@ -145,7 +153,12 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { block = ClusterBlocks.builder() .addGlobalBlock(new ClusterBlock(1, "non retryable", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL)); clusterService.setState(ClusterState.builder(clusterService.state()).blocks(block)); - assertListenerThrows("primary phase should fail operation when moving from a retryable block a non-retryable one", listener, ClusterBlockException.class); + assertListenerThrows("primary phase should fail operation when moving from a retryable block to a non-retryable one", listener, ClusterBlockException.class); + assertIndexShardUninitialized(); + } + + public void assertIndexShardUninitialized() { + assertEquals(1, count.get()); } ClusterState stateWithStartedPrimary(String index, boolean primaryLocal, int numberOfReplicas) { @@ -163,7 +176,6 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { replicaStates[i] = ShardRoutingState.UNASSIGNED; } return state(index, primaryLocal, randomFrom(ShardRoutingState.STARTED, ShardRoutingState.RELOCATING), replicaStates); - } ClusterState state(String index, boolean primaryLocal, ShardRoutingState primaryState, ShardRoutingState... replicaStates) { @@ -225,7 +237,6 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { } indexShardRoutingBuilder.addShard( new ImmutableShardRouting(index, shardId.id(), replicaNode, relocatingNode, false, replicaState, 0)); - } ClusterState.Builder state = ClusterState.builder(new ClusterName("test")); @@ -268,6 +279,7 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { listener.get(); assertTrue("request wasn't processed on primary, despite of it being assigned", request.processedOnPrimary.get()); + assertIndexShardCounter(1); } @Test @@ -290,17 +302,23 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { if (primaryNodeId.equals(clusterService.localNode().id())) { logger.info("--> primary is assigned locally, testing for execution"); assertTrue("request failed to be processed on a local primary", request.processedOnPrimary.get()); + if (transport.capturedRequests().length > 0) { + assertIndexShardCounter(2); + } else { + assertIndexShardCounter(1); + } } else { logger.info("--> primary is assigned to [{}], checking request forwarded", primaryNodeId); final List capturedRequests = transport.capturedRequestsByTargetNode().get(primaryNodeId); assertThat(capturedRequests, notNullValue()); assertThat(capturedRequests.size(), equalTo(1)); assertThat(capturedRequests.get(0).action, equalTo("testAction")); + assertIndexShardUninitialized(); } } @Test - public void testWriteConsistency() { + public void testWriteConsistency() throws ExecutionException, InterruptedException { action = new ActionWithConsistency(ImmutableSettings.EMPTY, "testActionWithConsistency", transportService, clusterService, threadPool); final String index = "test"; final ShardId shardId = new ShardId(index, 0); @@ -348,17 +366,23 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { assertThat(primaryPhase.checkWriteConsistency(shardRoutingTable.primaryShard()), nullValue()); primaryPhase.run(); assertTrue("operations should have been perform, consistency level is met", request.processedOnPrimary.get()); + if (assignedReplicas > 0) { + assertIndexShardCounter(2); + } else { + assertIndexShardCounter(1); + } } else { assertThat(primaryPhase.checkWriteConsistency(shardRoutingTable.primaryShard()), notNullValue()); primaryPhase.run(); assertFalse("operations should not have been perform, consistency level is *NOT* met", request.processedOnPrimary.get()); + assertIndexShardUninitialized(); for (int i = 0; i < replicaStates.length; i++) { replicaStates[i] = ShardRoutingState.STARTED; } clusterService.setState(state(index, true, ShardRoutingState.STARTED, replicaStates)); assertTrue("once the consistency level met, operation should continue", request.processedOnPrimary.get()); + assertIndexShardCounter(2); } - } @Test @@ -407,7 +431,6 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { totalShards++; } } - runReplicateTest(shardRoutingTable, assignedReplicas, totalShards); } @@ -421,13 +444,14 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { logger.debug("expecting [{}] assigned replicas, [{}] total shards. using state: \n{}", assignedReplicas, totalShards, clusterService.state().prettyPrint()); - final TransportShardReplicationOperationAction.InternalRequest internalRequest = action.new InternalRequest(request); internalRequest.concreteIndex(shardId.index().name()); + Releasable reference = getOrCreateIndexShardOperationsCounter(); + assertIndexShardCounter(2); TransportShardReplicationOperationAction.ReplicationPhase replicationPhase = action.new ReplicationPhase(shardIt, request, new Response(), new ClusterStateObserver(clusterService, logger), - primaryShard, internalRequest, listener); + primaryShard, internalRequest, listener, reference); assertThat(replicationPhase.totalShards(), equalTo(totalShards)); assertThat(replicationPhase.pending(), equalTo(assignedReplicas)); @@ -472,8 +496,158 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { for (CapturingTransport.CapturedRequest capturedRequest : transport.capturedRequests()) { assertThat(capturedRequest.action, equalTo(ShardStateAction.SHARD_FAILED_ACTION_NAME)); } + // all replicas have responded so the counter should be decreased again + assertIndexShardCounter(1); } + @Test + public void testCounterOnPrimary() throws InterruptedException, ExecutionException, IOException { + final String index = "test"; + final ShardId shardId = new ShardId(index, 0); + // no replica, we only want to test on primary + clusterService.setState(state(index, true, + ShardRoutingState.STARTED)); + logger.debug("--> using initial state:\n{}", clusterService.state().prettyPrint()); + Request request = new Request(shardId).timeout("100ms"); + PlainActionFuture listener = new PlainActionFuture<>(); + + /** + * Execute an action that is stuck in shard operation until a latch is counted down. + * That way we can start the operation, check if the counter was incremented and then unblock the operation + * again to see if the counter is decremented afterwards. + * TODO: I could also write an action that asserts that the counter is 2 in the shard operation. + * However, this failure would only become apparent once listener.get is called. Seems a little implicit. + * */ + action = new ActionWithDelay(ImmutableSettings.EMPTY, "testActionWithExceptions", transportService, clusterService, threadPool); + final TransportShardReplicationOperationAction.PrimaryPhase primaryPhase = action.new PrimaryPhase(request, listener); + Thread t = new Thread() { + public void run() { + primaryPhase.run(); + } + }; + t.start(); + // shard operation should be ongoing, so the counter is at 2 + // we have to wait here because increment happens in thread + awaitBusy(new Predicate() { + @Override + public boolean apply(@Nullable Object input) { + return (count.get() == 2); + } + }); + + assertIndexShardCounter(2); + assertThat(transport.capturedRequests().length, equalTo(0)); + ((ActionWithDelay) action).countDownLatch.countDown(); + t.join(); + listener.get(); + // operation finished, counter back to 0 + assertIndexShardCounter(1); + assertThat(transport.capturedRequests().length, equalTo(0)); + } + + @Test + public void testCounterIncrementedWhileReplicationOngoing() throws InterruptedException, ExecutionException, IOException { + final String index = "test"; + final ShardId shardId = new ShardId(index, 0); + // one replica to make sure replication is attempted + clusterService.setState(state(index, true, + ShardRoutingState.STARTED, ShardRoutingState.STARTED)); + logger.debug("--> using initial state:\n{}", clusterService.state().prettyPrint()); + Request request = new Request(shardId).timeout("100ms"); + PlainActionFuture listener = new PlainActionFuture<>(); + TransportShardReplicationOperationAction.PrimaryPhase primaryPhase = action.new PrimaryPhase(request, listener); + primaryPhase.run(); + assertIndexShardCounter(2); + assertThat(transport.capturedRequests().length, equalTo(1)); + // try once with successful response + transport.handleResponse(transport.capturedRequests()[0].requestId, TransportResponse.Empty.INSTANCE); + assertIndexShardCounter(1); + transport.clear(); + request = new Request(shardId).timeout("100ms"); + primaryPhase = action.new PrimaryPhase(request, listener); + primaryPhase.run(); + assertIndexShardCounter(2); + assertThat(transport.capturedRequests().length, equalTo(1)); + // try with failure response + transport.handleResponse(transport.capturedRequests()[0].requestId, new CorruptIndexException("simulated", (String) null)); + assertIndexShardCounter(1); + } + + @Test + public void testReplicasCounter() throws Exception { + final ShardId shardId = new ShardId("test", 0); + clusterService.setState(state(shardId.index().getName(), true, + ShardRoutingState.STARTED, ShardRoutingState.STARTED)); + action = new ActionWithDelay(ImmutableSettings.EMPTY, "testActionWithExceptions", transportService, clusterService, threadPool); + final Action.ReplicaOperationTransportHandler replicaOperationTransportHandler = action.new ReplicaOperationTransportHandler(); + Thread t = new Thread() { + public void run() { + try { + replicaOperationTransportHandler.messageReceived(new Request(), createTransportChannel()); + } catch (Exception e) { + } + } + }; + t.start(); + // shard operation should be ongoing, so the counter is at 2 + // we have to wait here because increment happens in thread + awaitBusy(new Predicate() { + @Override + public boolean apply(@Nullable Object input) { + return count.get() == 2; + } + }); + ((ActionWithDelay) action).countDownLatch.countDown(); + t.join(); + // operation should have finished and counter decreased because no outstanding replica requests + assertIndexShardCounter(1); + // now check if this also works if operation throws exception + action = new ActionWithExceptions(ImmutableSettings.EMPTY, "testActionWithExceptions", transportService, clusterService, threadPool); + final Action.ReplicaOperationTransportHandler replicaOperationTransportHandlerForException = action.new ReplicaOperationTransportHandler(); + try { + replicaOperationTransportHandlerForException.messageReceived(new Request(shardId), createTransportChannel()); + fail(); + } catch (Throwable t2) { + } + assertIndexShardCounter(1); + } + + @Test + public void testCounterDecrementedIfShardOperationThrowsException() throws InterruptedException, ExecutionException, IOException { + action = new ActionWithExceptions(ImmutableSettings.EMPTY, "testActionWithExceptions", transportService, clusterService, threadPool); + final String index = "test"; + final ShardId shardId = new ShardId(index, 0); + clusterService.setState(state(index, true, + ShardRoutingState.STARTED, ShardRoutingState.STARTED)); + logger.debug("--> using initial state:\n{}", clusterService.state().prettyPrint()); + Request request = new Request(shardId).timeout("100ms"); + PlainActionFuture listener = new PlainActionFuture<>(); + TransportShardReplicationOperationAction.PrimaryPhase primaryPhase = action.new PrimaryPhase(request, listener); + primaryPhase.run(); + // no replica request should have been sent yet + assertThat(transport.capturedRequests().length, equalTo(0)); + // no matter if the operation is retried or not, counter must be be back to 1 + assertIndexShardCounter(1); + } + + private void assertIndexShardCounter(int expected) { + assertThat(count.get(), equalTo(expected)); + } + + private final AtomicInteger count = new AtomicInteger(0); + + /* + * Returns testIndexShardOperationsCounter or initializes it if it was already created in this test run. + * */ + private synchronized Releasable getOrCreateIndexShardOperationsCounter() { + count.incrementAndGet(); + return new Releasable() { + @Override + public void close() { + count.decrementAndGet(); + } + }; + } static class Request extends ShardReplicationOperationRequest { int shardId; @@ -481,7 +655,7 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { public AtomicInteger processedOnReplicas = new AtomicInteger(); Request() { - this.operationThreaded(false); + this.operationThreaded(randomBoolean()); } Request(ShardId shardId) { @@ -505,10 +679,9 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { } static class Response extends ActionWriteResponse { - } - static class Action extends TransportShardReplicationOperationAction { + class Action extends TransportShardReplicationOperationAction { Action(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, @@ -549,9 +722,14 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { protected boolean resolveIndex() { return false; } + + @Override + protected Releasable getIndexShardOperationsCounter(ShardId shardId) { + return getOrCreateIndexShardOperationsCounter(); + } } - static class ActionWithConsistency extends Action { + class ActionWithConsistency extends Action { ActionWithConsistency(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) { super(settings, actionName, transportService, clusterService, threadPool); @@ -567,5 +745,97 @@ public class ShardReplicationOperationTests extends ElasticsearchTestCase { return new DiscoveryNode("node_" + nodeId, DummyTransportAddress.INSTANCE, Version.CURRENT); } + /* + * Throws exceptions when executed. Used for testing if the counter is correctly decremented in case an operation fails. + * */ + class ActionWithExceptions extends Action { + + ActionWithExceptions(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) throws IOException { + super(settings, actionName, transportService, clusterService, threadPool); + } + + @Override + protected Tuple shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) throws Throwable { + return throwException(shardRequest.shardId); + } + + private Tuple throwException(ShardId shardId) { + try { + if (randomBoolean()) { + // throw a generic exception + // for testing on replica this will actually cause an NPE because it will make the shard fail but + // for this we need an IndicesService which is null. + throw new ElasticsearchException("simulated"); + } else { + // throw an exception which will cause retry on primary and be ignored on replica + throw new IndexShardNotStartedException(shardId, IndexShardState.RECOVERING); + } + } catch (Exception e) { + logger.info("throwing ", e); + throw e; + } + } + + @Override + protected void shardOperationOnReplica(ShardId shardId, Request shardRequest) { + throwException(shardRequest.internalShardId); + } + } + + /** + * Delays the operation until countDownLatch is counted down + */ + class ActionWithDelay extends Action { + CountDownLatch countDownLatch = new CountDownLatch(1); + + ActionWithDelay(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) throws IOException { + super(settings, actionName, transportService, clusterService, threadPool); + } + + @Override + protected Tuple shardOperationOnPrimary(ClusterState clusterState, PrimaryOperationRequest shardRequest) throws Throwable { + awaitLatch(); + return new Tuple<>(new Response(), shardRequest.request); + } + + private void awaitLatch() throws InterruptedException { + countDownLatch.await(); + countDownLatch = new CountDownLatch(1); + } + + @Override + protected void shardOperationOnReplica(ShardId shardId, Request shardRequest) { + try { + awaitLatch(); + } catch (InterruptedException e) { + } + } + + } + + /* + * Transport channel that is needed for replica operation testing. + * */ + public TransportChannel createTransportChannel() { + return new TransportChannel() { + + @Override + public String action() { + return null; + } + + @Override + public void sendResponse(TransportResponse response) throws IOException { + } + + @Override + public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException { + } + + @Override + public void sendResponse(Throwable error) throws IOException { + } + }; + } } diff --git a/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index e17721a0f00..8464cf8e42a 100644 --- a/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -23,18 +23,23 @@ import org.elasticsearch.cluster.routing.MutableShardRouting; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.IndexService; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.test.ElasticsearchSingleNodeTest; +import org.junit.Test; +import java.io.Closeable; import java.io.IOException; import java.nio.file.Path; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ExecutionException; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.equalTo; /** * Simple unit-test IndexShard related operations. @@ -95,20 +100,20 @@ public class IndexShardTests extends ElasticsearchSingleNodeTest { IndexShard shard = test.shard(0); ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(getShardStateMetadata(shard), shardStateMetaData); - ShardRouting routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version()+1); + ShardRouting routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version() + 1); shard.updateRoutingEntry(routing, true); shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_UUID))); - routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version()+1); + routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version() + 1); shard.updateRoutingEntry(routing, true); shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); assertEquals(shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_UUID))); - routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version()+1); + routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version() + 1); shard.updateRoutingEntry(routing, true); shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); @@ -122,13 +127,13 @@ public class IndexShardTests extends ElasticsearchSingleNodeTest { assertEquals("inactive shard state shouldn't be persisted", shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_UUID))); - shard.updateRoutingEntry(new MutableShardRouting(shard.shardRouting, shard.shardRouting.version()+1), false); + shard.updateRoutingEntry(new MutableShardRouting(shard.shardRouting, shard.shardRouting.version() + 1), false); shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertFalse("shard state persisted despite of persist=false", shardStateMetaData.equals(getShardStateMetadata(shard))); assertEquals("shard state persisted despite of persist=false", shardStateMetaData, new ShardStateMetaData(routing.version(), routing.primary(), shard.indexSettings.get(IndexMetaData.SETTING_UUID))); - routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version()+1); + routing = new MutableShardRouting(shard.shardRouting, shard.shardRouting.version() + 1); shard.updateRoutingEntry(routing, true); shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); @@ -153,15 +158,13 @@ public class IndexShardTests extends ElasticsearchSingleNodeTest { ShardStateMetaData shardStateMetaData = load(logger, env.availableShardPaths(shard.shardId)); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); - routing = new MutableShardRouting(shard.shardId.index().getName(), shard.shardId.id(), routing.currentNodeId(), routing.primary(), ShardRoutingState.INITIALIZING, shard.shardRouting.version()+1); + routing = new MutableShardRouting(shard.shardId.index().getName(), shard.shardId.id(), routing.currentNodeId(), routing.primary(), ShardRoutingState.INITIALIZING, shard.shardRouting.version() + 1); shard.updateRoutingEntry(routing, true); shard.deleteShardState(); assertNull("no shard state expected after delete on initializing", load(logger, env.availableShardPaths(shard.shardId))); - - } ShardStateMetaData getShardStateMetadata(IndexShard shard) { @@ -180,7 +183,7 @@ public class IndexShardTests extends ElasticsearchSingleNodeTest { assertEquals(meta.hashCode(), new ShardStateMetaData(meta.version, meta.primary, meta.indexUUID).hashCode()); assertFalse(meta.equals(new ShardStateMetaData(meta.version, !meta.primary, meta.indexUUID))); - assertFalse(meta.equals(new ShardStateMetaData(meta.version+1, meta.primary, meta.indexUUID))); + assertFalse(meta.equals(new ShardStateMetaData(meta.version + 1, meta.primary, meta.indexUUID))); assertFalse(meta.equals(new ShardStateMetaData(meta.version, !meta.primary, meta.indexUUID + "foo"))); Set hashCodes = new HashSet<>(); for (int i = 0; i < 30; i++) { // just a sanity check that we impl hashcode @@ -191,6 +194,41 @@ public class IndexShardTests extends ElasticsearchSingleNodeTest { } + @Test + public void testDeleteIndexDecreasesCounter() throws InterruptedException, ExecutionException, IOException { + assertAcked(client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).get()); + ensureGreen("test"); + IndicesService indicesService = getInstanceFromNode(IndicesService.class); + IndexService indexService = indicesService.indexServiceSafe("test"); + IndexShard indexShard = indexService.shard(0); + client().admin().indices().prepareDelete("test").get(); + assertThat(indexShard.getOperationsCount(), equalTo(0)); + try { + indexShard.incrementOperationCounter(); + fail("we should not be able to increment anymore"); + } catch (IndexShardClosedException e) { + // expected + } + } + + @Test + public void testIndexShardCounter() throws InterruptedException, ExecutionException, IOException { + assertAcked(client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).get()); + ensureGreen("test"); + IndicesService indicesService = getInstanceFromNode(IndicesService.class); + IndexService indexService = indicesService.indexServiceSafe("test"); + IndexShard indexShard = indexService.shard(0); + indexShard.incrementOperationCounter(); + assertEquals(2, indexShard.getOperationsCount()); + indexShard.incrementOperationCounter(); + assertEquals(3, indexShard.getOperationsCount()); + indexShard.decrementOperationCounter(); + indexShard.decrementOperationCounter(); + assertEquals(1, indexShard.getOperationsCount()); + + + } + public static ShardStateMetaData load(ESLogger logger, Path... shardPaths) throws IOException { return ShardStateMetaData.FORMAT.loadLatestState(logger, shardPaths); } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 109bd030023..10ad832eef2 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -648,6 +648,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } ensureClusterSizeConsistency(); ensureClusterStateConsistency(); + cluster().beforeIndexDeletion(); cluster().wipe(); // wipe after to make sure we fail in the test that didn't ack the delete if (afterClass || currentClusterScope == Scope.TEST) { cluster().close(); diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 194d54968b2..639b30ede4f 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -26,16 +26,10 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.carrotsearch.randomizedtesting.generators.RandomStrings; import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import com.google.common.collect.*; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; - import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; @@ -80,7 +74,9 @@ import org.elasticsearch.index.cache.filter.FilterCacheModule; import org.elasticsearch.index.cache.filter.FilterCacheModule.FilterCacheSettings; import org.elasticsearch.index.cache.filter.index.IndexFilterCache; import org.elasticsearch.index.cache.filter.none.NoneFilterCache; +import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardModule; +import org.elasticsearch.index.shard.IndexShardState; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.indices.IndicesService; @@ -112,34 +108,19 @@ import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NavigableMap; -import java.util.Random; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import static junit.framework.Assert.fail; -import static org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY; -import static org.apache.lucene.util.LuceneTestCase.rarely; -import static org.apache.lucene.util.LuceneTestCase.usually; +import static org.apache.lucene.util.LuceneTestCase.*; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.elasticsearch.test.ElasticsearchTestCase.assertBusy; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -855,6 +836,7 @@ public final class InternalTestCluster extends TestCluster { } public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_"; + static class TransportClientFactory { private final boolean sniff; private final Settings settings; @@ -976,6 +958,26 @@ public final class InternalTestCluster extends TestCluster { randomlyResetClients(); /* reset all clients - each test gets its own client based on the Random instance created above. */ } + @Override + public void beforeIndexDeletion() { + assertShardIndexCounter(); + } + + private void assertShardIndexCounter() { + final Collection nodesAndClients = nodes.values(); + for (NodeAndClient nodeAndClient : nodesAndClients) { + IndicesService indexServices = getInstance(IndicesService.class, nodeAndClient.name); + for (IndexService indexService : indexServices) { + for (IndexShard indexShard : indexService) { + assertThat(indexShard.getOperationsCount(), anyOf(equalTo(1), equalTo(0))); + if (indexShard.getOperationsCount() == 0) { + assertThat(indexShard.state(), equalTo(IndexShardState.CLOSED)); + } + } + } + } + } + private void randomlyResetClients() throws IOException { // only reset the clients on nightly tests, it causes heavy load... if (RandomizedTest.isNightly() && rarely(random)) { diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java index c8d48521b14..a1f5f016a8d 100644 --- a/src/test/java/org/elasticsearch/test/TestCluster.java +++ b/src/test/java/org/elasticsearch/test/TestCluster.java @@ -76,6 +76,12 @@ public abstract class TestCluster implements Iterable, Closeable { wipeRepositories(); } + /** + * Assertions that should run before the cluster is wiped should be called in this method + */ + public void beforeIndexDeletion() { + } + /** * This method checks all the things that need to be checked after each test */ From b8efa8ea21788f2f19eff4be4f3b9be404ed83f2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 12:30:03 -0400 Subject: [PATCH 06/22] Remove JNI permissions, improve JNI testing. --- pom.xml | 3 + .../elasticsearch/bootstrap/Bootstrap.java | 56 +++++++++++----- .../org/elasticsearch/bootstrap/Security.java | 4 -- .../common/jna/Kernel32Library.java | 18 ++++-- .../elasticsearch/bootstrap/security.policy | 3 - .../common/jna/NativesTests.java | 64 ++----------------- .../org/elasticsearch/monitor/SigarTests.java | 42 ++++++++++++ .../org/elasticsearch/test/SecurityHack.java | 3 + 8 files changed, 105 insertions(+), 88 deletions(-) create mode 100644 src/test/java/org/elasticsearch/monitor/SigarTests.java diff --git a/pom.xml b/pom.xml index 432aa22744e..8adf415700f 100644 --- a/pom.xml +++ b/pom.xml @@ -635,6 +635,9 @@ ${tests.security.manager} ${tests.compatibility} true + + true ${basedir}/src/main/resources/org/elasticsearch/bootstrap/security.policy diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index d351a9d4ea2..d787ff84289 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -19,6 +19,7 @@ package org.elasticsearch.bootstrap; +import org.apache.lucene.util.StringHelper; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.Version; import org.elasticsearch.common.PidFile; @@ -27,6 +28,7 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.inject.CreationException; import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.jna.Kernel32Library; import org.elasticsearch.common.jna.Natives; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -38,6 +40,7 @@ import org.elasticsearch.monitor.process.JmxProcessProbe; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.elasticsearch.node.internal.InternalSettingsPreparer; +import org.hyperic.sigar.Sigar; import java.util.Locale; import java.util.Set; @@ -57,24 +60,16 @@ public class Bootstrap { private static volatile Thread keepAliveThread; private static volatile CountDownLatch keepAliveLatch; private static Bootstrap bootstrap; - - private void setup(boolean addShutdownHook, Settings settings, Environment environment) throws Exception { - if (settings.getAsBoolean("bootstrap.mlockall", false)) { + + /** initialize native resources */ + public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) { + // mlockall if requested + if (mlockAll) { Natives.tryMlockall(); } - NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settings).loadConfigSettings(false); - node = nodeBuilder.build(); - if (addShutdownHook) { - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - node.close(); - } - }); - } - - if (settings.getAsBoolean("bootstrap.ctrlhandler", true)) { + // listener for windows close event + if (ctrlHandler) { Natives.addConsoleCtrlHandler(new ConsoleCtrlHandler() { @Override public boolean handle(int code) { @@ -89,7 +84,36 @@ public class Bootstrap { } }); } - // install SM after natives, JNA can require strange permissions + Kernel32Library.getInstance(); + + // initialize sigar explicitly + try { + Sigar.load(); + Loggers.getLogger(Bootstrap.class).trace("sigar libraries loaded successfully"); + } catch (Throwable t) { + Loggers.getLogger(Bootstrap.class).trace("failed to load sigar libraries", t); + } + + // init lucene random seed. it will use /dev/urandom where available: + StringHelper.randomId(); + } + + private void setup(boolean addShutdownHook, Settings settings, Environment environment) throws Exception { + initializeNatives(settings.getAsBoolean("bootstrap.mlockall", false), + settings.getAsBoolean("bootstrap.ctrlhandler", true)); + + NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settings).loadConfigSettings(false); + node = nodeBuilder.build(); + if (addShutdownHook) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + node.close(); + } + }); + } + + // install SM after natives, shutdown hooks, etc. setupSecurity(settings, environment); } diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index a9eedb7816a..cdb79ab9b4e 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -19,7 +19,6 @@ package org.elasticsearch.bootstrap; -import org.apache.lucene.util.StringHelper; import org.elasticsearch.env.Environment; import java.io.*; @@ -49,9 +48,6 @@ class Security { * Can only happen once! */ static void configure(Environment environment) throws Exception { - // init lucene random seed. it will use /dev/urandom where available: - StringHelper.randomId(); - // enable security policy: union of template and environment-based paths. URI template = Security.class.getResource(POLICY_RESOURCE).toURI(); Policy.setPolicy(new ESPolicy(template, createPermissions(environment))); diff --git a/src/main/java/org/elasticsearch/common/jna/Kernel32Library.java b/src/main/java/org/elasticsearch/common/jna/Kernel32Library.java index 386da4a5401..04549d78f1d 100644 --- a/src/main/java/org/elasticsearch/common/jna/Kernel32Library.java +++ b/src/main/java/org/elasticsearch/common/jna/Kernel32Library.java @@ -22,6 +22,8 @@ package org.elasticsearch.common.jna; import com.google.common.collect.ImmutableList; import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary; + +import org.apache.lucene.util.Constants; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -46,13 +48,15 @@ public class Kernel32Library { } private Kernel32Library() { - try { - Native.register("kernel32"); - logger.debug("windows/Kernel32 library loaded"); - } catch (NoClassDefFoundError e) { - logger.warn("JNA not found. native methods and handlers will be disabled."); - } catch (UnsatisfiedLinkError e) { - logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); + if (Constants.WINDOWS) { + try { + Native.register("kernel32"); + logger.debug("windows/Kernel32 library loaded"); + } catch (NoClassDefFoundError e) { + logger.warn("JNA not found. native methods and handlers will be disabled."); + } catch (UnsatisfiedLinkError e) { + logger.warn("unable to link Windows/Kernel32 library. native methods and handlers will be disabled."); + } } } diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 993868c18b3..f71105af7da 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -82,9 +82,6 @@ grant { // needed by groovy scripting permission java.lang.RuntimePermission "getProtectionDomain"; - // needed for natives calls - permission java.lang.RuntimePermission "loadLibrary.*"; - // reflection hacks: // needed for Striped64 (what is this doing), also enables unmap hack permission java.lang.RuntimePermission "accessClassInPackage.sun.misc"; diff --git a/src/test/java/org/elasticsearch/common/jna/NativesTests.java b/src/test/java/org/elasticsearch/common/jna/NativesTests.java index 7a53b8d6895..72b973c0db9 100644 --- a/src/test/java/org/elasticsearch/common/jna/NativesTests.java +++ b/src/test/java/org/elasticsearch/common/jna/NativesTests.java @@ -20,83 +20,31 @@ package org.elasticsearch.common.jna; import org.apache.lucene.util.Constants; -import org.elasticsearch.common.jna.Kernel32Library.ConsoleCtrlHandler; import org.elasticsearch.test.ElasticsearchTestCase; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.Matchers.equalTo; public class NativesTests extends ElasticsearchTestCase { - /** - * Those properties are set by the JNA Api and if not ignored, - * lead to tests failure (see AbstractRandomizedTest#IGNORED_INVARIANT_PROPERTIES) - */ - private static final String[] JNA_INVARIANT_PROPERTIES = { - "jna.platform.library.path", - "jnidispatch.path" - }; - - private Map properties = new HashMap<>(); - - @Before - public void saveProperties() { - assumeTrue("Natives can't load libraries from path if security manager is enabled.", System.getSecurityManager() == null); - for (String p : JNA_INVARIANT_PROPERTIES) { - properties.put(p, System.getProperty(p)); - } - } - - @After - public void restoreProperties() { - for (String p : JNA_INVARIANT_PROPERTIES) { - if (properties.get(p) != null) { - System.setProperty(p, properties.get(p)); - } else { - System.clearProperty(p); - } - } - } - @Test - public void testTryMlockall() { - Natives.tryMlockall(); - + public void testMlockall() { if (Constants.WINDOWS) { assertFalse("Memory locking is not available on Windows platforms", Natives.LOCAL_MLOCKALL); } + if (Constants.MAC_OS_X) { + assertFalse("Memory locking is not available on OS X platforms", Natives.LOCAL_MLOCKALL); + } } - + @Test - public void testAddConsoleCtrlHandler() { - ConsoleCtrlHandler handler = new ConsoleCtrlHandler() { - @Override - public boolean handle(int code) { - return false; - } - }; - - Natives.addConsoleCtrlHandler(handler); - + public void testConsoleCtrlHandler() { if (Constants.WINDOWS) { assertNotNull(Kernel32Library.getInstance()); assertThat(Kernel32Library.getInstance().getCallbacks().size(), equalTo(1)); - } else { assertNotNull(Kernel32Library.getInstance()); assertThat(Kernel32Library.getInstance().getCallbacks().size(), equalTo(0)); - - try { - Kernel32Library.getInstance().addConsoleCtrlHandler(handler); - fail("should have thrown an unsupported operation exception"); - } catch (UnsatisfiedLinkError e) { - // UnsatisfiedLinkError is expected - } } } } diff --git a/src/test/java/org/elasticsearch/monitor/SigarTests.java b/src/test/java/org/elasticsearch/monitor/SigarTests.java new file mode 100644 index 00000000000..f582c2fdc1c --- /dev/null +++ b/src/test/java/org/elasticsearch/monitor/SigarTests.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch 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.monitor; + +import org.elasticsearch.test.ElasticsearchTestCase; +import org.hyperic.sigar.Sigar; + +public class SigarTests extends ElasticsearchTestCase { + + @Override + public void setUp() throws Exception { + super.setUp(); + assumeTrue("we can only ensure sigar is working when running from maven", + Boolean.parseBoolean(System.getProperty("tests.maven"))); + } + + public void testSigarLoads() throws Exception { + Sigar.load(); + } + + public void testSigarWorks() throws Exception { + Sigar sigar = new Sigar(); + assertNotNull(sigar.getCpu()); + } +} diff --git a/src/test/java/org/elasticsearch/test/SecurityHack.java b/src/test/java/org/elasticsearch/test/SecurityHack.java index 092eda99f7d..90223ce4ac2 100644 --- a/src/test/java/org/elasticsearch/test/SecurityHack.java +++ b/src/test/java/org/elasticsearch/test/SecurityHack.java @@ -20,6 +20,7 @@ package org.elasticsearch.test; import org.apache.lucene.util.TestSecurityManager; +import org.elasticsearch.bootstrap.Bootstrap; import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean; @@ -33,6 +34,8 @@ import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAs class SecurityHack { static { + // just like bootstrap, initialize natives, then SM + Bootstrap.initializeNatives(true, true); // for IDEs, we check that security.policy is set if (systemPropertyAsBoolean("tests.security.manager", true) && System.getProperty("java.security.policy") != null) { From babfd8a18117731b1143d1f60d21e269b2b219f9 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 4 May 2015 13:16:08 -0400 Subject: [PATCH 07/22] [TEST] Stabilize MovAvgTests with more lenient floating point checks It appears the previous failure (-Dtests.seed=D9EF60095522804F) is just accumulation of floating point error differences between expected and actual results. Making the tests less stringent by requiring closeTo(0.1) instead of the previous 0.00001 --- .../reducers/moving/avg/MovAvgTests.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java b/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java index 77b7c8bc208..f6f92ab278d 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java @@ -59,9 +59,7 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.min; import static org.elasticsearch.search.aggregations.AggregationBuilders.range; import static org.elasticsearch.search.aggregations.reducers.ReducerBuilders.movingAvg; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.*; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; @@ -308,7 +306,6 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { * test simple moving average on single value field */ @Test - @AwaitsFix(bugUrl = "Fails with certain seeds including -Dtests.seed=D9EF60095522804F") public void simpleSingleValuedField() { SearchResponse response = client() @@ -361,7 +358,6 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { } @Test - @AwaitsFix(bugUrl = "Fails with certain seeds including -Dtests.seed=D9EF60095522804F") public void linearSingleValuedField() { SearchResponse response = client() @@ -414,7 +410,6 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { } @Test - @AwaitsFix(bugUrl = "Fails with certain seeds including -Dtests.seed=D9EF60095522804F") public void singleSingleValuedField() { SearchResponse response = client() @@ -467,7 +462,6 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { } @Test - @AwaitsFix(bugUrl = "Fails with certain seeds including -Dtests.seed=D9EF60095522804F") public void doubleSingleValuedField() { SearchResponse response = client() @@ -1038,7 +1032,7 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { } else { assertThat("[_count] movavg is null", countMovAvg, notNullValue()); assertThat("[_count] movavg does not match expected ["+countMovAvg.value()+" vs "+expectedCount+"]", - Math.abs(countMovAvg.value() - expectedCount) <= 0.000001, equalTo(true)); + countMovAvg.value(), closeTo(expectedCount, 0.1)); } // This is a gap bucket @@ -1047,7 +1041,8 @@ public class MovAvgTests extends ElasticsearchIntegrationTest { assertThat("[value] movavg is not null", valuesMovAvg, Matchers.nullValue()); } else { assertThat("[value] movavg is null", valuesMovAvg, notNullValue()); - assertThat("[value] movavg does not match expected ["+valuesMovAvg.value()+" vs "+expectedValue+"]", Math.abs(valuesMovAvg.value() - expectedValue) <= 0.000001, equalTo(true)); + assertThat("[value] movavg does not match expected ["+valuesMovAvg.value()+" vs "+expectedValue+"]", + valuesMovAvg.value(), closeTo(expectedValue, 0.1)); } } From a048f8944b41fbf8cf54de0d30125f8e4c191290 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 14:06:32 -0400 Subject: [PATCH 08/22] Remove exitVM permission --- .../elasticsearch/bootstrap/Bootstrap.java | 105 +++++++----------- .../bootstrap/Elasticsearch.java | 4 - .../bootstrap/ElasticsearchF.java | 4 - .../elasticsearch/bootstrap/security.policy | 3 - 4 files changed, 40 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 17e87c150ee..3edb65a2fc5 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -55,11 +55,33 @@ import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_ */ public class Bootstrap { - private Node node; + private static volatile Bootstrap INSTANCE; - private static volatile Thread keepAliveThread; - private static volatile CountDownLatch keepAliveLatch; - private static Bootstrap bootstrap; + private Node node; + private final CountDownLatch keepAliveLatch = new CountDownLatch(1); + private final Thread keepAliveThread; + + /** creates a new instance */ + Bootstrap() { + keepAliveThread = new Thread(new Runnable() { + @Override + public void run() { + try { + keepAliveLatch.await(); + } catch (InterruptedException e) { + // bail out + } + } + }, "elasticsearch[keepAlive/" + Version.CURRENT + "]"); + keepAliveThread.setDaemon(false); + // keep this thread alive (non daemon thread) until we shutdown + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + keepAliveLatch.countDown(); + } + }); + } /** initialize native resources */ public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) { @@ -77,7 +99,7 @@ public class Bootstrap { ESLogger logger = Loggers.getLogger(Bootstrap.class); logger.info("running graceful exit on windows"); - System.exit(0); + Bootstrap.INSTANCE.stop(); return true; } return false; @@ -148,47 +170,22 @@ public class Bootstrap { return InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true); } - /** - * hook for JSVC - */ - public void init(String[] args) throws Exception { - Tuple tuple = initialSettings(); - Settings settings = tuple.v1(); - Environment environment = tuple.v2(); - setupLogging(settings, environment); - setup(true, settings, environment); - } - - /** - * hook for JSVC - */ - public void start() { + private void start() { node.start(); + keepAliveThread.start(); } - /** - * hook for JSVC - */ - public void stop() { - destroy(); - } - - - /** - * hook for JSVC - */ - public void destroy() { - node.close(); - } - - public static void close(String[] args) { - bootstrap.destroy(); - keepAliveLatch.countDown(); + private void stop() { + try { + node.close(); + } finally { + keepAliveLatch.countDown(); + } } public static void main(String[] args) { System.setProperty("es.logger.prefix", ""); - bootstrap = new Bootstrap(); + INSTANCE = new Bootstrap(); final String pidFile = System.getProperty("es.pidfile", System.getProperty("es-pidfile")); if (pidFile != null) { @@ -240,40 +237,18 @@ public class Bootstrap { // fail if using broken version JVMCheck.check(); - keepAliveLatch = new CountDownLatch(1); - // keep this thread alive (non daemon thread) until we shutdown - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - keepAliveLatch.countDown(); - } - }); - - bootstrap.setup(true, settings, environment); + INSTANCE.setup(true, settings, environment); stage = "Startup"; - bootstrap.start(); + INSTANCE.start(); if (!foreground) { closeSysError(); } - - keepAliveThread = new Thread(new Runnable() { - @Override - public void run() { - try { - keepAliveLatch.await(); - } catch (InterruptedException e) { - // bail out - } - } - }, "elasticsearch[keepAlive/" + Version.CURRENT + "]"); - keepAliveThread.setDaemon(false); - keepAliveThread.start(); } catch (Throwable e) { ESLogger logger = Loggers.getLogger(Bootstrap.class); - if (bootstrap.node != null) { - logger = Loggers.getLogger(Bootstrap.class, bootstrap.node.settings().get("name")); + if (INSTANCE.node != null) { + logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("name")); } String errorMessage = buildErrorMessage(stage, e); if (foreground) { diff --git a/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index cb35d33bb45..e9a851ecea1 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -24,10 +24,6 @@ package org.elasticsearch.bootstrap; */ public class Elasticsearch extends Bootstrap { - public static void close(String[] args) { - Bootstrap.close(args); - } - public static void main(String[] args) { Bootstrap.main(args); } diff --git a/src/main/java/org/elasticsearch/bootstrap/ElasticsearchF.java b/src/main/java/org/elasticsearch/bootstrap/ElasticsearchF.java index a07ec8c162e..96e310eff3f 100644 --- a/src/main/java/org/elasticsearch/bootstrap/ElasticsearchF.java +++ b/src/main/java/org/elasticsearch/bootstrap/ElasticsearchF.java @@ -25,10 +25,6 @@ package org.elasticsearch.bootstrap; */ public class ElasticsearchF { - public static void close(String[] args) { - Bootstrap.close(args); - } - public static void main(String[] args) { System.setProperty("es.foreground", "yes"); Bootstrap.main(args); diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index bbdf7964093..ac5df915bd2 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -63,9 +63,6 @@ grant { // needed by ImmutableSettings permission java.lang.RuntimePermission "getenv.*"; - // needed by BootStrap, etc - permission java.lang.RuntimePermission "exitVM.*"; - // needed by PluginManager permission java.lang.RuntimePermission "setFactory"; From 2be1a09c777e00c3f8d8260b614ad5b08a68acac Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 14:21:11 -0400 Subject: [PATCH 09/22] add a null check for safety --- src/main/java/org/elasticsearch/bootstrap/Bootstrap.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 3edb65a2fc5..8318fae0726 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -177,7 +177,9 @@ public class Bootstrap { private void stop() { try { - node.close(); + if (node != null) { + node.close(); + } } finally { keepAliveLatch.countDown(); } From 06482e842433a4f0532720cb26f217b17326dac3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 14:55:10 -0400 Subject: [PATCH 10/22] Use Releasables.close here --- src/main/java/org/elasticsearch/bootstrap/Bootstrap.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 8318fae0726..74e8ec62cbc 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.inject.spi.Message; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.jna.Kernel32Library; import org.elasticsearch.common.jna.Natives; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.log4j.LogConfigurator; @@ -177,9 +178,7 @@ public class Bootstrap { private void stop() { try { - if (node != null) { - node.close(); - } + Releasables.close(node); } finally { keepAliveLatch.countDown(); } From fe046df12589dd4477637f26c0ca255d70aba169 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 15:38:46 -0400 Subject: [PATCH 11/22] hacky state --- .pom.xml.swp | Bin 0 -> 122880 bytes pom.xml | 6 +- .../org/elasticsearch/bootstrap/ESPolicy.java | 53 ++++++++++++++++++ .../org/elasticsearch/bootstrap/Security.java | 28 +-------- .../org/elasticsearch/test/SecurityHack.java | 16 ++++-- 5 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 .pom.xml.swp create mode 100644 src/main/java/org/elasticsearch/bootstrap/ESPolicy.java diff --git a/.pom.xml.swp b/.pom.xml.swp new file mode 100644 index 0000000000000000000000000000000000000000..08f99ccc7b22f6c6ffba697bf0e7754a2bf92ac1 GIT binary patch literal 122880 zcmeI52b>&7mH!7YCi+PJlWd?ZoFr>zw2~YUqXk*PmXR!-Rt}tv<=L6u-H|4FdPb|Y zEwImI6ORlg9m#~lN9Hh?Xq#|=$zcBQCmqRv;Sv})?*Dz&Rn^@y)6+d0WC`zl^waEA zSG}rwUFp4g^=f>@xtq5-r{-2?_&hL^dG6=VIOm7Oi!v)7mdUhgok~l>6F%c^(Q7Bf zk;hL}1o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L~{G$ubK<01&$P6mJTGn$|1Na)I+FsO1+sWm?j36Ta??E>HUm)`TqqRKxWi9t# z!1rn3JIMC?z%&rw|L;bw-voY&EH7vO^WawG_I=zE zu{YXJ>XfykZ%C8%f_M?BUzDLvrzK~!Pg-0X{773tlP)<2r4EcH8PVrIUmy; z{hNgQWEB5~ZPFkY(I#&96`^!?|4uORUZJ-4MY*_R`&K+cY}j}@8ZhZ^L^{!P(GmN` zhCzJ-DSWAtYlA$jekaH6VeOo<#K_6Ti`8s!t&-lX*q^nrvl81QA_I&K43P*j5Mvxa zMsZx-)g*?UIjQY_d~##>k@Mtee37wwKaB1P^X)*ps08GFeR8|etdC+375dd31xdeI z?$nw&(Va7*C=a%k)_!gWp7a>q{iM-Y{b(@CUh0mXJhGBoqk=SkXb|63yqR=cxvD5E zMmO%*v26#e>I%+?{Qm`H?^VdVqqrk6_`^EqNQXqH! zy$GxYKScJIy?i#HoGw66%R>=ugJ+oY&sz2&k|?pu{gO}sWHOHQd+7h^Q83wEdRJK1R_S8b|T zZEve@@<$HaY(m3PG{WE_NBXt=pzW!!gk&?gcxnd&41H}JlPgKApCqK8qViRDTYaor a+#8%U^88>S6OAyKTAm?dU276+jQ2.1.14 auto true - onerror + always ${project.basedir}/backwards random random false + true ERROR 512m ${basedir}/logs/ @@ -583,6 +584,7 @@ -Des.logger.prefix= -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${tests.heapdump.path} + -Djava.security.debug=access:failure,policy ${tests.shuffle} ${tests.verbose} @@ -638,8 +640,6 @@ true - - ${basedir}/src/main/resources/org/elasticsearch/bootstrap/security.policy diff --git a/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java b/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java new file mode 100644 index 00000000000..5bf7f7ce299 --- /dev/null +++ b/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch 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.bootstrap; + +import org.elasticsearch.common.SuppressForbidden; + +import java.net.URI; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.security.ProtectionDomain; +import java.security.URIParameter; + +/** custom policy for union of static and dynamic permissions */ +public class ESPolicy extends Policy { + + /** template policy file, the one used in tests */ + static final String POLICY_RESOURCE = "security.policy"; + + final Policy template; + final PermissionCollection dynamic; + + @SuppressForbidden(reason = "ok") + public ESPolicy(PermissionCollection dynamic) throws Exception { + URI uri = getClass().getResource(POLICY_RESOURCE).toURI(); + System.out.println("temp=" + System.getProperty("java.io.tmpdir")); + this.template = Policy.getInstance("JavaPolicy", new URIParameter(uri)); + this.dynamic = dynamic; + } + + @Override @SuppressForbidden(reason = "ok") + public boolean implies(ProtectionDomain domain, Permission permission) { + //System.out.println("domain=" + domain); + return template.implies(domain, permission) || dynamic.implies(permission); + } +} diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index cdb79ab9b4e..9ed66af4499 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -25,12 +25,8 @@ import java.io.*; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; -import java.security.Permission; -import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; -import java.security.ProtectionDomain; -import java.security.URIParameter; /** * Initializes securitymanager with necessary permissions. @@ -39,18 +35,14 @@ import java.security.URIParameter; * permissions based on the environment (data paths, etc) */ class Security { - - /** template policy file, the one used in tests */ - static final String POLICY_RESOURCE = "security.policy"; - + /** * Initializes securitymanager for the environment * Can only happen once! */ static void configure(Environment environment) throws Exception { // enable security policy: union of template and environment-based paths. - URI template = Security.class.getResource(POLICY_RESOURCE).toURI(); - Policy.setPolicy(new ESPolicy(template, createPermissions(environment))); + Policy.setPolicy(new ESPolicy(createPermissions(environment))); // enable security manager System.setSecurityManager(new SecurityManager()); @@ -98,20 +90,4 @@ class Security { throw new SecurityException("Security misconfiguration: cannot access java.io.tmpdir", problem); } } - - /** custom policy for union of static and dynamic permissions */ - static class ESPolicy extends Policy { - final Policy template; - final PermissionCollection dynamic; - - ESPolicy(URI template, PermissionCollection dynamic) throws Exception { - this.template = Policy.getInstance("JavaPolicy", new URIParameter(template)); - this.dynamic = dynamic; - } - - @Override - public boolean implies(ProtectionDomain domain, Permission permission) { - return template.implies(domain, permission) || dynamic.implies(permission); - } - } } diff --git a/src/test/java/org/elasticsearch/test/SecurityHack.java b/src/test/java/org/elasticsearch/test/SecurityHack.java index 90223ce4ac2..9aa44e4f5da 100644 --- a/src/test/java/org/elasticsearch/test/SecurityHack.java +++ b/src/test/java/org/elasticsearch/test/SecurityHack.java @@ -21,6 +21,10 @@ package org.elasticsearch.test; import org.apache.lucene.util.TestSecurityManager; import org.elasticsearch.bootstrap.Bootstrap; +import org.elasticsearch.bootstrap.ESPolicy; + +import java.security.Permissions; +import java.security.Policy; import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean; @@ -36,10 +40,14 @@ class SecurityHack { static { // just like bootstrap, initialize natives, then SM Bootstrap.initializeNatives(true, true); - // for IDEs, we check that security.policy is set - if (systemPropertyAsBoolean("tests.security.manager", true) && - System.getProperty("java.security.policy") != null) { - System.setSecurityManager(new TestSecurityManager()); + // install security manager if requested + if (systemPropertyAsBoolean("tests.security.manager", false)) { + try { + Policy.setPolicy(new ESPolicy(new Permissions())); + System.setSecurityManager(new TestSecurityManager()); + } catch (Exception e) { + throw new RuntimeException("unable to install test security manager", e); + } } } From 18ab7186939adc5ec34095c29a19d57b1dfe7bd1 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Mon, 4 May 2015 10:22:11 -0600 Subject: [PATCH 12/22] Allow shards on shared filesystems to be recovered on any node Currently, when all copies of a shard are lost, we reach out to all other nodes to see whether they have a copy of the data. For a shared filesystem, though, we can assume that each node has a copy of the data available, so return a state version of at least 0 for each node. This feature is set using the dynamic index setting `index.shared_filesystem.recover_on_any_node`, which defaults to `false`. Fixes #10932 --- .../cluster/metadata/IndexMetaData.java | 1 + .../gateway/GatewayAllocator.java | 20 ++++++++- .../settings/IndexDynamicSettingsModule.java | 1 + .../index/IndexWithShadowReplicasTests.java | 42 +++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index fe76d0f3f2b..69bdd2808dc 100644 --- a/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -165,6 +165,7 @@ public class IndexMetaData implements Diffable { public static final String SETTING_LEGACY_ROUTING_HASH_FUNCTION = "index.legacy.routing.hash.type"; public static final String SETTING_LEGACY_ROUTING_USE_TYPE = "index.legacy.routing.use_type"; public static final String SETTING_DATA_PATH = "index.data_path"; + public static final String SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE = "index.shared_filesystem.recover_on_any_node"; public static final String INDEX_UUID_NA_VALUE = "_na_"; // hard-coded hash function as of 2.0 diff --git a/src/main/java/org/elasticsearch/gateway/GatewayAllocator.java b/src/main/java/org/elasticsearch/gateway/GatewayAllocator.java index 399e9607cfb..def54a45b35 100644 --- a/src/main/java/org/elasticsearch/gateway/GatewayAllocator.java +++ b/src/main/java/org/elasticsearch/gateway/GatewayAllocator.java @@ -372,6 +372,14 @@ public class GatewayAllocator extends AbstractComponent { return changed; } + /** + * Build a map of DiscoveryNodes to shard state number for the given shard. + * A state of -1 means the shard does not exist on the node, where any + * shard state >= 0 is the state version of the shard on that node's disk. + * + * A shard on shared storage will return at least shard state 0 for all + * nodes, indicating that the shard can be allocated to any node. + */ private ObjectLongOpenHashMap buildShardStates(final DiscoveryNodes nodes, MutableShardRouting shard, IndexMetaData indexMetaData) { ObjectLongOpenHashMap shardStates = cachedShardsState.get(shard.shardId()); ObjectOpenHashSet nodeIds; @@ -405,10 +413,18 @@ public class GatewayAllocator extends AbstractComponent { logListActionFailures(shard, "state", response.failures()); for (TransportNodesListGatewayStartedShards.NodeGatewayStartedShards nodeShardState : response) { + long version = nodeShardState.version(); + Settings idxSettings = indexMetaData.settings(); + if (IndexMetaData.isOnSharedFilesystem(idxSettings) && + idxSettings.getAsBoolean(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, false)) { + // Shared filesystems use 0 as a minimum shard state, which + // means that the shard can be allocated to any node + version = Math.max(0, version); + } // -1 version means it does not exists, which is what the API returns, and what we expect to logger.trace("[{}] on node [{}] has version [{}] of shard", - shard, nodeShardState.getNode(), nodeShardState.version()); - shardStates.put(nodeShardState.getNode(), nodeShardState.version()); + shard, nodeShardState.getNode(), version); + shardStates.put(nodeShardState.getNode(), version); } return shardStates; } diff --git a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java index 3fa975a31ed..ff502ea27bc 100644 --- a/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java +++ b/src/main/java/org/elasticsearch/index/settings/IndexDynamicSettingsModule.java @@ -71,6 +71,7 @@ public class IndexDynamicSettingsModule extends AbstractModule { indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_READ); indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_WRITE); indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_METADATA); + indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE); indexDynamicSettings.addDynamicSetting(IndicesTTLService.INDEX_TTL_DISABLE_PURGE); indexDynamicSettings.addDynamicSetting(IndexShard.INDEX_REFRESH_INTERVAL, Validator.TIME); indexDynamicSettings.addDynamicSetting(GatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS); diff --git a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java index c0a63d22922..bbd8babb241 100644 --- a/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java +++ b/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasTests.java @@ -448,4 +448,46 @@ public class IndexWithShadowReplicasTests extends ElasticsearchIntegrationTest { assertThat(hits[2].field("foo").getValue().toString(), equalTo("eggplant")); assertThat(hits[3].field("foo").getValue().toString(), equalTo("foo")); } + + @Test + public void testIndexOnSharedFSRecoversToAnyNode() throws Exception { + Settings nodeSettings = ImmutableSettings.builder() + .put("node.add_id_to_custom_path", false) + .put("node.enable_custom_paths", true) + .build(); + + internalCluster().startNode(nodeSettings); + Path dataPath = createTempDir(); + String IDX = "test"; + + Settings idxSettings = ImmutableSettings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetaData.SETTING_DATA_PATH, dataPath.toAbsolutePath().toString()) + .put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true) + .put(IndexMetaData.SETTING_SHARED_FS_ALLOW_RECOVERY_ON_ANY_NODE, true) + .build(); + + // only one node, so all primaries will end up on node1 + prepareCreate(IDX).setSettings(idxSettings).addMapping("doc", "foo", "type=string,index=not_analyzed").get(); + ensureGreen(IDX); + + // Index some documents + client().prepareIndex(IDX, "doc", "1").setSource("foo", "foo").get(); + client().prepareIndex(IDX, "doc", "2").setSource("foo", "bar").get(); + client().prepareIndex(IDX, "doc", "3").setSource("foo", "baz").get(); + client().prepareIndex(IDX, "doc", "4").setSource("foo", "eggplant").get(); + + // start a second node + internalCluster().startNode(nodeSettings); + + // node1 is master, stop that one, since we only have primaries, + // usually this would mean data loss, but not on shared fs! + internalCluster().stopCurrentMasterNode(); + + ensureGreen(IDX); + refresh(); + SearchResponse resp = client().prepareSearch(IDX).setQuery(matchAllQuery()).addFieldDataField("foo").addSort("foo", SortOrder.ASC).get(); + assertHitCount(resp, 4); + } } From 2ed2c4f884f01e51adf396aac3496bcc0a8f14c8 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 16:27:24 -0400 Subject: [PATCH 13/22] fix permissions bugs --- .pom.xml.swp | Bin 122880 -> 0 bytes pom.xml | 3 +- .../org/elasticsearch/bootstrap/ESPolicy.java | 7 +---- .../org/elasticsearch/bootstrap/Security.java | 15 +++++---- .../elasticsearch/bootstrap/security.policy | 29 +++++++++++++++--- .../bootstrap/SecurityTests.java | 7 +++-- .../test/ElasticsearchTestCase.java | 2 +- .../ElasticsearchTokenStreamTestCase.java | 2 +- ...curityHack.java => SecurityBootstrap.java} | 17 +++++++--- 9 files changed, 55 insertions(+), 27 deletions(-) delete mode 100644 .pom.xml.swp rename src/test/java/org/elasticsearch/test/{SecurityHack.java => SecurityBootstrap.java} (72%) diff --git a/.pom.xml.swp b/.pom.xml.swp deleted file mode 100644 index 08f99ccc7b22f6c6ffba697bf0e7754a2bf92ac1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 122880 zcmeI52b>&7mH!7YCi+PJlWd?ZoFr>zw2~YUqXk*PmXR!-Rt}tv<=L6u-H|4FdPb|Y zEwImI6ORlg9m#~lN9Hh?Xq#|=$zcBQCmqRv;Sv})?*Dz&Rn^@y)6+d0WC`zl^waEA zSG}rwUFp4g^=f>@xtq5-r{-2?_&hL^dG6=VIOm7Oi!v)7mdUhgok~l>6F%c^(Q7Bf zk;hL}1oP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~{G$ubK<01&$P6mJTGn$|1Na)I+FsO1+sWm?j36Ta??E>HUm)`TqqRKxWi9t# z!1rn3JIMC?z%&rw|L;bw-voY&EH7vO^WawG_I=zE zu{YXJ>XfykZ%C8%f_M?BUzDLvrzK~!Pg-0X{773tlP)<2r4EcH8PVrIUmy; z{hNgQWEB5~ZPFkY(I#&96`^!?|4uORUZJ-4MY*_R`&K+cY}j}@8ZhZ^L^{!P(GmN` zhCzJ-DSWAtYlA$jekaH6VeOo<#K_6Ti`8s!t&-lX*q^nrvl81QA_I&K43P*j5Mvxa zMsZx-)g*?UIjQY_d~##>k@Mtee37wwKaB1P^X)*ps08GFeR8|etdC+375dd31xdeI z?$nw&(Va7*C=a%k)_!gWp7a>q{iM-Y{b(@CUh0mXJhGBoqk=SkXb|63yqR=cxvD5E zMmO%*v26#e>I%+?{Qm`H?^VdVqqrk6_`^EqNQXqH! zy$GxYKScJIy?i#HoGw66%R>=ugJ+oY&sz2&k|?pu{gO}sWHOHQd+7h^Q83wEdRJK1R_S8b|T zZEve@@<$HaY(m3PG{WE_NBXt=pzW!!gk&?gcxnd&41H}JlPgKApCqK8qViRDTYaor a+#8%U^88>S6OAyKTAm?dU276+jQ2.1.14 auto true - always + onerror ${project.basedir}/backwards random @@ -584,7 +584,6 @@ -Des.logger.prefix= -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${tests.heapdump.path} - -Djava.security.debug=access:failure,policy ${tests.shuffle} ${tests.verbose} diff --git a/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java b/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java index 5bf7f7ce299..befef74251b 100644 --- a/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java +++ b/src/main/java/org/elasticsearch/bootstrap/ESPolicy.java @@ -19,8 +19,6 @@ package org.elasticsearch.bootstrap; -import org.elasticsearch.common.SuppressForbidden; - import java.net.URI; import java.security.Permission; import java.security.PermissionCollection; @@ -37,17 +35,14 @@ public class ESPolicy extends Policy { final Policy template; final PermissionCollection dynamic; - @SuppressForbidden(reason = "ok") public ESPolicy(PermissionCollection dynamic) throws Exception { URI uri = getClass().getResource(POLICY_RESOURCE).toURI(); - System.out.println("temp=" + System.getProperty("java.io.tmpdir")); this.template = Policy.getInstance("JavaPolicy", new URIParameter(uri)); this.dynamic = dynamic; } - @Override @SuppressForbidden(reason = "ok") + @Override public boolean implies(ProtectionDomain domain, Permission permission) { - //System.out.println("domain=" + domain); return template.implies(domain, permission) || dynamic.implies(permission); } } diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 9ed66af4499..82a6edf752f 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -19,10 +19,10 @@ package org.elasticsearch.bootstrap; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.env.Environment; import java.io.*; -import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.security.Permissions; @@ -34,7 +34,7 @@ import java.security.Policy; * We use a template file (the one we test with), and add additional * permissions based on the environment (data paths, etc) */ -class Security { +public class Security { /** * Initializes securitymanager for the environment @@ -42,7 +42,7 @@ class Security { */ static void configure(Environment environment) throws Exception { // enable security policy: union of template and environment-based paths. - Policy.setPolicy(new ESPolicy(createPermissions(environment))); + Policy.setPolicy(new ESPolicy(createPermissions(environment, true))); // enable security manager System.setSecurityManager(new SecurityManager()); @@ -52,10 +52,13 @@ class Security { } /** returns dynamic Permissions to configured paths */ - static Permissions createPermissions(Environment environment) throws IOException { + static Permissions createPermissions(Environment environment, boolean addTempDir) throws IOException { // TODO: improve test infra so we can reduce permissions where read/write // is not really needed... Permissions policy = new Permissions(); + if (addTempDir) { + addPath(policy, PathUtils.get(System.getProperty("java.io.tmpdir")), "read,readlink,write,delete"); + } addPath(policy, environment.homeFile(), "read,readlink,write,delete"); addPath(policy, environment.configFile(), "read,readlink,write,delete"); addPath(policy, environment.logsFile(), "read,readlink,write,delete"); @@ -71,7 +74,7 @@ class Security { } /** Add access to path (and all files underneath it */ - static void addPath(Permissions policy, Path path, String permissions) throws IOException { + public static void addPath(Permissions policy, Path path, String permissions) throws IOException { // paths may not exist yet Files.createDirectories(path); // add each path twice: once for itself, again for files underneath it @@ -80,7 +83,7 @@ class Security { } /** Simple checks that everything is ok */ - static void selfTest() { + public static void selfTest() { // check we can manipulate temporary files try { Files.delete(Files.createTempFile(null, null)); diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index ac5df915bd2..b10a2949df3 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -21,15 +21,36 @@ // On startup, BootStrap reads environment and adds additional permissions // for configured paths to these. +//// System code permissions: + +// These permissions apply to javac +grant codeBase "file:${java.home}/lib/-" { + permission java.security.AllPermission; +}; + +// These permissions apply to all shared system extensions +grant codeBase "file:${java.home}/jre/lib/ext/-" { + permission java.security.AllPermission; +}; + +// These permissions apply to javac when ${java.home] points at $JAVA_HOME/jre +grant codeBase "file:${java.home}/../lib/-" { + permission java.security.AllPermission; +}; + +// These permissions apply to all shared system extensions when +// ${java.home} points at $JAVA_HOME/jre +grant codeBase "file:${java.home}/lib/ext/-" { + permission java.security.AllPermission; +}; + +//// Everything else: + grant { // system jar resources permission java.io.FilePermission "${java.home}${/}-", "read"; - // temporary files - permission java.io.FilePermission "${java.io.tmpdir}", "read,write"; - permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; - // paths used for running tests // compiled classes permission java.io.FilePermission "${project.basedir}${/}target${/}classes${/}-", "read"; diff --git a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java index edbcafdddbd..01f370b0037 100644 --- a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java +++ b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java @@ -40,11 +40,12 @@ public class SecurityTests extends ElasticsearchTestCase { Settings settings = settingsBuilder.build(); Environment environment = new Environment(settings); - Permissions permissions = Security.createPermissions(environment); + // we pass false to not include temp (or it will grant permissions to everything here) + Permissions permissions = Security.createPermissions(environment, false); // the fake es home assertTrue(permissions.implies(new FilePermission(esHome.toString(), "read"))); - // its parent + // its filesystem root assertFalse(permissions.implies(new FilePermission(path.toString(), "read"))); // some other sibling assertFalse(permissions.implies(new FilePermission(path.resolve("other").toString(), "read"))); @@ -63,7 +64,7 @@ public class SecurityTests extends ElasticsearchTestCase { Settings settings = settingsBuilder.build(); Environment environment = new Environment(settings); - Permissions permissions = Security.createPermissions(environment); + Permissions permissions = Security.createPermissions(environment, false); // check that all directories got permissions: // homefile: this is needed unless we break out rules for "lib" dir. diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java index 02c02b2ed6e..f102087b2b4 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java @@ -93,7 +93,7 @@ import static com.google.common.collect.Lists.newArrayList; public abstract class ElasticsearchTestCase extends LuceneTestCase { static { - SecurityHack.ensureInitialized(); + SecurityBootstrap.ensureInitialized(); } protected final ESLogger logger = Loggers.getLogger(getClass()); diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java index a61fe704867..8374472dba8 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java @@ -43,7 +43,7 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; public abstract class ElasticsearchTokenStreamTestCase extends BaseTokenStreamTestCase { static { - SecurityHack.ensureInitialized(); + SecurityBootstrap.ensureInitialized(); } public static Version randomVersion() { diff --git a/src/test/java/org/elasticsearch/test/SecurityHack.java b/src/test/java/org/elasticsearch/test/SecurityBootstrap.java similarity index 72% rename from src/test/java/org/elasticsearch/test/SecurityHack.java rename to src/test/java/org/elasticsearch/test/SecurityBootstrap.java index 9aa44e4f5da..d5e050a0d3e 100644 --- a/src/test/java/org/elasticsearch/test/SecurityHack.java +++ b/src/test/java/org/elasticsearch/test/SecurityBootstrap.java @@ -22,6 +22,8 @@ package org.elasticsearch.test; import org.apache.lucene.util.TestSecurityManager; import org.elasticsearch.bootstrap.Bootstrap; import org.elasticsearch.bootstrap.ESPolicy; +import org.elasticsearch.bootstrap.Security; +import org.elasticsearch.common.io.PathUtils; import java.security.Permissions; import java.security.Policy; @@ -32,10 +34,13 @@ import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAs * Installs test security manager (ensures it happens regardless of which * test case happens to be first, test ordering, etc). *

- * Note that this is BS, this should be done by the jvm (by passing -Djava.security.manager). - * turning it on/off needs to be the role of maven, not this stuff. + * The idea is to mimic as much as possible what happens with ES in production + * mode (e.g. assign permissions and install security manager the same way) */ -class SecurityHack { +class SecurityBootstrap { + + // TODO: can we share more code with the non-test side here + // without making things complex??? static { // just like bootstrap, initialize natives, then SM @@ -43,8 +48,12 @@ class SecurityHack { // install security manager if requested if (systemPropertyAsBoolean("tests.security.manager", false)) { try { - Policy.setPolicy(new ESPolicy(new Permissions())); + // initialize tmpdir the same exact way as bootstrap. + Permissions perms = new Permissions(); + Security.addPath(perms, PathUtils.get(System.getProperty("java.io.tmpdir")), "read,readlink,write,delete"); + Policy.setPolicy(new ESPolicy(perms)); System.setSecurityManager(new TestSecurityManager()); + Security.selfTest(); } catch (Exception e) { throw new RuntimeException("unable to install test security manager", e); } From 8e8b95faeb29d597ef932d00538f20526c688573 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 16:30:42 -0400 Subject: [PATCH 14/22] fix wrong comment change --- src/test/java/org/elasticsearch/bootstrap/SecurityTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java index 01f370b0037..372bf99466e 100644 --- a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java +++ b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java @@ -45,7 +45,7 @@ public class SecurityTests extends ElasticsearchTestCase { // the fake es home assertTrue(permissions.implies(new FilePermission(esHome.toString(), "read"))); - // its filesystem root + // its parent assertFalse(permissions.implies(new FilePermission(path.toString(), "read"))); // some other sibling assertFalse(permissions.implies(new FilePermission(path.resolve("other").toString(), "read"))); From bd453db411b455bd5556c1e621b8e285a1047b88 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Mon, 4 May 2015 17:00:36 -0400 Subject: [PATCH 15/22] Docs: clarify cluster state handling --- .../elasticsearch/cluster/ClusterState.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/org/elasticsearch/cluster/ClusterState.java b/src/main/java/org/elasticsearch/cluster/ClusterState.java index 4f63d9e00e3..355b3f19875 100644 --- a/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -33,6 +33,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.*; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; +import org.elasticsearch.cluster.service.InternalClusterService; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -46,6 +47,10 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.discovery.Discovery; +import org.elasticsearch.discovery.DiscoveryService; +import org.elasticsearch.discovery.local.LocalDiscovery; +import org.elasticsearch.discovery.zen.publish.PublishClusterStateAction; import java.io.IOException; import java.util.EnumSet; @@ -54,7 +59,29 @@ import java.util.Locale; import java.util.Map; /** + * Represents the current state of the cluster. * + * The cluster state object is immutable with an + * exception of the {@link RoutingNodes} structure, which is built on demand from the {@link RoutingTable}, + * and cluster state {@link #status}, which is updated during cluster state publishing and applying + * processing. The cluster state can be updated only on the master node. All updates are performed by on a + * single thread and controlled by the {@link InternalClusterService}. After every update the + * {@link DiscoveryService#publish} method publishes new version of the cluster state to all other nodes in the + * cluster. The actual publishing mechanism is delegated to the {@link Discovery#publish} method and depends on + * the type of discovery. For example, for local discovery it is implemented by the {@link LocalDiscovery#publish} + * method. In the Zen Discovery it is handled in the {@link PublishClusterStateAction#publish} method. The + * publishing mechanism can be overridden by other discovery. + * + * The cluster state implements the {@link Diffable} interface in order to support publishing of cluster state + * differences instead of the entire state on each change. The publishing mechanism should only send differences + * to a node if this node was present in the previous version of the cluster state. If a node is not present was + * not present in the previous version of the cluster state, such node is unlikely to have the previous cluster + * state version and should be sent a complete version. In order to make sure that the differences are applied to + * correct version of the cluster state, each cluster state version update generates {@link #uuid} that uniquely + * identifies this version of the state. This uuid is verified by the {@link ClusterStateDiff#apply} method to + * makes sure that the correct diffs are applied. If uuids don’t match, the {@link ClusterStateDiff#apply} method + * throws the {@link IncompatibleClusterStateVersionException}, which should cause the publishing mechanism to send + * a full version of the cluster state to the node on which this exception was thrown. */ public class ClusterState implements ToXContent, Diffable { From 072b90296aa0cea3b684cce2cba56ef459096bdc Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 4 May 2015 17:16:08 -0400 Subject: [PATCH 16/22] Use the special java.ext.dirs path instead of 4 tomcat heuristics --- .../elasticsearch/bootstrap/security.policy | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index b10a2949df3..e6500109dc7 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -22,25 +22,9 @@ // for configured paths to these. //// System code permissions: +//// These permissions apply to the JDK itself: -// These permissions apply to javac -grant codeBase "file:${java.home}/lib/-" { - permission java.security.AllPermission; -}; - -// These permissions apply to all shared system extensions -grant codeBase "file:${java.home}/jre/lib/ext/-" { - permission java.security.AllPermission; -}; - -// These permissions apply to javac when ${java.home] points at $JAVA_HOME/jre -grant codeBase "file:${java.home}/../lib/-" { - permission java.security.AllPermission; -}; - -// These permissions apply to all shared system extensions when -// ${java.home} points at $JAVA_HOME/jre -grant codeBase "file:${java.home}/lib/ext/-" { +grant codeBase "file:${{java.ext.dirs}}/*" { permission java.security.AllPermission; }; From 187d79b6df99ee9ff94605b4ecf6417df552aa33 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 4 May 2015 16:23:08 +0200 Subject: [PATCH 17/22] Centralize admin implementations and action execution This change removes the multiple implementations of different admin interfaces and centralizes it with AbstractClient. It also makes sure *all* executions of actions now go through a single AbstractClient#execute method, taking care of copying headers and wrapping listener. This also has the side benefit of removing all the code around differnet possible clients, and removes quite a bit of code (most of the + code is actually removal of generics and such). This change also changes how TransportClient is constructed, requiring a Builder to create it, its a breaking change and its noted in the migration guide. Yea another step towards simplifying the action infra and making it simpler... --- docs/java-api/client.asciidoc | 6 +- docs/reference/migration/migrate_2_0.asciidoc | 20 + .../java/org/elasticsearch/action/Action.java | 4 +- .../action/ActionRequestBuilder.java | 22 +- .../elasticsearch/action/ClientAction.java | 33 - .../action/admin/cluster/ClusterAction.java | 37 - .../cluster/health/ClusterHealthAction.java | 10 +- .../health/ClusterHealthRequestBuilder.java | 14 +- .../hotthreads/NodesHotThreadsAction.java | 10 +- .../NodesHotThreadsRequestBuilder.java | 10 +- .../cluster/node/info/NodesInfoAction.java | 10 +- .../node/info/NodesInfoRequestBuilder.java | 12 +- .../cluster/node/stats/NodesStatsAction.java | 10 +- .../node/stats/NodesStatsRequestBuilder.java | 11 +- .../delete/DeleteRepositoryAction.java | 10 +- .../DeleteRepositoryRequestBuilder.java | 22 +- .../get/GetRepositoriesAction.java | 10 +- .../get/GetRepositoriesRequestBuilder.java | 23 +- .../repositories/put/PutRepositoryAction.java | 10 +- .../put/PutRepositoryRequestBuilder.java | 22 +- .../verify/VerifyRepositoryAction.java | 10 +- .../VerifyRepositoryRequestBuilder.java | 23 +- .../cluster/reroute/ClusterRerouteAction.java | 10 +- .../reroute/ClusterRerouteRequestBuilder.java | 14 +- .../settings/ClusterUpdateSettingsAction.java | 10 +- .../ClusterUpdateSettingsRequestBuilder.java | 14 +- .../shards/ClusterSearchShardsAction.java | 10 +- .../ClusterSearchShardsRequestBuilder.java | 15 +- .../create/CreateSnapshotAction.java | 10 +- .../create/CreateSnapshotRequestBuilder.java | 23 +- .../delete/DeleteSnapshotAction.java | 10 +- .../delete/DeleteSnapshotRequestBuilder.java | 23 +- .../snapshots/get/GetSnapshotsAction.java | 10 +- .../get/GetSnapshotsRequestBuilder.java | 25 +- .../restore/RestoreSnapshotAction.java | 10 +- .../RestoreSnapshotRequestBuilder.java | 32 +- .../status/SnapshotsStatusAction.java | 10 +- .../status/SnapshotsStatusRequestBuilder.java | 22 +- .../cluster/state/ClusterStateAction.java | 10 +- .../state/ClusterStateRequestBuilder.java | 14 +- .../cluster/stats/ClusterStatsAction.java | 10 +- .../stats/ClusterStatsRequestBuilder.java | 12 +- .../tasks/PendingClusterTasksAction.java | 10 +- .../PendingClusterTasksRequestBuilder.java | 14 +- .../action/admin/indices/IndicesAction.java | 34 - .../indices/alias/IndicesAliasesAction.java | 10 +- .../alias/IndicesAliasesRequestBuilder.java | 54 +- .../alias/exists/AliasesExistAction.java | 10 +- .../exists/AliasesExistRequestBuilder.java | 13 +- .../alias/get/BaseAliasesRequestBuilder.java | 8 +- .../indices/alias/get/GetAliasesAction.java | 10 +- .../alias/get/GetAliasesRequestBuilder.java | 13 +- .../admin/indices/analyze/AnalyzeAction.java | 10 +- .../analyze/AnalyzeRequestBuilder.java | 16 +- .../cache/clear/ClearIndicesCacheAction.java | 10 +- .../ClearIndicesCacheRequestBuilder.java | 15 +- .../admin/indices/close/CloseIndexAction.java | 10 +- .../close/CloseIndexRequestBuilder.java | 19 +- .../indices/create/CreateIndexAction.java | 10 +- .../create/CreateIndexRequestBuilder.java | 18 +- .../indices/delete/DeleteIndexAction.java | 10 +- .../delete/DeleteIndexRequestBuilder.java | 16 +- .../exists/indices/IndicesExistsAction.java | 10 +- .../indices/IndicesExistsRequestBuilder.java | 16 +- .../exists/types/TypesExistsAction.java | 10 +- .../types/TypesExistsRequestBuilder.java | 18 +- .../admin/indices/flush/FlushAction.java | 10 +- .../indices/flush/FlushRequestBuilder.java | 14 +- .../admin/indices/get/GetIndexAction.java | 10 +- .../indices/get/GetIndexRequestBuilder.java | 12 +- .../mapping/get/GetFieldMappingsAction.java | 10 +- .../get/GetFieldMappingsRequestBuilder.java | 13 +- .../mapping/get/GetMappingsAction.java | 10 +- .../get/GetMappingsRequestBuilder.java | 12 +- .../indices/mapping/put/PutMappingAction.java | 10 +- .../mapping/put/PutMappingRequestBuilder.java | 16 +- .../admin/indices/open/OpenIndexAction.java | 10 +- .../indices/open/OpenIndexRequestBuilder.java | 19 +- .../indices/optimize/OptimizeAction.java | 10 +- .../optimize/OptimizeRequestBuilder.java | 14 +- .../indices/recovery/RecoveryAction.java | 10 +- .../recovery/RecoveryRequestBuilder.java | 16 +- .../admin/indices/refresh/RefreshAction.java | 10 +- .../refresh/RefreshRequestBuilder.java | 14 +- .../segments/IndicesSegmentsAction.java | 10 +- .../IndicesSegmentsRequestBuilder.java | 16 +- .../settings/get/GetSettingsAction.java | 10 +- .../get/GetSettingsRequestBuilder.java | 16 +- .../settings/put/UpdateSettingsAction.java | 10 +- .../put/UpdateSettingsRequestBuilder.java | 15 +- .../indices/stats/IndicesStatsAction.java | 10 +- .../stats/IndicesStatsRequestBuilder.java | 14 +- .../delete/DeleteIndexTemplateAction.java | 10 +- .../DeleteIndexTemplateRequestBuilder.java | 18 +- .../template/get/GetIndexTemplatesAction.java | 10 +- .../get/GetIndexTemplatesRequestBuilder.java | 18 +- .../template/put/PutIndexTemplateAction.java | 10 +- .../put/PutIndexTemplateRequestBuilder.java | 19 +- .../validate/query/ValidateQueryAction.java | 10 +- .../query/ValidateQueryRequestBuilder.java | 13 +- .../warmer/delete/DeleteWarmerAction.java | 10 +- .../delete/DeleteWarmerRequestBuilder.java | 17 +- .../indices/warmer/get/GetWarmersAction.java | 10 +- .../warmer/get/GetWarmersRequestBuilder.java | 12 +- .../indices/warmer/put/PutWarmerAction.java | 10 +- .../warmer/put/PutWarmerRequestBuilder.java | 19 +- .../elasticsearch/action/bulk/BulkAction.java | 10 +- .../action/bulk/BulkRequestBuilder.java | 14 +- .../action/count/CountAction.java | 10 +- .../action/count/CountRequestBuilder.java | 18 +- .../action/delete/DeleteAction.java | 10 +- .../action/delete/DeleteRequestBuilder.java | 16 +- .../action/exists/ExistsAction.java | 10 +- .../action/exists/ExistsRequestBuilder.java | 15 +- .../action/explain/ExplainAction.java | 10 +- .../action/explain/ExplainRequestBuilder.java | 26 +- .../action/fieldstats/FieldStatsAction.java | 10 +- .../fieldstats/FieldStatsRequestBuilder.java | 14 +- .../elasticsearch/action/get/GetAction.java | 10 +- .../action/get/GetRequestBuilder.java | 29 +- .../action/get/MultiGetAction.java | 10 +- .../action/get/MultiGetRequestBuilder.java | 14 +- .../action/index/IndexAction.java | 10 +- .../action/index/IndexRequestBuilder.java | 18 +- .../delete/DeleteIndexedScriptAction.java | 10 +- .../DeleteIndexedScriptRequestBuilder.java | 14 +- .../get/GetIndexedScriptAction.java | 10 +- .../get/GetIndexedScriptRequestBuilder.java | 15 +- .../put/PutIndexedScriptAction.java | 10 +- .../put/PutIndexedScriptRequestBuilder.java | 34 +- .../action/mlt/MoreLikeThisAction.java | 10 +- .../mlt/MoreLikeThisRequestBuilder.java | 21 +- .../percolate/MultiPercolateAction.java | 10 +- .../MultiPercolateRequestBuilder.java | 16 +- .../action/percolate/PercolateAction.java | 10 +- .../percolate/PercolateRequestBuilder.java | 16 +- .../action/search/ClearScrollAction.java | 10 +- .../search/ClearScrollRequestBuilder.java | 14 +- .../action/search/MultiSearchAction.java | 10 +- .../search/MultiSearchRequestBuilder.java | 16 +- .../action/search/SearchAction.java | 10 +- .../action/search/SearchRequestBuilder.java | 32 +- .../action/search/SearchScrollAction.java | 10 +- .../search/SearchScrollRequestBuilder.java | 18 +- .../action/suggest/SuggestAction.java | 10 +- .../action/suggest/SuggestRequestBuilder.java | 14 +- .../support/ThreadedActionListener.java | 4 + .../BroadcastOperationRequestBuilder.java | 11 +- .../master/AcknowledgedRequestBuilder.java | 15 +- .../MasterNodeOperationRequestBuilder.java | 9 +- ...MasterNodeReadOperationRequestBuilder.java | 9 +- .../info/ClusterInfoRequestBuilder.java | 8 +- .../nodes/NodesOperationRequestBuilder.java | 9 +- ...ardReplicationOperationRequestBuilder.java | 8 +- .../SingleCustomOperationRequestBuilder.java | 8 +- .../InstanceShardOperationRequestBuilder.java | 8 +- .../SingleShardOperationRequestBuilder.java | 8 +- .../termvectors/MultiTermVectorsAction.java | 9 +- .../MultiTermVectorsRequestBuilder.java | 15 +- .../action/termvectors/TermVectorsAction.java | 10 +- .../TermVectorsRequestBuilder.java | 19 +- .../action/update/UpdateAction.java | 10 +- .../action/update/UpdateRequestBuilder.java | 22 +- .../java/org/elasticsearch/client/Client.java | 23 +- .../client/ClusterAdminClient.java | 2 +- .../client/ElasticsearchClient.java | 8 +- .../elasticsearch/client/FilterClient.java | 123 +- .../client/IndicesAdminClient.java | 2 +- .../client/node/NodeAdminClient.java | 54 - .../elasticsearch/client/node/NodeClient.java | 62 +- .../client/node/NodeClientModule.java | 6 - .../client/node/NodeClusterAdminClient.java | 87 -- .../client/node/NodeIndicesAdminClient.java | 87 -- .../client/support/AbstractClient.java | 1146 ++++++++++++++++- .../support/AbstractClusterAdminClient.java | 409 ------ .../support/AbstractIndicesAdminClient.java | 602 --------- .../transport/ClientTransportModule.java | 10 +- .../client/transport/TransportClient.java | 383 ++---- .../support/InternalTransportAdminClient.java | 54 - .../support/InternalTransportClient.java | 117 -- .../InternalTransportClusterAdminClient.java | 99 -- .../InternalTransportIndicesAdminClient.java | 98 -- .../support/TransportProxyClient.java | 62 + .../elasticsearch/rest/BaseRestHandler.java | 77 +- .../action/bulk/BulkIntegrationTests.java | 2 +- .../action/bulk/BulkProcessorTests.java | 2 +- .../count/CountRequestBuilderTests.java | 16 +- .../search/SearchRequestBuilderTests.java | 16 +- .../termvectors/MultiTermVectorsTests.java | 2 +- .../ClusterStateBackwardsCompatTests.java | 2 +- .../NodesStatsBasicBackwardsCompatTests.java | 4 +- ...sportClientBackwardsCompatibilityTest.java | 2 +- .../client/node/NodeClientHeadersTests.java | 7 +- .../InternalTransportClientTests.java | 342 ----- .../TransportClientHeadersTests.java | 8 +- .../transport/TransportClientRetryTests.java | 2 +- .../transport/TransportClientTests.java | 2 +- .../cluster/NoMasterNodeTests.java | 2 +- .../HeadersAndContextCopyClientTests.java | 311 ++--- .../expression/ExpressionScriptTests.java | 9 +- .../stresstest/client/ClientFailover.java | 2 +- .../ManyIndicesRemoteStressTest.java | 2 +- .../test/CompositeTestCluster.java | 32 +- .../org/elasticsearch/test/ExternalNode.java | 3 +- .../test/ExternalTestCluster.java | 2 +- .../test/InternalTestCluster.java | 2 +- .../hamcrest/ElasticsearchAssertions.java | 12 +- ...ttyTransportMultiPortIntegrationTests.java | 2 +- 208 files changed, 2341 insertions(+), 4216 deletions(-) delete mode 100644 src/main/java/org/elasticsearch/action/ClientAction.java delete mode 100644 src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java delete mode 100644 src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java delete mode 100644 src/main/java/org/elasticsearch/client/node/NodeAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java delete mode 100644 src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java delete mode 100644 src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java create mode 100644 src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java delete mode 100644 src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java diff --git a/docs/java-api/client.asciidoc b/docs/java-api/client.asciidoc index be946673491..0dccd485c2a 100644 --- a/docs/java-api/client.asciidoc +++ b/docs/java-api/client.asciidoc @@ -134,7 +134,7 @@ be "two hop" operations). -------------------------------------------------- // on startup -Client client = new TransportClient() +Client client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress("host1", 9300)) .addTransportAddress(new InetSocketTransportAddress("host2", 9300)); @@ -150,7 +150,7 @@ Note that you have to set the cluster name if you use one different than -------------------------------------------------- Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", "myClusterName").build(); -Client client = new TransportClient(settings); +Client client = TransportClient.builder().settings(settings).build(); //Add transport addresses and do something with the client... -------------------------------------------------- @@ -166,7 +166,7 @@ used will be the ones that the other nodes were started with (the -------------------------------------------------- Settings settings = ImmutableSettings.settingsBuilder() .put("client.transport.sniff", true).build(); -TransportClient client = new TransportClient(settings); +TransportClient client = TransportClient.builder().settings(settings).build(); -------------------------------------------------- Other transport client level settings include: diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index d9409406742..9f0cefbd370 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -463,3 +463,23 @@ The `index.store.distributor` setting has also been removed. The parameter `indices.analysis.hunspell.dictionary.location` has been removed, and `/hunspell` is always used. + +=== Java API Transport API construction + +The `TransportClient` construction code has changed, it now uses the builder +pattern. Instead of using: + +[source,java] +-------------------------------------------------- +Settings settings = ImmutableSettings.settingsBuilder() + .put("cluster.name", "myClusterName").build(); +Client client = new TransportClient(settings); + +Use: + +[source,java] +-------------------------------------------------- +Settings settings = ImmutableSettings.settingsBuilder() + .put("cluster.name", "myClusterName").build(); +Client client = TransportClient.builder().settings(settings).build(); +-------------------------------------------------- diff --git a/src/main/java/org/elasticsearch/action/Action.java b/src/main/java/org/elasticsearch/action/Action.java index f45e525c58f..51e3f5440ea 100644 --- a/src/main/java/org/elasticsearch/action/Action.java +++ b/src/main/java/org/elasticsearch/action/Action.java @@ -24,7 +24,7 @@ import org.elasticsearch.client.ElasticsearchClient; /** * Base action. Supports building the Request through a RequestBuilder. */ -public abstract class Action, Client extends ElasticsearchClient> +public abstract class Action> extends GenericAction { protected Action(String name) { @@ -34,5 +34,5 @@ public abstract class Action { +public abstract class ActionRequestBuilder> { + protected final Action action; protected final Request request; private final ThreadPool threadPool; - protected final Client client; + protected final ElasticsearchClient client; - protected ActionRequestBuilder(Client client, Request request) { + protected ActionRequestBuilder(ElasticsearchClient client, Action action, Request request) { + Preconditions.checkNotNull(action, "action must not be null"); + this.action = action; this.request = request; this.client = client; threadPool = client.threadPool(); @@ -81,9 +86,14 @@ public abstract class ActionRequestBuilder listener) { - doExecute(listener); + public final void execute(ActionListener listener) { + client.execute(action, beforeExecute(request), listener); } - protected abstract void doExecute(ActionListener listener); + /** + * A callback to additionally process the request before its executed + */ + protected Request beforeExecute(Request request) { + return request; + } } diff --git a/src/main/java/org/elasticsearch/action/ClientAction.java b/src/main/java/org/elasticsearch/action/ClientAction.java deleted file mode 100644 index a38b8dad1e0..00000000000 --- a/src/main/java/org/elasticsearch/action/ClientAction.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.Client; - -/** - * Action (used with {@link Client} API). - */ -public abstract class ClientAction> - extends Action { - - protected ClientAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java deleted file mode 100644 index 91ce66543d4..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/cluster/ClusterAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elasticsearch 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; - -import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.client.ClusterAdminClient; - -/** - * Cluster action (used with {@link ClusterAdminClient} API). - */ -public abstract class ClusterAction> - extends Action { - - protected ClusterAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java index b8ec1c70d07..9770b05bae0 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.health; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterHealthAction extends ClusterAction { +public class ClusterHealthAction extends Action { public static final ClusterHealthAction INSTANCE = new ClusterHealthAction(); public static final String NAME = "cluster:monitor/health"; @@ -39,7 +39,7 @@ public class ClusterHealthAction extends ClusterAction { +public class ClusterHealthRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterHealthRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterHealthRequest()); + public ClusterHealthRequestBuilder(ElasticsearchClient client, ClusterHealthAction action) { + super(client, action, new ClusterHealthRequest()); } public ClusterHealthRequestBuilder setIndices(String... indices) { @@ -86,9 +85,4 @@ public class ClusterHealthRequestBuilder extends MasterNodeReadOperationRequestB request.waitForEvents(waitForEvents); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.health(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java index 64b3c3cfcd8..7010b4cb143 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.hotthreads; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesHotThreadsAction extends ClusterAction { +public class NodesHotThreadsAction extends Action { public static final NodesHotThreadsAction INSTANCE = new NodesHotThreadsAction(); public static final String NAME = "cluster:monitor/nodes/hot_threads"; @@ -39,7 +39,7 @@ public class NodesHotThreadsAction extends ClusterAction { - public NodesHotThreadsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesHotThreadsRequest()); + public NodesHotThreadsRequestBuilder(ElasticsearchClient client, NodesHotThreadsAction action) { + super(client, action, new NodesHotThreadsRequest()); } public NodesHotThreadsRequestBuilder setThreads(int threads) { @@ -51,9 +52,4 @@ public class NodesHotThreadsRequestBuilder extends NodesOperationRequestBuilder< request.interval(interval); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.nodesHotThreads(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java index 47d6fae7616..adfd9481e74 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.info; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesInfoAction extends ClusterAction { +public class NodesInfoAction extends Action { public static final NodesInfoAction INSTANCE = new NodesInfoAction(); public static final String NAME = "cluster:monitor/nodes/info"; @@ -39,7 +39,7 @@ public class NodesInfoAction extends ClusterAction { - public NodesInfoRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesInfoRequest()); + public NodesInfoRequestBuilder(ElasticsearchClient client, NodesInfoAction action) { + super(client, action, new NodesInfoRequest()); } /** @@ -119,9 +118,4 @@ public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder listener) { - client.nodesInfo(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java index 252eb1cc1db..3c322e3335e 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.node.stats; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class NodesStatsAction extends ClusterAction { +public class NodesStatsAction extends Action { public static final NodesStatsAction INSTANCE = new NodesStatsAction(); public static final String NAME = "cluster:monitor/nodes/stats"; @@ -39,7 +39,7 @@ public class NodesStatsAction extends ClusterAction { - public NodesStatsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new NodesStatsRequest()); + public NodesStatsRequestBuilder(ElasticsearchClient client, NodesStatsAction action) { + super(client, action, new NodesStatsRequest()); } /** @@ -133,9 +133,4 @@ public class NodesStatsRequestBuilder extends NodesOperationRequestBuilder listener) { - client.nodesStats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java index 2a9be85e37e..83166753b27 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/delete/DeleteRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.delete; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Unregister repository action */ -public class DeleteRepositoryAction extends ClusterAction { +public class DeleteRepositoryAction extends Action { public static final DeleteRepositoryAction INSTANCE = new DeleteRepositoryAction(); public static final String NAME = "cluster:admin/repository/delete"; @@ -40,8 +40,8 @@ public class DeleteRepositoryAction extends ClusterAction { +public class DeleteRepositoryRequestBuilder extends AcknowledgedRequestBuilder { /** * Constructs unregister repository request builder - * - * @param clusterAdminClient cluster admin client */ - public DeleteRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new DeleteRepositoryRequest()); + public DeleteRepositoryRequestBuilder(ElasticsearchClient client, DeleteRepositoryAction action) { + super(client, action, new DeleteRepositoryRequest()); } /** * Constructs unregister repository request builder with specified repository name - * - * @param clusterAdminClient cluster adming client */ - public DeleteRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new DeleteRepositoryRequest(name)); + public DeleteRepositoryRequestBuilder(ElasticsearchClient client, DeleteRepositoryAction action, String name) { + super(client, action, new DeleteRepositoryRequest(name)); } /** @@ -55,9 +50,4 @@ public class DeleteRepositoryRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.deleteRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java index befe51fdeb5..c0d1d1bcde7 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.get; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Get repositories action */ -public class GetRepositoriesAction extends ClusterAction { +public class GetRepositoriesAction extends Action { public static final GetRepositoriesAction INSTANCE = new GetRepositoriesAction(); public static final String NAME = "cluster:admin/repository/get"; @@ -40,8 +40,8 @@ public class GetRepositoriesAction extends ClusterAction { +public class GetRepositoriesRequestBuilder extends MasterNodeReadOperationRequestBuilder { /** * Creates new get repository request builder - * - * @param clusterAdminClient cluster admin client */ - public GetRepositoriesRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new GetRepositoriesRequest()); + public GetRepositoriesRequestBuilder(ElasticsearchClient client, GetRepositoriesAction action) { + super(client, action, new GetRepositoriesRequest()); } /** * Creates new get repository request builder - * - * @param clusterAdminClient cluster admin client - * @param repositories list of repositories to get */ - public GetRepositoriesRequestBuilder(ClusterAdminClient clusterAdminClient, String... repositories) { - super(clusterAdminClient, new GetRepositoriesRequest(repositories)); + public GetRepositoriesRequestBuilder(ElasticsearchClient client, GetRepositoriesAction action, String... repositories) { + super(client, action, new GetRepositoriesRequest(repositories)); } /** @@ -69,9 +63,4 @@ public class GetRepositoriesRequestBuilder extends MasterNodeReadOperationReques request.repositories(ObjectArrays.concat(request.repositories(), repositories, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getRepositories(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java index 30e9733663c..f3f8b51eeea 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/put/PutRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.put; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Register repository action */ -public class PutRepositoryAction extends ClusterAction { +public class PutRepositoryAction extends Action { public static final PutRepositoryAction INSTANCE = new PutRepositoryAction(); public static final String NAME = "cluster:admin/repository/put"; @@ -40,8 +40,8 @@ public class PutRepositoryAction extends ClusterAction { +public class PutRepositoryRequestBuilder extends AcknowledgedRequestBuilder { /** * Constructs register repository request - * - * @param clusterAdminClient cluster admin client */ - public PutRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new PutRepositoryRequest()); + public PutRepositoryRequestBuilder(ElasticsearchClient client, PutRepositoryAction action) { + super(client, action, new PutRepositoryRequest()); } /** * Constructs register repository request for the repository with a given name - * - * @param clusterAdminClient cluster admin client - * @param name repository name */ - public PutRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new PutRepositoryRequest(name)); + public PutRepositoryRequestBuilder(ElasticsearchClient client, PutRepositoryAction action, String name) { + super(client, action, new PutRepositoryRequest(name)); } /** @@ -126,9 +121,4 @@ public class PutRepositoryRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java index 25f1b5004cd..d52945ac28c 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.repositories.verify; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Unregister repository action */ -public class VerifyRepositoryAction extends ClusterAction { +public class VerifyRepositoryAction extends Action { public static final VerifyRepositoryAction INSTANCE = new VerifyRepositoryAction(); public static final String NAME = "cluster:admin/repository/verify"; @@ -40,8 +40,8 @@ public class VerifyRepositoryAction extends ClusterAction { +public class VerifyRepositoryRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs unregister repository request builder - * - * @param clusterAdminClient cluster admin client */ - public VerifyRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new VerifyRepositoryRequest()); + public VerifyRepositoryRequestBuilder(ElasticsearchClient client, VerifyRepositoryAction action) { + super(client, action, new VerifyRepositoryRequest()); } /** * Constructs unregister repository request builder with specified repository name - * - * @param clusterAdminClient cluster adming client */ - public VerifyRepositoryRequestBuilder(ClusterAdminClient clusterAdminClient, String name) { - super(clusterAdminClient, new VerifyRepositoryRequest(name)); + public VerifyRepositoryRequestBuilder(ElasticsearchClient client, VerifyRepositoryAction action, String name) { + super(client, action, new VerifyRepositoryRequest(name)); } /** @@ -56,9 +50,4 @@ public class VerifyRepositoryRequestBuilder extends MasterNodeOperationRequestBu request.name(name); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.verifyRepository(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java index d2fc5a313ec..7aa6dc25cdc 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.reroute; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterRerouteAction extends ClusterAction { +public class ClusterRerouteAction extends Action { public static final ClusterRerouteAction INSTANCE = new ClusterRerouteAction(); public static final String NAME = "cluster:admin/reroute"; @@ -39,7 +39,7 @@ public class ClusterRerouteAction extends ClusterAction { +public class ClusterRerouteRequestBuilder extends AcknowledgedRequestBuilder { - public ClusterRerouteRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterRerouteRequest()); + public ClusterRerouteRequestBuilder(ElasticsearchClient client, ClusterRerouteAction action) { + super(client, action, new ClusterRerouteRequest()); } /** @@ -68,9 +67,4 @@ public class ClusterRerouteRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.reroute(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java index 8e8a6bdb365..15b3e70dd04 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/settings/ClusterUpdateSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.settings; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterUpdateSettingsAction extends ClusterAction { +public class ClusterUpdateSettingsAction extends Action { public static final ClusterUpdateSettingsAction INSTANCE = new ClusterUpdateSettingsAction(); public static final String NAME = "cluster:admin/settings/update"; @@ -39,7 +39,7 @@ public class ClusterUpdateSettingsAction extends ClusterAction { +public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder { - public ClusterUpdateSettingsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterUpdateSettingsRequest()); + public ClusterUpdateSettingsRequestBuilder(ElasticsearchClient client, ClusterUpdateSettingsAction action) { + super(client, action, new ClusterUpdateSettingsRequest()); } /** @@ -98,9 +97,4 @@ public class ClusterUpdateSettingsRequestBuilder extends AcknowledgedRequestBuil request.persistentSettings(settings); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.updateSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java index 15a218fc1f1..28f7557a2e2 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.shards; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterSearchShardsAction extends ClusterAction { +public class ClusterSearchShardsAction extends Action { public static final ClusterSearchShardsAction INSTANCE = new ClusterSearchShardsAction(); public static final String NAME = "indices:admin/shards/search_shards"; @@ -39,7 +39,7 @@ public class ClusterSearchShardsAction extends ClusterAction { +public class ClusterSearchShardsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterSearchShardsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterSearchShardsRequest()); + public ClusterSearchShardsRequestBuilder(ElasticsearchClient client, ClusterSearchShardsAction action) { + super(client, action, new ClusterSearchShardsRequest()); } /** @@ -83,10 +82,4 @@ public class ClusterSearchShardsRequestBuilder extends MasterNodeReadOperationRe request().indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.searchShards(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java index 0bbeb2d5279..9bdcd2c96bd 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.create; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Create snapshot action */ -public class CreateSnapshotAction extends ClusterAction { +public class CreateSnapshotAction extends Action { public static final CreateSnapshotAction INSTANCE = new CreateSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/create"; @@ -40,8 +40,8 @@ public class CreateSnapshotAction extends ClusterAction { +public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs a new create snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public CreateSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new CreateSnapshotRequest()); + public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action) { + super(client, action, new CreateSnapshotRequest()); } /** * Constructs a new create snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository repository name - * @param snapshot snapshot name */ - public CreateSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String snapshot) { - super(clusterAdminClient, new CreateSnapshotRequest(repository, snapshot)); + public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action, String repository, String snapshot) { + super(client, action, new CreateSnapshotRequest(repository, snapshot)); } /** @@ -184,9 +178,4 @@ public class CreateSnapshotRequestBuilder extends MasterNodeOperationRequestBuil request.includeGlobalState(includeGlobalState); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.createSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java index 3abf3937627..8a794a0c8ff 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/DeleteSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.delete; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Delete snapshot action */ -public class DeleteSnapshotAction extends ClusterAction { +public class DeleteSnapshotAction extends Action { public static final DeleteSnapshotAction INSTANCE = new DeleteSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/delete"; @@ -40,8 +40,8 @@ public class DeleteSnapshotAction extends ClusterAction { +public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs delete snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public DeleteSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new DeleteSnapshotRequest()); + public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action) { + super(client, action, new DeleteSnapshotRequest()); } /** * Constructs delete snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository repository name - * @param snapshot snapshot name */ - public DeleteSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String snapshot) { - super(clusterAdminClient, new DeleteSnapshotRequest(repository, snapshot)); + public DeleteSnapshotRequestBuilder(ElasticsearchClient client, DeleteSnapshotAction action, String repository, String snapshot) { + super(client, action, new DeleteSnapshotRequest(repository, snapshot)); } /** @@ -69,9 +63,4 @@ public class DeleteSnapshotRequestBuilder extends MasterNodeOperationRequestBuil request.snapshot(snapshot); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java index 0613b3776c8..7d2cafb9ced 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.get; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Get snapshots action */ -public class GetSnapshotsAction extends ClusterAction { +public class GetSnapshotsAction extends Action { public static final GetSnapshotsAction INSTANCE = new GetSnapshotsAction(); public static final String NAME = "cluster:admin/snapshot/get"; @@ -40,8 +40,8 @@ public class GetSnapshotsAction extends ClusterAction { +public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs the new get snapshot request - * - * @param clusterAdminClient cluster admin client */ - public GetSnapshotsRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new GetSnapshotsRequest()); + public GetSnapshotsRequestBuilder(ElasticsearchClient client, GetSnapshotsAction action) { + super(client, action, new GetSnapshotsRequest()); } /** * Constructs the new get snapshot request with specified repository - * - * @param clusterAdminClient cluster admin client - * @param repository repository name */ - public GetSnapshotsRequestBuilder(ClusterAdminClient clusterAdminClient, String repository) { - super(clusterAdminClient, new GetSnapshotsRequest(repository)); + public GetSnapshotsRequestBuilder(ElasticsearchClient client, GetSnapshotsAction action, String repository) { + super(client, action, new GetSnapshotsRequest(repository)); } /** @@ -76,7 +70,7 @@ public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilde * @return this builder */ public GetSnapshotsRequestBuilder setCurrentSnapshot() { - request.snapshots(new String[] {GetSnapshotsRequest.CURRENT_SNAPSHOT}); + request.snapshots(new String[]{GetSnapshotsRequest.CURRENT_SNAPSHOT}); return this; } @@ -90,9 +84,4 @@ public class GetSnapshotsRequestBuilder extends MasterNodeOperationRequestBuilde request.snapshots(ObjectArrays.concat(request.snapshots(), snapshots, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getSnapshots(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java index 3e7cbb5e602..3836d2d7fa5 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.restore; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Restore snapshot action */ -public class RestoreSnapshotAction extends ClusterAction { +public class RestoreSnapshotAction extends Action { public static final RestoreSnapshotAction INSTANCE = new RestoreSnapshotAction(); public static final String NAME = "cluster:admin/snapshot/restore"; @@ -40,8 +40,8 @@ public class RestoreSnapshotAction extends ClusterAction { +public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs new restore snapshot request builder - * - * @param clusterAdminClient cluster admin client */ - public RestoreSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new RestoreSnapshotRequest()); + public RestoreSnapshotRequestBuilder(ElasticsearchClient client, RestoreSnapshotAction action) { + super(client, action, new RestoreSnapshotRequest()); } /** * Constructs new restore snapshot request builder with specified repository and snapshot names - * - * @param clusterAdminClient cluster admin client - * @param repository reposiory name - * @param name snapshot name */ - public RestoreSnapshotRequestBuilder(ClusterAdminClient clusterAdminClient, String repository, String name) { - super(clusterAdminClient, new RestoreSnapshotRequest(repository, name)); + public RestoreSnapshotRequestBuilder(ElasticsearchClient client, RestoreSnapshotAction action, String repository, String name) { + super(client, action, new RestoreSnapshotRequest(repository, name)); } @@ -233,6 +226,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore + * * @param settings index settings * @return this builder */ @@ -243,7 +237,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param settings index settings * @return this builder */ @@ -254,7 +248,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param source index settings * @return this builder */ @@ -265,7 +259,7 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui /** * Sets index settings that should be added or replaced during restore - + * * @param source index settings * @return this builder */ @@ -290,10 +284,4 @@ public class RestoreSnapshotRequestBuilder extends MasterNodeOperationRequestBui request.ignoreIndexSettings(ignoreIndexSettings); return this; } - - - @Override - protected void doExecute(ActionListener listener) { - client.restoreSnapshot(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java index adfea744547..0a2d26198ec 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.cluster.snapshots.status; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Snapshots status action */ -public class SnapshotsStatusAction extends ClusterAction { +public class SnapshotsStatusAction extends Action { public static final SnapshotsStatusAction INSTANCE = new SnapshotsStatusAction(); public static final String NAME = "cluster:admin/snapshot/status"; @@ -40,8 +40,8 @@ public class SnapshotsStatusAction extends ClusterAction { +public class SnapshotsStatusRequestBuilder extends MasterNodeOperationRequestBuilder { /** * Constructs the new snapshotstatus request - * - * @param clusterAdminClient cluster admin client */ - public SnapshotsStatusRequestBuilder(ClusterAdminClient clusterAdminClient) { - super(clusterAdminClient, new SnapshotsStatusRequest()); + public SnapshotsStatusRequestBuilder(ElasticsearchClient client, SnapshotsStatusAction action) { + super(client, action, new SnapshotsStatusRequest()); } /** * Constructs the new snapshot status request with specified repository - * - * @param clusterAdminClient cluster admin client - * @param repository repository name */ - public SnapshotsStatusRequestBuilder(ClusterAdminClient clusterAdminClient, String repository) { - super(clusterAdminClient, new SnapshotsStatusRequest(repository)); + public SnapshotsStatusRequestBuilder(ElasticsearchClient client, SnapshotsStatusAction action, String repository) { + super(client, action, new SnapshotsStatusRequest(repository)); } /** @@ -80,9 +75,4 @@ public class SnapshotsStatusRequestBuilder extends MasterNodeOperationRequestBui request.snapshots(ObjectArrays.concat(request.snapshots(), snapshots, String.class)); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.snapshotsStatus(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java index a339129ec09..70786f99e0d 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.state; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterStateAction extends ClusterAction { +public class ClusterStateAction extends Action { public static final ClusterStateAction INSTANCE = new ClusterStateAction(); public static final String NAME = "cluster:monitor/state"; @@ -39,7 +39,7 @@ public class ClusterStateAction extends ClusterAction { +public class ClusterStateRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public ClusterStateRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterStateRequest()); + public ClusterStateRequestBuilder(ElasticsearchClient client, ClusterStateAction action) { + super(client, action, new ClusterStateRequest()); } /** @@ -94,9 +93,4 @@ public class ClusterStateRequestBuilder extends MasterNodeReadOperationRequestBu request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.state(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java index 34bddac0234..1cddf37ad31 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.stats; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClusterStatsAction extends ClusterAction { +public class ClusterStatsAction extends Action { public static final ClusterStatsAction INSTANCE = new ClusterStatsAction(); public static final String NAME = "cluster:monitor/stats"; @@ -39,7 +39,7 @@ public class ClusterStatsAction extends ClusterAction { - public ClusterStatsRequestBuilder(ClusterAdminClient clusterClient) { - super(clusterClient, new ClusterStatsRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.clusterStats(request, listener); + public ClusterStatsRequestBuilder(ElasticsearchClient client, ClusterStatsAction action) { + super(client, action, new ClusterStatsRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java b/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java index b074d054e60..1e3eb3f6e81 100644 --- a/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java +++ b/src/main/java/org/elasticsearch/action/admin/cluster/tasks/PendingClusterTasksAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.cluster.tasks; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PendingClusterTasksAction extends ClusterAction { +public class PendingClusterTasksAction extends Action { public static final PendingClusterTasksAction INSTANCE = new PendingClusterTasksAction(); public static final String NAME = "cluster:monitor/task"; @@ -39,7 +39,7 @@ public class PendingClusterTasksAction extends ClusterAction { +public class PendingClusterTasksRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public PendingClusterTasksRequestBuilder(ClusterAdminClient client) { - super(client, new PendingClusterTasksRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.pendingClusterTasks(request, listener); + public PendingClusterTasksRequestBuilder(ElasticsearchClient client, PendingClusterTasksAction action) { + super(client, action, new PendingClusterTasksRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java deleted file mode 100644 index 4fae668f77e..00000000000 --- a/src/main/java/org/elasticsearch/action/admin/indices/IndicesAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch 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.*; -import org.elasticsearch.client.IndicesAdminClient; - -/** - * Indices action (used with {@link IndicesAdminClient} API). - */ -public abstract class IndicesAction> - extends Action { - - protected IndicesAction(String name) { - super(name); - } -} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java index c8dea4db2b9..3cf0ca574fb 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.alias; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesAliasesAction extends IndicesAction { +public class IndicesAliasesAction extends Action { public static final IndicesAliasesAction INSTANCE = new IndicesAliasesAction(); public static final String NAME = "indices:admin/aliases"; @@ -39,7 +39,7 @@ public class IndicesAliasesAction extends IndicesAction { +public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder { - public IndicesAliasesRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesAliasesRequest()); + public IndicesAliasesRequestBuilder(ElasticsearchClient client, IndicesAliasesAction action) { + super(client, action, new IndicesAliasesRequest()); } - + /** * Adds an alias to the index. * - * @param index The index - * @param alias The alias + * @param index The index + * @param alias The alias */ public IndicesAliasesRequestBuilder addAlias(String index, String alias) { request.addAlias(alias, index); return this; } - + /** * Adds an alias to the index. * * @param indices The indices - * @param alias The alias + * @param alias The alias */ public IndicesAliasesRequestBuilder addAlias(String[] indices, String alias) { request.addAlias(alias, indices); @@ -71,32 +70,32 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder filter) { request.addAlias(alias, filter, indices); return this; } - + /** * Adds an alias to the index. * @@ -120,11 +119,11 @@ public class IndicesAliasesRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.aliases(request, listener); - } - + /** * Adds an alias action to the request. * diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java index 18d281eb99a..23dc1e13a56 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/exists/AliasesExistAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.alias.exists; -import org.elasticsearch.action.admin.indices.IndicesAction; +import org.elasticsearch.action.Action; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class AliasesExistAction extends IndicesAction { +public class AliasesExistAction extends Action { public static final AliasesExistAction INSTANCE = new AliasesExistAction(); public static final String NAME = "indices:admin/aliases/exists"; @@ -35,8 +35,8 @@ public class AliasesExistAction extends IndicesAction { - public AliasesExistRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, aliases); + public AliasesExistRequestBuilder(ElasticsearchClient client, AliasesExistAction action, String... aliases) { + super(client, action, aliases); } - - @Override - protected void doExecute(ActionListener listener) { - client.aliasesExist(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java index 312a3f65d14..da7c505771c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/BaseAliasesRequestBuilder.java @@ -20,17 +20,19 @@ package org.elasticsearch.action.admin.indices.alias.get; import com.google.common.collect.ObjectArrays; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class BaseAliasesRequestBuilder> extends MasterNodeReadOperationRequestBuilder { +public abstract class BaseAliasesRequestBuilder> extends MasterNodeReadOperationRequestBuilder { - public BaseAliasesRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, new GetAliasesRequest(aliases)); + public BaseAliasesRequestBuilder(ElasticsearchClient client, Action action, String... aliases) { + super(client, action, new GetAliasesRequest(aliases)); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java index fd8acb8beba..188f72e1e34 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/alias/get/GetAliasesAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.alias.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetAliasesAction extends IndicesAction { +public class GetAliasesAction extends Action { public static final GetAliasesAction INSTANCE = new GetAliasesAction(); public static final String NAME = "indices:admin/aliases/get"; @@ -34,8 +34,8 @@ public class GetAliasesAction extends IndicesAction { - public GetAliasesRequestBuilder(IndicesAdminClient client, String... aliases) { - super(client, aliases); + public GetAliasesRequestBuilder(ElasticsearchClient client, GetAliasesAction action, String... aliases) { + super(client, action, aliases); } - - @Override - protected void doExecute(ActionListener listener) { - client.getAliases(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java index b2843e71099..b29ba7507f8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.analyze; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class AnalyzeAction extends IndicesAction { +public class AnalyzeAction extends Action { public static final AnalyzeAction INSTANCE = new AnalyzeAction(); public static final String NAME = "indices:admin/analyze"; @@ -39,7 +39,7 @@ public class AnalyzeAction extends IndicesAction { - public AnalyzeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new AnalyzeRequest()); + public AnalyzeRequestBuilder(ElasticsearchClient client, AnalyzeAction action) { + super(client, action, new AnalyzeRequest()); } - public AnalyzeRequestBuilder(IndicesAdminClient indicesClient, String index, String text) { - super(indicesClient, new AnalyzeRequest(index).text(text)); + public AnalyzeRequestBuilder(ElasticsearchClient client, AnalyzeAction action, String index, String text) { + super(client, action, new AnalyzeRequest(index).text(text)); } /** @@ -87,9 +86,4 @@ public class AnalyzeRequestBuilder extends SingleCustomOperationRequestBuilder listener) { - client.analyze(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java index 16adc9cb1a4..0880c66802e 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/cache/clear/ClearIndicesCacheAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.cache.clear; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClearIndicesCacheAction extends IndicesAction { +public class ClearIndicesCacheAction extends Action { public static final ClearIndicesCacheAction INSTANCE = new ClearIndicesCacheAction(); public static final String NAME = "indices:admin/cache/clear"; @@ -39,7 +39,7 @@ public class ClearIndicesCacheAction extends IndicesAction { +public class ClearIndicesCacheRequestBuilder extends BroadcastOperationRequestBuilder { - public ClearIndicesCacheRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new ClearIndicesCacheRequest()); + public ClearIndicesCacheRequestBuilder(ElasticsearchClient client, ClearIndicesCacheAction action) { + super(client, action, new ClearIndicesCacheRequest()); } public ClearIndicesCacheRequestBuilder setFilterCache(boolean filterCache) { @@ -57,9 +55,4 @@ public class ClearIndicesCacheRequestBuilder extends BroadcastOperationRequestBu request.idCache(idCache); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.clearCache(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java index 01e6c3e37a3..fcb38b01da5 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.close; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CloseIndexAction extends IndicesAction { +public class CloseIndexAction extends Action { public static final CloseIndexAction INSTANCE = new CloseIndexAction(); public static final String NAME = "indices:admin/close"; @@ -39,7 +39,7 @@ public class CloseIndexAction extends IndicesAction { +public class CloseIndexRequestBuilder extends AcknowledgedRequestBuilder { - public CloseIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CloseIndexRequest()); + public CloseIndexRequestBuilder(ElasticsearchClient client, CloseIndexAction action) { + super(client, action, new CloseIndexRequest()); } - public CloseIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new CloseIndexRequest(indices)); + public CloseIndexRequestBuilder(ElasticsearchClient client, CloseIndexAction action, String... indices) { + super(client, action, new CloseIndexRequest(indices)); } /** * Sets the indices to be closed + * * @param indices the indices to be closed * @return the request itself */ @@ -58,9 +58,4 @@ public class CloseIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.close(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java index 520b3d1a0a2..aa3d3ac92ad 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.create; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CreateIndexAction extends IndicesAction { +public class CreateIndexAction extends Action { public static final CreateIndexAction INSTANCE = new CreateIndexAction(); public static final String NAME = "indices:admin/create"; @@ -39,7 +39,7 @@ public class CreateIndexAction extends IndicesAction { +public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder { - public CreateIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new CreateIndexRequest()); + public CreateIndexRequestBuilder(ElasticsearchClient client, CreateIndexAction action) { + super(client, action, new CreateIndexRequest()); } - public CreateIndexRequestBuilder(IndicesAdminClient indicesClient, String index) { - super(indicesClient, new CreateIndexRequest(index)); + public CreateIndexRequestBuilder(ElasticsearchClient client, CreateIndexAction action, String index) { + super(client, action, new CreateIndexRequest(index)); } /** @@ -244,9 +243,4 @@ public class CreateIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.create(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java index ac9d5eba86f..135aacc197b 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/delete/DeleteIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexAction extends IndicesAction { +public class DeleteIndexAction extends Action { public static final DeleteIndexAction INSTANCE = new DeleteIndexAction(); public static final String NAME = "indices:admin/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexAction extends IndicesAction { +public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder { - public DeleteIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new DeleteIndexRequest(indices)); + public DeleteIndexRequestBuilder(ElasticsearchClient client, DeleteIndexAction action, String... indices) { + super(client, action, new DeleteIndexRequest(indices)); } /** @@ -54,16 +53,11 @@ public class DeleteIndexRequestBuilder extends MasterNodeOperationRequestBuilder /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public DeleteIndexRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.delete(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java index 734e20e407f..b9bfa00d7a2 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.exists.indices; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesExistsAction extends IndicesAction { +public class IndicesExistsAction extends Action { public static final IndicesExistsAction INSTANCE = new IndicesExistsAction(); public static final String NAME = "indices:admin/exists"; @@ -39,7 +39,7 @@ public class IndicesExistsAction extends IndicesAction { +public class IndicesExistsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public IndicesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new IndicesExistsRequest(indices)); + public IndicesExistsRequestBuilder(ElasticsearchClient client, IndicesExistsAction action, String... indices) { + super(client, action, new IndicesExistsRequest(indices)); } public IndicesExistsRequestBuilder setIndices(String... indices) { @@ -40,16 +39,11 @@ public class IndicesExistsRequestBuilder extends MasterNodeReadOperationRequestB /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public IndicesExistsRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.exists(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java index 9feb5568668..b7fea539d13 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/exists/types/TypesExistsAction.java @@ -18,12 +18,12 @@ */ package org.elasticsearch.action.admin.indices.exists.types; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class TypesExistsAction extends IndicesAction { +public class TypesExistsAction extends Action { public static final TypesExistsAction INSTANCE = new TypesExistsAction(); public static final String NAME = "indices:admin/types/exists"; @@ -38,7 +38,7 @@ public class TypesExistsAction extends IndicesAction { +public class TypesExistsRequestBuilder extends MasterNodeReadOperationRequestBuilder { /** * @param indices What indices to check for types */ - public TypesExistsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); + public TypesExistsRequestBuilder(ElasticsearchClient client, TypesExistsAction action, String... indices) { + super(client, action, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY)); } - TypesExistsRequestBuilder(IndicesAdminClient client) { - super(client, new TypesExistsRequest()); + TypesExistsRequestBuilder(ElasticsearchClient client, TypesExistsAction action) { + super(client, action, new TypesExistsRequest()); } /** @@ -63,9 +62,4 @@ public class TypesExistsRequestBuilder extends MasterNodeReadOperationRequestBui request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.typesExists(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java index 78e46715139..4cc116fd1dd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/flush/FlushAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.flush; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class FlushAction extends IndicesAction { +public class FlushAction extends Action { public static final FlushAction INSTANCE = new FlushAction(); public static final String NAME = "indices:admin/flush"; @@ -39,7 +39,7 @@ public class FlushAction extends IndicesAction { +public class FlushRequestBuilder extends BroadcastOperationRequestBuilder { - public FlushRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new FlushRequest()); + public FlushRequestBuilder(ElasticsearchClient client, FlushAction action) { + super(client, action, new FlushRequest()); } public FlushRequestBuilder setForce(boolean force) { @@ -37,11 +36,6 @@ public class FlushRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.flush(request, listener); - } - public FlushRequestBuilder setWaitIfOngoing(boolean waitIfOngoing) { request.waitIfOngoing(waitIfOngoing); return this; diff --git a/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java index 6481808c616..74111c82b2f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetIndexAction extends IndicesAction { +public class GetIndexAction extends Action { public static final GetIndexAction INSTANCE = new GetIndexAction(); public static final String NAME = "indices:admin/get"; @@ -34,8 +34,8 @@ public class GetIndexAction extends IndicesAction { - public GetIndexRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetIndexRequest().indices(indices)); + public GetIndexRequestBuilder(ElasticsearchClient client, GetIndexAction action, String... indices) { + super(client, action, new GetIndexRequest().indices(indices)); } public GetIndexRequestBuilder setFeatures(Feature... features) { @@ -42,9 +41,4 @@ public class GetIndexRequestBuilder extends ClusterInfoRequestBuilder listener) { - client.getIndex(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java index 222b99762c5..520ed7b2cd4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetFieldMappingsAction extends IndicesAction { +public class GetFieldMappingsAction extends Action { public static final GetFieldMappingsAction INSTANCE = new GetFieldMappingsAction(); public static final String NAME = "indices:admin/mappings/fields/get"; @@ -34,8 +34,8 @@ public class GetFieldMappingsAction extends IndicesAction { +public class GetFieldMappingsRequestBuilder extends ActionRequestBuilder { - public GetFieldMappingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetFieldMappingsRequest().indices(indices)); + public GetFieldMappingsRequestBuilder(ElasticsearchClient client, GetFieldMappingsAction action, String... indices) { + super(client, action, new GetFieldMappingsRequest().indices(indices)); } public GetFieldMappingsRequestBuilder setIndices(String... indices) { @@ -69,10 +70,4 @@ public class GetFieldMappingsRequestBuilder extends ActionRequestBuilder listener) { - client.getFieldMappings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java index 2ac4d58bc88..d7dbebc600c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetMappingsAction extends IndicesAction { +public class GetMappingsAction extends Action { public static final GetMappingsAction INSTANCE = new GetMappingsAction(); public static final String NAME = "indices:admin/mappings/get"; @@ -34,8 +34,8 @@ public class GetMappingsAction extends IndicesAction { - public GetMappingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetMappingsRequest().indices(indices)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.getMappings(request, listener); + public GetMappingsRequestBuilder(ElasticsearchClient client, GetMappingsAction action, String... indices) { + super(client, action, new GetMappingsRequest().indices(indices)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java index 01bfccdb46c..5ed79ceca98 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.mapping.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutMappingAction extends IndicesAction { +public class PutMappingAction extends Action { public static final PutMappingAction INSTANCE = new PutMappingAction(); public static final String NAME = "indices:admin/mapping/put"; @@ -39,7 +39,7 @@ public class PutMappingAction extends IndicesAction { +public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder { - public PutMappingRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutMappingRequest()); + public PutMappingRequestBuilder(ElasticsearchClient client, PutMappingAction action) { + super(client, action, new PutMappingRequest()); } public PutMappingRequestBuilder setIndices(String... indices) { @@ -43,7 +42,7 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public PutMappingRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -101,9 +100,4 @@ public class PutMappingRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putMapping(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java index 09bd6ff8f5a..c12e8d23c9c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.open; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class OpenIndexAction extends IndicesAction { +public class OpenIndexAction extends Action { public static final OpenIndexAction INSTANCE = new OpenIndexAction(); public static final String NAME = "indices:admin/open"; @@ -39,7 +39,7 @@ public class OpenIndexAction extends IndicesAction { +public class OpenIndexRequestBuilder extends AcknowledgedRequestBuilder { - public OpenIndexRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OpenIndexRequest()); + public OpenIndexRequestBuilder(ElasticsearchClient client, OpenIndexAction action) { + super(client, action, new OpenIndexRequest()); } - public OpenIndexRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new OpenIndexRequest(indices)); + public OpenIndexRequestBuilder(ElasticsearchClient client, OpenIndexAction action, String... indices) { + super(client, action, new OpenIndexRequest(indices)); } /** * Sets the indices to be opened + * * @param indices the indices to be opened * @return the request itself */ @@ -58,9 +58,4 @@ public class OpenIndexRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.open(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java index 65d2ce43f01..b44d372f7c9 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/optimize/OptimizeAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.optimize; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class OptimizeAction extends IndicesAction { +public class OptimizeAction extends Action { public static final OptimizeAction INSTANCE = new OptimizeAction(); public static final String NAME = "indices:admin/optimize"; @@ -39,7 +39,7 @@ public class OptimizeAction extends IndicesAction{@link #setMaxNumSegments(int)} allows to control the number of segments to optimize down to. By default, will * cause the optimize process to optimize down to half the configured number of segments. */ -public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder { +public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder { - public OptimizeRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new OptimizeRequest()); + public OptimizeRequestBuilder(ElasticsearchClient client, OptimizeAction action) { + super(client, action, new OptimizeRequest()); } /** @@ -61,9 +60,4 @@ public class OptimizeRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.optimize(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java index 1b210c004a0..a8848a23edc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.recovery; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.action.admin.indices.IndicesAction; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Recovery information action */ -public class RecoveryAction extends IndicesAction { +public class RecoveryAction extends Action { public static final RecoveryAction INSTANCE = new RecoveryAction(); public static final String NAME = "indices:monitor/recovery"; @@ -35,8 +35,8 @@ public class RecoveryAction extends IndicesAction { +public class RecoveryRequestBuilder extends BroadcastOperationRequestBuilder { /** * Constructs a new recovery information request builder. - * - * @param indicesClient Indices admin client */ - public RecoveryRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new RecoveryRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.recoveries(request, listener); + public RecoveryRequestBuilder(ElasticsearchClient client, RecoveryAction action) { + super(client, action, new RecoveryRequest()); } public RecoveryRequestBuilder setDetailed(boolean detailed) { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java index 985de9fd85d..79db06ec3f0 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/refresh/RefreshAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.refresh; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class RefreshAction extends IndicesAction { +public class RefreshAction extends Action { public static final RefreshAction INSTANCE = new RefreshAction(); public static final String NAME = "indices:admin/refresh"; @@ -39,7 +39,7 @@ public class RefreshAction extends IndicesAction { +public class RefreshRequestBuilder extends BroadcastOperationRequestBuilder { - public RefreshRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new RefreshRequest()); - } - - @Override - protected void doExecute(ActionListener listener) { - client.refresh(request, listener); + public RefreshRequestBuilder(ElasticsearchClient client, RefreshAction action) { + super(client, action, new RefreshRequest()); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java index 80a01d8ae3c..d98bc56aa5c 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.segments; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesSegmentsAction extends IndicesAction { +public class IndicesSegmentsAction extends Action { public static final IndicesSegmentsAction INSTANCE = new IndicesSegmentsAction(); public static final String NAME = "indices:monitor/segments"; @@ -39,7 +39,7 @@ public class IndicesSegmentsAction extends IndicesAction { +public class IndicesSegmentsRequestBuilder extends BroadcastOperationRequestBuilder { - public IndicesSegmentsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesSegmentsRequest()); + public IndicesSegmentsRequestBuilder(ElasticsearchClient client, IndicesSegmentsAction action) { + super(client, action, new IndicesSegmentsRequest()); } - + public IndicesSegmentsRequestBuilder setVerbose(boolean verbose) { request.verbose = verbose; return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.segments(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java index 0b729bd7999..448a5e25fbd 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.settings.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetSettingsAction extends IndicesAction { +public class GetSettingsAction extends Action { public static final GetSettingsAction INSTANCE = new GetSettingsAction(); public static final String NAME = "indices:monitor/settings/get"; @@ -34,8 +34,8 @@ public class GetSettingsAction extends IndicesAction { +public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public GetSettingsRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetSettingsRequest().indices(indices)); + public GetSettingsRequestBuilder(ElasticsearchClient client, GetSettingsAction action, String... indices) { + super(client, action, new GetSettingsRequest().indices(indices)); } public GetSettingsRequestBuilder setIndices(String... indices) { @@ -45,7 +44,7 @@ public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBui /** * Specifies what type of requested indices to ignore and wildcard indices expressions. - * + *

* For example indices that don't exist. */ public GetSettingsRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -57,9 +56,4 @@ public class GetSettingsRequestBuilder extends MasterNodeReadOperationRequestBui request.names(names); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.getSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java index df67115bb3a..17001b7376d 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/settings/put/UpdateSettingsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.settings.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class UpdateSettingsAction extends IndicesAction { +public class UpdateSettingsAction extends Action { public static final UpdateSettingsAction INSTANCE = new UpdateSettingsAction(); public static final String NAME = "indices:admin/settings/update"; @@ -39,7 +39,7 @@ public class UpdateSettingsAction extends IndicesAction { +public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder { - public UpdateSettingsRequestBuilder(IndicesAdminClient indicesClient, String... indices) { - super(indicesClient, new UpdateSettingsRequest(indices)); + public UpdateSettingsRequestBuilder(ElasticsearchClient client, UpdateSettingsAction action, String... indices) { + super(client, action, new UpdateSettingsRequest(indices)); } /** @@ -46,7 +46,7 @@ public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public UpdateSettingsRequestBuilder setIndicesOptions(IndicesOptions options) { @@ -85,9 +85,4 @@ public class UpdateSettingsRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.updateSettings(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java index 19b4f5ceca3..d83e368b216 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.stats; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndicesStatsAction extends IndicesAction { +public class IndicesStatsAction extends Action { public static final IndicesStatsAction INSTANCE = new IndicesStatsAction(); public static final String NAME = "indices:monitor/stats"; @@ -39,7 +39,7 @@ public class IndicesStatsAction extends IndicesActionAll the stats to be returned can be cleared using {@link #clear()}, at which point, specific * stats can be enabled. */ -public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder { +public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder { - public IndicesStatsRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new IndicesStatsRequest()); + public IndicesStatsRequestBuilder(ElasticsearchClient client, IndicesStatsAction action) { + super(client, action, new IndicesStatsRequest()); } /** @@ -172,9 +171,4 @@ public class IndicesStatsRequestBuilder extends BroadcastOperationRequestBuilder request.recovery(recovery); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.stats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java index e826b76f971..570ced293d8 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/delete/DeleteIndexTemplateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.template.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexTemplateAction extends IndicesAction { +public class DeleteIndexTemplateAction extends Action { public static final DeleteIndexTemplateAction INSTANCE = new DeleteIndexTemplateAction(); public static final String NAME = "indices:admin/template/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexTemplateAction extends IndicesAction { +public class DeleteIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { - public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteIndexTemplateRequest()); + public DeleteIndexTemplateRequestBuilder(ElasticsearchClient client, DeleteIndexTemplateAction action) { + super(client, action, new DeleteIndexTemplateRequest()); } - public DeleteIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new DeleteIndexTemplateRequest(name)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteTemplate(request, listener); + public DeleteIndexTemplateRequestBuilder(ElasticsearchClient client, DeleteIndexTemplateAction action, String name) { + super(client, action, new DeleteIndexTemplateRequest(name)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java index de3ded1a64e..b4db5e0529f 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/get/GetIndexTemplatesAction.java @@ -18,13 +18,13 @@ */ package org.elasticsearch.action.admin.indices.template.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * */ -public class GetIndexTemplatesAction extends IndicesAction { +public class GetIndexTemplatesAction extends Action { public static final GetIndexTemplatesAction INSTANCE = new GetIndexTemplatesAction(); public static final String NAME = "indices:admin/template/get"; @@ -39,7 +39,7 @@ public class GetIndexTemplatesAction extends IndicesAction { +public class GetIndexTemplatesRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public GetIndexTemplatesRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new GetIndexTemplatesRequest()); + public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, GetIndexTemplatesAction action) { + super(client, action, new GetIndexTemplatesRequest()); } - public GetIndexTemplatesRequestBuilder(IndicesAdminClient indicesClient, String... names) { - super(indicesClient, new GetIndexTemplatesRequest(names)); - } - - @Override - protected void doExecute(ActionListener listener) { - client.getTemplates(request, listener); + public GetIndexTemplatesRequestBuilder(ElasticsearchClient client, GetIndexTemplatesAction action, String... names) { + super(client, action, new GetIndexTemplatesRequest(names)); } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java index 00f98bc46b6..51adc0b5cfc 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.template.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutIndexTemplateAction extends IndicesAction { +public class PutIndexTemplateAction extends Action { public static final PutIndexTemplateAction INSTANCE = new PutIndexTemplateAction(); public static final String NAME = "indices:admin/template/put"; @@ -39,7 +39,7 @@ public class PutIndexTemplateAction extends IndicesAction { +public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBuilder { - public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutIndexTemplateRequest()); + public PutIndexTemplateRequestBuilder(ElasticsearchClient client, PutIndexTemplateAction action) { + super(client, action, new PutIndexTemplateRequest()); } - public PutIndexTemplateRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutIndexTemplateRequest(name)); + public PutIndexTemplateRequestBuilder(ElasticsearchClient client, PutIndexTemplateAction action, String name) { + super(client, action, new PutIndexTemplateRequest(name)); } /** @@ -153,7 +153,7 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu /** * Adds an alias that will be added when the index template gets created. * - * @param alias The alias + * @param alias The alias * @return the request builder */ public PutIndexTemplateRequestBuilder addAlias(Alias alias) { @@ -238,9 +238,4 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu request.source(templateSource, offset, length); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.putTemplate(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java index 76bb9523183..fdec5490c97 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/ValidateQueryAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.admin.indices.validate.query; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ValidateQueryAction extends IndicesAction { +public class ValidateQueryAction extends Action { public static final ValidateQueryAction INSTANCE = new ValidateQueryAction(); public static final String NAME = "indices:admin/validate/query"; @@ -39,7 +39,7 @@ public class ValidateQueryAction extends IndicesAction { +public class ValidateQueryRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public ValidateQueryRequestBuilder(IndicesAdminClient client) { - super(client, new ValidateQueryRequest()); + public ValidateQueryRequestBuilder(ElasticsearchClient client, ValidateQueryAction action) { + super(client, action, new ValidateQueryRequest()); } /** @@ -94,12 +94,11 @@ public class ValidateQueryRequestBuilder extends BroadcastOperationRequestBuilde } @Override - protected void doExecute(ActionListener listener) { + protected ValidateQueryRequest beforeExecute(ValidateQueryRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.validateQuery(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java index 9c3e4a001a0..86c447d3ca4 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/delete/DeleteWarmerAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.delete; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/delete API. */ -public class DeleteWarmerAction extends IndicesAction { +public class DeleteWarmerAction extends Action { public static final DeleteWarmerAction INSTANCE = new DeleteWarmerAction(); public static final String NAME = "indices:admin/warmers/delete"; @@ -40,7 +40,7 @@ public class DeleteWarmerAction extends IndicesAction { +public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder { - public DeleteWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new DeleteWarmerRequest()); + public DeleteWarmerRequestBuilder(ElasticsearchClient client, DeleteWarmerAction action) { + super(client, action, new DeleteWarmerRequest()); } public DeleteWarmerRequestBuilder setIndices(String... indices) { @@ -50,16 +50,11 @@ public class DeleteWarmerRequestBuilder extends AcknowledgedRequestBuilder * For example indices that don't exist. */ public DeleteWarmerRequestBuilder setIndicesOptions(IndicesOptions options) { request.indicesOptions(options); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.deleteWarmer(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java index 4170509b904..e2debde72a6 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/get/GetWarmersAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.get; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/get API. */ -public class GetWarmersAction extends IndicesAction { +public class GetWarmersAction extends Action { public static final GetWarmersAction INSTANCE = new GetWarmersAction(); public static final String NAME = "indices:admin/warmers/get"; @@ -35,8 +35,8 @@ public class GetWarmersAction extends IndicesAction { - public GetWarmersRequestBuilder(IndicesAdminClient client, String... indices) { - super(client, new GetWarmersRequest().indices(indices)); + public GetWarmersRequestBuilder(ElasticsearchClient client, GetWarmersAction action, String... indices) { + super(client, action, new GetWarmersRequest().indices(indices)); } public GetWarmersRequestBuilder setWarmers(String... warmers) { @@ -44,9 +43,4 @@ public class GetWarmersRequestBuilder extends ClusterInfoRequestBuilder listener) { - client.getWarmers(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java index 4b295286de3..3c5c8b7c412 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.admin.indices.warmer.put; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Action for the admin/warmers/put API. */ -public class PutWarmerAction extends IndicesAction { +public class PutWarmerAction extends Action { public static final PutWarmerAction INSTANCE = new PutWarmerAction(); public static final String NAME = "indices:admin/warmers/put"; @@ -40,7 +40,7 @@ public class PutWarmerAction extends IndicesAction { +public class PutWarmerRequestBuilder extends AcknowledgedRequestBuilder { /** * Creates a new {@link PutWarmerRequestBuilder} with a given name. */ - public PutWarmerRequestBuilder(IndicesAdminClient indicesClient, String name) { - super(indicesClient, new PutWarmerRequest().name(name)); + public PutWarmerRequestBuilder(ElasticsearchClient client, PutWarmerAction action, String name) { + super(client, action, new PutWarmerRequest().name(name)); } /** * Creates a new {@link PutWarmerRequestBuilder} * Note: {@link #setName(String)} must be called with a non-null value before this request is executed. */ - public PutWarmerRequestBuilder(IndicesAdminClient indicesClient) { - super(indicesClient, new PutWarmerRequest()); + public PutWarmerRequestBuilder(ElasticsearchClient client, PutWarmerAction action) { + super(client, action, new PutWarmerRequest()); } /** @@ -69,9 +69,4 @@ public class PutWarmerRequestBuilder extends AcknowledgedRequestBuilder listener) { - client.putWarmer(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/bulk/BulkAction.java b/src/main/java/org/elasticsearch/action/bulk/BulkAction.java index e7a8ea13de8..42d0c22508b 100644 --- a/src/main/java/org/elasticsearch/action/bulk/BulkAction.java +++ b/src/main/java/org/elasticsearch/action/bulk/BulkAction.java @@ -19,14 +19,14 @@ package org.elasticsearch.action.bulk; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportRequestOptions; /** */ -public class BulkAction extends ClientAction { +public class BulkAction extends Action { public static final BulkAction INSTANCE = new BulkAction(); public static final String NAME = "indices:data/write/bulk"; @@ -41,8 +41,8 @@ public class BulkAction extends ClientAction { +public class BulkRequestBuilder extends ActionRequestBuilder { - public BulkRequestBuilder(Client client) { - super(client, new BulkRequest()); + public BulkRequestBuilder(ElasticsearchClient client, BulkAction action) { + super(client, action, new BulkRequest()); } /** @@ -149,9 +148,4 @@ public class BulkRequestBuilder extends ActionRequestBuilder listener) { - client.bulk(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/count/CountAction.java b/src/main/java/org/elasticsearch/action/count/CountAction.java index 319ca5366d5..4c7c8a2fcc2 100644 --- a/src/main/java/org/elasticsearch/action/count/CountAction.java +++ b/src/main/java/org/elasticsearch/action/count/CountAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.count; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class CountAction extends ClientAction { +public class CountAction extends Action { public static final CountAction INSTANCE = new CountAction(); public static final String NAME = "indices:data/read/count"; @@ -39,7 +39,7 @@ public class CountAction extends ClientAction { +public class CountRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public CountRequestBuilder(Client client) { - super(client, new CountRequest()); + public CountRequestBuilder(ElasticsearchClient client, CountAction action) { + super(client, action, new CountRequest()); } /** @@ -101,7 +100,7 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected CountRequest beforeExecute(CountRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.count(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { @@ -155,7 +153,7 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder { +public class DeleteAction extends Action { public static final DeleteAction INSTANCE = new DeleteAction(); public static final String NAME = "indices:data/write/delete"; @@ -39,7 +39,7 @@ public class DeleteAction extends ClientAction { - public DeleteRequestBuilder(Client client) { - super(client, new DeleteRequest()); + public DeleteRequestBuilder(ElasticsearchClient client, DeleteAction action) { + super(client, action, new DeleteRequest()); } - public DeleteRequestBuilder(Client client, @Nullable String index) { - super(client, new DeleteRequest(index)); + public DeleteRequestBuilder(ElasticsearchClient client, DeleteAction action, @Nullable String index) { + super(client, action, new DeleteRequest(index)); } /** @@ -98,9 +97,4 @@ public class DeleteRequestBuilder extends ShardReplicationOperationRequestBuilde request.versionType(versionType); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.delete(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/exists/ExistsAction.java b/src/main/java/org/elasticsearch/action/exists/ExistsAction.java index e37f81c5e44..d4463aea0d6 100644 --- a/src/main/java/org/elasticsearch/action/exists/ExistsAction.java +++ b/src/main/java/org/elasticsearch/action/exists/ExistsAction.java @@ -19,10 +19,10 @@ package org.elasticsearch.action.exists; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; -public class ExistsAction extends ClientAction { +public class ExistsAction extends Action { public static final ExistsAction INSTANCE = new ExistsAction(); public static final String NAME = "indices:data/read/exists"; @@ -37,7 +37,7 @@ public class ExistsAction extends ClientAction { - +public class ExistsRequestBuilder extends BroadcastOperationRequestBuilder { private QuerySourceBuilder sourceBuilder; - public ExistsRequestBuilder(Client client) { - super(client, new ExistsRequest()); + public ExistsRequestBuilder(ElasticsearchClient client, ExistsAction action) { + super(client, action, new ExistsRequest()); } /** @@ -104,12 +102,11 @@ public class ExistsRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected ExistsRequest beforeExecute(ExistsRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.exists(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/explain/ExplainAction.java b/src/main/java/org/elasticsearch/action/explain/ExplainAction.java index 3d7645db09b..b48530ce527 100644 --- a/src/main/java/org/elasticsearch/action/explain/ExplainAction.java +++ b/src/main/java/org/elasticsearch/action/explain/ExplainAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.explain; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** * Entry point for the explain feature. */ -public class ExplainAction extends ClientAction { +public class ExplainAction extends Action { public static final ExplainAction INSTANCE = new ExplainAction(); public static final String NAME = "indices:data/read/explain"; @@ -35,8 +35,8 @@ public class ExplainAction extends ClientAction listener) { + protected ExplainRequest beforeExecute(ExplainRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - - client.explain(request, listener); + return request; } private QuerySourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java b/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java index fb4a3f77833..085952c9be6 100644 --- a/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java +++ b/src/main/java/org/elasticsearch/action/fieldstats/FieldStatsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.fieldstats; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class FieldStatsAction extends ClientAction { +public class FieldStatsAction extends Action { public static final FieldStatsAction INSTANCE = new FieldStatsAction(); public static final String NAME = "indices:data/read/field_stats"; @@ -39,7 +39,7 @@ public class FieldStatsAction extends ClientAction { +public class FieldStatsRequestBuilder extends BroadcastOperationRequestBuilder { - public FieldStatsRequestBuilder(Client client) { - super(client, new FieldStatsRequest()); + public FieldStatsRequestBuilder(ElasticsearchClient client, FieldStatsAction action) { + super(client, action, new FieldStatsRequest()); } public FieldStatsRequestBuilder setFields(String... fields) { @@ -40,9 +39,4 @@ public class FieldStatsRequestBuilder extends BroadcastOperationRequestBuilder listener) { - client.fieldStats(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/get/GetAction.java b/src/main/java/org/elasticsearch/action/get/GetAction.java index 93e4f26e150..eb499ffb8c2 100644 --- a/src/main/java/org/elasticsearch/action/get/GetAction.java +++ b/src/main/java/org/elasticsearch/action/get/GetAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetAction extends ClientAction { +public class GetAction extends Action { public static final GetAction INSTANCE = new GetAction(); public static final String NAME = "indices:data/read/get"; @@ -39,7 +39,7 @@ public class GetAction extends ClientAction { - public GetRequestBuilder(Client client) { - super(client, new GetRequest()); + public GetRequestBuilder(ElasticsearchClient client, GetAction action) { + super(client, action, new GetRequest()); } - public GetRequestBuilder(Client client, @Nullable String index) { - super(client, new GetRequest(index)); + public GetRequestBuilder(ElasticsearchClient client, GetAction action, @Nullable String index) { + super(client, action, new GetRequest(index)); } /** @@ -96,14 +95,14 @@ public class GetRequestBuilder extends SingleShardOperationRequestBuilder listener) { - client.get(request, listener); - } - - } diff --git a/src/main/java/org/elasticsearch/action/get/MultiGetAction.java b/src/main/java/org/elasticsearch/action/get/MultiGetAction.java index 0a15892a057..38036d391e8 100644 --- a/src/main/java/org/elasticsearch/action/get/MultiGetAction.java +++ b/src/main/java/org/elasticsearch/action/get/MultiGetAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiGetAction extends ClientAction { +public class MultiGetAction extends Action { public static final MultiGetAction INSTANCE = new MultiGetAction(); public static final String NAME = "indices:data/read/mget"; @@ -39,7 +39,7 @@ public class MultiGetAction extends ClientAction { +public class MultiGetRequestBuilder extends ActionRequestBuilder { - public MultiGetRequestBuilder(Client client) { - super(client, new MultiGetRequest()); + public MultiGetRequestBuilder(ElasticsearchClient client, MultiGetAction action) { + super(client, action, new MultiGetRequest()); } public MultiGetRequestBuilder add(String index, @Nullable String type, String id) { @@ -86,9 +85,4 @@ public class MultiGetRequestBuilder extends ActionRequestBuilder listener) { - client.multiGet(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/index/IndexAction.java b/src/main/java/org/elasticsearch/action/index/IndexAction.java index 1f6e5a5c8ea..ceacbcf2df7 100644 --- a/src/main/java/org/elasticsearch/action/index/IndexAction.java +++ b/src/main/java/org/elasticsearch/action/index/IndexAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.index; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class IndexAction extends ClientAction { +public class IndexAction extends Action { public static final IndexAction INSTANCE = new IndexAction(); public static final String NAME = "indices:data/write/index"; @@ -39,7 +39,7 @@ public class IndexAction extends ClientAction { - public IndexRequestBuilder(Client client) { - super(client, new IndexRequest()); + public IndexRequestBuilder(ElasticsearchClient client, IndexAction action) { + super(client, action, new IndexRequest()); } - public IndexRequestBuilder(Client client, @Nullable String index) { - super(client, new IndexRequest(index)); + public IndexRequestBuilder(ElasticsearchClient client, IndexAction action, @Nullable String index) { + super(client, action, new IndexRequest(index)); } /** @@ -180,7 +179,7 @@ public class IndexRequestBuilder extends ShardReplicationOperationRequestBuilder /** * Constructs a simple document with a field name and value pairs. - * Note: the number of objects passed to this method must be an even number. + * Note: the number of objects passed to this method must be an even number. */ public IndexRequestBuilder setSource(Object... source) { request.source(source); @@ -260,9 +259,4 @@ public class IndexRequestBuilder extends ShardReplicationOperationRequestBuilder request.ttl(ttl); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.index(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java index 94009796b19..4ccbdf7801d 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/delete/DeleteIndexedScriptAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.indexedscripts.delete; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class DeleteIndexedScriptAction extends ClientAction { +public class DeleteIndexedScriptAction extends Action { public static final DeleteIndexedScriptAction INSTANCE = new DeleteIndexedScriptAction(); public static final String NAME = "indices:data/write/script/delete"; @@ -39,7 +39,7 @@ public class DeleteIndexedScriptAction extends ClientAction { +public class DeleteIndexedScriptRequestBuilder extends ActionRequestBuilder { - public DeleteIndexedScriptRequestBuilder(Client client) { - super(client, new DeleteIndexedScriptRequest()); + public DeleteIndexedScriptRequestBuilder(ElasticsearchClient client, DeleteIndexedScriptAction action) { + super(client, action, new DeleteIndexedScriptRequest()); } /** @@ -56,9 +55,4 @@ public class DeleteIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.deleteIndexedScript(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java index a909b78d289..898d33691f6 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/get/GetIndexedScriptAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.indexedscripts.get; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class GetIndexedScriptAction extends ClientAction { +public class GetIndexedScriptAction extends Action { public static final GetIndexedScriptAction INSTANCE = new GetIndexedScriptAction(); public static final String NAME = "indices:data/read/script/get"; @@ -39,8 +39,8 @@ public class GetIndexedScriptAction extends ClientAction { +public class GetIndexedScriptRequestBuilder extends ActionRequestBuilder { - public GetIndexedScriptRequestBuilder(Client client) { - super(client, new GetIndexedScriptRequest()); + public GetIndexedScriptRequestBuilder(ElasticsearchClient client, GetIndexedScriptAction action) { + super(client, action, new GetIndexedScriptRequest()); } /** @@ -68,10 +67,4 @@ public class GetIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.getIndexedScript(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java b/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java index 3949e05af18..e0f364b0ad1 100644 --- a/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java +++ b/src/main/java/org/elasticsearch/action/indexedscripts/put/PutIndexedScriptAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.indexedscripts.put; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PutIndexedScriptAction extends ClientAction { +public class PutIndexedScriptAction extends Action { public static final PutIndexedScriptAction INSTANCE = new PutIndexedScriptAction(); public static final String NAME = "indices:data/write/script/put"; @@ -42,7 +42,7 @@ public class PutIndexedScriptAction extends ClientAction { +public class PutIndexedScriptRequestBuilder extends ActionRequestBuilder { - public PutIndexedScriptRequestBuilder(Client client) { - super(client, new PutIndexedScriptRequest()); + public PutIndexedScriptRequestBuilder(ElasticsearchClient client, PutIndexedScriptAction action) { + super(client, action, new PutIndexedScriptRequest()); } /** @@ -126,7 +125,7 @@ public class PutIndexedScriptRequestBuilder extends ActionRequestBuilderNote: the number of objects passed to this method must be an even number. + * Note: the number of objects passed to this method must be an even number. */ public PutIndexedScriptRequestBuilder setSource(Object... source) { request.source(source); @@ -182,27 +181,4 @@ public class PutIndexedScriptRequestBuilder extends ActionRequestBuilder listener) { - client.putIndexedScript(request, listener); - /* - try { - scriptService.putScriptToIndex(client, request.safeSource(), request.id(), request.scriptLang(), null, request.opType().toString(), new ActionListener() { - @Override - public void onResponse(IndexResponse indexResponse) { - listener.onResponse(new PutIndexedScriptResponse(indexResponse.getType(),indexResponse.getId(),indexResponse.getVersion(),indexResponse.isCreated())); - } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } - }); - } catch (IOException ioe) { - listener.onFailure(ioe); - } - */ - } } diff --git a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java index b2561650d77..83313dfc095 100644 --- a/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java +++ b/src/main/java/org/elasticsearch/action/mlt/MoreLikeThisAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.mlt; -import org.elasticsearch.action.ClientAction; +import org.elasticsearch.action.Action; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MoreLikeThisAction extends ClientAction { +public class MoreLikeThisAction extends Action { public static final MoreLikeThisAction INSTANCE = new MoreLikeThisAction(); public static final String NAME = "indices:data/read/mlt"; @@ -40,7 +40,7 @@ public class MoreLikeThisAction extends ClientAction { +public class MoreLikeThisRequestBuilder extends ActionRequestBuilder { - public MoreLikeThisRequestBuilder(Client client) { - super(client, new MoreLikeThisRequest()); + public MoreLikeThisRequestBuilder(ElasticsearchClient client, MoreLikeThisAction action) { + super(client, action, new MoreLikeThisRequest()); } - public MoreLikeThisRequestBuilder(Client client, String index, String type, String id) { - super(client, new MoreLikeThisRequest(index).type(type).id(id)); + public MoreLikeThisRequestBuilder(ElasticsearchClient client, MoreLikeThisAction action, String index, String type, String id) { + super(client, action, new MoreLikeThisRequest(index).type(type).id(id)); } /** @@ -63,7 +62,7 @@ public class MoreLikeThisRequestBuilder extends ActionRequestBuilder30%. * - * @see org.elasticsearch.common.lucene.search.Queries#calculateMinShouldMatch(int, String) + * @see org.elasticsearch.common.lucene.search.Queries#calculateMinShouldMatch(int, String) */ public MoreLikeThisRequestBuilder setMinimumShouldMatch(String minimumShouldMatch) { request.minimumShouldMatch(minimumShouldMatch); @@ -259,10 +258,4 @@ public class MoreLikeThisRequestBuilder extends ActionRequestBuilder listener) { - client.moreLikeThis(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java index fadb290683c..2b9538ae054 100644 --- a/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/MultiPercolateAction.java @@ -18,12 +18,12 @@ */ package org.elasticsearch.action.percolate; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiPercolateAction extends ClientAction { +public class MultiPercolateAction extends Action { public static final MultiPercolateAction INSTANCE = new MultiPercolateAction(); public static final String NAME = "indices:data/read/mpercolate"; @@ -38,8 +38,8 @@ public class MultiPercolateAction extends ClientAction { +public class MultiPercolateRequestBuilder extends ActionRequestBuilder { - public MultiPercolateRequestBuilder(Client client) { - super(client, new MultiPercolateRequest()); + public MultiPercolateRequestBuilder(ElasticsearchClient client, MultiPercolateAction action) { + super(client, action, new MultiPercolateRequest()); } /** @@ -50,16 +49,11 @@ public class MultiPercolateRequestBuilder extends ActionRequestBuilder * Invoke this method before invoking {@link #add(PercolateRequestBuilder)}. */ public MultiPercolateRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { request.indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.multiPercolate(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java b/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java index 6d85d207719..412f4e3ed62 100644 --- a/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java +++ b/src/main/java/org/elasticsearch/action/percolate/PercolateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.percolate; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class PercolateAction extends ClientAction { +public class PercolateAction extends Action { public static final PercolateAction INSTANCE = new PercolateAction(); public static final String NAME = "indices:data/read/percolate"; @@ -39,7 +39,7 @@ public class PercolateAction extends ClientAction { +public class PercolateRequestBuilder extends BroadcastOperationRequestBuilder { private PercolateSourceBuilder sourceBuilder; - public PercolateRequestBuilder(Client client) { - super(client, new PercolateRequest()); + public PercolateRequestBuilder(ElasticsearchClient client, PercolateAction action) { + super(client, action, new PercolateRequest()); } /** @@ -252,11 +249,10 @@ public class PercolateRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected PercolateRequest beforeExecute(PercolateRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder); } - client.percolate(request, listener); + return request; } - } diff --git a/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java b/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java index 769c14fa369..6523378df4d 100644 --- a/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java +++ b/src/main/java/org/elasticsearch/action/search/ClearScrollAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class ClearScrollAction extends ClientAction { +public class ClearScrollAction extends Action { public static final ClearScrollAction INSTANCE = new ClearScrollAction(); public static final String NAME = "indices:data/read/scroll/clear"; @@ -39,7 +39,7 @@ public class ClearScrollAction extends ClientAction { +public class ClearScrollRequestBuilder extends ActionRequestBuilder { - public ClearScrollRequestBuilder(Client client) { - super(client, new ClearScrollRequest()); + public ClearScrollRequestBuilder(ElasticsearchClient client, ClearScrollAction action) { + super(client, action, new ClearScrollRequest()); } public ClearScrollRequestBuilder setScrollIds(List cursorIds) { @@ -42,9 +41,4 @@ public class ClearScrollRequestBuilder extends ActionRequestBuilder listener) { - client.clearScroll(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java b/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java index f052a927a16..ffa0a4b63f0 100644 --- a/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/MultiSearchAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiSearchAction extends ClientAction { +public class MultiSearchAction extends Action { public static final MultiSearchAction INSTANCE = new MultiSearchAction(); public static final String NAME = "indices:data/read/msearch"; @@ -39,7 +39,7 @@ public class MultiSearchAction extends ClientAction { +public class MultiSearchRequestBuilder extends ActionRequestBuilder { - public MultiSearchRequestBuilder(Client client) { - super(client, new MultiSearchRequest()); + public MultiSearchRequestBuilder(ElasticsearchClient client, MultiSearchAction action) { + super(client, action, new MultiSearchRequest()); } /** @@ -65,16 +64,11 @@ public class MultiSearchRequestBuilder extends ActionRequestBuilder * Invoke this method before invoking {@link #add(SearchRequestBuilder)}. */ public MultiSearchRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { request().indicesOptions(indicesOptions); return this; } - - @Override - protected void doExecute(ActionListener listener) { - client.multiSearch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/search/SearchAction.java b/src/main/java/org/elasticsearch/action/search/SearchAction.java index 450e65eed19..501fe1afb76 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchAction.java +++ b/src/main/java/org/elasticsearch/action/search/SearchAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class SearchAction extends ClientAction { +public class SearchAction extends Action { public static final SearchAction INSTANCE = new SearchAction(); public static final String NAME = "indices:data/read/search"; @@ -39,7 +39,7 @@ public class SearchAction extends ClientAction { +public class SearchRequestBuilder extends ActionRequestBuilder { private SearchSourceBuilder sourceBuilder; - public SearchRequestBuilder(Client client) { - super(client, new SearchRequest()); + public SearchRequestBuilder(ElasticsearchClient client, SearchAction action) { + super(client, action, new SearchRequest()); } /** @@ -168,7 +166,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder * For example indices that don't exist. */ public SearchRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { @@ -703,6 +701,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder templateParams) { + public SearchRequestBuilder setTemplateParams(Map templateParams) { request.templateParams(templateParams); return this; } @@ -994,7 +1000,7 @@ public class SearchRequestBuilder extends ActionRequestBuilder listener) { + protected SearchRequest beforeExecute(SearchRequest request) { if (sourceBuilder != null) { request.source(sourceBuilder()); } - client.search(request, listener); + return request; } private SearchSourceBuilder sourceBuilder() { diff --git a/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java b/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java index 0647b2e6554..eccfa0526a1 100644 --- a/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java +++ b/src/main/java/org/elasticsearch/action/search/SearchScrollAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.search; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class SearchScrollAction extends ClientAction { +public class SearchScrollAction extends Action { public static final SearchScrollAction INSTANCE = new SearchScrollAction(); public static final String NAME = "indices:data/read/scroll"; @@ -39,7 +39,7 @@ public class SearchScrollAction extends ClientAction { +public class SearchScrollRequestBuilder extends ActionRequestBuilder { - public SearchScrollRequestBuilder(Client client) { - super(client, new SearchScrollRequest()); + public SearchScrollRequestBuilder(ElasticsearchClient client, SearchScrollAction action) { + super(client, action, new SearchScrollRequest()); } - public SearchScrollRequestBuilder(Client client, String scrollId) { - super(client, new SearchScrollRequest(scrollId)); + public SearchScrollRequestBuilder(ElasticsearchClient client, SearchScrollAction action, String scrollId) { + super(client, action, new SearchScrollRequest(scrollId)); } /** @@ -69,9 +68,4 @@ public class SearchScrollRequestBuilder extends ActionRequestBuilder listener) { - client.searchScroll(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java b/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java index 59bfe4e6e19..88d2a92f331 100644 --- a/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java +++ b/src/main/java/org/elasticsearch/action/suggest/SuggestAction.java @@ -19,13 +19,13 @@ package org.elasticsearch.action.suggest; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.search.suggest.Suggest; /** */ -public class SuggestAction extends ClientAction { +public class SuggestAction extends Action { public static final SuggestAction INSTANCE = new SuggestAction(); public static final String NAME = "indices:data/read/suggest"; @@ -40,7 +40,7 @@ public class SuggestAction extends ClientAction { +public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder { final SuggestBuilder suggest = new SuggestBuilder(); - public SuggestRequestBuilder(Client client) { - super(client, new SuggestRequest()); + public SuggestRequestBuilder(ElasticsearchClient client, SuggestAction action) { + super(client, action, new SuggestRequest()); } /** @@ -84,7 +83,7 @@ public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder listener) { + protected SuggestRequest beforeExecute(SuggestRequest request) { try { XContentBuilder builder = XContentFactory.contentBuilder(Requests.CONTENT_TYPE); suggest.toXContent(builder, ToXContent.EMPTY_PARAMS); @@ -92,7 +91,6 @@ public class SuggestRequestBuilder extends BroadcastOperationRequestBuilder implements ActionListener(logger, threadPool, ThreadPool.Names.LISTENER, listener); } } diff --git a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java index 9a24917222f..50fb7b097f2 100644 --- a/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/broadcast/BroadcastOperationRequestBuilder.java @@ -19,19 +19,18 @@ package org.elasticsearch.action.support.broadcast; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.client.Client; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder, Client extends ElasticsearchClient> - extends ActionRequestBuilder { +public abstract class BroadcastOperationRequestBuilder, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder> + extends ActionRequestBuilder { - protected BroadcastOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected BroadcastOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java index fcc92ed7959..939f47f9acf 100644 --- a/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequestBuilder.java @@ -18,19 +18,18 @@ */ package org.elasticsearch.action.support.master; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.action.Action; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.common.unit.TimeValue; /** * Base request builder for master node operations that support acknowledgements */ -public abstract class AcknowledgedRequestBuilder, Response extends AcknowledgedResponse, RequestBuilder extends AcknowledgedRequestBuilder, Client extends ElasticsearchClient> - extends MasterNodeOperationRequestBuilder { +public abstract class AcknowledgedRequestBuilder, Response extends AcknowledgedResponse, RequestBuilder extends AcknowledgedRequestBuilder> + extends MasterNodeOperationRequestBuilder { - protected AcknowledgedRequestBuilder(Client client, Request request) { - super(client, request); + protected AcknowledgedRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** @@ -39,7 +38,7 @@ public abstract class AcknowledgedRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder, Client extends ElasticsearchClient> - extends ActionRequestBuilder { +public abstract class MasterNodeOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeOperationRequestBuilder> + extends ActionRequestBuilder { - protected MasterNodeOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected MasterNodeOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java index 0b0644cc428..02c83298c25 100644 --- a/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadOperationRequestBuilder.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.support.master; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.ElasticsearchClient; @@ -27,11 +28,11 @@ import org.elasticsearch.client.IndicesAdminClient; /** * Base request builder for master node read operations that can be executed on the local node as well */ -public abstract class MasterNodeReadOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeReadOperationRequestBuilder, Client extends ElasticsearchClient> - extends MasterNodeOperationRequestBuilder { +public abstract class MasterNodeReadOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends MasterNodeReadOperationRequestBuilder> + extends MasterNodeOperationRequestBuilder { - protected MasterNodeReadOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected MasterNodeReadOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java index d310a2abe7f..cc12e2836dd 100644 --- a/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java @@ -19,19 +19,21 @@ package org.elasticsearch.action.support.master.info; import com.google.common.collect.ObjectArrays; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ -public abstract class ClusterInfoRequestBuilder, Response extends ActionResponse, Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder { +public abstract class ClusterInfoRequestBuilder, Response extends ActionResponse, Builder extends ClusterInfoRequestBuilder> extends MasterNodeReadOperationRequestBuilder { - protected ClusterInfoRequestBuilder(IndicesAdminClient client, Request request) { - super(client, request); + protected ClusterInfoRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java index e9c38539ede..303671db595 100644 --- a/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/nodes/NodesOperationRequestBuilder.java @@ -19,17 +19,18 @@ package org.elasticsearch.action.support.nodes; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class NodesOperationRequestBuilder, Response extends NodesOperationResponse, RequestBuilder extends NodesOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected NodesOperationRequestBuilder(ClusterAdminClient client, Request request) { - super(client, request); + protected NodesOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java index 80a0c96bd6a..aa34e249d9d 100644 --- a/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/replication/ShardReplicationOperationRequestBuilder.java @@ -19,19 +19,21 @@ package org.elasticsearch.action.support.replication; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.WriteConsistencyLevel; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class ShardReplicationOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends ShardReplicationOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected ShardReplicationOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected ShardReplicationOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java index 8b0cc7fbe47..46019916f46 100644 --- a/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/custom/SingleCustomOperationRequestBuilder.java @@ -18,19 +18,21 @@ */ package org.elasticsearch.action.support.single.custom; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.IndicesAdminClient; /** */ public abstract class SingleCustomOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleCustomOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected SingleCustomOperationRequestBuilder(IndicesAdminClient client, Request request) { - super(client, request); + protected SingleCustomOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java index 5d1299c60b1..a40e293f64e 100644 --- a/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/instance/InstanceShardOperationRequestBuilder.java @@ -19,18 +19,20 @@ package org.elasticsearch.action.support.single.instance; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.common.unit.TimeValue; /** */ public abstract class InstanceShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends InstanceShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected InstanceShardOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected InstanceShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java index cca130375ee..e9ce5204aaf 100644 --- a/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java +++ b/src/main/java/org/elasticsearch/action/support/single/shard/SingleShardOperationRequestBuilder.java @@ -19,17 +19,19 @@ package org.elasticsearch.action.support.single.shard; +import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ public abstract class SingleShardOperationRequestBuilder, Response extends ActionResponse, RequestBuilder extends SingleShardOperationRequestBuilder> - extends ActionRequestBuilder { + extends ActionRequestBuilder { - protected SingleShardOperationRequestBuilder(Client client, Request request) { - super(client, request); + protected SingleShardOperationRequestBuilder(ElasticsearchClient client, Action action, Request request) { + super(client, action, request); } /** diff --git a/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java b/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java index 99faae076c0..d4451157c4b 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java +++ b/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsAction.java @@ -19,12 +19,13 @@ package org.elasticsearch.action.termvectors; -import org.elasticsearch.action.ClientAction; +import org.elasticsearch.action.Action; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class MultiTermVectorsAction extends ClientAction { +public class MultiTermVectorsAction extends Action { public static final MultiTermVectorsAction INSTANCE = new MultiTermVectorsAction(); public static final String NAME = "indices:data/read/mtv"; @@ -39,7 +40,7 @@ public class MultiTermVectorsAction extends ClientAction { - public MultiTermVectorsRequestBuilder(Client client) { - super(client, new MultiTermVectorsRequest()); +public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder { + + public MultiTermVectorsRequestBuilder(ElasticsearchClient client, MultiTermVectorsAction action) { + super(client, action, new MultiTermVectorsRequest()); } public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, Iterable ids) { @@ -47,9 +47,4 @@ public class MultiTermVectorsRequestBuilder extends ActionRequestBuilder listener) { - client.multiTermVectors(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java index 96269d55f1b..a4c53ee4a2d 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java +++ b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.termvectors; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class TermVectorsAction extends ClientAction { +public class TermVectorsAction extends Action { public static final TermVectorsAction INSTANCE = new TermVectorsAction(); public static final String NAME = "indices:data/read/tv"; @@ -39,7 +39,7 @@ public class TermVectorsAction extends ClientAction { +public class TermVectorsRequestBuilder extends ActionRequestBuilder { - public TermVectorsRequestBuilder(Client client) { - super(client, new TermVectorsRequest()); + public TermVectorsRequestBuilder(ElasticsearchClient client, TermVectorsAction action) { + super(client, action, new TermVectorsRequest()); } /** @@ -45,8 +45,8 @@ public class TermVectorsRequestBuilder extends ActionRequestBuilder listener) { - client.termVectors(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/action/update/UpdateAction.java b/src/main/java/org/elasticsearch/action/update/UpdateAction.java index c149a8839d2..4ac1002dbc6 100644 --- a/src/main/java/org/elasticsearch/action/update/UpdateAction.java +++ b/src/main/java/org/elasticsearch/action/update/UpdateAction.java @@ -19,12 +19,12 @@ package org.elasticsearch.action.update; -import org.elasticsearch.action.ClientAction; -import org.elasticsearch.client.Client; +import org.elasticsearch.action.Action; +import org.elasticsearch.client.ElasticsearchClient; /** */ -public class UpdateAction extends ClientAction { +public class UpdateAction extends Action { public static final UpdateAction INSTANCE = new UpdateAction(); public static final String NAME = "indices:data/write/update"; @@ -39,7 +39,7 @@ public class UpdateAction extends ClientAction { - public UpdateRequestBuilder(Client client) { - super(client, new UpdateRequest()); + public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action) { + super(client, action, new UpdateRequest()); } - public UpdateRequestBuilder(Client client, String index, String type, String id) { - super(client, new UpdateRequest(index, type, id)); + public UpdateRequestBuilder(ElasticsearchClient client, UpdateAction action, String index, String type, String id) { + super(client, action, new UpdateRequest(index, type, id)); } /** @@ -77,7 +76,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder + *

* The script works with the variable ctx, which is bound to the entry, * e.g. ctx._source.mycounter += 1. * @@ -93,7 +92,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder * Default: groovy - *

+ *

* Ref: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html */ public UpdateRequestBuilder setScriptLang(String scriptLang) { @@ -344,7 +343,7 @@ public class UpdateRequestBuilder extends InstanceShardOperationRequestBuilder listener) { - client.update(request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/Client.java b/src/main/java/org/elasticsearch/client/Client.java index 973ebf511c3..e356244db1a 100644 --- a/src/main/java/org/elasticsearch/client/Client.java +++ b/src/main/java/org/elasticsearch/client/Client.java @@ -62,6 +62,7 @@ import org.elasticsearch.action.termvectors.*; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.settings.Settings; @@ -79,7 +80,7 @@ import org.elasticsearch.common.settings.Settings; * @see org.elasticsearch.node.Node#client() * @see org.elasticsearch.client.transport.TransportClient */ -public interface Client extends ElasticsearchClient, Releasable { +public interface Client extends ElasticsearchClient, Releasable { String CLIENT_TYPE_SETTING = "client.type"; @@ -256,18 +257,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Put the indexed script - * @param scriptLang - * @param id - * @param source - * @return */ PutIndexedScriptRequestBuilder preparePutIndexedScript(@Nullable String scriptLang, String id, String source); /** * delete an indexed script - * - * @param request - * @param listener */ void deleteIndexedScript(DeleteIndexedScriptRequest request, ActionListener listener); @@ -287,17 +281,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Delete an indexed script - * @param scriptLang - * @param id - * @return */ DeleteIndexedScriptRequestBuilder prepareDeleteIndexedScript(@Nullable String scriptLang, String id); /** * Put an indexed script - * - * @param request - * @param listener */ void putIndexedScript(PutIndexedScriptRequest request, ActionListener listener); @@ -317,17 +305,11 @@ public interface Client extends ElasticsearchClient, Releasable { /** * Get the indexed script - * @param scriptLang - * @param id - * @return */ GetIndexedScriptRequestBuilder prepareGetIndexedScript(@Nullable String scriptLang, String id); /** * Get an indexed script - * - * @param request - * @param listener */ void getIndexedScript(GetIndexedScriptRequest request, ActionListener listener); @@ -670,4 +652,5 @@ public interface Client extends ElasticsearchClient, Releasable { */ Settings settings(); + Headers headers(); } diff --git a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index 0169151fc93..c3eb51585c2 100644 --- a/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -83,7 +83,7 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; * * @see AdminClient#cluster() */ -public interface ClusterAdminClient extends ElasticsearchClient { +public interface ClusterAdminClient extends ElasticsearchClient { /** * The health of the cluster. diff --git a/src/main/java/org/elasticsearch/client/ElasticsearchClient.java b/src/main/java/org/elasticsearch/client/ElasticsearchClient.java index 807dcc84f57..08a95bc71e6 100644 --- a/src/main/java/org/elasticsearch/client/ElasticsearchClient.java +++ b/src/main/java/org/elasticsearch/client/ElasticsearchClient.java @@ -23,7 +23,7 @@ package org.elasticsearch.client; import org.elasticsearch.action.*; import org.elasticsearch.threadpool.ThreadPool; -public interface ElasticsearchClient { +public interface ElasticsearchClient { /** * Executes a generic action, denoted by an {@link org.elasticsearch.action.Action}. @@ -35,7 +35,7 @@ public interface ElasticsearchClient { * @param The request builder type. * @return A future allowing to get back the response. */ - > ActionFuture execute(final Action action, final Request request); + > ActionFuture execute(final Action action, final Request request); /** * Executes a generic action, denoted by an {@link Action}. @@ -47,7 +47,7 @@ public interface ElasticsearchClient { * @param The response type. * @param The request builder type. */ - > void execute(final Action action, final Request request, ActionListener listener); + > void execute(final Action action, final Request request, ActionListener listener); /** * Prepares a request builder to execute, specified by {@link Action}. @@ -58,7 +58,7 @@ public interface ElasticsearchClient { * @param The request builder. * @return The request builder, that can, at a later stage, execute the request. */ - > RequestBuilder prepareExecute(final Action action); + > RequestBuilder prepareExecute(final Action action); /** * Returns the threadpool used to execute requests on this client diff --git a/src/main/java/org/elasticsearch/client/FilterClient.java b/src/main/java/org/elasticsearch/client/FilterClient.java index 2fc9f5f9f6a..c0a93f5aa05 100644 --- a/src/main/java/org/elasticsearch/client/FilterClient.java +++ b/src/main/java/org/elasticsearch/client/FilterClient.java @@ -20,10 +20,6 @@ package org.elasticsearch.client; import org.elasticsearch.action.*; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; /** @@ -31,16 +27,18 @@ import org.elasticsearch.threadpool.ThreadPool; * uses as its basic source, possibly transforming the requests / responses along the * way or providing additional functionality. */ -public abstract class FilterClient extends AbstractClient implements AdminClient { +public abstract class FilterClient extends AbstractClient { protected final Client in; /** * Creates a new FilterClient + * * @param in the client to delegate to * @see #in() */ public FilterClient(Client in) { + super(in.settings(), in.threadPool(), in.headers()); this.in = in; } @@ -50,127 +48,14 @@ public abstract class FilterClient extends AbstractClient implements AdminClient } @Override - public AdminClient admin() { - return this; - } - - @Override - public > ActionFuture execute( - Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute( - Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { in().execute(action, request, listener); } - @Override - public Settings settings() { - return in().settings(); - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - /** * Returns the delegate {@link Client} */ protected Client in() { return in; } - - @Override - public ClusterAdminClient cluster() { - return in().admin().cluster(); - } - - @Override - public IndicesAdminClient indices() { - return in().admin().indices(); - } - - /** - * A {@link IndicesAdminClient} that contains another {@link IndicesAdminClient} which it - * uses as its basic source, possibly transforming the requests / responses along the - * way or providing additional functionality. - */ - public static class IndicesAdmin extends AbstractIndicesAdminClient { - protected final IndicesAdminClient in; - - /** - * Creates a new IndicesAdmin - * @param in the client to delegate to - * @see #in() - */ - public IndicesAdmin(IndicesAdminClient in) { - this.in = in; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - in().execute(action, request, listener); - } - - - /** - * Returns the delegate {@link Client} - */ - protected IndicesAdminClient in() { - return in; - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - } - - /** - * A {@link ClusterAdminClient} that contains another {@link ClusterAdminClient} which it - * uses as its basic source, possibly transforming the requests / responses along the - * way or providing additional functionality. - */ - public static class ClusterAdmin extends AbstractClusterAdminClient { - protected final ClusterAdminClient in; - - /** - * Creates a new ClusterAdmin - * @param in the client to delegate to - * @see #in() - */ - public ClusterAdmin(ClusterAdminClient in) { - this.in = in; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return in().execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - in().execute(action, request, listener); - } - - /** - * Returns the delegate {@link Client} - */ - protected ClusterAdminClient in() { - return in; - } - - @Override - public ThreadPool threadPool() { - return in().threadPool(); - } - } } diff --git a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java index 0852643444a..bd1af4586a7 100644 --- a/src/main/java/org/elasticsearch/client/IndicesAdminClient.java +++ b/src/main/java/org/elasticsearch/client/IndicesAdminClient.java @@ -112,7 +112,7 @@ import org.elasticsearch.common.Nullable; * * @see AdminClient#indices() */ -public interface IndicesAdminClient extends ElasticsearchClient { +public interface IndicesAdminClient extends ElasticsearchClient { /** diff --git a/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java deleted file mode 100644 index 40e25178454..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeAdminClient.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.node; - -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; - -/** - * - */ -public class NodeAdminClient extends AbstractComponent implements AdminClient { - - private final NodeIndicesAdminClient indicesAdminClient; - - private final NodeClusterAdminClient clusterAdminClient; - - @Inject - public NodeAdminClient(Settings settings, NodeClusterAdminClient clusterAdminClient, NodeIndicesAdminClient indicesAdminClient) { - super(settings); - this.indicesAdminClient = indicesAdminClient; - this.clusterAdminClient = clusterAdminClient; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdminClient; - } - - @Override - public ClusterAdminClient cluster() { - return this.clusterAdminClient; - } -} diff --git a/src/main/java/org/elasticsearch/client/node/NodeClient.java b/src/main/java/org/elasticsearch/client/node/NodeClient.java index 0c7495e3412..2ee07aee55b 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClient.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClient.java @@ -26,6 +26,8 @@ import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; +import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.MapBuilder; @@ -42,42 +44,12 @@ import java.util.Map; */ public class NodeClient extends AbstractClient { - private final ESLogger logger; - private final Settings settings; - private final ThreadPool threadPool; - - private final NodeAdminClient admin; - - private final ImmutableMap actions; - - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; + private final ImmutableMap actions; @Inject - public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - this.threadPool = threadPool; - this.admin = admin; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof ClientAction) { - actionsBuilder.put((ClientAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; + public NodeClient(Settings settings, ThreadPool threadPool, Headers headers, Map actions) { + super(settings, threadPool, headers); + this.actions = ImmutableMap.copyOf(actions); } @Override @@ -85,25 +57,13 @@ public class NodeClient extends AbstractClient { // nothing really to do } - @Override - public AdminClient admin() { - return this.admin; - } - @SuppressWarnings("unchecked") @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((ClientAction)action); + public > void doExecute(Action action, Request request, ActionListener listener) { + TransportAction transportAction = actions.get(action); + if (transportAction == null) { + throw new IllegalStateException("failed to find action [" + action + "] to execute"); + } transportAction.execute(request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClientModule.java b/src/main/java/org/elasticsearch/client/node/NodeClientModule.java index ea3a81a105f..fb0891da8cc 100644 --- a/src/main/java/org/elasticsearch/client/node/NodeClientModule.java +++ b/src/main/java/org/elasticsearch/client/node/NodeClientModule.java @@ -19,10 +19,7 @@ package org.elasticsearch.client.node; -import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.inject.AbstractModule; @@ -34,9 +31,6 @@ public class NodeClientModule extends AbstractModule { @Override protected void configure() { bind(Headers.class).asEagerSingleton(); - bind(ClusterAdminClient.class).to(NodeClusterAdminClient.class).asEagerSingleton(); - bind(IndicesAdminClient.class).to(NodeIndicesAdminClient.class).asEagerSingleton(); - bind(AdminClient.class).to(NodeAdminClient.class).asEagerSingleton(); bind(Client.class).to(NodeClient.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java deleted file mode 100644 index 3e5144b5449..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.node; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.action.support.TransportAction; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.Map; - -/** - * - */ -public class NodeClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { - - private final ESLogger logger; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof ClusterAction) { - actionsBuilder.put((ClusterAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((ClusterAction)action); - transportAction.execute(request, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java deleted file mode 100644 index 6db38103f59..00000000000 --- a/src/main/java/org/elasticsearch/client/node/NodeIndicesAdminClient.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.node; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.action.support.TransportAction; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; - -import java.util.Map; - -/** - * - */ -public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { - - private final ESLogger logger; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (Map.Entry entry : actions.entrySet()) { - if (entry.getKey() instanceof IndicesAction) { - actionsBuilder.put((IndicesAction) entry.getKey(), entry.getValue()); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(Action action, Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - TransportAction transportAction = actions.get((IndicesAction)action); - transportAction.execute(request, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/support/AbstractClient.java b/src/main/java/org/elasticsearch/client/support/AbstractClient.java index 7bfdfa14198..6ac9a0202ab 100644 --- a/src/main/java/org/elasticsearch/client/support/AbstractClient.java +++ b/src/main/java/org/elasticsearch/client/support/AbstractClient.java @@ -20,6 +20,194 @@ package org.elasticsearch.client.support; import org.elasticsearch.action.*; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryAction; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequestBuilder; +import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; +import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotAction; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequestBuilder; +import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; +import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder; +import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksAction; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequestBuilder; +import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistAction; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; +import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder; +import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; +import org.elasticsearch.action.admin.indices.close.CloseIndexAction; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; +import org.elasticsearch.action.admin.indices.create.CreateIndexAction; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequestBuilder; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; +import org.elasticsearch.action.admin.indices.flush.FlushAction; +import org.elasticsearch.action.admin.indices.flush.FlushRequest; +import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder; +import org.elasticsearch.action.admin.indices.flush.FlushResponse; +import org.elasticsearch.action.admin.indices.get.GetIndexAction; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.get.GetIndexResponse; +import org.elasticsearch.action.admin.indices.mapping.get.*; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; +import org.elasticsearch.action.admin.indices.open.OpenIndexAction; +import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; +import org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; +import org.elasticsearch.action.admin.indices.optimize.OptimizeAction; +import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; +import org.elasticsearch.action.admin.indices.optimize.OptimizeRequestBuilder; +import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; +import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; +import org.elasticsearch.action.admin.indices.recovery.RecoveryRequest; +import org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder; +import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; +import org.elasticsearch.action.admin.indices.refresh.RefreshAction; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; +import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsAction; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder; +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder; +import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder; +import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequestBuilder; +import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder; +import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequestBuilder; +import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerAction; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequest; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersAction; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequest; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerAction; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequest; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequestBuilder; +import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse; import org.elasticsearch.action.bulk.BulkAction; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequestBuilder; @@ -70,24 +258,83 @@ import org.elasticsearch.action.suggest.SuggestAction; import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestResponse; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.action.support.ThreadedActionListener; import org.elasticsearch.action.termvectors.*; import org.elasticsearch.action.update.UpdateAction; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.action.update.UpdateResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.*; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; /** * */ -public abstract class AbstractClient implements Client { +public abstract class AbstractClient extends AbstractComponent implements Client { + + private final ThreadPool threadPool; + private final Admin admin; + + private final Headers headers; + private final ThreadedActionListener.Wrapper threadedWrapper; + + public AbstractClient(Settings settings, ThreadPool threadPool, Headers headers) { + super(settings); + this.threadPool = threadPool; + this.headers = headers; + this.admin = new Admin(this); + this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); + } @Override - public > RequestBuilder prepareExecute(final Action action) { + public Headers headers() { + return this.headers; + } + + @Override + public final Settings settings() { + return this.settings; + } + + @Override + public final ThreadPool threadPool() { + return this.threadPool; + } + + @Override + public final AdminClient admin() { + return admin; + } + + @Override + public final > RequestBuilder prepareExecute(final Action action) { return action.newRequestBuilder(this); } + @Override + public final > ActionFuture execute(Action action, Request request) { + PlainActionFuture actionFuture = PlainActionFuture.newFuture(); + execute(action, request, actionFuture); + return actionFuture; + } + + /** + * This is the single execution point of *all* clients. + */ + @Override + public final > void execute(Action action, Request request, ActionListener listener) { + headers.applyTo(request); + listener = threadedWrapper.wrap(listener); + doExecute(action, request, listener); + } + + protected abstract > void doExecute(final Action action, final Request request, ActionListener listener); + + @Override public ActionFuture index(final IndexRequest request) { return execute(IndexAction.INSTANCE, request); @@ -100,7 +347,7 @@ public abstract class AbstractClient implements Client { @Override public IndexRequestBuilder prepareIndex() { - return new IndexRequestBuilder(this, null); + return new IndexRequestBuilder(this, IndexAction.INSTANCE, null); } @Override @@ -125,12 +372,12 @@ public abstract class AbstractClient implements Client { @Override public UpdateRequestBuilder prepareUpdate() { - return new UpdateRequestBuilder(this, null, null, null); + return new UpdateRequestBuilder(this, UpdateAction.INSTANCE, null, null, null); } @Override public UpdateRequestBuilder prepareUpdate(String index, String type, String id) { - return new UpdateRequestBuilder(this, index, type, id); + return new UpdateRequestBuilder(this, UpdateAction.INSTANCE, index, type, id); } @Override @@ -145,7 +392,7 @@ public abstract class AbstractClient implements Client { @Override public DeleteRequestBuilder prepareDelete() { - return new DeleteRequestBuilder(this, null); + return new DeleteRequestBuilder(this, DeleteAction.INSTANCE, null); } @Override @@ -165,7 +412,7 @@ public abstract class AbstractClient implements Client { @Override public BulkRequestBuilder prepareBulk() { - return new BulkRequestBuilder(this); + return new BulkRequestBuilder(this, BulkAction.INSTANCE); } @Override @@ -180,7 +427,7 @@ public abstract class AbstractClient implements Client { @Override public GetRequestBuilder prepareGet() { - return new GetRequestBuilder(this, null); + return new GetRequestBuilder(this, GetAction.INSTANCE, null); } @Override @@ -201,7 +448,7 @@ public abstract class AbstractClient implements Client { @Override public GetIndexedScriptRequestBuilder prepareGetIndexedScript() { - return new GetIndexedScriptRequestBuilder(this); + return new GetIndexedScriptRequestBuilder(this, GetIndexedScriptAction.INSTANCE); } @Override @@ -215,15 +462,11 @@ public abstract class AbstractClient implements Client { */ @Override public PutIndexedScriptRequestBuilder preparePutIndexedScript() { - return new PutIndexedScriptRequestBuilder(this); + return new PutIndexedScriptRequestBuilder(this, PutIndexedScriptAction.INSTANCE); } /** * Put the indexed script - * @param scriptLang - * @param id - * @param source - * @return */ @Override public PutIndexedScriptRequestBuilder preparePutIndexedScript(@Nullable String scriptLang, String id, String source){ @@ -232,9 +475,6 @@ public abstract class AbstractClient implements Client { /** * Put an indexed script - * - * @param request - * @param listener */ @Override public void putIndexedScript(final PutIndexedScriptRequest request, ActionListener listener){ @@ -255,9 +495,6 @@ public abstract class AbstractClient implements Client { /** * delete an indexed script - * - * @param request - * @param listener */ @Override public void deleteIndexedScript(DeleteIndexedScriptRequest request, ActionListener listener){ @@ -286,9 +523,6 @@ public abstract class AbstractClient implements Client { /** * Delete an indexed script - * @param scriptLang - * @param id - * @return */ @Override public DeleteIndexedScriptRequestBuilder prepareDeleteIndexedScript(@Nullable String scriptLang, String id){ @@ -309,7 +543,7 @@ public abstract class AbstractClient implements Client { @Override public MultiGetRequestBuilder prepareMultiGet() { - return new MultiGetRequestBuilder(this); + return new MultiGetRequestBuilder(this, MultiGetAction.INSTANCE); } @Override @@ -324,7 +558,7 @@ public abstract class AbstractClient implements Client { @Override public SearchRequestBuilder prepareSearch(String... indices) { - return new SearchRequestBuilder(this).setIndices(indices); + return new SearchRequestBuilder(this, SearchAction.INSTANCE).setIndices(indices); } @Override @@ -339,7 +573,7 @@ public abstract class AbstractClient implements Client { @Override public SearchScrollRequestBuilder prepareSearchScroll(String scrollId) { - return new SearchScrollRequestBuilder(this, scrollId); + return new SearchScrollRequestBuilder(this, SearchScrollAction.INSTANCE, scrollId); } @Override @@ -354,7 +588,7 @@ public abstract class AbstractClient implements Client { @Override public MultiSearchRequestBuilder prepareMultiSearch() { - return new MultiSearchRequestBuilder(this); + return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE); } @Override @@ -369,7 +603,7 @@ public abstract class AbstractClient implements Client { @Override public CountRequestBuilder prepareCount(String... indices) { - return new CountRequestBuilder(this).setIndices(indices); + return new CountRequestBuilder(this, CountAction.INSTANCE).setIndices(indices); } @Override @@ -384,7 +618,7 @@ public abstract class AbstractClient implements Client { @Override public ExistsRequestBuilder prepareExists(String... indices) { - return new ExistsRequestBuilder(this).setIndices(indices); + return new ExistsRequestBuilder(this, ExistsAction.INSTANCE).setIndices(indices); } @Override @@ -399,7 +633,7 @@ public abstract class AbstractClient implements Client { @Override public SuggestRequestBuilder prepareSuggest(String... indices) { - return new SuggestRequestBuilder(this).setIndices(indices); + return new SuggestRequestBuilder(this, SuggestAction.INSTANCE).setIndices(indices); } @Override @@ -414,7 +648,7 @@ public abstract class AbstractClient implements Client { @Override public MoreLikeThisRequestBuilder prepareMoreLikeThis(String index, String type, String id) { - return new MoreLikeThisRequestBuilder(this, index, type, id); + return new MoreLikeThisRequestBuilder(this, MoreLikeThisAction.INSTANCE, index, type, id); } @Override @@ -429,12 +663,12 @@ public abstract class AbstractClient implements Client { @Override public TermVectorsRequestBuilder prepareTermVectors() { - return new TermVectorsRequestBuilder(this); + return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE); } @Override public TermVectorsRequestBuilder prepareTermVectors(String index, String type, String id) { - return new TermVectorsRequestBuilder(this, index, type, id); + return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE, index, type, id); } @Deprecated @@ -473,7 +707,7 @@ public abstract class AbstractClient implements Client { @Override public MultiTermVectorsRequestBuilder prepareMultiTermVectors() { - return new MultiTermVectorsRequestBuilder(this); + return new MultiTermVectorsRequestBuilder(this, MultiTermVectorsAction.INSTANCE); } @Override @@ -488,12 +722,12 @@ public abstract class AbstractClient implements Client { @Override public PercolateRequestBuilder preparePercolate() { - return new PercolateRequestBuilder(this); + return new PercolateRequestBuilder(this, PercolateAction.INSTANCE); } @Override public MultiPercolateRequestBuilder prepareMultiPercolate() { - return new MultiPercolateRequestBuilder(this); + return new MultiPercolateRequestBuilder(this, MultiPercolateAction.INSTANCE); } @Override @@ -508,7 +742,7 @@ public abstract class AbstractClient implements Client { @Override public ExplainRequestBuilder prepareExplain(String index, String type, String id) { - return new ExplainRequestBuilder(this, index, type, id); + return new ExplainRequestBuilder(this, ExplainAction.INSTANCE, index, type, id); } @Override @@ -533,7 +767,7 @@ public abstract class AbstractClient implements Client { @Override public ClearScrollRequestBuilder prepareClearScroll() { - return new ClearScrollRequestBuilder(this); + return new ClearScrollRequestBuilder(this, ClearScrollAction.INSTANCE); } @Override @@ -548,6 +782,838 @@ public abstract class AbstractClient implements Client { @Override public FieldStatsRequestBuilder prepareFieldStats() { - return new FieldStatsRequestBuilder(this); + return new FieldStatsRequestBuilder(this, FieldStatsAction.INSTANCE); + } + + static class Admin implements AdminClient { + + private final ClusterAdmin clusterAdmin; + private final IndicesAdmin indicesAdmin; + + public Admin(ElasticsearchClient client) { + this.clusterAdmin = new ClusterAdmin(client); + this.indicesAdmin = new IndicesAdmin(client); + } + + @Override + public ClusterAdminClient cluster() { + return clusterAdmin; + } + + @Override + public IndicesAdminClient indices() { + return indicesAdmin; + } + } + + static class ClusterAdmin implements ClusterAdminClient { + + private final ElasticsearchClient client; + + public ClusterAdmin(ElasticsearchClient client) { + this.client = client; + } + + @Override + public > ActionFuture execute(Action action, Request request) { + return client.execute(action, request); + } + + @Override + public > void execute(Action action, Request request, ActionListener listener) { + client.execute(action, request, listener); + } + + @Override + public > RequestBuilder prepareExecute(Action action) { + return client.prepareExecute(action); + } + + @Override + public ThreadPool threadPool() { + return client.threadPool(); + } + + @Override + public ActionFuture health(final ClusterHealthRequest request) { + return execute(ClusterHealthAction.INSTANCE, request); + } + + @Override + public void health(final ClusterHealthRequest request, final ActionListener listener) { + execute(ClusterHealthAction.INSTANCE, request, listener); + } + + @Override + public ClusterHealthRequestBuilder prepareHealth(String... indices) { + return new ClusterHealthRequestBuilder(this, ClusterHealthAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture state(final ClusterStateRequest request) { + return execute(ClusterStateAction.INSTANCE, request); + } + + @Override + public void state(final ClusterStateRequest request, final ActionListener listener) { + execute(ClusterStateAction.INSTANCE, request, listener); + } + + @Override + public ClusterStateRequestBuilder prepareState() { + return new ClusterStateRequestBuilder(this, ClusterStateAction.INSTANCE); + } + + @Override + public ActionFuture reroute(final ClusterRerouteRequest request) { + return execute(ClusterRerouteAction.INSTANCE, request); + } + + @Override + public void reroute(final ClusterRerouteRequest request, final ActionListener listener) { + execute(ClusterRerouteAction.INSTANCE, request, listener); + } + + @Override + public ClusterRerouteRequestBuilder prepareReroute() { + return new ClusterRerouteRequestBuilder(this, ClusterRerouteAction.INSTANCE); + } + + @Override + public ActionFuture updateSettings(final ClusterUpdateSettingsRequest request) { + return execute(ClusterUpdateSettingsAction.INSTANCE, request); + } + + @Override + public void updateSettings(final ClusterUpdateSettingsRequest request, final ActionListener listener) { + execute(ClusterUpdateSettingsAction.INSTANCE, request, listener); + } + + @Override + public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { + return new ClusterUpdateSettingsRequestBuilder(this, ClusterUpdateSettingsAction.INSTANCE); + } + + @Override + public ActionFuture nodesInfo(final NodesInfoRequest request) { + return execute(NodesInfoAction.INSTANCE, request); + } + + @Override + public void nodesInfo(final NodesInfoRequest request, final ActionListener listener) { + execute(NodesInfoAction.INSTANCE, request, listener); + } + + @Override + public NodesInfoRequestBuilder prepareNodesInfo(String... nodesIds) { + return new NodesInfoRequestBuilder(this, NodesInfoAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture nodesStats(final NodesStatsRequest request) { + return execute(NodesStatsAction.INSTANCE, request); + } + + @Override + public void nodesStats(final NodesStatsRequest request, final ActionListener listener) { + execute(NodesStatsAction.INSTANCE, request, listener); + } + + @Override + public NodesStatsRequestBuilder prepareNodesStats(String... nodesIds) { + return new NodesStatsRequestBuilder(this, NodesStatsAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture clusterStats(ClusterStatsRequest request) { + return execute(ClusterStatsAction.INSTANCE, request); + } + + @Override + public void clusterStats(ClusterStatsRequest request, ActionListener listener) { + execute(ClusterStatsAction.INSTANCE, request, listener); + } + + @Override + public ClusterStatsRequestBuilder prepareClusterStats() { + return new ClusterStatsRequestBuilder(this, ClusterStatsAction.INSTANCE); + } + + @Override + public ActionFuture nodesHotThreads(NodesHotThreadsRequest request) { + return execute(NodesHotThreadsAction.INSTANCE, request); + } + + @Override + public void nodesHotThreads(NodesHotThreadsRequest request, ActionListener listener) { + execute(NodesHotThreadsAction.INSTANCE, request, listener); + } + + @Override + public NodesHotThreadsRequestBuilder prepareNodesHotThreads(String... nodesIds) { + return new NodesHotThreadsRequestBuilder(this, NodesHotThreadsAction.INSTANCE).setNodesIds(nodesIds); + } + + @Override + public ActionFuture searchShards(final ClusterSearchShardsRequest request) { + return execute(ClusterSearchShardsAction.INSTANCE, request); + } + + @Override + public void searchShards(final ClusterSearchShardsRequest request, final ActionListener listener) { + execute(ClusterSearchShardsAction.INSTANCE, request, listener); + } + + @Override + public ClusterSearchShardsRequestBuilder prepareSearchShards() { + return new ClusterSearchShardsRequestBuilder(this, ClusterSearchShardsAction.INSTANCE); + } + + @Override + public ClusterSearchShardsRequestBuilder prepareSearchShards(String... indices) { + return new ClusterSearchShardsRequestBuilder(this, ClusterSearchShardsAction.INSTANCE).setIndices(indices); + } + + @Override + public PendingClusterTasksRequestBuilder preparePendingClusterTasks() { + return new PendingClusterTasksRequestBuilder(this, PendingClusterTasksAction.INSTANCE); + } + + @Override + public ActionFuture pendingClusterTasks(PendingClusterTasksRequest request) { + return execute(PendingClusterTasksAction.INSTANCE, request); + } + + @Override + public void pendingClusterTasks(PendingClusterTasksRequest request, ActionListener listener) { + execute(PendingClusterTasksAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture putRepository(PutRepositoryRequest request) { + return execute(PutRepositoryAction.INSTANCE, request); + } + + @Override + public void putRepository(PutRepositoryRequest request, ActionListener listener) { + execute(PutRepositoryAction.INSTANCE, request, listener); + } + + @Override + public PutRepositoryRequestBuilder preparePutRepository(String name) { + return new PutRepositoryRequestBuilder(this, PutRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture createSnapshot(CreateSnapshotRequest request) { + return execute(CreateSnapshotAction.INSTANCE, request); + } + + @Override + public void createSnapshot(CreateSnapshotRequest request, ActionListener listener) { + execute(CreateSnapshotAction.INSTANCE, request, listener); + } + + @Override + public CreateSnapshotRequestBuilder prepareCreateSnapshot(String repository, String name) { + return new CreateSnapshotRequestBuilder(this, CreateSnapshotAction.INSTANCE, repository, name); + } + + @Override + public ActionFuture getSnapshots(GetSnapshotsRequest request) { + return execute(GetSnapshotsAction.INSTANCE, request); + } + + @Override + public void getSnapshots(GetSnapshotsRequest request, ActionListener listener) { + execute(GetSnapshotsAction.INSTANCE, request, listener); + } + + @Override + public GetSnapshotsRequestBuilder prepareGetSnapshots(String repository) { + return new GetSnapshotsRequestBuilder(this, GetSnapshotsAction.INSTANCE, repository); + } + + + @Override + public ActionFuture deleteSnapshot(DeleteSnapshotRequest request) { + return execute(DeleteSnapshotAction.INSTANCE, request); + } + + @Override + public void deleteSnapshot(DeleteSnapshotRequest request, ActionListener listener) { + execute(DeleteSnapshotAction.INSTANCE, request, listener); + } + + @Override + public DeleteSnapshotRequestBuilder prepareDeleteSnapshot(String repository, String name) { + return new DeleteSnapshotRequestBuilder(this, DeleteSnapshotAction.INSTANCE, repository, name); + } + + + @Override + public ActionFuture deleteRepository(DeleteRepositoryRequest request) { + return execute(DeleteRepositoryAction.INSTANCE, request); + } + + @Override + public void deleteRepository(DeleteRepositoryRequest request, ActionListener listener) { + execute(DeleteRepositoryAction.INSTANCE, request, listener); + } + + @Override + public DeleteRepositoryRequestBuilder prepareDeleteRepository(String name) { + return new DeleteRepositoryRequestBuilder(this, DeleteRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture verifyRepository(VerifyRepositoryRequest request) { + return execute(VerifyRepositoryAction.INSTANCE, request); + } + + @Override + public void verifyRepository(VerifyRepositoryRequest request, ActionListener listener) { + execute(VerifyRepositoryAction.INSTANCE, request, listener); + } + + @Override + public VerifyRepositoryRequestBuilder prepareVerifyRepository(String name) { + return new VerifyRepositoryRequestBuilder(this, VerifyRepositoryAction.INSTANCE, name); + } + + @Override + public ActionFuture getRepositories(GetRepositoriesRequest request) { + return execute(GetRepositoriesAction.INSTANCE, request); + } + + @Override + public void getRepositories(GetRepositoriesRequest request, ActionListener listener) { + execute(GetRepositoriesAction.INSTANCE, request, listener); + } + + @Override + public GetRepositoriesRequestBuilder prepareGetRepositories(String... name) { + return new GetRepositoriesRequestBuilder(this, GetRepositoriesAction.INSTANCE, name); + } + + @Override + public ActionFuture restoreSnapshot(RestoreSnapshotRequest request) { + return execute(RestoreSnapshotAction.INSTANCE, request); + } + + @Override + public void restoreSnapshot(RestoreSnapshotRequest request, ActionListener listener) { + execute(RestoreSnapshotAction.INSTANCE, request, listener); + } + + @Override + public RestoreSnapshotRequestBuilder prepareRestoreSnapshot(String repository, String snapshot) { + return new RestoreSnapshotRequestBuilder(this, RestoreSnapshotAction.INSTANCE, repository, snapshot); + } + + + @Override + public ActionFuture snapshotsStatus(SnapshotsStatusRequest request) { + return execute(SnapshotsStatusAction.INSTANCE, request); + } + + @Override + public void snapshotsStatus(SnapshotsStatusRequest request, ActionListener listener) { + execute(SnapshotsStatusAction.INSTANCE, request, listener); + } + + @Override + public SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository) { + return new SnapshotsStatusRequestBuilder(this, SnapshotsStatusAction.INSTANCE, repository); + } + + @Override + public SnapshotsStatusRequestBuilder prepareSnapshotStatus() { + return new SnapshotsStatusRequestBuilder(this, SnapshotsStatusAction.INSTANCE); + } + } + + static class IndicesAdmin implements IndicesAdminClient { + + private final ElasticsearchClient client; + + public IndicesAdmin(ElasticsearchClient client) { + this.client = client; + } + + @Override + public > ActionFuture execute(Action action, Request request) { + return client.execute(action, request); + } + + @Override + public > void execute(Action action, Request request, ActionListener listener) { + client.execute(action, request, listener); + } + + @Override + public > RequestBuilder prepareExecute(Action action) { + return client.prepareExecute(action); + } + + @Override + public ThreadPool threadPool() { + return client.threadPool(); + } + + @Override + public ActionFuture exists(final IndicesExistsRequest request) { + return execute(IndicesExistsAction.INSTANCE, request); + } + + @Override + public void exists(final IndicesExistsRequest request, final ActionListener listener) { + execute(IndicesExistsAction.INSTANCE, request, listener); + } + + @Override + public IndicesExistsRequestBuilder prepareExists(String... indices) { + return new IndicesExistsRequestBuilder(this, IndicesExistsAction.INSTANCE, indices); + } + + @Override + public ActionFuture typesExists(TypesExistsRequest request) { + return execute(TypesExistsAction.INSTANCE, request); + } + + @Override + public void typesExists(TypesExistsRequest request, ActionListener listener) { + execute(TypesExistsAction.INSTANCE, request, listener); + } + + @Override + public TypesExistsRequestBuilder prepareTypesExists(String... index) { + return new TypesExistsRequestBuilder(this, TypesExistsAction.INSTANCE, index); + } + + @Override + public ActionFuture aliases(final IndicesAliasesRequest request) { + return execute(IndicesAliasesAction.INSTANCE, request); + } + + @Override + public void aliases(final IndicesAliasesRequest request, final ActionListener listener) { + execute(IndicesAliasesAction.INSTANCE, request, listener); + } + + @Override + public IndicesAliasesRequestBuilder prepareAliases() { + return new IndicesAliasesRequestBuilder(this, IndicesAliasesAction.INSTANCE); + } + + @Override + public ActionFuture getAliases(GetAliasesRequest request) { + return execute(GetAliasesAction.INSTANCE, request); + } + + @Override + public void getAliases(GetAliasesRequest request, ActionListener listener) { + execute(GetAliasesAction.INSTANCE, request, listener); + } + + @Override + public GetAliasesRequestBuilder prepareGetAliases(String... aliases) { + return new GetAliasesRequestBuilder(this, GetAliasesAction.INSTANCE, aliases); + } + + @Override + public ActionFuture clearCache(final ClearIndicesCacheRequest request) { + return execute(ClearIndicesCacheAction.INSTANCE, request); + } + + @Override + public void aliasesExist(GetAliasesRequest request, ActionListener listener) { + execute(AliasesExistAction.INSTANCE, request, listener); + } + + @Override + public ActionFuture aliasesExist(GetAliasesRequest request) { + return execute(AliasesExistAction.INSTANCE, request); + } + + @Override + public AliasesExistRequestBuilder prepareAliasesExist(String... aliases) { + return new AliasesExistRequestBuilder(this, AliasesExistAction.INSTANCE, aliases); + } + + @Override + public ActionFuture getIndex(GetIndexRequest request) { + return execute(GetIndexAction.INSTANCE, request); + } + + @Override + public void getIndex(GetIndexRequest request, ActionListener listener) { + execute(GetIndexAction.INSTANCE, request, listener); + } + + @Override + public GetIndexRequestBuilder prepareGetIndex() { + return new GetIndexRequestBuilder(this, GetIndexAction.INSTANCE); + } + + @Override + public void clearCache(final ClearIndicesCacheRequest request, final ActionListener listener) { + execute(ClearIndicesCacheAction.INSTANCE, request, listener); + } + + @Override + public ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { + return new ClearIndicesCacheRequestBuilder(this, ClearIndicesCacheAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture create(final CreateIndexRequest request) { + return execute(CreateIndexAction.INSTANCE, request); + } + + @Override + public void create(final CreateIndexRequest request, final ActionListener listener) { + execute(CreateIndexAction.INSTANCE, request, listener); + } + + @Override + public CreateIndexRequestBuilder prepareCreate(String index) { + return new CreateIndexRequestBuilder(this, CreateIndexAction.INSTANCE, index); + } + + @Override + public ActionFuture delete(final DeleteIndexRequest request) { + return execute(DeleteIndexAction.INSTANCE, request); + } + + @Override + public void delete(final DeleteIndexRequest request, final ActionListener listener) { + execute(DeleteIndexAction.INSTANCE, request, listener); + } + + @Override + public DeleteIndexRequestBuilder prepareDelete(String... indices) { + return new DeleteIndexRequestBuilder(this, DeleteIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture close(final CloseIndexRequest request) { + return execute(CloseIndexAction.INSTANCE, request); + } + + @Override + public void close(final CloseIndexRequest request, final ActionListener listener) { + execute(CloseIndexAction.INSTANCE, request, listener); + } + + @Override + public CloseIndexRequestBuilder prepareClose(String... indices) { + return new CloseIndexRequestBuilder(this, CloseIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture open(final OpenIndexRequest request) { + return execute(OpenIndexAction.INSTANCE, request); + } + + @Override + public void open(final OpenIndexRequest request, final ActionListener listener) { + execute(OpenIndexAction.INSTANCE, request, listener); + } + + @Override + public OpenIndexRequestBuilder prepareOpen(String... indices) { + return new OpenIndexRequestBuilder(this, OpenIndexAction.INSTANCE, indices); + } + + @Override + public ActionFuture flush(final FlushRequest request) { + return execute(FlushAction.INSTANCE, request); + } + + @Override + public void flush(final FlushRequest request, final ActionListener listener) { + execute(FlushAction.INSTANCE, request, listener); + } + + @Override + public FlushRequestBuilder prepareFlush(String... indices) { + return new FlushRequestBuilder(this, FlushAction.INSTANCE).setIndices(indices); + } + + @Override + public void getMappings(GetMappingsRequest request, ActionListener listener) { + execute(GetMappingsAction.INSTANCE, request, listener); + } + + @Override + public void getFieldMappings(GetFieldMappingsRequest request, ActionListener listener) { + execute(GetFieldMappingsAction.INSTANCE, request, listener); + } + + @Override + public GetMappingsRequestBuilder prepareGetMappings(String... indices) { + return new GetMappingsRequestBuilder(this, GetMappingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getMappings(GetMappingsRequest request) { + return execute(GetMappingsAction.INSTANCE, request); + } + + @Override + public GetFieldMappingsRequestBuilder prepareGetFieldMappings(String... indices) { + return new GetFieldMappingsRequestBuilder(this, GetFieldMappingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getFieldMappings(GetFieldMappingsRequest request) { + return execute(GetFieldMappingsAction.INSTANCE, request); + } + + @Override + public ActionFuture putMapping(final PutMappingRequest request) { + return execute(PutMappingAction.INSTANCE, request); + } + + @Override + public void putMapping(final PutMappingRequest request, final ActionListener listener) { + execute(PutMappingAction.INSTANCE, request, listener); + } + + @Override + public PutMappingRequestBuilder preparePutMapping(String... indices) { + return new PutMappingRequestBuilder(this, PutMappingAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture optimize(final OptimizeRequest request) { + return execute(OptimizeAction.INSTANCE, request); + } + + @Override + public void optimize(final OptimizeRequest request, final ActionListener listener) { + execute(OptimizeAction.INSTANCE, request, listener); + } + + @Override + public OptimizeRequestBuilder prepareOptimize(String... indices) { + return new OptimizeRequestBuilder(this, OptimizeAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture refresh(final RefreshRequest request) { + return execute(RefreshAction.INSTANCE, request); + } + + @Override + public void refresh(final RefreshRequest request, final ActionListener listener) { + execute(RefreshAction.INSTANCE, request, listener); + } + + @Override + public RefreshRequestBuilder prepareRefresh(String... indices) { + return new RefreshRequestBuilder(this, RefreshAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture stats(final IndicesStatsRequest request) { + return execute(IndicesStatsAction.INSTANCE, request); + } + + @Override + public void stats(final IndicesStatsRequest request, final ActionListener listener) { + execute(IndicesStatsAction.INSTANCE, request, listener); + } + + @Override + public IndicesStatsRequestBuilder prepareStats(String... indices) { + return new IndicesStatsRequestBuilder(this, IndicesStatsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture recoveries(final RecoveryRequest request) { + return execute(RecoveryAction.INSTANCE, request); + } + + @Override + public void recoveries(final RecoveryRequest request, final ActionListener listener) { + execute(RecoveryAction.INSTANCE, request, listener); + } + + @Override + public RecoveryRequestBuilder prepareRecoveries(String... indices) { + return new RecoveryRequestBuilder(this, RecoveryAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture segments(final IndicesSegmentsRequest request) { + return execute(IndicesSegmentsAction.INSTANCE, request); + } + + @Override + public void segments(final IndicesSegmentsRequest request, final ActionListener listener) { + execute(IndicesSegmentsAction.INSTANCE, request, listener); + } + + @Override + public IndicesSegmentsRequestBuilder prepareSegments(String... indices) { + return new IndicesSegmentsRequestBuilder(this, IndicesSegmentsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture updateSettings(final UpdateSettingsRequest request) { + return execute(UpdateSettingsAction.INSTANCE, request); + } + + @Override + public void updateSettings(final UpdateSettingsRequest request, final ActionListener listener) { + execute(UpdateSettingsAction.INSTANCE, request, listener); + } + + @Override + public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { + return new UpdateSettingsRequestBuilder(this, UpdateSettingsAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture analyze(final AnalyzeRequest request) { + return execute(AnalyzeAction.INSTANCE, request); + } + + @Override + public void analyze(final AnalyzeRequest request, final ActionListener listener) { + execute(AnalyzeAction.INSTANCE, request, listener); + } + + @Override + public AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text) { + return new AnalyzeRequestBuilder(this, AnalyzeAction.INSTANCE, index, text); + } + + @Override + public AnalyzeRequestBuilder prepareAnalyze(String text) { + return new AnalyzeRequestBuilder(this, AnalyzeAction.INSTANCE, null, text); + } + + @Override + public ActionFuture putTemplate(final PutIndexTemplateRequest request) { + return execute(PutIndexTemplateAction.INSTANCE, request); + } + + @Override + public void putTemplate(final PutIndexTemplateRequest request, final ActionListener listener) { + execute(PutIndexTemplateAction.INSTANCE, request, listener); + } + + @Override + public PutIndexTemplateRequestBuilder preparePutTemplate(String name) { + return new PutIndexTemplateRequestBuilder(this, PutIndexTemplateAction.INSTANCE, name); + } + + @Override + public ActionFuture getTemplates(final GetIndexTemplatesRequest request) { + return execute(GetIndexTemplatesAction.INSTANCE, request); + } + + @Override + public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener listener) { + execute(GetIndexTemplatesAction.INSTANCE, request, listener); + } + + @Override + public GetIndexTemplatesRequestBuilder prepareGetTemplates(String... names) { + return new GetIndexTemplatesRequestBuilder(this, GetIndexTemplatesAction.INSTANCE, names); + } + + @Override + public ActionFuture deleteTemplate(final DeleteIndexTemplateRequest request) { + return execute(DeleteIndexTemplateAction.INSTANCE, request); + } + + @Override + public void deleteTemplate(final DeleteIndexTemplateRequest request, final ActionListener listener) { + execute(DeleteIndexTemplateAction.INSTANCE, request, listener); + } + + @Override + public DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) { + return new DeleteIndexTemplateRequestBuilder(this, DeleteIndexTemplateAction.INSTANCE, name); + } + + @Override + public ActionFuture validateQuery(final ValidateQueryRequest request) { + return execute(ValidateQueryAction.INSTANCE, request); + } + + @Override + public void validateQuery(final ValidateQueryRequest request, final ActionListener listener) { + execute(ValidateQueryAction.INSTANCE, request, listener); + } + + @Override + public ValidateQueryRequestBuilder prepareValidateQuery(String... indices) { + return new ValidateQueryRequestBuilder(this, ValidateQueryAction.INSTANCE).setIndices(indices); + } + + @Override + public ActionFuture putWarmer(PutWarmerRequest request) { + return execute(PutWarmerAction.INSTANCE, request); + } + + @Override + public void putWarmer(PutWarmerRequest request, ActionListener listener) { + execute(PutWarmerAction.INSTANCE, request, listener); + } + + @Override + public PutWarmerRequestBuilder preparePutWarmer(String name) { + return new PutWarmerRequestBuilder(this, PutWarmerAction.INSTANCE, name); + } + + @Override + public ActionFuture deleteWarmer(DeleteWarmerRequest request) { + return execute(DeleteWarmerAction.INSTANCE, request); + } + + @Override + public void deleteWarmer(DeleteWarmerRequest request, ActionListener listener) { + execute(DeleteWarmerAction.INSTANCE, request, listener); + } + + @Override + public DeleteWarmerRequestBuilder prepareDeleteWarmer() { + return new DeleteWarmerRequestBuilder(this, DeleteWarmerAction.INSTANCE); + } + + @Override + public GetWarmersRequestBuilder prepareGetWarmers(String... indices) { + return new GetWarmersRequestBuilder(this, GetWarmersAction.INSTANCE, indices); + } + + @Override + public ActionFuture getWarmers(GetWarmersRequest request) { + return execute(GetWarmersAction.INSTANCE, request); + } + + @Override + public void getWarmers(GetWarmersRequest request, ActionListener listener) { + execute(GetWarmersAction.INSTANCE, request, listener); + } + + @Override + public GetSettingsRequestBuilder prepareGetSettings(String... indices) { + return new GetSettingsRequestBuilder(this, GetSettingsAction.INSTANCE, indices); + } + + @Override + public ActionFuture getSettings(GetSettingsRequest request) { + return execute(GetSettingsAction.INSTANCE, request); + } + + @Override + public void getSettings(GetSettingsRequest request, ActionListener listener) { + execute(GetSettingsAction.INSTANCE, request, listener); + } } } diff --git a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java deleted file mode 100644 index f4a6e58e49a..00000000000 --- a/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequest; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsAction; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesAction; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryAction; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequestBuilder; -import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteAction; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; -import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsAction; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequestBuilder; -import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsResponse; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsAction; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotAction; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusAction; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequestBuilder; -import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; -import org.elasticsearch.action.admin.cluster.state.ClusterStateAction; -import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; -import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder; -import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksAction; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequestBuilder; -import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse; -import org.elasticsearch.client.ClusterAdminClient; - -/** - * - */ -public abstract class AbstractClusterAdminClient implements ClusterAdminClient { - - @Override - public > RequestBuilder prepareExecute(Action action) { - return action.newRequestBuilder(this); - } - - @Override - public ActionFuture health(final ClusterHealthRequest request) { - return execute(ClusterHealthAction.INSTANCE, request); - } - - @Override - public void health(final ClusterHealthRequest request, final ActionListener listener) { - execute(ClusterHealthAction.INSTANCE, request, listener); - } - - @Override - public ClusterHealthRequestBuilder prepareHealth(String... indices) { - return new ClusterHealthRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture state(final ClusterStateRequest request) { - return execute(ClusterStateAction.INSTANCE, request); - } - - @Override - public void state(final ClusterStateRequest request, final ActionListener listener) { - execute(ClusterStateAction.INSTANCE, request, listener); - } - - @Override - public ClusterStateRequestBuilder prepareState() { - return new ClusterStateRequestBuilder(this); - } - - @Override - public ActionFuture reroute(final ClusterRerouteRequest request) { - return execute(ClusterRerouteAction.INSTANCE, request); - } - - @Override - public void reroute(final ClusterRerouteRequest request, final ActionListener listener) { - execute(ClusterRerouteAction.INSTANCE, request, listener); - } - - @Override - public ClusterRerouteRequestBuilder prepareReroute() { - return new ClusterRerouteRequestBuilder(this); - } - - @Override - public ActionFuture updateSettings(final ClusterUpdateSettingsRequest request) { - return execute(ClusterUpdateSettingsAction.INSTANCE, request); - } - - @Override - public void updateSettings(final ClusterUpdateSettingsRequest request, final ActionListener listener) { - execute(ClusterUpdateSettingsAction.INSTANCE, request, listener); - } - - @Override - public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { - return new ClusterUpdateSettingsRequestBuilder(this); - } - - @Override - public ActionFuture nodesInfo(final NodesInfoRequest request) { - return execute(NodesInfoAction.INSTANCE, request); - } - - @Override - public void nodesInfo(final NodesInfoRequest request, final ActionListener listener) { - execute(NodesInfoAction.INSTANCE, request, listener); - } - - @Override - public NodesInfoRequestBuilder prepareNodesInfo(String... nodesIds) { - return new NodesInfoRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture nodesStats(final NodesStatsRequest request) { - return execute(NodesStatsAction.INSTANCE, request); - } - - @Override - public void nodesStats(final NodesStatsRequest request, final ActionListener listener) { - execute(NodesStatsAction.INSTANCE, request, listener); - } - - @Override - public NodesStatsRequestBuilder prepareNodesStats(String... nodesIds) { - return new NodesStatsRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture clusterStats(ClusterStatsRequest request) { - return execute(ClusterStatsAction.INSTANCE, request); - } - - @Override - public void clusterStats(ClusterStatsRequest request, ActionListener listener) { - execute(ClusterStatsAction.INSTANCE, request, listener); - } - - @Override - public ClusterStatsRequestBuilder prepareClusterStats() { - return new ClusterStatsRequestBuilder(this); - } - - @Override - public ActionFuture nodesHotThreads(NodesHotThreadsRequest request) { - return execute(NodesHotThreadsAction.INSTANCE, request); - } - - @Override - public void nodesHotThreads(NodesHotThreadsRequest request, ActionListener listener) { - execute(NodesHotThreadsAction.INSTANCE, request, listener); - } - - @Override - public NodesHotThreadsRequestBuilder prepareNodesHotThreads(String... nodesIds) { - return new NodesHotThreadsRequestBuilder(this).setNodesIds(nodesIds); - } - - @Override - public ActionFuture searchShards(final ClusterSearchShardsRequest request) { - return execute(ClusterSearchShardsAction.INSTANCE, request); - } - - @Override - public void searchShards(final ClusterSearchShardsRequest request, final ActionListener listener) { - execute(ClusterSearchShardsAction.INSTANCE, request, listener); - } - - @Override - public ClusterSearchShardsRequestBuilder prepareSearchShards() { - return new ClusterSearchShardsRequestBuilder(this); - } - - @Override - public ClusterSearchShardsRequestBuilder prepareSearchShards(String... indices) { - return new ClusterSearchShardsRequestBuilder(this).setIndices(indices); - } - - @Override - public PendingClusterTasksRequestBuilder preparePendingClusterTasks() { - return new PendingClusterTasksRequestBuilder(this); - } - - @Override - public ActionFuture pendingClusterTasks(PendingClusterTasksRequest request) { - return execute(PendingClusterTasksAction.INSTANCE, request); - } - - @Override - public void pendingClusterTasks(PendingClusterTasksRequest request, ActionListener listener) { - execute(PendingClusterTasksAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture putRepository(PutRepositoryRequest request) { - return execute(PutRepositoryAction.INSTANCE, request); - } - - @Override - public void putRepository(PutRepositoryRequest request, ActionListener listener) { - execute(PutRepositoryAction.INSTANCE, request, listener); - } - - @Override - public PutRepositoryRequestBuilder preparePutRepository(String name) { - return new PutRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture createSnapshot(CreateSnapshotRequest request) { - return execute(CreateSnapshotAction.INSTANCE, request); - } - - @Override - public void createSnapshot(CreateSnapshotRequest request, ActionListener listener) { - execute(CreateSnapshotAction.INSTANCE, request, listener); - } - - @Override - public CreateSnapshotRequestBuilder prepareCreateSnapshot(String repository, String name) { - return new CreateSnapshotRequestBuilder(this, repository, name); - } - - @Override - public ActionFuture getSnapshots(GetSnapshotsRequest request) { - return execute(GetSnapshotsAction.INSTANCE, request); - } - - @Override - public void getSnapshots(GetSnapshotsRequest request, ActionListener listener) { - execute(GetSnapshotsAction.INSTANCE, request, listener); - } - - @Override - public GetSnapshotsRequestBuilder prepareGetSnapshots(String repository) { - return new GetSnapshotsRequestBuilder(this, repository); - } - - - @Override - public ActionFuture deleteSnapshot(DeleteSnapshotRequest request) { - return execute(DeleteSnapshotAction.INSTANCE, request); - } - - @Override - public void deleteSnapshot(DeleteSnapshotRequest request, ActionListener listener) { - execute(DeleteSnapshotAction.INSTANCE, request, listener); - } - - @Override - public DeleteSnapshotRequestBuilder prepareDeleteSnapshot(String repository, String name) { - return new DeleteSnapshotRequestBuilder(this, repository, name); - } - - - @Override - public ActionFuture deleteRepository(DeleteRepositoryRequest request) { - return execute(DeleteRepositoryAction.INSTANCE, request); - } - - @Override - public void deleteRepository(DeleteRepositoryRequest request, ActionListener listener) { - execute(DeleteRepositoryAction.INSTANCE, request, listener); - } - - @Override - public DeleteRepositoryRequestBuilder prepareDeleteRepository(String name) { - return new DeleteRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture verifyRepository(VerifyRepositoryRequest request) { - return execute(VerifyRepositoryAction.INSTANCE, request); - } - - @Override - public void verifyRepository(VerifyRepositoryRequest request, ActionListener listener) { - execute(VerifyRepositoryAction.INSTANCE, request, listener); - } - - @Override - public VerifyRepositoryRequestBuilder prepareVerifyRepository(String name) { - return new VerifyRepositoryRequestBuilder(this, name); - } - - @Override - public ActionFuture getRepositories(GetRepositoriesRequest request) { - return execute(GetRepositoriesAction.INSTANCE, request); - } - - @Override - public void getRepositories(GetRepositoriesRequest request, ActionListener listener) { - execute(GetRepositoriesAction.INSTANCE, request, listener); - } - - @Override - public GetRepositoriesRequestBuilder prepareGetRepositories(String... name) { - return new GetRepositoriesRequestBuilder(this, name); - } - - @Override - public ActionFuture restoreSnapshot(RestoreSnapshotRequest request) { - return execute(RestoreSnapshotAction.INSTANCE, request); - } - - @Override - public void restoreSnapshot(RestoreSnapshotRequest request, ActionListener listener) { - execute(RestoreSnapshotAction.INSTANCE, request, listener); - } - - @Override - public RestoreSnapshotRequestBuilder prepareRestoreSnapshot(String repository, String snapshot) { - return new RestoreSnapshotRequestBuilder(this, repository, snapshot); - } - - - @Override - public ActionFuture snapshotsStatus(SnapshotsStatusRequest request) { - return execute(SnapshotsStatusAction.INSTANCE, request); - } - - @Override - public void snapshotsStatus(SnapshotsStatusRequest request, ActionListener listener) { - execute(SnapshotsStatusAction.INSTANCE, request, listener); - } - - @Override - public SnapshotsStatusRequestBuilder prepareSnapshotStatus(String repository) { - return new SnapshotsStatusRequestBuilder(this, repository); - } - - @Override - public SnapshotsStatusRequestBuilder prepareSnapshotStatus() { - return new SnapshotsStatusRequestBuilder(this); - } -} diff --git a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java deleted file mode 100644 index 02f8a015170..00000000000 --- a/src/main/java/org/elasticsearch/client/support/AbstractIndicesAdminClient.java +++ /dev/null @@ -1,602 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.support; - -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistAction; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.exists.AliasesExistResponse; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesAction; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequestBuilder; -import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheAction; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder; -import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse; -import org.elasticsearch.action.admin.indices.close.CloseIndexAction; -import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; -import org.elasticsearch.action.admin.indices.close.CloseIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; -import org.elasticsearch.action.admin.indices.create.CreateIndexAction; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsAction; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsAction; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequestBuilder; -import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; -import org.elasticsearch.action.admin.indices.flush.FlushAction; -import org.elasticsearch.action.admin.indices.flush.FlushRequest; -import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder; -import org.elasticsearch.action.admin.indices.flush.FlushResponse; -import org.elasticsearch.action.admin.indices.get.GetIndexAction; -import org.elasticsearch.action.admin.indices.get.GetIndexRequest; -import org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.get.GetIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.get.*; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingAction; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; -import org.elasticsearch.action.admin.indices.open.OpenIndexAction; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; -import org.elasticsearch.action.admin.indices.optimize.OptimizeAction; -import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; -import org.elasticsearch.action.admin.indices.optimize.OptimizeRequestBuilder; -import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; -import org.elasticsearch.action.admin.indices.recovery.RecoveryAction; -import org.elasticsearch.action.admin.indices.recovery.RecoveryRequest; -import org.elasticsearch.action.admin.indices.recovery.RecoveryRequestBuilder; -import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; -import org.elasticsearch.action.admin.indices.refresh.RefreshAction; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; -import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder; -import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsAction; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest; -import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsAction; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsAction; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder; -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder; -import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder; -import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequestBuilder; -import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequestBuilder; -import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerAction; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequest; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.delete.DeleteWarmerResponse; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersAction; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequest; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersResponse; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerAction; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequest; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerRequestBuilder; -import org.elasticsearch.action.admin.indices.warmer.put.PutWarmerResponse; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.Nullable; - -/** - * - */ -public abstract class AbstractIndicesAdminClient implements IndicesAdminClient { - - @Override - public > RequestBuilder prepareExecute(final Action action) { - return action.newRequestBuilder(this); - } - - @Override - public ActionFuture exists(final IndicesExistsRequest request) { - return execute(IndicesExistsAction.INSTANCE, request); - } - - @Override - public void exists(final IndicesExistsRequest request, final ActionListener listener) { - execute(IndicesExistsAction.INSTANCE, request, listener); - } - - @Override - public IndicesExistsRequestBuilder prepareExists(String... indices) { - return new IndicesExistsRequestBuilder(this, indices); - } - - @Override - public ActionFuture typesExists(TypesExistsRequest request) { - return execute(TypesExistsAction.INSTANCE, request); - } - - @Override - public void typesExists(TypesExistsRequest request, ActionListener listener) { - execute(TypesExistsAction.INSTANCE, request, listener); - } - - @Override - public TypesExistsRequestBuilder prepareTypesExists(String... index) { - return new TypesExistsRequestBuilder(this, index); - } - - @Override - public ActionFuture aliases(final IndicesAliasesRequest request) { - return execute(IndicesAliasesAction.INSTANCE, request); - } - - @Override - public void aliases(final IndicesAliasesRequest request, final ActionListener listener) { - execute(IndicesAliasesAction.INSTANCE, request, listener); - } - - @Override - public IndicesAliasesRequestBuilder prepareAliases() { - return new IndicesAliasesRequestBuilder(this); - } - - @Override - public ActionFuture getAliases(GetAliasesRequest request) { - return execute(GetAliasesAction.INSTANCE, request); - } - - @Override - public void getAliases(GetAliasesRequest request, ActionListener listener) { - execute(GetAliasesAction.INSTANCE, request, listener); - } - - @Override - public GetAliasesRequestBuilder prepareGetAliases(String... aliases) { - return new GetAliasesRequestBuilder(this, aliases); - } - - @Override - public ActionFuture clearCache(final ClearIndicesCacheRequest request) { - return execute(ClearIndicesCacheAction.INSTANCE, request); - } - - @Override - public void aliasesExist(GetAliasesRequest request, ActionListener listener) { - execute(AliasesExistAction.INSTANCE, request, listener); - } - - @Override - public ActionFuture aliasesExist(GetAliasesRequest request) { - return execute(AliasesExistAction.INSTANCE, request); - } - - @Override - public AliasesExistRequestBuilder prepareAliasesExist(String... aliases) { - return new AliasesExistRequestBuilder(this, aliases); - } - - @Override - public ActionFuture getIndex(GetIndexRequest request) { - return execute(GetIndexAction.INSTANCE, request); - } - - @Override - public void getIndex(GetIndexRequest request, ActionListener listener) { - execute(GetIndexAction.INSTANCE, request, listener); - } - - @Override - public GetIndexRequestBuilder prepareGetIndex() { - return new GetIndexRequestBuilder(this); - } - - @Override - public void clearCache(final ClearIndicesCacheRequest request, final ActionListener listener) { - execute(ClearIndicesCacheAction.INSTANCE, request, listener); - } - - @Override - public ClearIndicesCacheRequestBuilder prepareClearCache(String... indices) { - return new ClearIndicesCacheRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture create(final CreateIndexRequest request) { - return execute(CreateIndexAction.INSTANCE, request); - } - - @Override - public void create(final CreateIndexRequest request, final ActionListener listener) { - execute(CreateIndexAction.INSTANCE, request, listener); - } - - @Override - public CreateIndexRequestBuilder prepareCreate(String index) { - return new CreateIndexRequestBuilder(this, index); - } - - @Override - public ActionFuture delete(final DeleteIndexRequest request) { - return execute(DeleteIndexAction.INSTANCE, request); - } - - @Override - public void delete(final DeleteIndexRequest request, final ActionListener listener) { - execute(DeleteIndexAction.INSTANCE, request, listener); - } - - @Override - public DeleteIndexRequestBuilder prepareDelete(String... indices) { - return new DeleteIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture close(final CloseIndexRequest request) { - return execute(CloseIndexAction.INSTANCE, request); - } - - @Override - public void close(final CloseIndexRequest request, final ActionListener listener) { - execute(CloseIndexAction.INSTANCE, request, listener); - } - - @Override - public CloseIndexRequestBuilder prepareClose(String... indices) { - return new CloseIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture open(final OpenIndexRequest request) { - return execute(OpenIndexAction.INSTANCE, request); - } - - @Override - public void open(final OpenIndexRequest request, final ActionListener listener) { - execute(OpenIndexAction.INSTANCE, request, listener); - } - - @Override - public OpenIndexRequestBuilder prepareOpen(String... indices) { - return new OpenIndexRequestBuilder(this, indices); - } - - @Override - public ActionFuture flush(final FlushRequest request) { - return execute(FlushAction.INSTANCE, request); - } - - @Override - public void flush(final FlushRequest request, final ActionListener listener) { - execute(FlushAction.INSTANCE, request, listener); - } - - @Override - public FlushRequestBuilder prepareFlush(String... indices) { - return new FlushRequestBuilder(this).setIndices(indices); - } - - @Override - public void getMappings(GetMappingsRequest request, ActionListener listener) { - execute(GetMappingsAction.INSTANCE, request, listener); - } - - @Override - public void getFieldMappings(GetFieldMappingsRequest request, ActionListener listener) { - execute(GetFieldMappingsAction.INSTANCE, request, listener); - } - - @Override - public GetMappingsRequestBuilder prepareGetMappings(String... indices) { - return new GetMappingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getMappings(GetMappingsRequest request) { - return execute(GetMappingsAction.INSTANCE, request); - } - - @Override - public GetFieldMappingsRequestBuilder prepareGetFieldMappings(String... indices) { - return new GetFieldMappingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getFieldMappings(GetFieldMappingsRequest request) { - return execute(GetFieldMappingsAction.INSTANCE, request); - } - - @Override - public ActionFuture putMapping(final PutMappingRequest request) { - return execute(PutMappingAction.INSTANCE, request); - } - - @Override - public void putMapping(final PutMappingRequest request, final ActionListener listener) { - execute(PutMappingAction.INSTANCE, request, listener); - } - - @Override - public PutMappingRequestBuilder preparePutMapping(String... indices) { - return new PutMappingRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture optimize(final OptimizeRequest request) { - return execute(OptimizeAction.INSTANCE, request); - } - - @Override - public void optimize(final OptimizeRequest request, final ActionListener listener) { - execute(OptimizeAction.INSTANCE, request, listener); - } - - @Override - public OptimizeRequestBuilder prepareOptimize(String... indices) { - return new OptimizeRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture refresh(final RefreshRequest request) { - return execute(RefreshAction.INSTANCE, request); - } - - @Override - public void refresh(final RefreshRequest request, final ActionListener listener) { - execute(RefreshAction.INSTANCE, request, listener); - } - - @Override - public RefreshRequestBuilder prepareRefresh(String... indices) { - return new RefreshRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture stats(final IndicesStatsRequest request) { - return execute(IndicesStatsAction.INSTANCE, request); - } - - @Override - public void stats(final IndicesStatsRequest request, final ActionListener listener) { - execute(IndicesStatsAction.INSTANCE, request, listener); - } - - @Override - public IndicesStatsRequestBuilder prepareStats(String... indices) { - return new IndicesStatsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture recoveries(final RecoveryRequest request) { - return execute(RecoveryAction.INSTANCE, request); - } - - @Override - public void recoveries(final RecoveryRequest request, final ActionListener listener) { - execute(RecoveryAction.INSTANCE, request, listener); - } - - @Override - public RecoveryRequestBuilder prepareRecoveries(String... indices) { - return new RecoveryRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture segments(final IndicesSegmentsRequest request) { - return execute(IndicesSegmentsAction.INSTANCE, request); - } - - @Override - public void segments(final IndicesSegmentsRequest request, final ActionListener listener) { - execute(IndicesSegmentsAction.INSTANCE, request, listener); - } - - @Override - public IndicesSegmentsRequestBuilder prepareSegments(String... indices) { - return new IndicesSegmentsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture updateSettings(final UpdateSettingsRequest request) { - return execute(UpdateSettingsAction.INSTANCE, request); - } - - @Override - public void updateSettings(final UpdateSettingsRequest request, final ActionListener listener) { - execute(UpdateSettingsAction.INSTANCE, request, listener); - } - - @Override - public UpdateSettingsRequestBuilder prepareUpdateSettings(String... indices) { - return new UpdateSettingsRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture analyze(final AnalyzeRequest request) { - return execute(AnalyzeAction.INSTANCE, request); - } - - @Override - public void analyze(final AnalyzeRequest request, final ActionListener listener) { - execute(AnalyzeAction.INSTANCE, request, listener); - } - - @Override - public AnalyzeRequestBuilder prepareAnalyze(@Nullable String index, String text) { - return new AnalyzeRequestBuilder(this, index, text); - } - - @Override - public AnalyzeRequestBuilder prepareAnalyze(String text) { - return new AnalyzeRequestBuilder(this, null, text); - } - - @Override - public ActionFuture putTemplate(final PutIndexTemplateRequest request) { - return execute(PutIndexTemplateAction.INSTANCE, request); - } - - @Override - public void putTemplate(final PutIndexTemplateRequest request, final ActionListener listener) { - execute(PutIndexTemplateAction.INSTANCE, request, listener); - } - - @Override - public PutIndexTemplateRequestBuilder preparePutTemplate(String name) { - return new PutIndexTemplateRequestBuilder(this, name); - } - - @Override - public ActionFuture getTemplates(final GetIndexTemplatesRequest request) { - return execute(GetIndexTemplatesAction.INSTANCE, request); - } - - @Override - public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener listener) { - execute(GetIndexTemplatesAction.INSTANCE, request, listener); - } - - @Override - public GetIndexTemplatesRequestBuilder prepareGetTemplates(String... names) { - return new GetIndexTemplatesRequestBuilder(this, names); - } - - @Override - public ActionFuture deleteTemplate(final DeleteIndexTemplateRequest request) { - return execute(DeleteIndexTemplateAction.INSTANCE, request); - } - - @Override - public void deleteTemplate(final DeleteIndexTemplateRequest request, final ActionListener listener) { - execute(DeleteIndexTemplateAction.INSTANCE, request, listener); - } - - @Override - public DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) { - return new DeleteIndexTemplateRequestBuilder(this, name); - } - - @Override - public ActionFuture validateQuery(final ValidateQueryRequest request) { - return execute(ValidateQueryAction.INSTANCE, request); - } - - @Override - public void validateQuery(final ValidateQueryRequest request, final ActionListener listener) { - execute(ValidateQueryAction.INSTANCE, request, listener); - } - - @Override - public ValidateQueryRequestBuilder prepareValidateQuery(String... indices) { - return new ValidateQueryRequestBuilder(this).setIndices(indices); - } - - @Override - public ActionFuture putWarmer(PutWarmerRequest request) { - return execute(PutWarmerAction.INSTANCE, request); - } - - @Override - public void putWarmer(PutWarmerRequest request, ActionListener listener) { - execute(PutWarmerAction.INSTANCE, request, listener); - } - - @Override - public PutWarmerRequestBuilder preparePutWarmer(String name) { - return new PutWarmerRequestBuilder(this, name); - } - - @Override - public ActionFuture deleteWarmer(DeleteWarmerRequest request) { - return execute(DeleteWarmerAction.INSTANCE, request); - } - - @Override - public void deleteWarmer(DeleteWarmerRequest request, ActionListener listener) { - execute(DeleteWarmerAction.INSTANCE, request, listener); - } - - @Override - public DeleteWarmerRequestBuilder prepareDeleteWarmer() { - return new DeleteWarmerRequestBuilder(this); - } - - @Override - public GetWarmersRequestBuilder prepareGetWarmers(String... indices) { - return new GetWarmersRequestBuilder(this, indices); - } - - @Override - public ActionFuture getWarmers(GetWarmersRequest request) { - return execute(GetWarmersAction.INSTANCE, request); - } - - @Override - public void getWarmers(GetWarmersRequest request, ActionListener listener) { - execute(GetWarmersAction.INSTANCE, request, listener); - } - - @Override - public GetSettingsRequestBuilder prepareGetSettings(String... indices) { - return new GetSettingsRequestBuilder(this, indices); - } - - @Override - public ActionFuture getSettings(GetSettingsRequest request) { - return execute(GetSettingsAction.INSTANCE, request); - } - - @Override - public void getSettings(GetSettingsRequest request, ActionListener listener) { - execute(GetSettingsAction.INSTANCE, request, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java b/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java index 573715c10f4..895b3d844f6 100644 --- a/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java +++ b/src/main/java/org/elasticsearch/client/transport/ClientTransportModule.java @@ -20,10 +20,7 @@ package org.elasticsearch.client.transport; import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.support.InternalTransportAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; -import org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient; +import org.elasticsearch.client.transport.support.TransportProxyClient; import org.elasticsearch.common.inject.AbstractModule; /** @@ -34,10 +31,7 @@ public class ClientTransportModule extends AbstractModule { @Override protected void configure() { bind(Headers.class).asEagerSingleton(); - bind(InternalTransportClient.class).asEagerSingleton(); - bind(InternalTransportAdminClient.class).asEagerSingleton(); - bind(InternalTransportIndicesAdminClient.class).asEagerSingleton(); - bind(InternalTransportClusterAdminClient.class).asEagerSingleton(); + bind(TransportProxyClient.class).asEagerSingleton(); bind(TransportClientNodesService.class).asEagerSingleton(); } } diff --git a/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/src/main/java/org/elasticsearch/client/transport/TransportClient.java index a39089e9a5a..c7866e6b1f9 100644 --- a/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -20,40 +20,12 @@ package org.elasticsearch.client.transport; import com.google.common.collect.ImmutableList; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.action.*; -import org.elasticsearch.action.bulk.BulkRequest; -import org.elasticsearch.action.bulk.BulkResponse; -import org.elasticsearch.action.count.CountRequest; -import org.elasticsearch.action.count.CountResponse; -import org.elasticsearch.action.delete.DeleteRequest; -import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.explain.ExplainRequest; -import org.elasticsearch.action.explain.ExplainResponse; -import org.elasticsearch.action.get.GetRequest; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetRequest; -import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.index.IndexRequest; -import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.mlt.MoreLikeThisRequest; -import org.elasticsearch.action.percolate.PercolateRequest; -import org.elasticsearch.action.percolate.PercolateResponse; -import org.elasticsearch.action.search.*; -import org.elasticsearch.action.suggest.SuggestRequest; -import org.elasticsearch.action.suggest.SuggestResponse; -import org.elasticsearch.action.termvectors.MultiTermVectorsRequest; -import org.elasticsearch.action.termvectors.MultiTermVectorsResponse; -import org.elasticsearch.action.termvectors.TermVectorsRequest; -import org.elasticsearch.action.termvectors.TermVectorsResponse; -import org.elasticsearch.action.update.UpdateRequest; -import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.cache.recycler.PageCacheRecycler; -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.Client; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; +import org.elasticsearch.client.support.Headers; +import org.elasticsearch.client.transport.support.TransportProxyClient; import org.elasticsearch.cluster.ClusterNameModule; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.collect.Tuple; @@ -93,92 +65,99 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde */ public class TransportClient extends AbstractClient { + /** + * Handy method ot create a {@link org.elasticsearch.client.transport.TransportClient.Builder}. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * A builder used to create an instance of the transport client. + */ + public static class Builder { + + private Settings settings = ImmutableSettings.EMPTY; + private boolean loadConfigSettings = true; + + /** + * The settings to configure the transport client with. + */ + public Builder settings(Settings.Builder settings) { + return settings(settings.build()); + } + + /** + * The settings to configure the transport client with. + */ + public Builder settings(Settings settings) { + this.settings = settings; + return this; + } + + /** + * Should the transport client load file based configuration automatically or not (and rely + * only on the provided settings), defaults to true. + */ + public Builder loadConfigSettings(boolean loadConfigSettings) { + this.loadConfigSettings = loadConfigSettings; + return this; + } + + /** + * Builds a new instance of the transport client. + */ + public TransportClient build() { + Tuple tuple = InternalSettingsPreparer.prepareSettings(settings, loadConfigSettings); + Settings settings = settingsBuilder() + .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval + .put(tuple.v1()) + .put("network.server", false) + .put("node.client", true) + .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) + .build(); + Environment environment = tuple.v2(); + + PluginsService pluginsService = new PluginsService(settings, tuple.v2()); + this.settings = pluginsService.updatedSettings(); + + Version version = Version.CURRENT; + + CompressorFactory.configure(this.settings); + + ModulesBuilder modules = new ModulesBuilder(); + modules.add(new Version.Module(version)); + modules.add(new PluginsModule(this.settings, pluginsService)); + modules.add(new EnvironmentModule(environment)); + modules.add(new SettingsModule(this.settings)); + modules.add(new NetworkModule()); + modules.add(new ClusterNameModule(this.settings)); + modules.add(new ThreadPoolModule(this.settings)); + modules.add(new TransportSearchModule()); + modules.add(new TransportModule(this.settings)); + modules.add(new ActionModule(true)); + modules.add(new ClientTransportModule()); + modules.add(new CircuitBreakerModule(this.settings)); + + Injector injector = modules.createInjector(); + injector.getInstance(TransportService.class).start(); + + return new TransportClient(injector); + } + } + public static final String CLIENT_TYPE = "transport"; final Injector injector; - private final Settings settings; - private final Environment environment; - private final PluginsService pluginsService; private final TransportClientNodesService nodesService; - private final InternalTransportClient internalClient; - - /** - * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file - * system (the elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient(Settings settings) { - this(settings, true); - } - - /** - * Constructs a new transport client with explicit settings and settings loaded either from the classpath or the file - * system (the elasticsearch.(yml|json) files optionally prefixed with config/). - */ - public TransportClient(Settings.Builder settings) { - this(settings.build(), true); - } - - /** - * Constructs a new transport client with the provided settings and the ability to control if settings will - * be loaded from the classpath / file system (the elasticsearch.(yml|json) files optionally prefixed with - * config/). - * - * @param settings The explicit settings. - * @param loadConfigSettings true if settings should be loaded from the classpath/file system. - * @throws org.elasticsearch.ElasticsearchException - */ - public TransportClient(Settings.Builder settings, boolean loadConfigSettings) { - this(settings.build(), loadConfigSettings); - } - - /** - * Constructs a new transport client with the provided settings and the ability to control if settings will - * be loaded from the classpath / file system (the elasticsearch.(yml|json) files optionally prefixed with - * config/). - * - * @param pSettings The explicit settings. - * @param loadConfigSettings true if settings should be loaded from the classpath/file system. - * @throws org.elasticsearch.ElasticsearchException - */ - public TransportClient(Settings pSettings, boolean loadConfigSettings) { - Tuple tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); - Settings settings = settingsBuilder() - .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval - .put(tuple.v1()) - .put("network.server", false) - .put("node.client", true) - .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) - .build(); - this.environment = tuple.v2(); - - this.pluginsService = new PluginsService(settings, tuple.v2()); - this.settings = pluginsService.updatedSettings(); - - Version version = Version.CURRENT; - - CompressorFactory.configure(this.settings); - - ModulesBuilder modules = new ModulesBuilder(); - modules.add(new Version.Module(version)); - modules.add(new PluginsModule(this.settings, pluginsService)); - modules.add(new EnvironmentModule(environment)); - modules.add(new SettingsModule(this.settings)); - modules.add(new NetworkModule()); - modules.add(new ClusterNameModule(this.settings)); - modules.add(new ThreadPoolModule(this.settings)); - modules.add(new TransportSearchModule()); - modules.add(new TransportModule(this.settings)); - modules.add(new ActionModule(true)); - modules.add(new ClientTransportModule()); - modules.add(new CircuitBreakerModule(this.settings)); - - injector = modules.createInjector(); - - injector.getInstance(TransportService.class).start(); + private final TransportProxyClient proxy; + private TransportClient(Injector injector) { + super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class), injector.getInstance(Headers.class)); + this.injector = injector; nodesService = injector.getInstance(TransportClientNodesService.class); - internalClient = injector.getInstance(InternalTransportClient.class); + proxy = injector.getInstance(TransportProxyClient.class); } TransportClientNodesService nodeService() { @@ -265,7 +244,7 @@ public class TransportClient extends AbstractClient { // ignore, might not be bounded } - for (Class plugin : pluginsService.services()) { + for (Class plugin : injector.getInstance(PluginsService.class).services()) { injector.getInstance(plugin).close(); } try { @@ -278,187 +257,7 @@ public class TransportClient extends AbstractClient { } @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return internalClient.threadPool(); - } - - @Override - public AdminClient admin() { - return internalClient.admin(); - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return internalClient.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - internalClient.execute(action, request, listener); - } - - @Override - public ActionFuture index(IndexRequest request) { - return internalClient.index(request); - } - - @Override - public void index(IndexRequest request, ActionListener listener) { - internalClient.index(request, listener); - } - - @Override - public ActionFuture update(UpdateRequest request) { - return internalClient.update(request); - } - - @Override - public void update(UpdateRequest request, ActionListener listener) { - internalClient.update(request, listener); - } - - @Override - public ActionFuture delete(DeleteRequest request) { - return internalClient.delete(request); - } - - @Override - public void delete(DeleteRequest request, ActionListener listener) { - internalClient.delete(request, listener); - } - - @Override - public ActionFuture bulk(BulkRequest request) { - return internalClient.bulk(request); - } - - @Override - public void bulk(BulkRequest request, ActionListener listener) { - internalClient.bulk(request, listener); - } - - @Override - public ActionFuture get(GetRequest request) { - return internalClient.get(request); - } - - @Override - public void get(GetRequest request, ActionListener listener) { - internalClient.get(request, listener); - } - - @Override - public ActionFuture multiGet(MultiGetRequest request) { - return internalClient.multiGet(request); - } - - @Override - public void multiGet(MultiGetRequest request, ActionListener listener) { - internalClient.multiGet(request, listener); - } - - @Override - public ActionFuture count(CountRequest request) { - return internalClient.count(request); - } - - @Override - public void count(CountRequest request, ActionListener listener) { - internalClient.count(request, listener); - } - - @Override - public ActionFuture suggest(SuggestRequest request) { - return internalClient.suggest(request); - } - - @Override - public void suggest(SuggestRequest request, ActionListener listener) { - internalClient.suggest(request, listener); - } - - @Override - public ActionFuture search(SearchRequest request) { - return internalClient.search(request); - } - - @Override - public void search(SearchRequest request, ActionListener listener) { - internalClient.search(request, listener); - } - - @Override - public ActionFuture searchScroll(SearchScrollRequest request) { - return internalClient.searchScroll(request); - } - - @Override - public void searchScroll(SearchScrollRequest request, ActionListener listener) { - internalClient.searchScroll(request, listener); - } - - @Override - public ActionFuture multiSearch(MultiSearchRequest request) { - return internalClient.multiSearch(request); - } - - @Override - public void multiSearch(MultiSearchRequest request, ActionListener listener) { - internalClient.multiSearch(request, listener); - } - - @Override - public ActionFuture moreLikeThis(MoreLikeThisRequest request) { - return internalClient.moreLikeThis(request); - } - - @Override - public void moreLikeThis(MoreLikeThisRequest request, ActionListener listener) { - internalClient.moreLikeThis(request, listener); - } - - @Override - public ActionFuture termVectors(TermVectorsRequest request) { - return internalClient.termVectors(request); - } - - @Override - public void termVectors(TermVectorsRequest request, ActionListener listener) { - internalClient.termVectors(request, listener); - } - - @Override - public ActionFuture multiTermVectors(final MultiTermVectorsRequest request) { - return internalClient.multiTermVectors(request); - } - - @Override - public void multiTermVectors(final MultiTermVectorsRequest request, final ActionListener listener) { - internalClient.multiTermVectors(request, listener); - } - - @Override - public ActionFuture percolate(PercolateRequest request) { - return internalClient.percolate(request); - } - - @Override - public void percolate(PercolateRequest request, ActionListener listener) { - internalClient.percolate(request, listener); - } - - @Override - public ActionFuture explain(ExplainRequest request) { - return internalClient.explain(request); - } - - @Override - public void explain(ExplainRequest request, ActionListener listener) { - internalClient.explain(request, listener); + protected > void doExecute(Action action, Request request, ActionListener listener) { + proxy.execute(action, request, listener); } } diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java deleted file mode 100644 index d2f51160d8b..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportAdminClient.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.transport.support; - -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; - -/** - * - */ -public class InternalTransportAdminClient extends AbstractComponent implements AdminClient { - - private final InternalTransportIndicesAdminClient indicesAdminClient; - - private final InternalTransportClusterAdminClient clusterAdminClient; - - @Inject - public InternalTransportAdminClient(Settings settings, InternalTransportIndicesAdminClient indicesAdminClient, InternalTransportClusterAdminClient clusterAdminClient) { - super(settings); - this.indicesAdminClient = indicesAdminClient; - this.clusterAdminClient = clusterAdminClient; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdminClient; - } - - @Override - public ClusterAdminClient cluster() { - return clusterAdminClient; - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java deleted file mode 100644 index 0aff540cb9e..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClient.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.AdminClient; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -public class InternalTransportClient extends AbstractClient { - - private final ESLogger logger; - private final Settings settings; - private final ThreadPool threadPool; - private final TransportClientNodesService nodesService; - private final InternalTransportAdminClient adminClient; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportClient(Settings settings, ThreadPool threadPool, TransportService transportService, - TransportClientNodesService nodesService, InternalTransportAdminClient adminClient, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.settings = settings; - this.threadPool = threadPool; - this.nodesService = nodesService; - this.adminClient = adminClient; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof Action) { - actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public void close() { - // nothing to do here - } - - @Override - public Settings settings() { - return this.settings; - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @Override - public AdminClient admin() { - return adminClient; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java deleted file mode 100644 index 5ede20849a3..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -@SuppressWarnings("unchecked") -public class InternalTransportClusterAdminClient extends AbstractClusterAdminClient implements ClusterAdminClient { - - private final ESLogger logger; - private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportClusterAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool, TransportService transportService, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.nodesService = nodesService; - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof ClusterAction) { - actionsBuilder.put((ClusterAction) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } - -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java b/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java deleted file mode 100644 index 49295b1c968..00000000000 --- a/src/main/java/org/elasticsearch/client/transport/support/InternalTransportIndicesAdminClient.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.transport.support; - -import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.action.support.ThreadedActionListener; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.TransportClientNodesService; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.logging.ESLogger; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; - -import java.util.Map; - -/** - * - */ -@SuppressWarnings("unchecked") -public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminClient implements IndicesAdminClient { - - private final ESLogger logger; - private final TransportClientNodesService nodesService; - private final ThreadPool threadPool; - private final ImmutableMap actions; - private final Headers headers; - private final ThreadedActionListener.Wrapper threadedWrapper; - - @Inject - public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, TransportService transportService, ThreadPool threadPool, - Map actions, Headers headers) { - this.logger = Loggers.getLogger(getClass(), settings); - this.nodesService = nodesService; - this.threadPool = threadPool; - this.headers = headers; - MapBuilder actionsBuilder = new MapBuilder<>(); - for (GenericAction action : actions.values()) { - if (action instanceof IndicesAction) { - actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); - } - } - this.actions = actionsBuilder.immutableMap(); - this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool); - } - - @Override - public ThreadPool threadPool() { - return this.threadPool; - } - - @SuppressWarnings("unchecked") - @Override - public > ActionFuture execute(final Action action, final Request request) { - PlainActionFuture actionFuture = PlainActionFuture.newFuture(); - execute(action, request, actionFuture); - return actionFuture; - } - - @SuppressWarnings("unchecked") - @Override - public > void execute(final Action action, final Request request, ActionListener listener) { - headers.applyTo(request); - listener = threadedWrapper.wrap(listener); - final TransportActionNodeProxy proxy = actions.get(action); - nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { - @Override - public void doWithNode(DiscoveryNode node, ActionListener listener) { - proxy.execute(node, request, listener); - } - }, listener); - } -} diff --git a/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java b/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java new file mode 100644 index 00000000000..89b3a042450 --- /dev/null +++ b/src/main/java/org/elasticsearch/client/transport/support/TransportProxyClient.java @@ -0,0 +1,62 @@ +/* + * Licensed to Elasticsearch 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.client.transport.support; + +import com.google.common.collect.ImmutableMap; +import org.elasticsearch.action.*; +import org.elasticsearch.client.transport.TransportClientNodesService; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.transport.TransportService; + +import java.util.Map; + +/** + * + */ +public class TransportProxyClient { + + private final TransportClientNodesService nodesService; + private final ImmutableMap proxies; + + @Inject + public TransportProxyClient(Settings settings, TransportService transportService, TransportClientNodesService nodesService, Map actions) { + this.nodesService = nodesService; + MapBuilder actionsBuilder = new MapBuilder<>(); + for (GenericAction action : actions.values()) { + if (action instanceof Action) { + actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService)); + } + } + this.proxies = actionsBuilder.immutableMap(); + } + + public > void execute(final Action action, final Request request, ActionListener listener) { + final TransportActionNodeProxy proxy = proxies.get(action); + nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { + @Override + public void doWithNode(DiscoveryNode node, ActionListener listener) { + proxy.execute(node, request, listener); + } + }, listener); + } +} diff --git a/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/src/main/java/org/elasticsearch/rest/BaseRestHandler.java index 9b83c2648b3..b291c4366de 100644 --- a/src/main/java/org/elasticsearch/rest/BaseRestHandler.java +++ b/src/main/java/org/elasticsearch/rest/BaseRestHandler.java @@ -21,9 +21,8 @@ package org.elasticsearch.rest; import org.elasticsearch.action.*; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.FilterClient; -import org.elasticsearch.client.IndicesAdminClient; +import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.settings.Settings; @@ -31,7 +30,7 @@ import java.util.Set; /** * Base handler for REST requests. - * + *

* This handler makes sure that the headers & context of the handled {@link RestRequest requests} are copied over to * the transport requests executed by the associated client. While the context is fully copied over, not all the headers * are copied, but a selected few. It is possible to control what headers are copied over by registering them using @@ -58,15 +57,11 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH static final class HeadersAndContextCopyClient extends FilterClient { private final RestRequest restRequest; - private final IndicesAdmin indicesAdmin; - private final ClusterAdmin clusterAdmin; private final Set headers; HeadersAndContextCopyClient(Client in, RestRequest restRequest, Set headers) { super(in); this.restRequest = restRequest; - this.indicesAdmin = new IndicesAdmin(in.admin().indices(), restRequest, headers); - this.clusterAdmin = new ClusterAdmin(in.admin().cluster(), restRequest, headers); this.headers = headers; } @@ -81,73 +76,9 @@ public abstract class BaseRestHandler extends AbstractComponent implements RestH } @Override - public > ActionFuture execute(Action action, Request request) { + protected > void doExecute(Action action, Request request, ActionListener listener) { copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } - - @Override - public ClusterAdminClient cluster() { - return clusterAdmin; - } - - @Override - public IndicesAdminClient indices() { - return indicesAdmin; - } - - private static final class ClusterAdmin extends FilterClient.ClusterAdmin { - - private final RestRequest restRequest; - private final Set headers; - - private ClusterAdmin(ClusterAdminClient in, RestRequest restRequest, Set headers) { - super(in); - this.restRequest = restRequest; - this.headers = headers; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } - } - - private final class IndicesAdmin extends FilterClient.IndicesAdmin { - - private final RestRequest restRequest; - private final Set headers; - - private IndicesAdmin(IndicesAdminClient in, RestRequest restRequest, Set headers) { - super(in); - this.restRequest = restRequest; - this.headers = headers; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - copyHeadersAndContext(request, restRequest, headers); - return super.execute(action, request); - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - copyHeadersAndContext(request, restRequest, headers); - super.execute(action, request, listener); - } + super.doExecute(action, request, listener); } } } \ No newline at end of file diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java index bace2472a3c..ea25cfb767f 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java @@ -33,7 +33,7 @@ public class BulkIntegrationTests extends ElasticsearchIntegrationTest { @Test public void testBulkIndexCreatesMapping() throws Exception { String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json"); - BulkRequestBuilder bulkBuilder = new BulkRequestBuilder(client()); + BulkRequestBuilder bulkBuilder = client().prepareBulk(); bulkBuilder.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), null, null); bulkBuilder.get(); assertBusy(new Runnable() { diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java index 68a11b0b8e5..920ae42333a 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkProcessorTests.java @@ -161,7 +161,7 @@ public class BulkProcessorTests extends ElasticsearchIntegrationTest { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - Client transportClient = new TransportClient(settings); + Client transportClient = TransportClient.builder().settings(settings).build(); int bulkActions = randomIntBetween(10, 100); int numDocs = randomIntBetween(bulkActions, bulkActions + 100); diff --git a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java index 85bb2a384cc..ceabdd58965 100644 --- a/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/count/CountRequestBuilderTests.java @@ -51,7 +51,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - client = new TransportClient(settings); + client = TransportClient.builder().settings(settings).build(); } @AfterClass @@ -62,20 +62,20 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testEmptySourceToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().toString())); } @Test public void testQueryBuilderQueryToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); countRequestBuilder.setQuery(QueryBuilders.matchAllQuery()); assertThat(countRequestBuilder.toString(), equalTo(new QuerySourceBuilder().setQuery(QueryBuilders.matchAllQuery()).toString())); } @Test public void testStringQueryToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); String query = "{ \"match_all\" : {} }"; countRequestBuilder.setQuery(new BytesArray(query)); assertThat(countRequestBuilder.toString(), containsString("\"query\":{ \"match_all\" : {} }")); @@ -83,7 +83,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderQueryToString() throws IOException { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -95,7 +95,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringSourceToString() { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); String query = "{ \"query\": { \"match_all\" : {} } }"; countRequestBuilder.setSource(new BytesArray(query)); assertThat(countRequestBuilder.toString(), equalTo("{ \"query\": { \"match_all\" : {} } }")); @@ -103,7 +103,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderSourceToString() throws IOException { - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client); + CountRequestBuilder countRequestBuilder = client.prepareCount(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -124,7 +124,7 @@ public class CountRequestBuilderTests extends ElasticsearchTestCase { " }\n" + " }\n" + " }"; - CountRequestBuilder countRequestBuilder = new CountRequestBuilder(client).setSource(new BytesArray(source)); + CountRequestBuilder countRequestBuilder = client.prepareCount().setSource(new BytesArray(source)); String preToString = countRequestBuilder.request().source().toUtf8(); assertThat(countRequestBuilder.toString(), equalTo(source)); String postToString = countRequestBuilder.request().source().toUtf8(); diff --git a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java index 9b4b8bc77b8..dec0e8238ea 100644 --- a/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java +++ b/src/test/java/org/elasticsearch/action/search/SearchRequestBuilderTests.java @@ -50,7 +50,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { Settings settings = ImmutableSettings.builder() .put("path.home", createTempDir().toString()) .build(); - client = new TransportClient(settings); + client = TransportClient.builder().settings(settings).build(); } @AfterClass @@ -61,20 +61,20 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testEmptySourceToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().toString())); } @Test public void testQueryBuilderQueryToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery()); assertThat(searchRequestBuilder.toString(), equalTo(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).toString())); } @Test public void testXContentBuilderQueryToString() throws IOException { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("match_all"); @@ -86,7 +86,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringQueryToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); String query = "{ \"match_all\" : {} }"; searchRequestBuilder.setQuery(query); assertThat(searchRequestBuilder.toString(), containsString("\"query\":{ \"match_all\" : {} }")); @@ -94,7 +94,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testStringSourceToString() { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); String source = "{ \"query\" : { \"match_all\" : {} } }"; searchRequestBuilder.setSource(source); assertThat(searchRequestBuilder.toString(), equalTo(source)); @@ -102,7 +102,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { @Test public void testXContentBuilderSourceToString() throws IOException { - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); xContentBuilder.startObject(); xContentBuilder.startObject("query"); @@ -125,7 +125,7 @@ public class SearchRequestBuilderTests extends ElasticsearchTestCase { " }\n" + " }\n" + " }"; - SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client).setSource(source); + SearchRequestBuilder searchRequestBuilder = client.prepareSearch().setSource(source); String preToString = searchRequestBuilder.request().source().toUtf8(); assertThat(searchRequestBuilder.toString(), equalTo(source)); String postToString = searchRequestBuilder.request().source().toUtf8(); diff --git a/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java b/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java index ecc767c3274..58a96aa5e1f 100644 --- a/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java +++ b/src/test/java/org/elasticsearch/action/termvectors/MultiTermVectorsTests.java @@ -74,7 +74,7 @@ public class MultiTermVectorsTests extends AbstractTermVectorsTests { @Test public void testMissingIndexThrowsMissingIndex() throws Exception { TermVectorsRequestBuilder requestBuilder = client().prepareTermVectors("testX", "typeX", Integer.toString(1)); - MultiTermVectorsRequestBuilder mtvBuilder = new MultiTermVectorsRequestBuilder(client()); + MultiTermVectorsRequestBuilder mtvBuilder = client().prepareMultiTermVectors(); mtvBuilder.add(requestBuilder.request()); MultiTermVectorsResponse response = mtvBuilder.execute().actionGet(); assertThat(response.getResponses().length, equalTo(1)); diff --git a/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java index c55681d3fd2..e67890bf030 100644 --- a/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/ClusterStateBackwardsCompatTests.java @@ -104,6 +104,6 @@ public class ClusterStateBackwardsCompatTests extends ElasticsearchBackwardsComp private TransportClient newTransportClient() { Settings settings = ImmutableSettings.settingsBuilder().put("client.transport.ignore_cluster_name", true) .put("node.name", "transport_client_" + getTestName()).build(); - return new TransportClient(settings); + return TransportClient.builder().settings(settings).build(); } } diff --git a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java index 0f93011a249..63b45909944 100644 --- a/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/NodesStatsBasicBackwardsCompatTests.java @@ -48,7 +48,7 @@ public class NodesStatsBasicBackwardsCompatTests extends ElasticsearchBackwardsC // We explicitly connect to each node with a custom TransportClient for (NodeInfo n : nodesInfo.getNodes()) { - TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address()); + TransportClient tc = TransportClient.builder().settings(settings).build().addTransportAddress(n.getNode().address()); // Just verify that the NS can be sent and serialized/deserialized between nodes with basic indices NodesStatsResponse ns = tc.admin().cluster().prepareNodesStats().setIndices(true).execute().actionGet(); tc.close(); @@ -67,7 +67,7 @@ public class NodesStatsBasicBackwardsCompatTests extends ElasticsearchBackwardsC // We explicitly connect to each node with a custom TransportClient for (NodeInfo n : nodesInfo.getNodes()) { - TransportClient tc = new TransportClient(settings).addTransportAddress(n.getNode().address()); + TransportClient tc = TransportClient.builder().settings(settings).build().addTransportAddress(n.getNode().address()); // randomize the combination of flags set // Uses reflection to find methods in an attempt to future-proof this test against newly added flags diff --git a/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java b/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java index a6bd13731f9..195165715aa 100644 --- a/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java +++ b/src/test/java/org/elasticsearch/bwcompat/TransportClientBackwardsCompatibilityTest.java @@ -50,7 +50,7 @@ public class TransportClientBackwardsCompatibilityTest extends ElasticsearchBack CompositeTestCluster compositeTestCluster = backwardsCluster(); TransportAddress transportAddress = compositeTestCluster.externalTransportAddress(); - try(TransportClient client = new TransportClient(settings)) { + try(TransportClient client = TransportClient.builder().settings(settings).build()) { client.addTransportAddress(transportAddress); assertAcked(client.admin().indices().prepareCreate("test")); diff --git a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java index ce4cfa43439..9f8dc0cf2f6 100644 --- a/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/node/NodeClientHeadersTests.java @@ -45,14 +45,9 @@ public class NodeClientHeadersTests extends AbstractClientHeadersTests { @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { Settings settings = HEADER_SETTINGS; - Headers headers = new Headers(settings); Actions actions = new Actions(settings, threadPool, testedActions); - - NodeClusterAdminClient clusterClient = new NodeClusterAdminClient(settings, threadPool, actions, headers); - NodeIndicesAdminClient indicesClient = new NodeIndicesAdminClient(settings, threadPool, actions, headers); - NodeAdminClient adminClient = new NodeAdminClient(settings, clusterClient, indicesClient); - return new NodeClient(settings, threadPool, adminClient, actions, headers); + return new NodeClient(settings, threadPool, headers, actions); } private static class Actions extends HashMap { diff --git a/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java deleted file mode 100644 index bdccf82deb1..00000000000 --- a/src/test/java/org/elasticsearch/client/transport/InternalTransportClientTests.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Licensed to Elasticsearch 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.client.transport; - -import org.elasticsearch.Version; -import org.elasticsearch.action.*; -import org.elasticsearch.action.admin.cluster.ClusterAction; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; -import org.elasticsearch.action.admin.indices.IndicesAction; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; -import org.elasticsearch.client.IndicesAdminClient; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.client.transport.support.InternalTransportAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportClient; -import org.elasticsearch.client.transport.support.InternalTransportClusterAdminClient; -import org.elasticsearch.client.transport.support.InternalTransportIndicesAdminClient; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.transport.LocalTransportAddress; -import org.elasticsearch.test.ElasticsearchTestCase; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.junit.Test; - -import java.io.Closeable; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.notNullValue; - -public class InternalTransportClientTests extends ElasticsearchTestCase { - - private static class TestIteration implements Closeable { - private final ThreadPool threadPool; - private final FailAndRetryMockTransport transport; - private final TransportService transportService; - private final TransportClientNodesService transportClientNodesService; - private final InternalTransportClient internalTransportClient; - private final int nodesCount; - - TestIteration() { - threadPool = new ThreadPool("internal-transport-client-tests"); - transport = new FailAndRetryMockTransport(getRandom()) { - @Override - protected TestResponse newResponse() { - return new TestResponse(); - } - }; - transportService = new TransportService(ImmutableSettings.EMPTY, transport, threadPool); - transportService.start(); - transportClientNodesService = new TransportClientNodesService(ImmutableSettings.EMPTY, ClusterName.DEFAULT, transportService, threadPool, Headers.EMPTY, Version.CURRENT); - Map actions = new HashMap<>(); - actions.put(NodesInfoAction.NAME, NodesInfoAction.INSTANCE); - actions.put(TestAction.NAME, TestAction.INSTANCE); - actions.put(IndicesAdminTestAction.NAME, IndicesAdminTestAction.INSTANCE); - actions.put(ClusterAdminTestAction.NAME, ClusterAdminTestAction.INSTANCE); - - InternalTransportIndicesAdminClient indicesAdminClient = new InternalTransportIndicesAdminClient(ImmutableSettings.EMPTY, transportClientNodesService, transportService, threadPool, actions, Headers.EMPTY); - InternalTransportClusterAdminClient clusterAdminClient = new InternalTransportClusterAdminClient(ImmutableSettings.EMPTY, transportClientNodesService, threadPool, transportService, actions, Headers.EMPTY); - InternalTransportAdminClient adminClient = new InternalTransportAdminClient(ImmutableSettings.EMPTY, indicesAdminClient, clusterAdminClient); - internalTransportClient = new InternalTransportClient(ImmutableSettings.EMPTY, threadPool, transportService, transportClientNodesService, adminClient, actions, Headers.EMPTY); - - nodesCount = randomIntBetween(1, 10); - for (int i = 0; i < nodesCount; i++) { - transportClientNodesService.addTransportAddresses(new LocalTransportAddress("node" + i)); - } - transport.endConnectMode(); - } - - @Override - public void close() { - threadPool.shutdown(); - try { - threadPool.awaitTermination(1, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Thread.currentThread().isInterrupted(); - } - transportService.stop(); - transportClientNodesService.close(); - internalTransportClient.close(); - } - } - - @Test - public void testListenerFailures() throws InterruptedException { - - int iters = iterations(10, 100); - for (int i = 0; i < iters; i++) { - try(final TestIteration iteration = new TestIteration()) { - final CountDownLatch latch = new CountDownLatch(1); - final AtomicInteger finalFailures = new AtomicInteger(); - final AtomicReference finalFailure = new AtomicReference<>(); - final AtomicReference response = new AtomicReference<>(); - ActionListener actionListener = new ActionListener() { - @Override - public void onResponse(TestResponse testResponse) { - response.set(testResponse); - latch.countDown(); - } - - @Override - public void onFailure(Throwable e) { - finalFailures.incrementAndGet(); - finalFailure.set(e); - latch.countDown(); - } - }; - - final AtomicInteger preSendFailures = new AtomicInteger(); - - Action action = randomFrom(Action.values()); - action.execute(iteration, actionListener); - - assertThat(latch.await(1, TimeUnit.SECONDS), equalTo(true)); - - //there can be only either one failure that causes the request to fail straightaway or success - assertThat(preSendFailures.get() + iteration.transport.failures() + iteration.transport.successes(), lessThanOrEqualTo(1)); - - if (iteration.transport.successes() == 1) { - assertThat(finalFailures.get(), equalTo(0)); - assertThat(finalFailure.get(), nullValue()); - assertThat(response.get(), notNullValue()); - } else { - assertThat(finalFailures.get(), equalTo(1)); - assertThat(finalFailure.get(), notNullValue()); - assertThat(response.get(), nullValue()); - if (preSendFailures.get() == 0 && iteration.transport.failures() == 0) { - assertThat(finalFailure.get(), instanceOf(NoNodeAvailableException.class)); - } - } - - assertThat(iteration.transport.triedNodes().size(), lessThanOrEqualTo(iteration.nodesCount)); - assertThat(iteration.transport.triedNodes().size(), equalTo(iteration.transport.connectTransportExceptions() + iteration.transport.failures() + iteration.transport.successes())); - } - } - } - - @Test - public void testSyncFailures() throws InterruptedException { - - int iters = iterations(10, 100); - for (int i = 0; i < iters; i++) { - try(final TestIteration iteration = new TestIteration()) { - TestResponse testResponse = null; - Throwable finalFailure = null; - - try { - Action action = randomFrom(Action.values()); - ActionFuture future = action.execute(iteration); - testResponse = future.actionGet(); - } catch (Throwable t) { - finalFailure = t; - } - - //there can be only either one failure that causes the request to fail straightaway or success - assertThat(iteration.transport.failures() + iteration.transport.successes(), lessThanOrEqualTo(1)); - - if (iteration.transport.successes() == 1) { - assertThat(finalFailure, nullValue()); - assertThat(testResponse, notNullValue()); - } else { - assertThat(testResponse, nullValue()); - assertThat(finalFailure, notNullValue()); - if (iteration.transport.failures() == 0) { - assertThat(finalFailure, instanceOf(NoNodeAvailableException.class)); - } - } - - assertThat(iteration.transport.triedNodes().size(), lessThanOrEqualTo(iteration.nodesCount)); - assertThat(iteration.transport.triedNodes().size(), equalTo(iteration.transport.connectTransportExceptions() + iteration.transport.failures() + iteration.transport.successes())); - } - } - } - - private static enum Action { - TEST { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.execute(TestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.execute(TestAction.INSTANCE, new TestRequest(), listener); - } - }, - INDICES_ADMIN { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.admin().indices().execute(IndicesAdminTestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.admin().indices().execute(IndicesAdminTestAction.INSTANCE, new TestRequest(), listener); - } - }, - CLUSTER_ADMIN { - @Override - ActionFuture execute(TestIteration iteration) { - return iteration.internalTransportClient.admin().cluster().execute(ClusterAdminTestAction.INSTANCE, new TestRequest()); - } - - @Override - void execute(TestIteration iteration, ActionListener listener) { - iteration.internalTransportClient.admin().cluster().execute(ClusterAdminTestAction.INSTANCE, new TestRequest(), listener); - } - }; - - abstract ActionFuture execute(TestIteration iteration); - - abstract void execute(TestIteration iteration, ActionListener listener); - } - - private static class TestRequest extends ActionRequest { - @Override - public ActionRequestValidationException validate() { - return null; - } - } - - private static class TestResponse extends ActionResponse { - - } - - private static class TestAction extends ClientAction { - static final String NAME = "test-action"; - static final TestAction INSTANCE = new TestAction(NAME); - - private TestAction(String name) { - super(name); - } - - @Override - public TestRequestBuilder newRequestBuilder(Client client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class TestRequestBuilder extends ActionRequestBuilder { - - protected TestRequestBuilder(Client client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } - - private static class IndicesAdminTestAction extends IndicesAction { - static final String NAME = "test-indices-action"; - static final IndicesAdminTestAction INSTANCE = new IndicesAdminTestAction(NAME); - - private IndicesAdminTestAction(String name) { - super(name); - } - - @Override - public IndicesAdminTestRequestBuilder newRequestBuilder(IndicesAdminClient client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class IndicesAdminTestRequestBuilder extends ActionRequestBuilder { - - protected IndicesAdminTestRequestBuilder(IndicesAdminClient client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } - - private static class ClusterAdminTestAction extends ClusterAction { - static final String NAME = "test-cluster-action"; - static final ClusterAdminTestAction INSTANCE = new ClusterAdminTestAction(NAME); - - private ClusterAdminTestAction(String name) { - super(name); - } - - @Override - public ClusterAdminTestRequestBuilder newRequestBuilder(ClusterAdminClient client) { - throw new UnsupportedOperationException(); - } - - @Override - public TestResponse newResponse() { - return new TestResponse(); - } - } - - private static class ClusterAdminTestRequestBuilder extends ActionRequestBuilder { - - protected ClusterAdminTestRequestBuilder(ClusterAdminClient client, TestRequest request) { - super(client, request); - } - - @Override - protected void doExecute(ActionListener listener) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index 07dd7f9c73d..8400b490301 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -55,12 +55,12 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { - TransportClient client = new TransportClient(ImmutableSettings.builder() + TransportClient client = TransportClient.builder().settings(ImmutableSettings.builder() .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(headersSettings) - .build()); + .build()).build(); client.addTransportAddress(address); return client; @@ -68,7 +68,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Test public void testWithSniffing() throws Exception { - TransportClient client = new TransportClient(ImmutableSettings.builder() + TransportClient client = TransportClient.builder().settings(ImmutableSettings.builder() .put("client.transport.sniff", true) .put("cluster.name", "cluster1") .put("node.name", "transport_client_" + this.getTestName() + "_1") @@ -76,7 +76,7 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, InternalTransportService.class.getName()) .put(HEADER_SETTINGS) .put("path.home", createTempDir().toString()) - .build()); + .build()).build(); try { client.addTransportAddress(address); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java index 3e8c2b09f38..b0090fff142 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientRetryTests.java @@ -65,7 +65,7 @@ public class TransportClientRetryTests extends ElasticsearchIntegrationTest { .put("config.ignore_system_properties", true) .put("path.home", createTempDir()); - try (TransportClient transportClient = new TransportClient(builder.build())) { + try (TransportClient transportClient = TransportClient.builder().settings(builder.build()).build()) { transportClient.addTransportAddresses(addresses); assertThat(transportClient.connectedNodes().size(), equalTo(internalCluster().size())); diff --git a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java index b540800c5d1..3abb071d4ee 100644 --- a/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java +++ b/src/test/java/org/elasticsearch/client/transport/TransportClientTests.java @@ -95,7 +95,7 @@ public class TransportClientTests extends ElasticsearchIntegrationTest { @Test public void testThatTransportClientSettingCannotBeChanged() { Settings baseSettings = settingsBuilder().put(Client.CLIENT_TYPE_SETTING, "anything").put("path.home", createTempDir()).build(); - try (TransportClient client = new TransportClient(baseSettings)) { + try (TransportClient client = TransportClient.builder().settings(baseSettings).build()) { Settings settings = client.injector.getInstance(Settings.class); assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); } diff --git a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java index af419cf68a9..d261b0a3b01 100644 --- a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java +++ b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java @@ -161,7 +161,7 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest { client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet(); } - void checkWriteAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { + void checkWriteAction(boolean autoCreateIndex, TimeValue timeout, ActionRequestBuilder builder) { // we clean the metadata when loosing a master, therefore all operations on indices will auto create it, if allowed long now = System.currentTimeMillis(); try { diff --git a/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java b/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java index dc58961cc4b..af07a25f3ae 100644 --- a/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java +++ b/src/test/java/org/elasticsearch/rest/HeadersAndContextCopyClientTests.java @@ -33,8 +33,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.*; import org.elasticsearch.client.support.AbstractClient; -import org.elasticsearch.client.support.AbstractClusterAdminClient; -import org.elasticsearch.client.support.AbstractIndicesAdminClient; +import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -110,31 +109,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - SearchRequest searchRequest = Requests.searchRequest(); - putHeaders(searchRequest, transportHeaders); - putContext(searchRequest, transportContext); - assertHeaders(searchRequest, transportHeaders); - client.search(searchRequest); - assertHeaders(searchRequest, expectedHeaders); - assertContext(searchRequest, expectedContext); + SearchRequest searchRequest = Requests.searchRequest(); + putHeaders(searchRequest, transportHeaders); + putContext(searchRequest, transportContext); + assertHeaders(searchRequest, transportHeaders); + client.search(searchRequest); + assertHeaders(searchRequest, expectedHeaders); + assertContext(searchRequest, expectedContext); - GetRequest getRequest = Requests.getRequest("index"); - putHeaders(getRequest, transportHeaders); - putContext(getRequest, transportContext); - assertHeaders(getRequest, transportHeaders); - client.get(getRequest); - assertHeaders(getRequest, expectedHeaders); - assertContext(getRequest, expectedContext); + GetRequest getRequest = Requests.getRequest("index"); + putHeaders(getRequest, transportHeaders); + putContext(getRequest, transportContext); + assertHeaders(getRequest, transportHeaders); + client.get(getRequest); + assertHeaders(getRequest, expectedHeaders); + assertContext(getRequest, expectedContext); - IndexRequest indexRequest = Requests.indexRequest(); - putHeaders(indexRequest, transportHeaders); - putContext(indexRequest, transportContext); - assertHeaders(indexRequest, transportHeaders); - client.index(indexRequest); - assertHeaders(indexRequest, expectedHeaders); - assertContext(indexRequest, expectedContext); + IndexRequest indexRequest = Requests.indexRequest(); + putHeaders(indexRequest, transportHeaders); + putContext(indexRequest, transportContext); + assertHeaders(indexRequest, transportHeaders); + client.index(indexRequest); + assertHeaders(indexRequest, expectedHeaders); + assertContext(indexRequest, expectedContext); + } } @Test @@ -155,31 +155,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, expectedContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, expectedContext), usefulRestHeaders)) { - ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); - putHeaders(clusterHealthRequest, transportHeaders); - putContext(clusterHealthRequest, transportContext); - assertHeaders(clusterHealthRequest, transportHeaders); - client.admin().cluster().health(clusterHealthRequest); - assertHeaders(clusterHealthRequest, expectedHeaders); - assertContext(clusterHealthRequest, expectedContext); + ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(); + putHeaders(clusterHealthRequest, transportHeaders); + putContext(clusterHealthRequest, transportContext); + assertHeaders(clusterHealthRequest, transportHeaders); + client.admin().cluster().health(clusterHealthRequest); + assertHeaders(clusterHealthRequest, expectedHeaders); + assertContext(clusterHealthRequest, expectedContext); - ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); - putHeaders(clusterStateRequest, transportHeaders); - putContext(clusterStateRequest, transportContext); - assertHeaders(clusterStateRequest, transportHeaders); - client.admin().cluster().state(clusterStateRequest); - assertHeaders(clusterStateRequest, expectedHeaders); - assertContext(clusterStateRequest, expectedContext); + ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); + putHeaders(clusterStateRequest, transportHeaders); + putContext(clusterStateRequest, transportContext); + assertHeaders(clusterStateRequest, transportHeaders); + client.admin().cluster().state(clusterStateRequest); + assertHeaders(clusterStateRequest, expectedHeaders); + assertContext(clusterStateRequest, expectedContext); - ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest(); - putHeaders(clusterStatsRequest, transportHeaders); - putContext(clusterStatsRequest, transportContext); - assertHeaders(clusterStatsRequest, transportHeaders); - client.admin().cluster().clusterStats(clusterStatsRequest); - assertHeaders(clusterStatsRequest, expectedHeaders); - assertContext(clusterStatsRequest, expectedContext); + ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest(); + putHeaders(clusterStatsRequest, transportHeaders); + putContext(clusterStatsRequest, transportContext); + assertHeaders(clusterStatsRequest, transportHeaders); + client.admin().cluster().clusterStats(clusterStatsRequest); + assertHeaders(clusterStatsRequest, expectedHeaders); + assertContext(clusterStatsRequest, expectedContext); + } } @Test @@ -200,31 +201,32 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test"); - putHeaders(createIndexRequest, transportHeaders); - putContext(createIndexRequest, transportContext); - assertHeaders(createIndexRequest, transportHeaders); - client.admin().indices().create(createIndexRequest); - assertHeaders(createIndexRequest, expectedHeaders); - assertContext(createIndexRequest, expectedContext); + CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test"); + putHeaders(createIndexRequest, transportHeaders); + putContext(createIndexRequest, transportContext); + assertHeaders(createIndexRequest, transportHeaders); + client.admin().indices().create(createIndexRequest); + assertHeaders(createIndexRequest, expectedHeaders); + assertContext(createIndexRequest, expectedContext); - CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test"); - putHeaders(closeIndexRequest, transportHeaders); - putContext(closeIndexRequest, transportContext); - assertHeaders(closeIndexRequest, transportHeaders); - client.admin().indices().close(closeIndexRequest); - assertHeaders(closeIndexRequest, expectedHeaders); - assertContext(closeIndexRequest, expectedContext); + CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test"); + putHeaders(closeIndexRequest, transportHeaders); + putContext(closeIndexRequest, transportContext); + assertHeaders(closeIndexRequest, transportHeaders); + client.admin().indices().close(closeIndexRequest); + assertHeaders(closeIndexRequest, expectedHeaders); + assertContext(closeIndexRequest, expectedContext); - FlushRequest flushRequest = Requests.flushRequest(); - putHeaders(flushRequest, transportHeaders); - putContext(flushRequest, transportContext); - assertHeaders(flushRequest, transportHeaders); - client.admin().indices().flush(flushRequest); - assertHeaders(flushRequest, expectedHeaders); - assertContext(flushRequest, expectedContext); + FlushRequest flushRequest = Requests.flushRequest(); + putHeaders(flushRequest, transportHeaders); + putContext(flushRequest, transportContext); + assertHeaders(flushRequest, transportHeaders); + client.admin().indices().flush(flushRequest); + assertHeaders(flushRequest, expectedHeaders); + assertContext(flushRequest, expectedContext); + } } @Test @@ -245,25 +247,26 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.prepareIndex("index", "type"), - client.prepareGet("index", "type", "id"), - client.prepareBulk(), - client.prepareDelete(), - client.prepareIndex(), - client.prepareClearScroll(), - client.prepareMultiGet(), - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.prepareIndex("index", "type"), + client.prepareGet("index", "type", "id"), + client.prepareBulk(), + client.prepareDelete(), + client.prepareIndex(), + client.prepareClearScroll(), + client.prepareMultiGet(), + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -285,24 +288,25 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.admin().cluster().prepareNodesInfo(), - client.admin().cluster().prepareClusterStats(), - client.admin().cluster().prepareState(), - client.admin().cluster().prepareCreateSnapshot("repo", "name"), - client.admin().cluster().prepareHealth(), - client.admin().cluster().prepareReroute() - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.admin().cluster().prepareNodesInfo(), + client.admin().cluster().prepareClusterStats(), + client.admin().cluster().prepareState(), + client.admin().cluster().prepareCreateSnapshot("repo", "name"), + client.admin().cluster().prepareHealth(), + client.admin().cluster().prepareReroute() + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -324,25 +328,26 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { expectedContext.putAll(transportContext); expectedContext.putAll(restContext); - Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); + try (Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders)) { - ActionRequestBuilder requestBuilders [] = new ActionRequestBuilder[] { - client.admin().indices().prepareValidateQuery(), - client.admin().indices().prepareCreate("test"), - client.admin().indices().prepareAliases(), - client.admin().indices().prepareAnalyze("text"), - client.admin().indices().prepareDeleteWarmer(), - client.admin().indices().prepareTypesExists("type"), - client.admin().indices().prepareClose() - }; + ActionRequestBuilder requestBuilders[] = new ActionRequestBuilder[]{ + client.admin().indices().prepareValidateQuery(), + client.admin().indices().prepareCreate("test"), + client.admin().indices().prepareAliases(), + client.admin().indices().prepareAnalyze("text"), + client.admin().indices().prepareDeleteWarmer(), + client.admin().indices().prepareTypesExists("type"), + client.admin().indices().prepareClose() + }; - for (ActionRequestBuilder requestBuilder : requestBuilders) { - putHeaders(requestBuilder.request(), transportHeaders); - putContext(requestBuilder.request(), transportContext); - assertHeaders(requestBuilder.request(), transportHeaders); - requestBuilder.get(); - assertHeaders(requestBuilder.request(), expectedHeaders); - assertContext(requestBuilder.request(), expectedContext); + for (ActionRequestBuilder requestBuilder : requestBuilders) { + putHeaders(requestBuilder.request(), transportHeaders); + putContext(requestBuilder.request(), transportContext); + assertHeaders(requestBuilder.request(), transportHeaders); + requestBuilder.get(); + assertHeaders(requestBuilder.request(), expectedHeaders); + assertContext(requestBuilder.request(), expectedContext); + } } } @@ -417,76 +422,24 @@ public class HeadersAndContextCopyClientTests extends ElasticsearchTestCase { } } - private static class NoOpClient extends AbstractClient implements AdminClient { + private class NoOpClient extends AbstractClient { - @Override - public AdminClient admin() { - return this; + public NoOpClient() { + super(ImmutableSettings.EMPTY, new ThreadPool(getTestName()), Headers.EMPTY); } @Override - public Settings settings() { - return null; - } - - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { + protected > void doExecute(Action action, Request request, ActionListener listener) { listener.onResponse(null); } - @Override - public ThreadPool threadPool() { - return null; - } - @Override public void close() { - - } - - @Override - public ClusterAdminClient cluster() { - return new AbstractClusterAdminClient() { - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - listener.onResponse(null); - } - - @Override - public ThreadPool threadPool() { - return null; - } - }; - } - - @Override - public IndicesAdminClient indices() { - return new AbstractIndicesAdminClient() { - @Override - public > ActionFuture execute(Action action, Request request) { - return null; - } - - @Override - public > void execute(Action action, Request request, ActionListener listener) { - listener.onResponse(null); - } - - @Override - public ThreadPool threadPool() { - return null; - } - }; + try { + terminate(threadPool()); + } catch (Throwable t) { + throw new ElasticsearchException(t.getMessage(), t); + } } } } diff --git a/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java b/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java index 1f04063a42d..2c8a7ddbc0d 100644 --- a/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java +++ b/src/test/java/org/elasticsearch/script/expression/ExpressionScriptTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.script.expression; -import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -53,7 +52,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { paramsMap.put(params[i].toString(), params[i + 1]); } - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addSort(SortBuilders.fieldSort("_uid") .order(SortOrder.ASC)).addScriptField("foo", "expression", script, paramsMap); @@ -86,7 +85,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye")); ScoreFunctionBuilder score = ScoreFunctionBuilders.scriptFunction("1 / _score", "expression"); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode("replace")); req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent SearchResponse rsp = req.get(); @@ -274,7 +273,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("x", 10, "y", 1.4), client().prepareIndex("test", "doc", "3").setSource("x", 13, "y", 1.8)); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addAggregation(AggregationBuilders.stats("int_agg").field("x").script("_value * 3").lang(ExpressionScriptEngineService.NAME)) .addAggregation(AggregationBuilders.stats("double_agg").field("y").script("_value - 1.1").lang(ExpressionScriptEngineService.NAME)); @@ -300,7 +299,7 @@ public class ExpressionScriptTests extends ElasticsearchIntegrationTest { client().prepareIndex("test", "doc", "2").setSource("text", "goodbye"), client().prepareIndex("test", "doc", "3").setSource("text", "hello")); - SearchRequestBuilder req = new SearchRequestBuilder(client()).setIndices("test"); + SearchRequestBuilder req = client().prepareSearch().setIndices("test"); req.setQuery(QueryBuilders.matchAllQuery()) .addAggregation(AggregationBuilders.terms("term_agg").field("text").script("_value").lang(ExpressionScriptEngineService.NAME)); diff --git a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java index c00ceec27b3..d11cec0ab0a 100644 --- a/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java +++ b/src/test/java/org/elasticsearch/stresstest/client/ClientFailover.java @@ -42,7 +42,7 @@ public class ClientFailover { // TODO: what is this? a public static void main test?!?! - final TransportClient client = new TransportClient(ImmutableSettings.EMPTY) + final TransportClient client = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress("localhost", 9300)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9301)) .addTransportAddress(new InetSocketTransportAddress("localhost", 9302)); diff --git a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java index fb113a604b7..0426ab647fd 100644 --- a/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java +++ b/src/test/java/org/elasticsearch/stresstest/manyindices/ManyIndicesRemoteStressTest.java @@ -49,7 +49,7 @@ public class ManyIndicesRemoteStressTest { Node node = null; // TODO: what is this? a public static void main test?!?!?! if (true) { - client = new TransportClient(ImmutableSettings.EMPTY).addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); + client = TransportClient.builder().settings(ImmutableSettings.EMPTY).build().addTransportAddress(new InetSocketTransportAddress("localhost", 9300)); } else { node = NodeBuilder.nodeBuilder().client(true).node(); client = node.client(); diff --git a/src/test/java/org/elasticsearch/test/CompositeTestCluster.java b/src/test/java/org/elasticsearch/test/CompositeTestCluster.java index 1e258abfa2a..03f4590daa5 100644 --- a/src/test/java/org/elasticsearch/test/CompositeTestCluster.java +++ b/src/test/java/org/elasticsearch/test/CompositeTestCluster.java @@ -26,9 +26,7 @@ import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.client.Client; -import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.FilterClient; -import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -292,34 +290,7 @@ public class CompositeTestCluster extends TestCluster { private final class ExternalClient extends FilterClient { public ExternalClient() { - super(null); - } - - @Override - protected Client in() { - return internalClient(); - } - - @Override - public ClusterAdminClient cluster() { - return new ClusterAdmin(null) { - - @Override - protected ClusterAdminClient in() { - return internalClient().admin().cluster(); - } - }; - } - - @Override - public IndicesAdminClient indices() { - return new IndicesAdmin(null) { - - @Override - protected IndicesAdminClient in() { - return internalClient().admin().indices(); - } - }; + super(internalClient()); } @Override @@ -327,5 +298,4 @@ public class CompositeTestCluster extends TestCluster { // never close this client } } - } diff --git a/src/test/java/org/elasticsearch/test/ExternalNode.java b/src/test/java/org/elasticsearch/test/ExternalNode.java index f304b71cd4b..bc520988a68 100644 --- a/src/test/java/org/elasticsearch/test/ExternalNode.java +++ b/src/test/java/org/elasticsearch/test/ExternalNode.java @@ -21,7 +21,6 @@ package org.elasticsearch.test; import com.google.common.base.Predicate; import org.apache.lucene.util.Constants; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; @@ -200,7 +199,7 @@ final class ExternalNode implements Closeable { .put("client.transport.nodes_sampler_interval", "1s") .put("name", "transport_client_" + nodeInfo.getNode().name()) .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", false).build(); - TransportClient client = new TransportClient(clientSettings); + TransportClient client = TransportClient.builder().settings(clientSettings).build(); client.addTransportAddress(addr); this.client = client; } diff --git a/src/test/java/org/elasticsearch/test/ExternalTestCluster.java b/src/test/java/org/elasticsearch/test/ExternalTestCluster.java index c0052f24044..cd30b9937fb 100644 --- a/src/test/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/ExternalTestCluster.java @@ -72,7 +72,7 @@ public final class ExternalTestCluster extends TestCluster { .put("client.transport.ignore_cluster_name", true) .put("node.mode", "network").build(); // we require network here! - this.client = new TransportClient(clientSettings).addTransportAddresses(transportAddresses); + this.client = TransportClient.builder().settings(clientSettings).build().addTransportAddresses(transportAddresses); NodesInfoResponse nodeInfos = this.client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); httpAddresses = new InetSocketAddress[nodeInfos.getNodes().length]; diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 639b30ede4f..92797894e38 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -864,7 +864,7 @@ public final class InternalTestCluster extends TestCluster { .put("config.ignore_system_properties", true) .put(settings); - TransportClient client = new TransportClient(builder.build()); + TransportClient client = TransportClient.builder().settings(builder.build()).build(); client.addTransportAddress(addr); return client; } diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 7a822e163cb..ab59da837e4 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -90,7 +90,7 @@ import static org.hamcrest.Matchers.*; */ public class ElasticsearchAssertions { - public static void assertAcked(AcknowledgedRequestBuilder builder) { + public static void assertAcked(AcknowledgedRequestBuilder builder) { assertAcked(builder.get()); } @@ -501,14 +501,14 @@ public class ElasticsearchAssertions { /** * Run the request from a given builder and check that it throws an exception of the right type */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass) { assertThrows(builder.execute(), exceptionClass); } /** * Run the request from a given builder and check that it throws an exception of the right type, with a given {@link org.elasticsearch.rest.RestStatus} */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, RestStatus status) { assertThrows(builder.execute(), exceptionClass, status); } @@ -517,7 +517,7 @@ public class ElasticsearchAssertions { * * @param extraInfo extra information to add to the failure message */ - public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, Class exceptionClass, String extraInfo) { assertThrows(builder.execute(), exceptionClass, extraInfo); } @@ -582,11 +582,11 @@ public class ElasticsearchAssertions { } } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status) { assertThrows(builder.execute(), status); } - public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { + public static void assertThrows(ActionRequestBuilder builder, RestStatus status, String extraInfo) { assertThrows(builder.execute(), status, extraInfo); } diff --git a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java index 53919f8a718..ac54fb70e07 100644 --- a/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java +++ b/src/test/java/org/elasticsearch/transport/netty/NettyTransportMultiPortIntegrationTests.java @@ -68,7 +68,7 @@ public class NettyTransportMultiPortIntegrationTests extends ElasticsearchIntegr .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) .put("path.home", createTempDir().toString()) .build(); - try (TransportClient transportClient = new TransportClient(settings, false)) { + try (TransportClient transportClient = TransportClient.builder().settings(settings).loadConfigSettings(false).build()) { transportClient.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", randomPort)); ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get(); assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN)); From b889b3b437fd8a124ad8691d878d18339f20425b Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 4 May 2015 15:28:08 -0700 Subject: [PATCH 18/22] Use java sys prop override in tests instead of flag to createPermissions --- .../org/elasticsearch/bootstrap/Security.java | 8 +++--- .../bootstrap/SecurityTests.java | 27 ++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 82a6edf752f..e90b162c7e3 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -42,7 +42,7 @@ public class Security { */ static void configure(Environment environment) throws Exception { // enable security policy: union of template and environment-based paths. - Policy.setPolicy(new ESPolicy(createPermissions(environment, true))); + Policy.setPolicy(new ESPolicy(createPermissions(environment))); // enable security manager System.setSecurityManager(new SecurityManager()); @@ -52,13 +52,11 @@ public class Security { } /** returns dynamic Permissions to configured paths */ - static Permissions createPermissions(Environment environment, boolean addTempDir) throws IOException { + static Permissions createPermissions(Environment environment) throws IOException { // TODO: improve test infra so we can reduce permissions where read/write // is not really needed... Permissions policy = new Permissions(); - if (addTempDir) { - addPath(policy, PathUtils.get(System.getProperty("java.io.tmpdir")), "read,readlink,write,delete"); - } + addPath(policy, PathUtils.get(System.getProperty("java.io.tmpdir")), "read,readlink,write,delete"); addPath(policy, environment.homeFile(), "read,readlink,write,delete"); addPath(policy, environment.configFile(), "read,readlink,write,delete"); addPath(policy, environment.logsFile(), "read,readlink,write,delete"); diff --git a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java index 372bf99466e..33433f1494c 100644 --- a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java +++ b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java @@ -40,8 +40,15 @@ public class SecurityTests extends ElasticsearchTestCase { Settings settings = settingsBuilder.build(); Environment environment = new Environment(settings); - // we pass false to not include temp (or it will grant permissions to everything here) - Permissions permissions = Security.createPermissions(environment, false); + Path fakeTmpDir = createTempDir(); + String realTmpDir = System.getProperty("java.io.tmpdir"); + Permissions permissions; + try { + System.setProperty("java.io.tmpdir", fakeTmpDir.toString()); + permissions = Security.createPermissions(environment); + } finally { + System.setProperty("java.io.tmpdir", realTmpDir); + } // the fake es home assertTrue(permissions.implies(new FilePermission(esHome.toString(), "read"))); @@ -49,6 +56,8 @@ public class SecurityTests extends ElasticsearchTestCase { assertFalse(permissions.implies(new FilePermission(path.toString(), "read"))); // some other sibling assertFalse(permissions.implies(new FilePermission(path.resolve("other").toString(), "read"))); + // double check we overwrote java.io.tmpdir correctly for the test + assertFalse(permissions.implies(new FilePermission(realTmpDir.toString(), "read"))); } /** test generated permissions for all configured paths */ @@ -64,7 +73,15 @@ public class SecurityTests extends ElasticsearchTestCase { Settings settings = settingsBuilder.build(); Environment environment = new Environment(settings); - Permissions permissions = Security.createPermissions(environment, false); + Path fakeTmpDir = createTempDir(); + String realTmpDir = System.getProperty("java.io.tmpdir"); + Permissions permissions; + try { + System.setProperty("java.io.tmpdir", fakeTmpDir.toString()); + permissions = Security.createPermissions(environment); + } finally { + System.setProperty("java.io.tmpdir", realTmpDir); + } // check that all directories got permissions: // homefile: this is needed unless we break out rules for "lib" dir. @@ -84,5 +101,9 @@ public class SecurityTests extends ElasticsearchTestCase { } // logs: r/w assertTrue(permissions.implies(new FilePermission(environment.logsFile().toString(), "read,readlink,write,delete"))); + // temp dir: r/w + assertTrue(permissions.implies(new FilePermission(fakeTmpDir.toString(), "read,readlink,write,delete"))); + // double check we overwrote java.io.tmpdir correctly for the test + assertFalse(permissions.implies(new FilePermission(realTmpDir.toString(), "read"))); } } From 1bc159ebf756c34fbbe5bad65d29d54031dc6c97 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 5 May 2015 10:04:52 +0200 Subject: [PATCH 19/22] mute test in favor of #10972 --- .../search/aggregations/reducers/moving/avg/MovAvgTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java b/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java index f6f92ab278d..b87de1cbb8a 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/reducers/moving/avg/MovAvgTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.reducers.moving.avg; import com.google.common.collect.EvictingQueue; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; @@ -64,6 +65,7 @@ import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; @ElasticsearchIntegrationTest.SuiteScopeTest +@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/10972") public class MovAvgTests extends ElasticsearchIntegrationTest { private static final String INTERVAL_FIELD = "l_value"; From af6d890ad5b7d5f76eb7f66e2c6e3bf0a2c3b64e Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Tue, 5 May 2015 09:03:15 +0100 Subject: [PATCH 20/22] Docs: Fixed typos Closes #10973 --- docs/community/clients.asciidoc | 2 +- docs/java-api/query-dsl-filters.asciidoc | 2 +- .../aggregations/bucket/daterange-aggregation.asciidoc | 2 +- .../aggregations/bucket/geohashgrid-aggregation.asciidoc | 2 +- .../aggregations/bucket/global-aggregation.asciidoc | 2 +- .../aggregations/bucket/histogram-aggregation.asciidoc | 2 +- .../aggregations/reducer/max-bucket-aggregation.asciidoc | 2 +- docs/reference/index-modules/allocation.asciidoc | 2 +- docs/reference/migration/migrate_1_0.asciidoc | 2 +- docs/reference/migration/migrate_2_0.asciidoc | 2 +- docs/reference/modules/advanced-scripting.asciidoc | 6 +++--- .../query-dsl/filters/geo-distance-filter.asciidoc | 2 +- docs/reference/query-dsl/filters/has-child-filter.asciidoc | 2 +- docs/reference/query-dsl/filters/has-parent-filter.asciidoc | 2 +- .../reference/query-dsl/queries/common-terms-query.asciidoc | 2 +- docs/reference/query-dsl/queries/has-child-query.asciidoc | 2 +- docs/reference/query-dsl/queries/has-parent-query.asciidoc | 2 +- docs/reference/query-dsl/queries/span-not-query.asciidoc | 2 +- .../reference/query-dsl/queries/top-children-query.asciidoc | 2 +- docs/reference/search/request/rescore.asciidoc | 2 +- docs/reference/search/request/search-type.asciidoc | 4 ++-- docs/reference/search/request/sort.asciidoc | 2 +- docs/reference/search/suggesters/phrase-suggest.asciidoc | 2 +- docs/reference/setup/configuration.asciidoc | 2 +- docs/resiliency/index.asciidoc | 2 +- docs/ruby/persistence.asciidoc | 4 ++-- 26 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/community/clients.asciidoc b/docs/community/clients.asciidoc index e0205816ca0..c92534eca7d 100644 --- a/docs/community/clients.asciidoc +++ b/docs/community/clients.asciidoc @@ -13,7 +13,7 @@ See the {client}/perl-api/current/index.html[official Elasticsearch Perl client] See the {client}/python-api/current/index.html[official Elasticsearch Python client]. * http://github.com/elasticsearch/elasticsearch-dsl-py[elasticsearch-dsl-py] - chainable query and filter construction built on top of offical client. + chainable query and filter construction built on top of official client. * http://github.com/rhec/pyelasticsearch[pyelasticsearch]: Python client. diff --git a/docs/java-api/query-dsl-filters.asciidoc b/docs/java-api/query-dsl-filters.asciidoc index 7070d0499c7..2240a3b93fc 100644 --- a/docs/java-api/query-dsl-filters.asciidoc +++ b/docs/java-api/query-dsl-filters.asciidoc @@ -150,7 +150,7 @@ FilterBuilder filter = geoDistanceFilter("pin.location") <1> <2> center point <3> distance from center point <4> optimize bounding box: `memory`, `indexed` or `none` -<5> distance computation mode: `GeoDistance.SLOPPY_ARC` (default), `GeoDistance.ARC` (slighly more precise but +<5> distance computation mode: `GeoDistance.SLOPPY_ARC` (default), `GeoDistance.ARC` (slightly more precise but significantly slower) or `GeoDistance.PLANE` (faster, but inaccurate on long distances and close to the poles) Note that you can cache the result using diff --git a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc index 7c5d6cc86fc..a965716269e 100644 --- a/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/daterange-aggregation.asciidoc @@ -2,7 +2,7 @@ === Date Range Aggregation A range aggregation that is dedicated for date values. The main difference between this aggregation and the normal <> aggregation is that the `from` and `to` values can be expressed in <> expressions, and it is also possible to specify a date format by which the `from` and `to` response fields will be returned. -Note that this aggregration includes the `from` value and excludes the `to` value for each range. +Note that this aggregation includes the `from` value and excludes the `to` value for each range. Example: diff --git a/docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc b/docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc index e74e3e96d1b..e90e1c95deb 100644 --- a/docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc @@ -119,7 +119,7 @@ size:: Optional. The maximum number of geohash buckets to return prioritised based on the volumes of documents they contain. A value of `0` will return all buckets that contain a hit, use with caution as this could use a lot of CPU - and network bandwith if there are many buckets. + and network bandwidth if there are many buckets. shard_size:: Optional. To allow for more accurate counting of the top cells returned in the final result the aggregation defaults to diff --git a/docs/reference/aggregations/bucket/global-aggregation.asciidoc b/docs/reference/aggregations/bucket/global-aggregation.asciidoc index fa500e1ff85..4e5addb46c1 100644 --- a/docs/reference/aggregations/bucket/global-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/global-aggregation.asciidoc @@ -30,7 +30,7 @@ Example: The above aggregation demonstrates how one would compute aggregations (`avg_price` in this example) on all the documents in the search context, regardless of the query (in our example, it will compute the average price over all products in our catalog, not just on the "shirts"). -The response for the above aggreation: +The response for the above aggregation: [source,js] -------------------------------------------------- diff --git a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc index cd1fd06ddaf..129732c0410 100644 --- a/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/histogram-aggregation.asciidoc @@ -160,7 +160,7 @@ Example: ==== Order -By default the returned buckets are sorted by their `key` ascending, though the order behaviour can be controled +By default the returned buckets are sorted by their `key` ascending, though the order behaviour can be controlled using the `order` setting. Ordering the buckets by their key - descending: diff --git a/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc b/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc index e1a5e9aa389..939140b4a26 100644 --- a/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc +++ b/docs/reference/aggregations/reducer/max-bucket-aggregation.asciidoc @@ -1,7 +1,7 @@ [[search-aggregations-reducer-max-bucket-aggregation]] === Max Bucket Aggregation -A sibling reducer aggregation which identifies the bucket(s) with the maximum value of a specified metric in a sibing aggregation +A sibling reducer aggregation which identifies the bucket(s) with the maximum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. diff --git a/docs/reference/index-modules/allocation.asciidoc b/docs/reference/index-modules/allocation.asciidoc index 910858f7fcd..800e4d5de5e 100644 --- a/docs/reference/index-modules/allocation.asciidoc +++ b/docs/reference/index-modules/allocation.asciidoc @@ -43,7 +43,7 @@ to be allocated to a node. This is in contrast to `include` which will include a node if ANY rule matches. The `include`, `exclude` and `require` values can have generic simple -matching wildcards, for example, `value1*`. Additonally, special attribute +matching wildcards, for example, `value1*`. Additionally, special attribute names called `_ip`, `_name`, `_id` and `_host` can be used to match by node ip address, name, id or host name, respectively. diff --git a/docs/reference/migration/migrate_1_0.asciidoc b/docs/reference/migration/migrate_1_0.asciidoc index f6cfd4f92a9..aa156676e85 100644 --- a/docs/reference/migration/migrate_1_0.asciidoc +++ b/docs/reference/migration/migrate_1_0.asciidoc @@ -59,7 +59,7 @@ you now use: GET /_cluster/state/nodes --------------- -Simliarly for the `nodes_stats` API, if you want the `transport` and `http` +Similarly for the `nodes_stats` API, if you want the `transport` and `http` metrics only, instead of: [source,sh] diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 9f0cefbd370..2158aacfc2f 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -309,7 +309,7 @@ Fields of type `murmur3` can no longer change `doc_values` or `index` setting. They are always stored with doc values, and not indexed. ==== Source field configuration -The `_source` field no longer supports `includes` and `excludes` paramters. When +The `_source` field no longer supports `includes` and `excludes` parameters. When `_source` is enabled, the entire original source will be stored. ==== Config based mappings diff --git a/docs/reference/modules/advanced-scripting.asciidoc b/docs/reference/modules/advanced-scripting.asciidoc index 4de55531697..ba96a6ec7ab 100644 --- a/docs/reference/modules/advanced-scripting.asciidoc +++ b/docs/reference/modules/advanced-scripting.asciidoc @@ -69,7 +69,7 @@ Field statistics can be accessed with a subscript operator like this: documents. -Field statistics are computed per shard and therfore these numbers can vary +Field statistics are computed per shard and therefore these numbers can vary depending on the shard the current document resides in. The number of terms in a field cannot be accessed using the `_index` variable. See <> on how to do that. @@ -90,7 +90,7 @@ affect is your set the `index_options` to `docs` (see <>. -Additionaly, every child document is mapped to its parent using a long +Additionally, every child document is mapped to its parent using a long value (approximately). It is advisable to keep the string parent ID short in order to reduce memory usage. diff --git a/docs/reference/query-dsl/filters/has-parent-filter.asciidoc b/docs/reference/query-dsl/filters/has-parent-filter.asciidoc index dc708cceda3..1f43c47d41d 100644 --- a/docs/reference/query-dsl/filters/has-parent-filter.asciidoc +++ b/docs/reference/query-dsl/filters/has-parent-filter.asciidoc @@ -50,7 +50,7 @@ The `has_parent` filter also accepts a filter instead of a query: In order to support parent-child joins, all of the (string) parent IDs must be resident in memory (in the <>. -Additionaly, every child document is mapped to its parent using a long +Additionally, every child document is mapped to its parent using a long value (approximately). It is advisable to keep the string parent ID short in order to reduce memory usage. diff --git a/docs/reference/query-dsl/queries/common-terms-query.asciidoc b/docs/reference/query-dsl/queries/common-terms-query.asciidoc index 3e9a73e31dc..b9aee04e401 100644 --- a/docs/reference/query-dsl/queries/common-terms-query.asciidoc +++ b/docs/reference/query-dsl/queries/common-terms-query.asciidoc @@ -55,7 +55,7 @@ Terms are allocated to the high or low frequency groups based on the `cutoff_frequency`, which can be specified as an absolute frequency (`>=1`) or as a relative frequency (`0.0 .. 1.0`). (Remember that document frequencies are computed on a per shard level as explained in the blog post -{defguide}/relevance-is-broken.html[Relevence is broken].) +{defguide}/relevance-is-broken.html[Relevance is broken].) Perhaps the most interesting property of this query is that it adapts to domain specific stopwords automatically. For example, on a video hosting diff --git a/docs/reference/query-dsl/queries/has-child-query.asciidoc b/docs/reference/query-dsl/queries/has-child-query.asciidoc index 0fcf7873c26..f161dd74842 100644 --- a/docs/reference/query-dsl/queries/has-child-query.asciidoc +++ b/docs/reference/query-dsl/queries/has-child-query.asciidoc @@ -86,7 +86,7 @@ the `score_mode` parameter. In order to support parent-child joins, all of the (string) parent IDs must be resident in memory (in the <>. -Additionaly, every child document is mapped to its parent using a long +Additionally, every child document is mapped to its parent using a long value (approximately). It is advisable to keep the string parent ID short in order to reduce memory usage. diff --git a/docs/reference/query-dsl/queries/has-parent-query.asciidoc b/docs/reference/query-dsl/queries/has-parent-query.asciidoc index f684173a45b..3e66e6f5b0c 100644 --- a/docs/reference/query-dsl/queries/has-parent-query.asciidoc +++ b/docs/reference/query-dsl/queries/has-parent-query.asciidoc @@ -54,7 +54,7 @@ matching parent document. The score type can be specified with the In order to support parent-child joins, all of the (string) parent IDs must be resident in memory (in the <>. -Additionaly, every child document is mapped to its parent using a long +Additionally, every child document is mapped to its parent using a long value (approximately). It is advisable to keep the string parent ID short in order to reduce memory usage. diff --git a/docs/reference/query-dsl/queries/span-not-query.asciidoc b/docs/reference/query-dsl/queries/span-not-query.asciidoc index ad6fd8ca4a4..abd6ef82a20 100644 --- a/docs/reference/query-dsl/queries/span-not-query.asciidoc +++ b/docs/reference/query-dsl/queries/span-not-query.asciidoc @@ -30,7 +30,7 @@ The `include` and `exclude` clauses can be any span type query. The `exclude` clause is the span query whose matches must not overlap those returned. -In the above example all documents with the term hoya are filtered except the ones that have 'la' preceeding them. +In the above example all documents with the term hoya are filtered except the ones that have 'la' preceding them. Other top level options: diff --git a/docs/reference/query-dsl/queries/top-children-query.asciidoc b/docs/reference/query-dsl/queries/top-children-query.asciidoc index a13250094d6..4616d87676b 100644 --- a/docs/reference/query-dsl/queries/top-children-query.asciidoc +++ b/docs/reference/query-dsl/queries/top-children-query.asciidoc @@ -68,7 +68,7 @@ same scope name that will work against the child documents. For example: In order to support parent-child joins, all of the (string) parent IDs must be resident in memory (in the <>. -Additionaly, every child document is mapped to its parent using a long +Additionally, every child document is mapped to its parent using a long value (approximately). It is advisable to keep the string parent ID short in order to reduce memory usage. diff --git a/docs/reference/search/request/rescore.asciidoc b/docs/reference/search/request/rescore.asciidoc index c1547e8784c..729ec8ad839 100644 --- a/docs/reference/search/request/rescore.asciidoc +++ b/docs/reference/search/request/rescore.asciidoc @@ -73,7 +73,7 @@ curl -s -XPOST 'localhost:9200/_search' -d '{ ' -------------------------------------------------- -The way the scores are combined can be controled with the `score_mode`: +The way the scores are combined can be controlled with the `score_mode`: [cols="<,<",options="header",] |======================================================================= |Score Mode |Description diff --git a/docs/reference/search/request/search-type.asciidoc b/docs/reference/search/request/search-type.asciidoc index f5532f66e85..b80264e9830 100644 --- a/docs/reference/search/request/search-type.asciidoc +++ b/docs/reference/search/request/search-type.asciidoc @@ -21,10 +21,10 @@ it does not take into account term frequencies and other search engine information from the other shards. If we want to support accurate ranking, we would need to first gather the term frequencies from all shards to calculate global term frequencies, then execute the query on -each shard using these globale frequencies. +each shard using these global frequencies. Also, because of the need to sort the results, getting back a large -document set, or even scrolling it, while maintaing the correct sorting +document set, or even scrolling it, while maintaining the correct sorting behavior can be a very expensive operation. For large result set scrolling without sorting, the `scan` search type (explained below) is also available. diff --git a/docs/reference/search/request/sort.asciidoc b/docs/reference/search/request/sort.asciidoc index 85ae2384fb7..39d1262a050 100644 --- a/docs/reference/search/request/sort.asciidoc +++ b/docs/reference/search/request/sort.asciidoc @@ -192,7 +192,7 @@ Allow to sort by `_geo_distance`. Here is an example: `distance_type`:: - How to compute the distance. Can either be `sloppy_arc` (default), `arc` (slighly more precise but significantly slower) or `plane` (faster, but inaccurate on long distances and close to the poles). + How to compute the distance. Can either be `sloppy_arc` (default), `arc` (slightly more precise but significantly slower) or `plane` (faster, but inaccurate on long distances and close to the poles). Note: the geo distance sorting supports `sort_mode` options: `min`, `max` and `avg`. diff --git a/docs/reference/search/suggesters/phrase-suggest.asciidoc b/docs/reference/search/suggesters/phrase-suggest.asciidoc index c191e6bf129..311a9a75304 100644 --- a/docs/reference/search/suggesters/phrase-suggest.asciidoc +++ b/docs/reference/search/suggesters/phrase-suggest.asciidoc @@ -125,7 +125,7 @@ can contain misspellings (See parameter descriptions below). query terms a number `>=1` as an absolute number of query terms. The default is set to `1.0` which corresponds to that only corrections with at most 1 misspelled term are returned. Note that setting this too high - can negativly impact performance. Low values like `1` or `2` are recommended + can negatively impact performance. Low values like `1` or `2` are recommended otherwise the time spend in suggest calls might exceed the time spend in query execution. diff --git a/docs/reference/setup/configuration.asciidoc b/docs/reference/setup/configuration.asciidoc index 7d0ad80e131..eed595e25ba 100644 --- a/docs/reference/setup/configuration.asciidoc +++ b/docs/reference/setup/configuration.asciidoc @@ -134,7 +134,7 @@ by running `ulimit -l unlimited` as `root` before starting Elasticsearch. Another possible reason why `mlockall` can fail is that the temporary directory (usually `/tmp`) is mounted with the `noexec` option. This can be solved by -specfying a new temp directory, by starting Elasticsearch with: +specifying a new temp directory, by starting Elasticsearch with: [source,sh] -------------- diff --git a/docs/resiliency/index.asciidoc b/docs/resiliency/index.asciidoc index d52e8804392..b1f3c7a3049 100644 --- a/docs/resiliency/index.asciidoc +++ b/docs/resiliency/index.asciidoc @@ -217,7 +217,7 @@ starts. See {GIT}9899[#9899] (STATUS; DONE, fixed in v1.5.0) Setting `zen.discovery.minimum_master_nodes` to a value higher than the current node count effectively leaves the cluster without a master and unable to process requests. The only -way to fix this is to add more master-eligibile nodes. {GIT}8321[#8321] adds a mechanism +way to fix this is to add more master-eligible nodes. {GIT}8321[#8321] adds a mechanism to validate settings before applying them, and {GIT}9051[#9051] extends this validation support to settings applied during a cluster restore. (STATUS: DONE, Fixed in v1.5.0) diff --git a/docs/ruby/persistence.asciidoc b/docs/ruby/persistence.asciidoc index 3d2d807e709..1860f0167f3 100644 --- a/docs/ruby/persistence.asciidoc +++ b/docs/ruby/persistence.asciidoc @@ -142,7 +142,7 @@ class Article # Execute code after saving the model. # - after_save { puts "Successfuly saved: #{self}" } + after_save { puts "Successfully saved: #{self}" } end ------------------------------------ @@ -215,7 +215,7 @@ Any callbacks defined in the model will be triggered during the persistence oper [source,ruby] ------------------------------------ article.save -# Successfuly saved: #

+# Successfully saved: #
------------------------------------ Please see the extensive documentation in the library From 123b0723fe279debe0c320ae917b34d26e51c51b Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Fri, 1 May 2015 10:52:32 +0100 Subject: [PATCH 21/22] Aggregations: Fixes Infinite values return from geo_bounds with non-zero bucket-ordinals If the collect method was called with a bucketOrd of > 0 the arrays holding the state for the aggregation would be grown but the initial values for the bucketOrds > 0 were all set to Double.NEGATIVE_INFINITY meaning that for the bottom, posLeft and negLeft values no collected document would change the value since NEGATIVE_INFINITY is always less than every other value. Closes #10804 --- .../metrics/geobounds/GeoBoundsAggregator.java | 6 +++--- .../search/aggregations/metrics/GeoBoundsTests.java | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java index 464d0a339a8..df356b5b8a3 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregator.java @@ -90,13 +90,13 @@ public final class GeoBoundsAggregator extends MetricsAggregator { tops = bigArrays.grow(tops, bucket + 1); tops.fill(from, tops.size(), Double.NEGATIVE_INFINITY); bottoms = bigArrays.resize(bottoms, tops.size()); - bottoms.fill(from, bottoms.size(), Double.NEGATIVE_INFINITY); + bottoms.fill(from, bottoms.size(), Double.POSITIVE_INFINITY); posLefts = bigArrays.resize(posLefts, tops.size()); - posLefts.fill(from, posLefts.size(), Double.NEGATIVE_INFINITY); + posLefts.fill(from, posLefts.size(), Double.POSITIVE_INFINITY); posRights = bigArrays.resize(posRights, tops.size()); posRights.fill(from, posRights.size(), Double.NEGATIVE_INFINITY); negLefts = bigArrays.resize(negLefts, tops.size()); - negLefts.fill(from, negLefts.size(), Double.NEGATIVE_INFINITY); + negLefts.fill(from, negLefts.size(), Double.POSITIVE_INFINITY); negRights = bigArrays.resize(negRights, tops.size()); negRights.fill(from, negRights.size(), Double.NEGATIVE_INFINITY); } diff --git a/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java b/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java index cf25345aa93..74b8849e790 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/metrics/GeoBoundsTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.util.BigArray; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.aggregations.bucket.global.Global; @@ -38,7 +37,6 @@ import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregat import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ElasticsearchIntegrationTest; -import org.elasticsearch.test.junit.annotations.TestLogging; import org.junit.Test; import java.util.ArrayList; @@ -51,7 +49,10 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.global; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.sameInstance; @@ -407,6 +408,10 @@ public class GeoBoundsTests extends ElasticsearchIntegrationTest { GeoBounds geoBounds = bucket.getAggregations().get("geoBounds"); assertThat(geoBounds, notNullValue()); assertThat(geoBounds.getName(), equalTo("geoBounds")); + assertThat(geoBounds.topLeft().getLat(), allOf(greaterThanOrEqualTo(-90.0), lessThanOrEqualTo(90.0))); + assertThat(geoBounds.topLeft().getLon(), allOf(greaterThanOrEqualTo(-180.0), lessThanOrEqualTo(180.0))); + assertThat(geoBounds.bottomRight().getLat(), allOf(greaterThanOrEqualTo(-90.0), lessThanOrEqualTo(90.0))); + assertThat(geoBounds.bottomRight().getLon(), allOf(greaterThanOrEqualTo(-180.0), lessThanOrEqualTo(180.0))); } } From e28ad853c73b4a25f706b283ed6c7d6354e22865 Mon Sep 17 00:00:00 2001 From: Clinton Gormley Date: Tue, 5 May 2015 11:17:05 +0200 Subject: [PATCH 22/22] Docs: Fixed bad asciidoc in migrate_2_0 --- docs/reference/migration/migrate_2_0.asciidoc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index 2158aacfc2f..b9e84b85839 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -400,9 +400,9 @@ be used separately to control whether `routing_nodes` should be returned. === Query DSL -Change to ranking behaviour: single-term queries on numeric fields now score in the same way as string fields (use of IDF, norms if enabled). +Change to ranking behaviour: single-term queries on numeric fields now score in the same way as string fields (use of IDF, norms if enabled). Previously, term queries on numeric fields were deliberately prevented from using the usual Lucene scoring logic and this behaviour was undocumented and, to some, unexpected. -If the introduction of scoring to numeric fields is undesirable for your query clauses the fix is simple: wrap them in a `constant_score` or use a `filter` expression instead. +If the introduction of scoring to numeric fields is undesirable for your query clauses the fix is simple: wrap them in a `constant_score` or use a `filter` expression instead. The `fuzzy_like_this` and `fuzzy_like_this_field` queries have been removed. @@ -462,7 +462,7 @@ The `index.store.distributor` setting has also been removed. === Hunspell dictionary configuration The parameter `indices.analysis.hunspell.dictionary.location` has been removed, -and `/hunspell` is always used. +and `/hunspell` is always used. === Java API Transport API construction @@ -474,6 +474,7 @@ pattern. Instead of using: Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", "myClusterName").build(); Client client = new TransportClient(settings); +-------------------------------------------------- Use: