Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/master' into stopgap-repo-gen-s…
Browse files Browse the repository at this point in the history
…olution
  • Loading branch information
original-brownbear committed Nov 12, 2019
2 parents 79c9569 + 13170a7 commit 46ade8d
Show file tree
Hide file tree
Showing 125 changed files with 3,107 additions and 1,468 deletions.
2 changes: 1 addition & 1 deletion .eclipseformat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="48"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="separate_lines_if_wrapped"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="48"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.keep_code_block_on_one_line" value="one_line_if_empty"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ subprojects {
// is greater than the number of unformatted projects, this can be
// switched to an exclude list, and eventualy removed completely.
def projectPathsToFormat = [
// ':build-tools'
':x-pack:plugin:enrich'
]

if (projectPathsToFormat.contains(project.path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.elasticsearch.client.indices.CloseIndexResponse;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
Expand Down Expand Up @@ -1062,4 +1063,28 @@ public Cancellable reloadAnalyzersAsync(ReloadAnalyzersRequest request, RequestO
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::reloadAnalyzers, options,
ReloadAnalyzersResponse::fromXContent, listener, emptySet());
}

/**
* Synchronously calls the delete alias api
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
*/
public org.elasticsearch.client.core.AcknowledgedResponse deleteAlias(DeleteAliasRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::deleteAlias, options,
org.elasticsearch.client.core.AcknowledgedResponse::fromXContent, emptySet());
}

/**
* Asynchronously calls the delete alias api
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
* @return cancellable that may be used to cancel the request
*/
public Cancellable deleteAliasAsync(DeleteAliasRequest request, RequestOptions options,
ActionListener<org.elasticsearch.client.core.AcknowledgedResponse> listener) {
return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::deleteAlias, options,
org.elasticsearch.client.core.AcknowledgedResponse::fromXContent, listener, emptySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.client.indices.AnalyzeRequest;
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
Expand Down Expand Up @@ -483,4 +484,17 @@ static Request reloadAnalyzers(ReloadAnalyzersRequest reloadAnalyzersRequest) {
request.addParameters(parameters.asMap());
return request;
}

static Request deleteAlias(DeleteAliasRequest deleteAliasRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPart(deleteAliasRequest.getIndex())
.addPathPartAsIs("_alias")
.addPathPart(deleteAliasRequest.getAlias()).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withTimeout(deleteAliasRequest.timeout());
parameters.withMasterTimeout(deleteAliasRequest.masterNodeTimeout());
request.addParameters(parameters.asMap());
return request;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.indices;

import org.elasticsearch.client.TimedRequest;

public class DeleteAliasRequest extends TimedRequest {

private final String index;
private final String alias;

public DeleteAliasRequest(String index, String alias) {
this.index = index;
this.alias = alias;
}

public String getIndex() {
return index;
}

public String getAlias() {
return alias;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
package org.elasticsearch.client.ml.job.results;

import org.elasticsearch.client.ml.job.config.DetectorFunction;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -256,6 +259,28 @@ void setInfluencers(List<Influence> influencers) {
this.influencers = Collections.unmodifiableList(influencers);
}

@Nullable
public GeoPoint getTypicalGeoPoint() {
if (DetectorFunction.LAT_LONG.getFullName().equals(function) == false || typical == null) {
return null;
}
if (typical.size() == 2) {
return new GeoPoint(typical.get(0), typical.get(1));
}
return null;
}

@Nullable
public GeoPoint getActualGeoPoint() {
if (DetectorFunction.LAT_LONG.getFullName().equals(function) == false || actual == null) {
return null;
}
if (actual.size() == 2) {
return new GeoPoint(actual.get(0), actual.get(1));
}
return null;
}

@Override
public int hashCode() {
return Objects.hash(probability, actual, typical, byFieldName, byFieldValue, correlatedByFieldValue, fieldName, function,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package org.elasticsearch.client.ml.job.results;

import org.elasticsearch.client.common.TimeUtil;
import org.elasticsearch.client.ml.job.config.DetectorFunction;
import org.elasticsearch.client.ml.job.config.Job;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -388,6 +391,28 @@ void setInfluencers(List<Influence> influencers) {
this.influences = Collections.unmodifiableList(influencers);
}

@Nullable
public GeoPoint getTypicalGeoPoint() {
if (DetectorFunction.LAT_LONG.getFullName().equals(function) == false || typical == null) {
return null;
}
if (typical.size() == 2) {
return new GeoPoint(typical.get(0), typical.get(1));
}
return null;
}

@Nullable
public GeoPoint getActualGeoPoint() {
if (DetectorFunction.LAT_LONG.getFullName().equals(function) == false || actual == null) {
return null;
}
if (actual.size() == 2) {
return new GeoPoint(actual.get(0), actual.get(1));
}
return null;
}

@Override
public int hashCode() {
return Objects.hash(jobId, detectorIndex, bucketSpan, probability, multiBucketImpact, recordScore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.elasticsearch.client.indices.CloseIndexResponse;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
Expand Down Expand Up @@ -1550,4 +1551,32 @@ public void testReloadAnalyzer() throws IOException {
assertNotNull(reloadResponse.shards());
assertTrue(reloadResponse.getReloadedDetails().containsKey("test"));
}

public void testDeleteAlias() throws IOException {
String index = "test";
createIndex(index, Settings.EMPTY);

String alias = "alias";
String alias2 = "alias2";
IndicesAliasesRequest aliasesAddRemoveRequest = new IndicesAliasesRequest();
aliasesAddRemoveRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).indices(index).alias(alias));
aliasesAddRemoveRequest.addAliasAction(new AliasActions(AliasActions.Type.ADD).indices(index).alias(alias + "2"));
AcknowledgedResponse aliasResponse = execute(aliasesAddRemoveRequest, highLevelClient().indices()::updateAliases,
highLevelClient().indices()::updateAliasesAsync);
assertTrue(aliasResponse.isAcknowledged());
assertThat(aliasExists(alias), equalTo(true));
assertThat(aliasExists(alias2), equalTo(true));
assertThat(aliasExists(index, alias), equalTo(true));
assertThat(aliasExists(index, alias2), equalTo(true));

DeleteAliasRequest request = new DeleteAliasRequest(index, alias);
org.elasticsearch.client.core.AcknowledgedResponse aliasDeleteResponse = execute(request,
highLevelClient().indices()::deleteAlias,
highLevelClient().indices()::deleteAliasAsync);

assertThat(aliasExists(alias), equalTo(false));
assertThat(aliasExists(alias2), equalTo(true));
assertThat(aliasExists(index, alias), equalTo(false));
assertThat(aliasExists(index, alias2), equalTo(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.elasticsearch.client.indices.AnalyzeRequest;
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
Expand Down Expand Up @@ -934,4 +935,18 @@ public void testReloadAnalyzers() {
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
Assert.assertThat(request.getEntity(), nullValue());
}

public void testDeleteAlias() {
DeleteAliasRequest deleteAliasRequest = new DeleteAliasRequest(randomAlphaOfLength(4), randomAlphaOfLength(4));

Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomMasterTimeout(deleteAliasRequest, expectedParams);
RequestConvertersTests.setRandomTimeout(deleteAliasRequest, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);

Request request = IndicesRequestConverters.deleteAlias(deleteAliasRequest);
Assert.assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
Assert.assertThat(request.getEndpoint(), equalTo("/" + deleteAliasRequest.getIndex() + "/_alias/" + deleteAliasRequest.getAlias()));
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
Assert.assertThat(request.getEntity(), nullValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ public void testApiNamingConventions() throws Exception {
"create",
"get_script_context",
"get_source",
"indices.delete_alias",
"indices.exists_type",
"indices.get_upgrade",
"indices.put_alias",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.elasticsearch.client.indices.CloseIndexResponse;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.DeleteAliasRequest;
import org.elasticsearch.client.indices.DetailAnalyzeResponse;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
Expand Down Expand Up @@ -2880,4 +2881,87 @@ public void onFailure(Exception e) {
// end::reload-analyzers-notfound
}
}

@SuppressWarnings("unused")
public void testDeleteAlias() throws Exception {
RestHighLevelClient client = highLevelClient();

{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index1"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
{
IndicesAliasesRequest request = new IndicesAliasesRequest();
AliasActions aliasAction =
new AliasActions(AliasActions.Type.ADD)
.index("index1")
.alias("alias1");
request.addAliasAction(aliasAction);
AcknowledgedResponse indicesAliasesResponse =
client.indices().updateAliases(request, RequestOptions.DEFAULT);
assertTrue(indicesAliasesResponse.isAcknowledged());
}
{
IndicesAliasesRequest request = new IndicesAliasesRequest();
AliasActions aliasAction =
new AliasActions(AliasActions.Type.ADD)
.index("index1")
.alias("alias2");
request.addAliasAction(aliasAction);
AcknowledgedResponse indicesAliasesResponse =
client.indices().updateAliases(request, RequestOptions.DEFAULT);
assertTrue(indicesAliasesResponse.isAcknowledged());
}
{
// tag::delete-alias-request
DeleteAliasRequest request = new DeleteAliasRequest("index1", "alias1");
// end::delete-alias-request

// tag::delete-alias-request-timeout
request.setTimeout(TimeValue.timeValueMinutes(2)); // <1>
// end::delete-alias-request-timeout
// tag::delete-alias-request-masterTimeout
request.setMasterTimeout(TimeValue.timeValueMinutes(1)); // <1>
// end::delete-alias-request-masterTimeout

// tag::delete-alias-execute
org.elasticsearch.client.core.AcknowledgedResponse deleteAliasResponse =
client.indices().deleteAlias(request, RequestOptions.DEFAULT);
// end::delete-alias-execute

// tag::delete-alias-response
boolean acknowledged = deleteAliasResponse.isAcknowledged(); // <1>
// end::delete-alias-response
assertTrue(acknowledged);
}

{
DeleteAliasRequest request = new DeleteAliasRequest("index1", "alias2"); // <1>

// tag::delete-alias-execute-listener
ActionListener<org.elasticsearch.client.core.AcknowledgedResponse> listener =
new ActionListener<org.elasticsearch.client.core.AcknowledgedResponse>() {
@Override
public void onResponse(org.elasticsearch.client.core.AcknowledgedResponse deleteAliasResponse) {
// <1>
}

@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::delete-alias-execute-listener

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

// tag::delete-alias-execute-async
client.indices().deleteAliasAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::delete-alias-execute-async

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

0 comments on commit 46ade8d

Please sign in to comment.