Skip to content

Commit

Permalink
Merge branch 'master' into index_line_len
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Nov 19, 2018
2 parents 5585d6d + c468d92 commit 890042a
Show file tree
Hide file tree
Showing 257 changed files with 2,593 additions and 1,156 deletions.
31 changes: 0 additions & 31 deletions buildSrc/src/main/resources/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotsService.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]threadpool[/\\]ThreadPool.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]VersionTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]RejectionActionIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]admin[/\\]HotThreadsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]search[/\\]SearchRequestBuilderTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]termvectors[/\\]AbstractTermVectorsTestCase.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]termvectors[/\\]GetTermVectorsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]termvectors[/\\]MultiTermVectorsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]termvectors[/\\]TermVectorsUnitTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]deps[/\\]joda[/\\]SimpleJodaTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]env[/\\]EnvironmentTests.java" checks="LineLength" />
Expand All @@ -134,30 +127,6 @@
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]get[/\\]GetActionIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indexing[/\\]IndexActionIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indexlifecycle[/\\]IndexLifecycleActionIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]IndexingMemoryControllerTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]IndicesLifecycleListenerIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]IndicesOptionsIntegrationIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]analyze[/\\]AnalyzeActionIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]exists[/\\]types[/\\]TypesExistsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]flush[/\\]FlushIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]flush[/\\]SyncedFlushSingleNodeTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]flush[/\\]SyncedFlushUtil.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]mapping[/\\]ConcurrentDynamicTemplateIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]mapping[/\\]SimpleGetFieldMappingsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]mapping[/\\]SimpleGetMappingsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]mapping[/\\]UpdateMappingIntegrationIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]memory[/\\]breaker[/\\]CircuitBreakerUnitTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]memory[/\\]breaker[/\\]RandomExceptionCircuitBreakerIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]recovery[/\\]IndexPrimaryRelocationIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]recovery[/\\]IndexRecoveryIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]recovery[/\\]RecoverySourceHandlerTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]recovery[/\\]RecoveryStatusTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]settings[/\\]UpdateNumberOfReplicasIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]state[/\\]OpenCloseIndexIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]state[/\\]RareClusterStateIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]stats[/\\]IndexStatsIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]store[/\\]IndicesStoreIntegrationIT.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indices[/\\]store[/\\]IndicesStoreTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]JvmGcMonitorServiceSettingsTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]plugins[/\\]PluginsServiceTests.java" checks="LineLength" />
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]recovery[/\\]FullRollingRestartIT.java" checks="LineLength" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class IndexLifecycleClient {
}

/**
* Retrieve one or more lifecycle policy definition
* See <a href="https://fix-me-when-we-have-docs.com">
* Retrieve one or more lifecycle policy definition. See
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-get-lifecycle-policy.html">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
Expand All @@ -62,8 +62,8 @@ public GetLifecyclePolicyResponse getLifecyclePolicy(GetLifecyclePolicyRequest r
}

/**
* Asynchronously retrieve one or more lifecycle policy definition
* See <a href="https://fix-me-when-we-have-docs.com">
* Asynchronously retrieve one or more lifecycle policy definition. See
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-get-lifecycle-policy.html">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public CountRequest source(SearchSourceBuilder searchSourceBuilder) {
/**
* The document types to execute the count against. Defaults to be executed against all types.
*
* @deprecated Types are going away, prefer filtering on a type.
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
* filter on a field on the document.
*/
@Deprecated
public CountRequest types(String... types) {
Expand Down Expand Up @@ -172,6 +173,11 @@ public CountRequest terminateAfter(int terminateAfter) {
return this;
}

/**
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
* filter on a field on the document.
*/
@Deprecated
public String[] types() {
return Arrays.copyOf(this.types, this.types.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
private final String index;
private final String type;
private String id = null;
private XContentBuilder docBuilder = null;

private String routing = null;
private String preference = null;
private boolean realtime = true;
Expand All @@ -44,7 +46,6 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
private boolean requestTermStatistics = false;
private Map<String, String> perFieldAnalyzer = null;
private Map<String, Integer> filterSettings = null;
private XContentBuilder docBuilder = null;


/**
Expand All @@ -54,18 +55,21 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
* @param docId - id of the document
*/
public TermVectorsRequest(String index, String type, String docId) {
this(index, type);
this.index = index;
this.type = type;
this.id = docId;
}

/**
* Constructs TermVectorRequest for an artificial document
* @param index - index of the document
* @param type - type of the document
* @param docBuilder - an artificial document
*/
public TermVectorsRequest(String index, String type) {
public TermVectorsRequest(String index, String type, XContentBuilder docBuilder) {
this.index = index;
this.type = type;
this.docBuilder = docBuilder;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public void testExists() throws IOException {
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
}
public void testSourceExists() throws IOException {

public void testSourceExists() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "type", "id");
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
Expand All @@ -215,17 +215,17 @@ public void testSourceExists() throws IOException {
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
}
public void testSourceDoesNotExist() throws IOException {

public void testSourceDoesNotExist() throws IOException {
final String noSourceIndex = "no_source";
{
// Prepare
Settings settings = Settings.builder()
.put("number_of_shards", 1)
.put("number_of_replicas", 0)
.build();
String mapping = "\"_doc\": { \"_source\": {\n" +
" \"enabled\": false\n" +
String mapping = "\"_doc\": { \"_source\": {\n" +
" \"enabled\": false\n" +
" } }";
createIndex(noSourceIndex, settings, mapping);
assertEquals(
Expand All @@ -240,13 +240,13 @@ public void testSourceDoesNotExist() throws IOException {
RequestOptions.DEFAULT
).status()
);
}
}
{
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
}
}

public void testGet() throws IOException {
{
Expand Down Expand Up @@ -1154,10 +1154,10 @@ public void testTermvectors() throws IOException {
}
{
// test _termvectors on artificial documents
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc");
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
docBuilder.startObject().field("field", "valuex").endObject();
tvRequest.setDoc(docBuilder);

TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc", docBuilder);
TermVectorsResponse tvResponse = execute(tvRequest, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync);

TermVectorsResponse.TermVector.Token expectedToken = new TermVectorsResponse.TermVector.Token(0, 6, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,10 +1565,12 @@ public void testTermVectors() throws Exception {

{
// tag::term-vectors-request-artificial
TermVectorsRequest request = new TermVectorsRequest("authors", "_doc");

XContentBuilder docBuilder = XContentFactory.jsonBuilder();
docBuilder.startObject().field("user", "guest-user").endObject();
request.setDoc(docBuilder); // <1>
TermVectorsRequest request = new TermVectorsRequest("authors",
"_doc",
docBuilder); // <1>
// end::term-vectors-request-artificial

// tag::term-vectors-request-optional-arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
import org.elasticsearch.client.core.AcknowledgedResponse;
import org.elasticsearch.client.indexlifecycle.DeleteAction;
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.LifecycleAction;
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
import org.elasticsearch.client.indexlifecycle.Phase;
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RolloverAction;
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -119,6 +124,108 @@ public void onFailure(Exception e) {

}

public void testGetLifecyclePolicy() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();

LifecyclePolicy myPolicyAsPut;
LifecyclePolicy otherPolicyAsPut;
// Set up some policies so we have something to get
{
Map<String, Phase> phases = new HashMap<>();
Map<String, LifecycleAction> hotActions = new HashMap<>();
hotActions.put(RolloverAction.NAME, new RolloverAction(
new ByteSizeValue(50, ByteSizeUnit.GB), null, null));
phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions));

Map<String, LifecycleAction> deleteActions =
Collections.singletonMap(DeleteAction.NAME,
new DeleteAction());
phases.put("delete",
new Phase("delete",
new TimeValue(90, TimeUnit.DAYS), deleteActions));

myPolicyAsPut = new LifecyclePolicy("my_policy", phases);
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(myPolicyAsPut);

Map<String, Phase> otherPolicyPhases = new HashMap<>(phases);
Map<String, LifecycleAction> warmActions = Collections.singletonMap(ShrinkAction.NAME, new ShrinkAction(1));
otherPolicyPhases.put("warm", new Phase("warm", new TimeValue(30, TimeUnit.DAYS), warmActions));
otherPolicyAsPut = new LifecyclePolicy("other_policy", otherPolicyPhases);

PutLifecyclePolicyRequest putRequest2 = new PutLifecyclePolicyRequest(otherPolicyAsPut);

AcknowledgedResponse putResponse = client.indexLifecycle().
putLifecyclePolicy(putRequest, RequestOptions.DEFAULT);
assertTrue(putResponse.isAcknowledged());
AcknowledgedResponse putResponse2 = client.indexLifecycle().
putLifecyclePolicy(putRequest2, RequestOptions.DEFAULT);
assertTrue(putResponse2.isAcknowledged());
}

// tag::ilm-get-lifecycle-policy-request
GetLifecyclePolicyRequest allRequest =
new GetLifecyclePolicyRequest(); // <1>
GetLifecyclePolicyRequest request =
new GetLifecyclePolicyRequest("my_policy", "other_policy"); // <2>
// end::ilm-get-lifecycle-policy-request

// tag::ilm-get-lifecycle-policy-execute
GetLifecyclePolicyResponse response = client.indexLifecycle()
.getLifecyclePolicy(request, RequestOptions.DEFAULT);
// end::ilm-get-lifecycle-policy-execute

// tag::ilm-get-lifecycle-policy-response
ImmutableOpenMap<String, LifecyclePolicyMetadata> policies =
response.getPolicies();
LifecyclePolicyMetadata myPolicyMetadata =
policies.get("my_policy"); // <1>
String myPolicyName = myPolicyMetadata.getName();
long version = myPolicyMetadata.getVersion();
String lastModified = myPolicyMetadata.getModifiedDateString();
long lastModifiedDate = myPolicyMetadata.getModifiedDate();
LifecyclePolicy myPolicy = myPolicyMetadata.getPolicy(); // <2>
// end::ilm-get-lifecycle-policy-response

assertEquals(myPolicyAsPut, myPolicy);
assertEquals("my_policy", myPolicyName);
assertNotNull(lastModified);
assertNotEquals(0, lastModifiedDate);

LifecyclePolicyMetadata otherPolicyMetadata = policies.get("other_policy");
assertEquals(otherPolicyAsPut, otherPolicyMetadata.getPolicy());
assertEquals("other_policy", otherPolicyMetadata.getName());
assertNotNull(otherPolicyMetadata.getModifiedDateString());
assertNotEquals(0, otherPolicyMetadata.getModifiedDate());

// tag::ilm-get-lifecycle-policy-execute-listener
ActionListener<GetLifecyclePolicyResponse> listener =
new ActionListener<GetLifecyclePolicyResponse>() {
@Override
public void onResponse(GetLifecyclePolicyResponse response)
{
ImmutableOpenMap<String, LifecyclePolicyMetadata>
policies = response.getPolicies(); // <1>
}

@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::ilm-get-lifecycle-policy-execute-listener

// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);

// tag::ilm-get-lifecycle-policy-execute-async
client.indexLifecycle().getLifecyclePolicyAsync(request,
RequestOptions.DEFAULT, listener); // <1>
// end::ilm-get-lifecycle-policy-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
}

static Map<String, Object> toMap(Response response) throws IOException {
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
}
Expand Down
Loading

0 comments on commit 890042a

Please sign in to comment.