From 6462c72e36e18e059685e663bd13c0aefa6d2158 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Mon, 31 Oct 2022 12:48:24 -0500 Subject: [PATCH] cleanup MappingUpdatedAction to remove unexecuted code Signed-off-by: Nicholas Walter Knize --- .../action/index/MappingUpdatedAction.java | 16 ++++------ .../index/MappingUpdatedActionTests.java | 30 ------------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/action/index/MappingUpdatedAction.java b/server/src/main/java/org/opensearch/cluster/action/index/MappingUpdatedAction.java index d5646e14aa32f..e24b39c1f3853 100644 --- a/server/src/main/java/org/opensearch/cluster/action/index/MappingUpdatedAction.java +++ b/server/src/main/java/org/opensearch/cluster/action/index/MappingUpdatedAction.java @@ -33,7 +33,6 @@ package org.opensearch.cluster.action.index; import org.opensearch.OpenSearchException; -import org.opensearch.Version; import org.opensearch.action.ActionListener; import org.opensearch.action.admin.indices.mapping.put.AutoPutMappingAction; import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; @@ -156,16 +155,11 @@ protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListe putMappingRequest.setConcreteIndex(index); putMappingRequest.source(mappingUpdate.toString(), XContentType.JSON); putMappingRequest.clusterManagerNodeTimeout(dynamicMappingUpdateTimeout); - putMappingRequest.timeout(TimeValue.ZERO); - if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_3_0_0)) { - client.execute( - AutoPutMappingAction.INSTANCE, - putMappingRequest, - ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure) - ); - } else { - client.putMapping(putMappingRequest, ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure)); - } + client.execute( + AutoPutMappingAction.INSTANCE, + putMappingRequest, + ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure) + ); } // todo: this explicit unwrap should not be necessary, but is until guessRootCause is fixed to allow wrapped non-es exception. diff --git a/server/src/test/java/org/opensearch/cluster/action/index/MappingUpdatedActionTests.java b/server/src/test/java/org/opensearch/cluster/action/index/MappingUpdatedActionTests.java index 2350392e7c48d..1998dbf9c4c5c 100644 --- a/server/src/test/java/org/opensearch/cluster/action/index/MappingUpdatedActionTests.java +++ b/server/src/test/java/org/opensearch/cluster/action/index/MappingUpdatedActionTests.java @@ -153,36 +153,6 @@ protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListe assertTrue(fut2.isDone()); } - public void testSendUpdateMappingUsingPutMappingAction() { - DiscoveryNodes nodes = DiscoveryNodes.builder() - .add(new DiscoveryNode("first", buildNewFakeTransportAddress(), Version.V_2_0_0)) - .build(); - ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).nodes(nodes).build(); - ClusterService clusterService = mock(ClusterService.class); - when(clusterService.state()).thenReturn(clusterState); - - IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); - AdminClient adminClient = mock(AdminClient.class); - when(adminClient.indices()).thenReturn(indicesAdminClient); - Client client = mock(Client.class); - when(client.admin()).thenReturn(adminClient); - - MappingUpdatedAction mua = new MappingUpdatedAction( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - clusterService - ); - mua.setClient(client); - - Settings indexSettings = Settings.builder().put(SETTING_VERSION_CREATED, Version.CURRENT).build(); - final Mapper.BuilderContext context = new Mapper.BuilderContext(indexSettings, new ContentPath()); - RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name").build(context); - Mapping update = new Mapping(Version.V_2_0_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of()); - - mua.sendUpdateMapping(new Index("name", "uuid"), update, ActionListener.wrap(() -> {})); - verify(indicesAdminClient).putMapping(any(), any()); - } - public void testSendUpdateMappingUsingAutoPutMappingAction() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add(new DiscoveryNode("first", buildNewFakeTransportAddress(), Version.V_3_0_0))