Skip to content

Commit

Permalink
[Remove] deprecated getMapping API from IndicesClient (#2262)
Browse files Browse the repository at this point in the history
Removes the deprecated types based get, getMapping, getAsync, and
getMappingAsync methods from IndicesClient. It also removes extra nesting of
mappings belong the deprecated type named object and removes the types based
methods from the affected request classes.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize authored Mar 2, 2022
1 parent 4b89410 commit 897f4e7
Show file tree
Hide file tree
Showing 38 changed files with 348 additions and 1,099 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,60 +550,6 @@ public Cancellable getMappingAsync(
);
}

/**
* Retrieves the mappings on an index or indices using the Get Mapping API.
*
* @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.opensearch.action.admin.indices.mapping.get.GetMappingsResponse getMapping(
org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
RequestOptions options
) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
emptySet()
);
}

/**
* Asynchronously retrieves the mappings on an index on indices using the Get Mapping API.
*
* @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.
* @return cancellable that may be used to cancel the request
*/
@Deprecated
public Cancellable getMappingAsync(
org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
RequestOptions options,
ActionListener<org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse> listener
) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
getMappingsRequest,
IndicesRequestConverters::getMappings,
options,
org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
listener,
emptySet()
);
}

/**
* Retrieves the field mappings on an index or indices using the Get Field Mapping API.
*
Expand Down Expand Up @@ -1008,56 +954,6 @@ public Cancellable getAsync(GetIndexRequest getIndexRequest, RequestOptions opti
);
}

/**
* Retrieve information about one or more indexes
*
* @param getIndexRequest 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 an old request object which still refers to types, a deprecated feature. The method
* {@link #get(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
*/
@Deprecated
public org.opensearch.action.admin.indices.get.GetIndexResponse get(
org.opensearch.action.admin.indices.get.GetIndexRequest getIndexRequest,
RequestOptions options
) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
getIndexRequest,
IndicesRequestConverters::getIndex,
options,
org.opensearch.action.admin.indices.get.GetIndexResponse::fromXContent,
emptySet()
);
}

/**
* Retrieve information about one or more indexes
*
* @param getIndexRequest 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 an old request object which still refers to types, a deprecated feature. The method
* {@link #getAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
* @return cancellable that may be used to cancel the request
*/
@Deprecated
public Cancellable getAsync(
org.opensearch.action.admin.indices.get.GetIndexRequest getIndexRequest,
RequestOptions options,
ActionListener<org.opensearch.action.admin.indices.get.GetIndexResponse> listener
) {
return restHighLevelClient.performRequestAsyncAndParseEntity(
getIndexRequest,
IndicesRequestConverters::getIndex,
options,
org.opensearch.action.admin.indices.get.GetIndexResponse::fromXContent,
listener,
emptySet()
);
}

/**
* Force merge one or more indices using the Force Merge API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,6 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) {
return request;
}

@Deprecated
static Request getMappings(org.opensearch.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();

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

RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
parameters.withLocal(getMappingsRequest.local());
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
request.addParameters(parameters.asMap());
return request;
}

static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) {
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.opensearch.client;

import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.ToXContent;
Expand All @@ -42,6 +43,10 @@
import org.opensearch.test.OpenSearchTestCase;

import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
* Base class for HLRC response parsing tests.
Expand Down Expand Up @@ -99,4 +104,16 @@ protected ToXContent.Params getParams() {
return ToXContent.EMPTY_PARAMS;
}

protected static <T> void assertMapEquals(ImmutableOpenMap<String, T> expected, Map<String, T> actual) {
Set<String> expectedKeys = new HashSet<>();
Iterator<String> keysIt = expected.keysIt();
while (keysIt.hasNext()) {
expectedKeys.add(keysIt.next());
}

assertEquals(expectedKeys, actual.keySet());
for (String key : expectedKeys) {
assertEquals(expected.get(key), actual.get(key));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
import org.opensearch.rest.RestStatus;
import org.opensearch.rest.action.admin.indices.RestCreateIndexAction;
import org.opensearch.rest.action.admin.indices.RestGetIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestGetIndicesAction;
import org.opensearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.opensearch.rest.action.admin.indices.RestRolloverIndexAction;

Expand Down Expand Up @@ -487,33 +486,6 @@ public void testGetIndex() throws IOException {
assertEquals("integer", fieldMapping.get("type"));
}

@SuppressWarnings("unchecked")
public void testGetIndexWithTypes() throws IOException {
String indexName = "get_index_test";
Settings basicSettings = Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).build();
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
createIndex(indexName, basicSettings, mappings);

org.opensearch.action.admin.indices.get.GetIndexRequest getIndexRequest =
new org.opensearch.action.admin.indices.get.GetIndexRequest().indices(indexName).includeDefaults(false);
org.opensearch.action.admin.indices.get.GetIndexResponse getIndexResponse = execute(
getIndexRequest,
highLevelClient().indices()::get,
highLevelClient().indices()::getAsync,
expectWarningsOnce(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)
);

// default settings should be null
assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
assertNotNull(getIndexResponse.getMappings().get(indexName));
MappingMetadata mappingMetadata = getIndexResponse.getMappings().get(indexName).get("_doc");
assertNotNull(mappingMetadata);
assertEquals("_doc", mappingMetadata.type());
assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetadata.source().string());
}

@SuppressWarnings("unchecked")
public void testGetIndexWithDefaults() throws IOException {
String indexName = "get_index_test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,53 +318,6 @@ public void testGetMapping() {
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
}

public void testGetMappingWithTypes() {
org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingRequest =
new org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest();

String[] indices = Strings.EMPTY_ARRAY;
if (randomBoolean()) {
indices = RequestConvertersTests.randomIndicesNames(0, 5);
getMappingRequest.indices(indices);
} else if (randomBoolean()) {
getMappingRequest.indices((String[]) null);
}

String type = null;
if (randomBoolean()) {
type = randomAlphaOfLengthBetween(3, 10);
getMappingRequest.types(type);
} else if (randomBoolean()) {
getMappingRequest.types((String[]) null);
}

Map<String, String> expectedParams = new HashMap<>();

RequestConvertersTests.setRandomIndicesOptions(
getMappingRequest::indicesOptions,
getMappingRequest::indicesOptions,
expectedParams
);
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams);
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");

Request request = IndicesRequestConverters.getMappings(getMappingRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
String index = String.join(",", indices);
if (Strings.hasLength(index)) {
endpoint.add(index);
}
endpoint.add("_mapping");
if (type != null) {
endpoint.add(type);
}
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));

Assert.assertThat(expectedParams, equalTo(request.getParameters()));
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
}

public void testGetFieldMapping() {
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();

Expand Down
Loading

0 comments on commit 897f4e7

Please sign in to comment.