Skip to content

Commit

Permalink
Merge branch 'master' into security_authz_engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymode committed Jan 29, 2019
2 parents 74f2e99 + 3c9f703 commit 5074683
Show file tree
Hide file tree
Showing 293 changed files with 7,163 additions and 1,599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ class VagrantTestPlugin implements Plugin<Project> {
void afterExecute(Task task, TaskState state) {
final String gradlew = Os.isFamily(Os.FAMILY_WINDOWS) ? "gradlew" : "./gradlew"
if (state.failure != null) {
println "REPRODUCE WITH: ${gradlew} ${reproTaskPath} -Dtests.seed=${project.testSeed} "
println "REPRODUCE WITH: ${gradlew} \"${reproTaskPath}\" -Dtests.seed=${project.testSeed} "
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

Expand All @@ -38,6 +39,7 @@
import java.util.Objects;
import java.util.stream.Collectors;

@Ignore // Awaiting a fix in https://github.com/elastic/elasticsearch/issues/37889.
public class BuildExamplePluginsIT extends GradleIntegrationTestCase {

private static final List<File> EXAMPLE_PLUGINS = Collections.unmodifiableList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.Ignore;

import java.util.Arrays;

@Ignore // Awaiting a fix in https://github.com/elastic/elasticsearch/issues/37889.
public class TestClustersPluginIT extends GradleIntegrationTestCase {

public void testListClusters() {
Expand Down
1 change: 1 addition & 0 deletions client/rest-high-level/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ integTestCluster {
// Truststore settings are not used since TLS is not enabled. Included for testing the get certificates API
setting 'xpack.security.http.ssl.certificate_authorities', 'testnode.crt'
setting 'xpack.security.transport.ssl.truststore.path', 'testnode.jks'
setting 'indices.lifecycle.poll_interval', '1000ms'
keystoreSetting 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
setupCommand 'setupDummyUser',
'bin/elasticsearch-users',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
Expand All @@ -61,6 +59,8 @@
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.GetMappingsResponse;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
Expand Down Expand Up @@ -261,8 +261,11 @@ public void putMappingAsync(org.elasticsearch.action.admin.indices.mapping.put.P
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, IndicesRequestConverters::getMappings, options,
GetMappingsResponse::fromXContent, emptySet());
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
GetMappingsResponse::fromXContent,
emptySet());
}

/**
Expand All @@ -275,8 +278,60 @@ public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, Req
*/
public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
ActionListener<GetMappingsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, IndicesRequestConverters::getMappings, options,
GetMappingsResponse::fromXContent, listener, emptySet());
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
GetMappingsResponse::fromXContent,
listener,
emptySet());
}

/**
* Retrieves the mappings on an index or indices using the Get Mapping API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
* Get Mapping API on elastic.co</a>
* @param getMappingsRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*
* @deprecated This method uses old request and response objects which still refer to types, a deprecated
* feature. The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which
* accepts a new request object.
*/
@Deprecated
public org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse getMapping(
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
emptySet());
}

/**
* Asynchronously retrieves the mappings on an index on indices using the Get Mapping API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
* Get Mapping API on elastic.co</a>
* @param getMappingsRequest 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
*
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
* The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which accepts a new
* request object.
*/
@Deprecated
public void getMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
RequestOptions options,
ActionListener<org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
listener,
emptySet());
}

/**
Expand All @@ -288,8 +343,9 @@ public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOption
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
* {@link #getFieldMapping(GetFieldMappingsRequest, RequestOptions)} should be used instead, which accepts a new request object.
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
* The method {@link #getFieldMapping(GetFieldMappingsRequest, RequestOptions)} should be used instead, which
* accepts a new request object.
*/
@Deprecated
public org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse getFieldMapping(
Expand All @@ -307,9 +363,9 @@ public org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRespon
* @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
*
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
* method {@link #getFieldMappingAsync(GetFieldMappingsRequest, RequestOptions, ActionListener)} should be used instead,
* which accepts a new request object.
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
* The method {@link #getFieldMappingAsync(GetFieldMappingsRequest, RequestOptions, ActionListener)} should be
* used instead, which accepts a new request object.
*/
@Deprecated
public void getFieldMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
Expand All @@ -49,6 +48,7 @@
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
Expand Down Expand Up @@ -148,6 +148,7 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio
return request;
}

@Deprecated
static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
if (putMappingRequest.getConcreteIndex() != null) {
Expand All @@ -166,7 +167,21 @@ static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.Put
return request;
}

static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException {
static Request getMappings(GetMappingsRequest getMappingsRequest) {
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();

Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping"));

RequestConverters.Params parameters = new RequestConverters.Params(request);
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
parameters.withLocal(getMappingsRequest.local());

return request;
}

@Deprecated
static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) {
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types();

Expand All @@ -176,6 +191,7 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
parameters.withLocal(getMappingsRequest.local());
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");

return request;
}
Expand All @@ -201,6 +217,7 @@ static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest)
return request;
}

@Deprecated
static Request getFieldMapping(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest) {
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
String[] types = getFieldMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.types();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.action.support.IndicesOptions;
import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.common.Strings;

public class GetMappingsRequest extends TimedRequest {

private boolean local = false;
private boolean includeDefaults = false;
private String[] indices = Strings.EMPTY_ARRAY;
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();

/**
* Indicates whether the receiving node should operate based on local index information or
* forward requests, where needed, to other nodes. If running locally, request will not
* raise errors if local index information is missing.
*/
public GetMappingsRequest local(boolean local) {
this.local = local;
return this;
}

public boolean local() {
return local;
}

public GetMappingsRequest indices(String... indices) {
this.indices = indices;
return this;
}

public GetMappingsRequest indicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
return this;
}

public String[] indices() {
return indices;
}

public IndicesOptions indicesOptions() {
return indicesOptions;
}

public boolean includeDefaults() {
return includeDefaults;
}

/** Indicates whether default mapping settings should be returned */
public GetMappingsRequest includeDefaults(boolean includeDefaults) {
this.includeDefaults = includeDefaults;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.index.mapper.MapperService;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class GetMappingsResponse {

static final ParseField MAPPINGS = new ParseField("mappings");

private Map<String, MappingMetaData> mappings;

public GetMappingsResponse(Map<String, MappingMetaData> mappings) {
this.mappings = mappings;
}

public Map<String, MappingMetaData> mappings() {
return mappings;
}

public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException {
if (parser.currentToken() == null) {
parser.nextToken();
}

XContentParserUtils.ensureExpectedToken(parser.currentToken(),
XContentParser.Token.START_OBJECT,
parser::getTokenLocation);

Map<String, Object> parts = parser.map();

Map<String, MappingMetaData> mappings = new HashMap<>();
for (Map.Entry<String, Object> entry : parts.entrySet()) {
String indexName = entry.getKey();
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();

@SuppressWarnings("unchecked")
final Map<String, Object> fieldMappings = (Map<String, Object>) ((Map<String, ?>) entry.getValue())
.get(MAPPINGS.getPreferredName());

mappings.put(indexName, new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, fieldMappings));
}

return new GetMappingsResponse(mappings);
}
}
Loading

0 comments on commit 5074683

Please sign in to comment.