diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java index 1301c1bdad7c6..26eb969f0ecb2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -105,10 +104,10 @@ public void testParsingFromEsResponse() throws IOException { assertThat(result.mappings().sourceAsMap(), equalTo(expectedMapping.get("_doc"))); assertThat(result.aliases().size(), equalTo(esIMD.aliases().size())); - List expectedAliases = Arrays.stream(esIMD.aliases().values().toArray(AliasMetadata.class)) + List expectedAliases = esIMD.aliases().values().stream() .sorted(Comparator.comparing(AliasMetadata::alias)) .collect(Collectors.toList()); - List actualAliases = Arrays.stream(result.aliases().values().toArray(AliasMetadata.class)) + List actualAliases = result.aliases().values().stream() .sorted(Comparator.comparing(AliasMetadata::alias)) .collect(Collectors.toList()); for (int j = 0; j < result.aliases().size(); j++) { @@ -186,8 +185,7 @@ static void toXContent(GetIndexTemplatesResponse response, XContentBuilder build serverTemplateBuilder.patterns(clientITMD.patterns()); - Iterator aliases = clientITMD.aliases().valuesIt(); - aliases.forEachRemaining((a)->serverTemplateBuilder.putAlias(a)); + clientITMD.aliases().values().forEach(serverTemplateBuilder::putAlias); serverTemplateBuilder.settings(clientITMD.settings()); serverTemplateBuilder.order(clientITMD.order()); diff --git a/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java b/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java index ce670f702b650..e2e7290fa9b68 100644 --- a/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java +++ b/modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderIT.java @@ -16,6 +16,7 @@ import org.elasticsearch.action.ingest.SimulatePipelineRequest; import org.elasticsearch.action.ingest.SimulatePipelineResponse; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -51,7 +52,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import java.util.zip.GZIPInputStream; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -398,8 +398,8 @@ private void putPipeline() throws IOException { } private List getGeoIpTmpDirs() throws IOException { - final Set ids = StreamSupport.stream(clusterService().state().nodes().getDataNodes().values().spliterator(), false) - .map(c -> c.value.getId()) + final Set ids = clusterService().state().nodes().getDataNodes().values().stream() + .map(DiscoveryNode::getId) .collect(Collectors.toSet()); // All nodes share the same geoip base dir in the shared tmp dir: Path geoipBaseTmpDir = internalCluster().getDataNodeInstance(Environment.class).tmpFile().resolve("geoip-databases"); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java index 6f75acd9ff389..3970095587932 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java @@ -86,7 +86,7 @@ public void testCreateShrinkIndexToN() { ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() .getDataNodes(); assertTrue("at least 2 nodes but was: " + dataNodes.size(), dataNodes.size() >= 2); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); String mergeNode = discoveryNodes[0].getName(); // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due @@ -159,7 +159,7 @@ public void testShrinkIndexPrimaryTerm() throws Exception { final ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes().getDataNodes(); assertThat(dataNodes.size(), greaterThanOrEqualTo(2)); - final DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + final DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); final String mergeNode = discoveryNodes[0].getName(); // This needs more than the default timeout if a large number of shards were created. ensureGreen(TimeValue.timeValueSeconds(120)); @@ -239,7 +239,7 @@ public void testCreateShrinkIndex() { ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes().getDataNodes(); assertTrue("at least 2 nodes but was: " + dataNodes.size(), dataNodes.size() >= 2); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due // to the require._name below. @@ -340,7 +340,7 @@ public void testCreateShrinkIndexFails() throws Exception { ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() .getDataNodes(); assertTrue("at least 2 nodes but was: " + dataNodes.size(), dataNodes.size() >= 2); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); String spareNode = discoveryNodes[0].getName(); String mergeNode = discoveryNodes[1].getName(); // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node @@ -419,7 +419,7 @@ public void testCreateShrinkWithIndexSort() throws Exception { ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() .getDataNodes(); assertTrue("at least 2 nodes but was: " + dataNodes.size(), dataNodes.size() >= 2); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); String mergeNode = discoveryNodes[0].getName(); // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due @@ -481,7 +481,7 @@ public void testShrinkCommitsMergeOnIdle() throws Exception { client().admin().indices().prepareFlush("source").get(); ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes().getDataNodes(); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due // to the require._name below. diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index 1b67e47f5f1f5..81c3cf2dc3b16 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; @@ -159,20 +158,20 @@ public void testClusterInfoServiceCollectsInformation() { assertNotNull(shardDataSetSizes); assertThat("some usages are populated", leastUsages.values().size(), Matchers.equalTo(2)); assertThat("some shard sizes are populated", shardSizes.values().size(), greaterThan(0)); - for (ObjectCursor usage : leastUsages.values()) { - logger.info("--> usage: {}", usage.value); - assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L)); + for (DiskUsage usage : leastUsages.values()) { + logger.info("--> usage: {}", usage); + assertThat("usage has be retrieved", usage.getFreeBytes(), greaterThan(0L)); } - for (ObjectCursor usage : mostUsages.values()) { - logger.info("--> usage: {}", usage.value); - assertThat("usage has be retrieved", usage.value.getFreeBytes(), greaterThan(0L)); + for (DiskUsage usage : mostUsages.values()) { + logger.info("--> usage: {}", usage); + assertThat("usage has be retrieved", usage.getFreeBytes(), greaterThan(0L)); } - for (ObjectCursor size : shardSizes.values()) { - logger.info("--> shard size: {}", size.value); - assertThat("shard size is greater than 0", size.value, greaterThanOrEqualTo(0L)); + for (Long size : shardSizes.values()) { + logger.info("--> shard size: {}", size); + assertThat("shard size is greater than 0", size, greaterThanOrEqualTo(0L)); } - for (ObjectCursor size : shardDataSetSizes.values()) { - assertThat("shard data set size is greater than 0", size.value, greaterThanOrEqualTo(0L)); + for (Long size : shardDataSetSizes.values()) { + assertThat("shard data set size is greater than 0", size, greaterThanOrEqualTo(0L)); } ClusterService clusterService = internalTestCluster.getInstance(ClusterService.class, internalTestCluster.getMasterName()); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/RemoveReplicaPriorityIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/RemoveReplicaPriorityIT.java index f5f07daddded1..ffe90a462af9f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/RemoveReplicaPriorityIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/RemoveReplicaPriorityIT.java @@ -9,6 +9,7 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.plugins.Plugin; @@ -19,7 +20,6 @@ import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; @@ -53,9 +53,9 @@ public void testReplicaRemovalPriority() throws Exception { }); } - final String dataNodeIdFilter = StreamSupport.stream(client().admin().cluster().prepareState().clear().setNodes(true).get() - .getState().nodes().getDataNodes().values().spliterator(), false) - .map(c -> c.value.getId()).limit(3).collect(Collectors.joining(",")); + final String dataNodeIdFilter = client().admin().cluster().prepareState().clear().setNodes(true).get() + .getState().nodes().getDataNodes().values().stream() + .map(DiscoveryNode::getId).limit(3).collect(Collectors.joining(",")); final String excludedDataNodeId = dataNodeIdFilter.substring(0, dataNodeIdFilter.indexOf(',')); createIndex(INDEX_NAME, Settings.builder() diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java index 017212bbde20b..3642b1a01fd61 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderIT.java @@ -40,7 +40,6 @@ import java.util.Locale; import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.stream.StreamSupport; import static org.elasticsearch.index.store.Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -206,8 +205,8 @@ private void refreshDiskUsage() { ClusterInfoServiceUtils.refresh(((InternalClusterInfoService) clusterInfoService)); // if the nodes were all under the low watermark already (but unbalanced) then a change in the disk usage doesn't trigger a reroute // even though it's now possible to achieve better balance, so we have to do an explicit reroute. TODO fix this? - if (StreamSupport.stream(clusterInfoService.getClusterInfo().getNodeMostAvailableDiskUsages().values().spliterator(), false) - .allMatch(cur -> cur.value.getFreeBytes() > WATERMARK_BYTES)) { + if (clusterInfoService.getClusterInfo().getNodeMostAvailableDiskUsages().values().stream() + .allMatch(e -> e.getFreeBytes() > WATERMARK_BYTES)) { assertAcked(client().admin().cluster().prepareReroute()); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java b/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java index 68426b47f2b6c..2f6d5b542d186 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java @@ -8,7 +8,6 @@ package org.elasticsearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction; import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest; import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction; @@ -133,8 +132,7 @@ private Map assertAndCapturePrimaryTerms(Map pre } final Map result = new HashMap<>(); final ClusterState state = client().admin().cluster().prepareState().get().getState(); - for (ObjectCursor cursor : state.metadata().indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (IndexMetadata indexMetadata : state.metadata().indices().values()) { final String index = indexMetadata.getIndex().getName(); final long[] previous = previousTerms.get(index); final long[] current = IntStream.range(0, indexMetadata.getNumberOfShards()).mapToLong(indexMetadata::primaryTerm).toArray(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexPrimaryRelocationIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexPrimaryRelocationIT.java index bc1a0289d29ac..405c4d0d845ae 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexPrimaryRelocationIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexPrimaryRelocationIT.java @@ -58,7 +58,7 @@ public void run() { indexingThread.start(); ClusterState initialState = client().admin().cluster().prepareState().get().getState(); - DiscoveryNode[] dataNodes = initialState.getNodes().getDataNodes().values().toArray(DiscoveryNode.class); + DiscoveryNode[] dataNodes = initialState.getNodes().getDataNodes().values().toArray(DiscoveryNode[]::new); DiscoveryNode relocationSource = initialState.getNodes().getDataNodes().get(initialState.getRoutingTable() .shardRoutingTable("test", 0).primaryShard().currentNodeId()); for (int i = 0; i < RELOCATION_COUNT; i++) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseIndexIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseIndexIT.java index 3e78c9707371b..729e76950fb38 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseIndexIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/state/CloseIndexIT.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexSettings; @@ -379,8 +378,8 @@ public void testNoopPeerRecoveriesWhenIndexClosed() throws Exception { public void testRecoverExistingReplica() throws Exception { final String indexName = "test-recover-existing-replica"; internalCluster().ensureAtLeastNumDataNodes(2); - List dataNodes = randomSubsetOf(2, Sets.newHashSet( - clusterService().state().nodes().getDataNodes().valuesIt()).stream().map(DiscoveryNode::getName).collect(Collectors.toSet())); + List dataNodes = randomSubsetOf(2, clusterService().state().nodes().getDataNodes().values() + .stream().map(DiscoveryNode::getName).collect(Collectors.toSet())); createIndex(indexName, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java b/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java index 8fa627dfe99e8..20ea1d0b6799b 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java @@ -84,7 +84,7 @@ public void testShrinking() throws Exception { client().admin().indices().prepareUpdateSettings(index) .setSettings(Settings.builder() .put("index.routing.allocation.require._name", client().admin().cluster().prepareState().get().getState().nodes() - .getDataNodes().values().toArray(DiscoveryNode.class)[0].getName()) + .getDataNodes().values().toArray(DiscoveryNode[]::new)[0].getName()) .put("index.blocks.write", true)).get(); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/CloneSnapshotIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/CloneSnapshotIT.java index 257ea05e236ca..a5e8a0ff3c8b6 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/CloneSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/CloneSnapshotIT.java @@ -7,8 +7,6 @@ */ package org.elasticsearch.snapshots; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionRunnable; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; @@ -684,8 +682,8 @@ public void testStartCloneDuringRunningDelete() throws Exception { for (SnapshotsInProgress.Entry entry : state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).forRepo(repoName)) { if (entry.shardsByRepoShardId().isEmpty() == false) { assertEquals(sourceSnapshot, entry.source().getName()); - for (ObjectCursor value : entry.shardsByRepoShardId().values()) { - assertSame(value.value, SnapshotsInProgress.ShardSnapshotStatus.UNASSIGNED_QUEUED); + for (SnapshotsInProgress.ShardSnapshotStatus value : entry.shardsByRepoShardId().values()) { + assertSame(value, SnapshotsInProgress.ShardSnapshotStatus.UNASSIGNED_QUEUED); } return true; } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java index 2b945950feaf8..af3c142935450 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/ConcurrentSnapshotsIT.java @@ -7,8 +7,6 @@ */ package org.elasticsearch.snapshots; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionFuture; @@ -1996,8 +1994,8 @@ private void createIndexWithContent(String indexName, String nodeInclude, String private static boolean snapshotHasCompletedShard(String repoName, String snapshot, SnapshotsInProgress snapshotsInProgress) { for (SnapshotsInProgress.Entry entry : snapshotsInProgress.forRepo(repoName)) { if (entry.snapshot().getSnapshotId().getName().equals(snapshot)) { - for (ObjectCursor shard : entry.shards().values()) { - if (shard.value.state().completed()) { + for (SnapshotsInProgress.ShardSnapshotStatus shard : entry.shards().values()) { + if (shard.state().completed()) { return true; } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java index 4edcaed358dc0..90672c003c112 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java @@ -8,7 +8,6 @@ package org.elasticsearch.action.admin.cluster.snapshots.status; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; @@ -127,9 +126,9 @@ protected void masterOperation( Set nodesIds = new HashSet<>(); for (SnapshotsInProgress.Entry entry : currentSnapshots) { - for (ObjectCursor status : entry.shardsByRepoShardId().values()) { - if (status.value.nodeId() != null) { - nodesIds.add(status.value.nodeId()); + for (SnapshotsInProgress.ShardSnapshotStatus status : entry.shardsByRepoShardId().values()) { + if (status.nodeId() != null) { + nodesIds.add(status.nodeId()); } } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java index 87c595690a543..afba42cd21e91 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/TransportIndicesAliasesAction.java @@ -8,7 +8,6 @@ package org.elasticsearch.action.admin.indices.alias; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; @@ -212,8 +211,8 @@ private static String[] concreteAliases(AliasActions action, Metadata metadata, String[] indexAsArray = {concreteIndex}; ImmutableOpenMap> aliasMetadata = metadata.findAliases(action, indexAsArray); List finalAliases = new ArrayList<>(); - for (ObjectCursor> curAliases : aliasMetadata.values()) { - for (AliasMetadata aliasMeta: curAliases.value) { + for (List aliases : aliasMetadata.values()) { + for (AliasMetadata aliasMeta : aliases) { finalAliases.add(aliasMeta.alias()); } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java index 180a72d9834c1..3b01afe80c4d2 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/template/get/TransportGetIndexTemplatesAction.java @@ -8,6 +8,7 @@ package org.elasticsearch.action.admin.indices.template.get; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; @@ -24,7 +25,6 @@ import org.elasticsearch.transport.TransportService; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class TransportGetIndexTemplatesAction extends @@ -50,7 +50,7 @@ protected void masterOperation(Task task, GetIndexTemplatesRequest request, Clus // If we did not ask for a specific name, then we return all templates if (request.names().length == 0) { - results = Arrays.asList(state.metadata().templates().values().toArray(IndexTemplateMetadata.class)); + results = new ArrayList<>(state.metadata().templates().values()); } else { results = new ArrayList<>(); } diff --git a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java index be4410b838271..7ed02ccd275f4 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java @@ -53,6 +53,6 @@ private DiscoveryNode randomIngestNode() { @Override public void applyClusterState(ClusterChangedEvent event) { - ingestNodes = event.state().getNodes().getIngestNodes().values().toArray(DiscoveryNode.class); + ingestNodes = event.state().getNodes().getIngestNodes().values().toArray(DiscoveryNode[]::new); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java b/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java index 6632e5703860a..7e2450de3fe87 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java @@ -10,6 +10,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.cluster.metadata.IndexGraveyard; import org.elasticsearch.cluster.metadata.IndexGraveyard.IndexGraveyardDiff; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -250,8 +251,7 @@ private List indicesDeletedFromClusterState() { final Metadata previousMetadata = previousState.metadata(); final Metadata currentMetadata = state.metadata(); - for (ObjectCursor cursor : previousMetadata.indices().values()) { - IndexMetadata index = cursor.value; + for (IndexMetadata index : previousMetadata.indices().values()) { IndexMetadata current = currentMetadata.index(index.getIndex()); if (current == null) { if (deleted == null) { diff --git a/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java b/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java index cc10503148a69..218219d570c6c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java +++ b/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java @@ -8,8 +8,8 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState.Custom; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -432,8 +432,7 @@ public RestoreInProgress(StreamInput in) throws IOException { @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(entries.size()); - for (ObjectCursor v : entries.values()) { - Entry entry = v.value; + for (Entry entry : entries.values()) { out.writeString(entry.uuid); entry.snapshot().writeTo(out); out.writeByte(entry.state().value()); @@ -445,8 +444,8 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startArray("snapshots"); - for (ObjectCursor entry : entries.values()) { - toXContent(entry.value, builder); + for (Entry entry : entries.values()) { + toXContent(entry, builder); } builder.endArray(); return builder; diff --git a/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java b/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java index 4974e3ee7d735..0eb189755dc18 100644 --- a/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java @@ -8,9 +8,8 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.ObjectContainer; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState.Custom; import org.elasticsearch.core.Nullable; @@ -272,9 +271,9 @@ public static Entry startClone(Snapshot snapshot, SnapshotId source, Map shards) { - for (ObjectCursor status : shards) { - if (status.value.state().completed == false) { + public static boolean completed(Collection shards) { + for (ShardSnapshotStatus status : shards) { + if (status.state().completed == false) { return false; } } @@ -282,8 +281,8 @@ public static boolean completed(ObjectContainer shards) { } private static boolean hasFailures(ImmutableOpenMap clones) { - for (ObjectCursor value : clones.values()) { - if (value.value.state().failed()) { + for (ShardSnapshotStatus value : clones.values()) { + if (value.state().failed()) { return true; } } diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java index c1a50aa75ff7b..74e2adabb87ac 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapMasterCommand.java @@ -7,8 +7,8 @@ */ package org.elasticsearch.cluster.coordination; -import com.carrotsearch.hppc.cursors.ObjectCursor; import joptsimple.OptionSet; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cli.Terminal; import org.elasticsearch.cluster.ClusterState; @@ -104,8 +104,7 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, OptionSet o .clusterUUIDCommitted(true) .persistentSettings(persistentSettings) .coordinationMetadata(newCoordinationMetadata); - for (ObjectCursor idx : metadata.indices().values()) { - IndexMetadata indexMetadata = idx.value; + for (IndexMetadata indexMetadata : metadata.indices().values()) { newMetadata.put(IndexMetadata.builder(indexMetadata).settings( Settings.builder().put(indexMetadata.getSettings()) .put(IndexMetadata.SETTING_HISTORY_UUID, UUIDs.randomBase64UUID()))); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java b/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java index 265f13deda13a..760be3cb40a69 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; @@ -98,8 +97,8 @@ public boolean expandToAllNodes() { private OptionalInt getDesiredNumberOfReplicas(IndexMetadata indexMetadata, RoutingAllocation allocation) { if (enabled) { int numMatchingDataNodes = 0; - for (ObjectCursor cursor : allocation.nodes().getDataNodes().values()) { - Decision decision = allocation.deciders().shouldAutoExpandToNode(indexMetadata, cursor.value, allocation); + for (DiscoveryNode discoveryNode : allocation.nodes().getDataNodes().values()) { + Decision decision = allocation.deciders().shouldAutoExpandToNode(indexMetadata, discoveryNode, allocation); if (decision.type() != Decision.Type.NO) { numMatchingDataNodes++; } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 3daef056f551f..b3b4fd4cd9710 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -911,12 +911,12 @@ public void writeTo(StreamOutput out) throws IOException { writeSettingsToStream(settings, out); out.writeVLongArray(primaryTerms); out.writeVInt(mappings.size()); - for (ObjectCursor cursor : mappings.values()) { - cursor.value.writeTo(out); + for (MappingMetadata mappingMetadata : mappings.values()) { + mappingMetadata.writeTo(out); } out.writeVInt(aliases.size()); - for (ObjectCursor cursor : aliases.values()) { - cursor.value.writeTo(out); + for (AliasMetadata aliasMetadata : aliases.values()) { + aliasMetadata.writeTo(out); } out.writeVInt(customData.size()); for (final ObjectObjectCursor cursor : customData) { @@ -929,8 +929,8 @@ public void writeTo(StreamOutput out) throws IOException { DiffableUtils.StringSetValueSerializer.getInstance().write(cursor.value, out); } out.writeVInt(rolloverInfos.size()); - for (ObjectCursor cursor : rolloverInfos.values()) { - cursor.value.writeTo(out); + for (RolloverInfo rolloverInfo : rolloverInfos.values()) { + rolloverInfo.writeTo(out); } if (out.getVersion().onOrAfter(SYSTEM_INDEX_FLAG_ADDED)) { out.writeBoolean(isSystem); @@ -1391,8 +1391,8 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build if (context != Metadata.XContentContext.API) { builder.startObject(KEY_ALIASES); - for (ObjectCursor cursor : indexMetadata.getAliases().values()) { - AliasMetadata.Builder.toXContent(cursor.value, builder, params); + for (AliasMetadata aliasMetadata : indexMetadata.getAliases().values()) { + AliasMetadata.Builder.toXContent(aliasMetadata, builder, params); } builder.endObject(); @@ -1427,8 +1427,8 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build builder.endObject(); builder.startObject(KEY_ROLLOVER_INFOS); - for (ObjectCursor cursor : indexMetadata.getRolloverInfos().values()) { - cursor.value.toXContent(builder, params); + for (RolloverInfo rolloverInfo : indexMetadata.getRolloverInfos().values()) { + rolloverInfo.toXContent(builder, params); } builder.endObject(); builder.field(KEY_SYSTEM, indexMetadata.isSystem); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index a8ee8afc7ec4e..03b994e25c529 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -49,11 +49,9 @@ import java.util.Objects; import java.util.Set; import java.util.SortedMap; -import java.util.Spliterators; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; public class IndexNameExpressionResolver { private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(IndexNameExpressionResolver.class); @@ -573,8 +571,7 @@ public String[] indexAliases(ClusterState state, String index, Predicate cursor.value) + aliasCandidates = indexAliases.values().stream() .filter(aliasMetadata -> resolvedExpressions.contains(aliasMetadata.alias())) .toArray(AliasMetadata[]::new); } else { diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java index ba4b26b5d7058..60a1473e97fe0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetadata.java @@ -7,8 +7,8 @@ */ package org.elasticsearch.cluster.metadata; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.Diff; @@ -213,8 +213,8 @@ public void writeTo(StreamOutput out) throws IOException { cursor.value.writeTo(out); } out.writeVInt(aliases.size()); - for (ObjectCursor cursor : aliases.values()) { - cursor.value.writeTo(out); + for (AliasMetadata aliasMetadata : aliases.values()) { + aliasMetadata.writeTo(out); } out.writeOptionalVInt(version); } @@ -402,8 +402,8 @@ private static void toInnerXContent(IndexTemplateMetadata indexTemplateMetadata, } builder.startObject("aliases"); - for (ObjectCursor cursor : indexTemplateMetadata.aliases().values()) { - AliasMetadata.Builder.toXContent(cursor.value, builder, params); + for (AliasMetadata aliasMetadata : indexTemplateMetadata.aliases().values()) { + AliasMetadata.Builder.toXContent(aliasMetadata, builder, params); } builder.endObject(); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java index cce12421ee6e0..b92a2fbb4538c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -27,16 +27,6 @@ import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.coordination.CoordinationMetadata; -import org.elasticsearch.common.xcontent.NamedObjectNotFoundException; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.ToXContentFragment; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentParserUtils; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.core.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.collect.HppcMaps; @@ -48,6 +38,16 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.NamedObjectNotFoundException; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentFragment; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentParserUtils; +import org.elasticsearch.core.Nullable; import org.elasticsearch.gateway.MetadataStateFormat; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; @@ -210,10 +210,10 @@ public interface NonRestorableCustom extends Custom { this.templates = templates; int totalNumberOfShards = 0; int totalOpenIndexShards = 0; - for (ObjectCursor cursor : indices.values()) { - totalNumberOfShards += cursor.value.getTotalNumberOfShards(); - if (IndexMetadata.State.OPEN.equals(cursor.value.getState())) { - totalOpenIndexShards += cursor.value.getTotalNumberOfShards(); + for (IndexMetadata indexMetadata : indices.values()) { + totalNumberOfShards += indexMetadata.getTotalNumberOfShards(); + if (IndexMetadata.State.OPEN.equals(indexMetadata.getState())) { + totalOpenIndexShards += indexMetadata.getTotalNumberOfShards(); } } this.totalNumberOfShards = totalNumberOfShards; @@ -277,8 +277,7 @@ public boolean hasAlias(String alias) { } public boolean equalsAliases(Metadata other) { - for (ObjectCursor cursor : other.indices().values()) { - IndexMetadata otherIndex = cursor.value; + for (IndexMetadata otherIndex : other.indices().values()) { IndexMetadata thisIndex = index(otherIndex.getIndex()); if (thisIndex == null) { return false; @@ -365,10 +364,9 @@ private ImmutableOpenMap> findAliases(final String[] for (String index : concreteIndices) { IndexMetadata indexMetadata = indices.get(index); List filteredValues = new ArrayList<>(); - for (ObjectCursor cursor : indexMetadata.getAliases().values()) { - AliasMetadata value = cursor.value; + for (AliasMetadata aliasMetadata : indexMetadata.getAliases().values()) { boolean matched = matchAllAliases; - String alias = value.alias(); + String alias = aliasMetadata.alias(); for (int i = 0; i < patterns.length; i++) { if (include[i]) { if (matched == false) { @@ -380,7 +378,7 @@ private ImmutableOpenMap> findAliases(final String[] } } if (matched) { - filteredValues.add(value); + filteredValues.add(aliasMetadata); } } if (filteredValues.isEmpty() == false) { @@ -831,8 +829,8 @@ public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2 } } int customCount2 = 0; - for (ObjectCursor cursor : metadata2.customs.values()) { - if (cursor.value.context().contains(XContentContext.GATEWAY)) { + for (Custom custom : metadata2.customs.values()) { + if (custom.context().contains(XContentContext.GATEWAY)) { customCount2++; } } @@ -1005,8 +1003,8 @@ public void writeTo(StreamOutput out) throws IOException { indexMetadata.writeTo(out); } out.writeVInt(templates.size()); - for (ObjectCursor cursor : templates.values()) { - cursor.value.writeTo(out); + for (IndexTemplateMetadata template : templates.values()) { + template.writeTo(out); } VersionedNamedWriteable.writeVersionedWritables(out, customs); } @@ -1668,8 +1666,8 @@ public static void toXContent(Metadata metadata, XContentBuilder builder, ToXCon } builder.startObject("templates"); - for (ObjectCursor cursor : metadata.templates().values()) { - IndexTemplateMetadata.Builder.toXContentWithTypes(cursor.value, builder, params); + for (IndexTemplateMetadata template : metadata.templates().values()) { + IndexTemplateMetadata.Builder.toXContentWithTypes(template, builder, params); } builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java index 2a80812b295b5..d6338c231c004 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java @@ -9,6 +9,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.CollectionUtil; @@ -888,8 +889,7 @@ public static List findV1Templates(Metadata metadata, Str .resolveExpression(indexName, new IndexNameExpressionResolver.Context(null, null, null)); final Predicate patternMatchPredicate = pattern -> Regex.simpleMatch(pattern, resolvedIndexName); final List matchedTemplates = new ArrayList<>(); - for (ObjectCursor cursor : metadata.templates().values()) { - final IndexTemplateMetadata template = cursor.value; + for (IndexTemplateMetadata template: metadata.templates().values()) { if (isHidden == null || isHidden == Boolean.FALSE) { final boolean matched = template.patterns().stream().anyMatch(patternMatchPredicate); if (matched) { diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index c6473f51522aa..373a296059d4b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -258,8 +258,7 @@ public DiscoveryNode getMasterNode() { * @return node identified by the given address or null if no such node exists */ public DiscoveryNode findByAddress(TransportAddress address) { - for (ObjectCursor cursor : nodes.values()) { - DiscoveryNode node = cursor.value; + for (DiscoveryNode node : nodes.values()) { if (node.getAddress().equals(address)) { return node; } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 56b405aea8c8e..965993955aeef 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -8,8 +8,6 @@ package org.elasticsearch.cluster.routing; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.Logger; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.Assertions; @@ -87,14 +85,14 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) { Map> nodesToShards = new HashMap<>(); // fill in the nodeToShards with the "live" nodes - for (ObjectCursor cursor : clusterState.nodes().getDataNodes().values()) { - nodesToShards.put(cursor.value.getId(), new LinkedHashMap<>()); // LinkedHashMap to preserve order + for (DiscoveryNode node : clusterState.nodes().getDataNodes().values()) { + nodesToShards.put(node.getId(), new LinkedHashMap<>()); // LinkedHashMap to preserve order } // fill in the inverse of node -> shards allocated // also fill replicaSet information - for (ObjectCursor indexRoutingTable : routingTable.indicesRouting().values()) { - for (IndexShardRoutingTable indexShard : indexRoutingTable.value) { + for (IndexRoutingTable indexRoutingTable : routingTable.indicesRouting().values()) { + for (IndexShardRoutingTable indexShard : indexRoutingTable) { assert indexShard.primary != null; for (ShardRouting shard : indexShard) { // to get all the shards belonging to an index, including the replicas, diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 36acc0ee4e4f6..8ea68ad3657db 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -9,8 +9,8 @@ package org.elasticsearch.cluster.routing; import com.carrotsearch.hppc.IntSet; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; import org.elasticsearch.cluster.DiffableUtils; @@ -343,8 +343,8 @@ public static RoutingTable readFrom(StreamInput in) throws IOException { public void writeTo(StreamOutput out) throws IOException { out.writeLong(version); out.writeVInt(indicesRouting.size()); - for (ObjectCursor index : indicesRouting.values()) { - index.value.writeTo(out); + for (IndexRoutingTable index : indicesRouting.values()) { + index.writeTo(out); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java index 468c3a670c6b7..34d234c1f9ff7 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.routing.allocation.decider; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; @@ -421,9 +420,9 @@ DiskUsage averageUsage(RoutingNode node, ImmutableOpenMap usa } long totalBytes = 0; long freeBytes = 0; - for (ObjectCursor du : usages.values()) { - totalBytes += du.value.getTotalBytes(); - freeBytes += du.value.getFreeBytes(); + for (DiskUsage du : usages.values()) { + totalBytes += du.getTotalBytes(); + freeBytes += du.getFreeBytes(); } return new DiskUsage(node.nodeId(), node.node().getName(), "_na_", totalBytes / usages.size(), freeBytes / usages.size()); } diff --git a/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java b/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java index 2f4720f619884..55e914d9216be 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java +++ b/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java @@ -20,8 +20,10 @@ import com.carrotsearch.hppc.predicates.ObjectPredicate; import com.carrotsearch.hppc.procedures.ObjectObjectProcedure; +import java.util.AbstractCollection; import java.util.AbstractMap; import java.util.AbstractSet; +import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -162,17 +164,27 @@ public boolean contains(Object o) { } /** - * @return Returns a container with all values stored in this map. + * Returns a direct iterator over the keys. */ - public ObjectContainer values() { - return map.values(); + public Iterator valuesIt() { + return iterator(map.values()); } /** - * Returns a direct iterator over the keys. + * Returns a {@link Collection} view of the values contained in the map. */ - public Iterator valuesIt() { - return iterator(map.values()); + public Collection values() { + return new AbstractCollection() { + @Override + public Iterator iterator() { + return valuesIt(); + } + + @Override + public int size() { + return map.size(); + } + }; } static Iterator iterator(ObjectCollection collection) { diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java index 9c263ab815ffe..1700a002a2f65 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/VersionedNamedWriteable.java @@ -8,7 +8,6 @@ package org.elasticsearch.common.io.stream; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.Version; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -54,15 +53,15 @@ static void writeVersionedWritables(StreamOu throws IOException { // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (final ObjectCursor cursor : customs.values()) { - if (shouldSerialize(out, cursor.value)) { + for (final T value : customs.values()) { + if (shouldSerialize(out, value)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (final ObjectCursor cursor : customs.values()) { - if (shouldSerialize(out, cursor.value)) { - out.writeNamedWriteable(cursor.value); + for (final T value : customs.values()) { + if (shouldSerialize(out, value)) { + out.writeNamedWriteable(value); } } } diff --git a/server/src/main/java/org/elasticsearch/discovery/PeerFinder.java b/server/src/main/java/org/elasticsearch/discovery/PeerFinder.java index c57f584c1a65e..d946c4241012a 100644 --- a/server/src/main/java/org/elasticsearch/discovery/PeerFinder.java +++ b/server/src/main/java/org/elasticsearch/discovery/PeerFinder.java @@ -8,7 +8,6 @@ package org.elasticsearch.discovery; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -243,8 +242,8 @@ private boolean handleWakeUp() { } logger.trace("probing master nodes from cluster state: {}", lastAcceptedNodes); - for (ObjectCursor discoveryNodeObjectCursor : lastAcceptedNodes.getMasterNodes().values()) { - startProbe(discoveryNodeObjectCursor.value.getAddress()); + for (DiscoveryNode discoveryNode : lastAcceptedNodes.getMasterNodes().values()) { + startProbe(discoveryNode.getAddress()); } configuredHostsResolver.resolveConfiguredHosts(providedAddresses -> { diff --git a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java index bfd3b2667b2b0..a982e9241da46 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java +++ b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java @@ -7,9 +7,11 @@ */ package org.elasticsearch.env; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import joptsimple.OptionParser; import joptsimple.OptionSet; + +import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cli.Terminal; import org.elasticsearch.cluster.ClusterState; @@ -31,7 +33,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.stream.StreamSupport; import static org.elasticsearch.env.NodeEnvironment.INDICES_FOLDER; @@ -93,8 +94,7 @@ private void processNoMasterNoDataNode(Terminal terminal, Path[] dataPaths, Envi } final Set indexUUIDs = Sets.union(indexUUIDsFor(indexPaths), - StreamSupport.stream(metadata.indices().values().spliterator(), false) - .map(imd -> imd.value.getIndexUUID()).collect(Collectors.toSet())); + metadata.indices().values().stream().map(IndexMetadata::getIndexUUID).collect(Collectors.toSet())); outputVerboseInformation(terminal, indexPaths, indexUUIDs, metadata); diff --git a/server/src/main/java/org/elasticsearch/gateway/ClusterStateUpdaters.java b/server/src/main/java/org/elasticsearch/gateway/ClusterStateUpdaters.java index 558053ca9dc31..604363a8d8ecd 100644 --- a/server/src/main/java/org/elasticsearch/gateway/ClusterStateUpdaters.java +++ b/server/src/main/java/org/elasticsearch/gateway/ClusterStateUpdaters.java @@ -8,7 +8,6 @@ package org.elasticsearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -82,8 +81,8 @@ static ClusterState recoverClusterBlocks(final ClusterState state) { static ClusterState updateRoutingTable(final ClusterState state) { // initialize all index routing tables as empty final RoutingTable.Builder routingTableBuilder = RoutingTable.builder(state.routingTable()); - for (final ObjectCursor cursor : state.metadata().indices().values()) { - routingTableBuilder.addAsRecovery(cursor.value); + for (final IndexMetadata indexMetadata : state.metadata().indices().values()) { + routingTableBuilder.addAsRecovery(indexMetadata); } // start with 0 based versions for routing table routingTableBuilder.version(0); diff --git a/server/src/main/java/org/elasticsearch/gateway/DanglingIndicesState.java b/server/src/main/java/org/elasticsearch/gateway/DanglingIndicesState.java index 9d31d78fedc21..ffa8f6d84947e 100644 --- a/server/src/main/java/org/elasticsearch/gateway/DanglingIndicesState.java +++ b/server/src/main/java/org/elasticsearch/gateway/DanglingIndicesState.java @@ -8,7 +8,6 @@ package org.elasticsearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.metadata.IndexGraveyard; @@ -54,8 +53,8 @@ public Map getDanglingIndices() { final Set excludeIndexPathIds = new HashSet<>(metadata.indices().size()); - for (ObjectCursor cursor : metadata.indices().values()) { - excludeIndexPathIds.add(cursor.value.getIndex().getUUID()); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + excludeIndexPathIds.add(indexMetadata.getIndex().getUUID()); } try { diff --git a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java index 1b19151c57546..cff89ca920ee3 100644 --- a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java +++ b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java @@ -7,8 +7,6 @@ */ package org.elasticsearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -673,8 +671,7 @@ private WriterStats updateMetadata(Metadata previouslyWrittenMetadata, Metadata } final Map indexMetadataVersionByUUID = new HashMap<>(previouslyWrittenMetadata.indices().size()); - for (ObjectCursor cursor : previouslyWrittenMetadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (IndexMetadata indexMetadata : previouslyWrittenMetadata.indices().values()) { final Long previousValue = indexMetadataVersionByUUID.putIfAbsent(indexMetadata.getIndexUUID(), indexMetadata.getVersion()); assert previousValue == null : indexMetadata.getIndexUUID() + " already mapped to " + previousValue; @@ -682,8 +679,7 @@ private WriterStats updateMetadata(Metadata previouslyWrittenMetadata, Metadata int numIndicesUpdated = 0; int numIndicesUnchanged = 0; - for (ObjectCursor cursor : metadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (IndexMetadata indexMetadata : metadata.indices().values()) { final Long previousVersion = indexMetadataVersionByUUID.get(indexMetadata.getIndexUUID()); if (previousVersion == null || indexMetadata.getVersion() != previousVersion) { logger.trace("updating metadata for [{}], changing version from [{}] to [{}]", @@ -739,8 +735,7 @@ private WriterStats addMetadata(Metadata metadata) throws IOException { metadataIndexWriter.updateGlobalMetadata(globalMetadataDocument); } - for (ObjectCursor cursor : metadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (IndexMetadata indexMetadata : metadata.indices().values()) { final Document indexMetadataDocument = makeIndexMetadataDocument(indexMetadata, documentBuffer); for (MetadataIndexWriter metadataIndexWriter : metadataIndexWriters) { metadataIndexWriter.updateIndexMetadataDocument(indexMetadataDocument, indexMetadata.getIndex()); diff --git a/server/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java b/server/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java index 43adcf9ef70e1..6eb1e25078731 100644 --- a/server/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java +++ b/server/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java @@ -8,8 +8,6 @@ package org.elasticsearch.gateway; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; @@ -240,8 +238,8 @@ public static Tuple> canBeAllocatedT Decision madeDecision = Decision.NO; final boolean explain = allocation.debugDecision(); Map nodeDecisions = explain ? new HashMap<>() : null; - for (ObjectCursor cursor : allocation.nodes().getDataNodes().values()) { - RoutingNode node = allocation.routingNodes().node(cursor.value.getId()); + for (DiscoveryNode discoveryNode : allocation.nodes().getDataNodes().values()) { + RoutingNode node = allocation.routingNodes().node(discoveryNode.getId()); if (node == null) { continue; } diff --git a/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java b/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java index 75a292790b1cf..d5381f1a1b0c1 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java +++ b/server/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java @@ -8,8 +8,8 @@ package org.elasticsearch.index.engine; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.Version; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -228,8 +228,8 @@ public void writeTo(StreamOutput out) throws IOException { out.writeLong(maxUnsafeAutoIdTimestamp); out.writeVInt(files.size()); - for (ObjectCursor file : files.values()) { - file.value.writeTo(out); + for (FileStats file : files.values()) { + file.writeTo(out); } } diff --git a/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java b/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java index b3e537cb34e08..7fb4741cdc396 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java +++ b/server/src/main/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommand.java @@ -57,7 +57,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; -import java.util.stream.StreamSupport; import static org.elasticsearch.common.lucene.Lucene.indexWriterConfigWithNoMerging; @@ -131,9 +130,9 @@ protected void findAndProcessShardPath(OptionSet options, Environment environmen && NodeEnvironment.INDICES_FOLDER.equals(shardParentParent.getFileName().toString()) // `indices` check ) { shardId = Integer.parseInt(shardIdFileName); - indexMetadata = StreamSupport.stream(clusterState.metadata().indices().values().spliterator(), false) - .map(imd -> imd.value) - .filter(imd -> imd.getIndexUUID().equals(indexUUIDFolderName)).findFirst() + indexMetadata = clusterState.metadata().indices().values().stream() + .filter(imd -> imd.getIndexUUID().equals(indexUUIDFolderName)) + .findFirst() .orElse(null); } else { throw new ElasticsearchException("Unable to resolve shard id. Wrong folder structure at [ " + path.toString() diff --git a/server/src/main/java/org/elasticsearch/indices/ShardLimitValidator.java b/server/src/main/java/org/elasticsearch/indices/ShardLimitValidator.java index fc874861e129a..fc37bb3983d53 100644 --- a/server/src/main/java/org/elasticsearch/indices/ShardLimitValidator.java +++ b/server/src/main/java/org/elasticsearch/indices/ShardLimitValidator.java @@ -22,7 +22,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; -import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; @@ -193,7 +192,7 @@ static Optional checkShardLimit(int newShards, ClusterState state, int m if ((currentOpenShards + newShards) > maxShardsInCluster) { Predicate indexMetadataPredicate = imd -> imd.getState().equals(IndexMetadata.State.OPEN) && group.equals(INDEX_SETTING_SHARD_LIMIT_GROUP.get(imd.getSettings())); - long currentFilteredShards = StreamSupport.stream(state.metadata().indices().values().spliterator(), false).map(oc -> oc.value) + long currentFilteredShards = state.metadata().indices().values().stream() .filter(indexMetadataPredicate).mapToInt(IndexMetadata::getTotalNumberOfShards).sum(); if ((currentFilteredShards + newShards) > maxShardsInCluster) { String errorMessage = "this action would add [" + newShards + "] shards, but this cluster currently has [" + @@ -205,9 +204,7 @@ static Optional checkShardLimit(int newShards, ClusterState state, int m } private static int nodeCount(ClusterState state, Predicate nodePredicate) { - return (int) - StreamSupport.stream(state.getNodes().getDataNodes().values().spliterator(), false) - .map(oc -> oc.value).filter(nodePredicate).count(); + return (int) state.getNodes().getDataNodes().values().stream().filter(nodePredicate).count(); } private static boolean hasFrozen(DiscoveryNode node) { diff --git a/server/src/main/java/org/elasticsearch/indices/TimestampFieldMapperService.java b/server/src/main/java/org/elasticsearch/indices/TimestampFieldMapperService.java index 531a2877ca6eb..080eb51c0eeab 100644 --- a/server/src/main/java/org/elasticsearch/indices/TimestampFieldMapperService.java +++ b/server/src/main/java/org/elasticsearch/indices/TimestampFieldMapperService.java @@ -8,7 +8,6 @@ package org.elasticsearch.indices; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -89,8 +88,7 @@ public void applyClusterState(ClusterChangedEvent event) { fieldTypesByIndex.keySet().removeIf(index -> hasUsefulTimestampField(metadata.index(index)) == false); // capture mappers for indices that do exist - for (ObjectCursor cursor : metadata.indices().values()) { - final IndexMetadata indexMetadata = cursor.value; + for (IndexMetadata indexMetadata : metadata.indices().values()) { final Index index = indexMetadata.getIndex(); if (hasUsefulTimestampField(indexMetadata) && fieldTypesByIndex.containsKey(index) == false) { diff --git a/server/src/main/java/org/elasticsearch/repositories/VerifyNodeRepositoryAction.java b/server/src/main/java/org/elasticsearch/repositories/VerifyNodeRepositoryAction.java index 259e208af5f75..d6db8d078ff31 100644 --- a/server/src/main/java/org/elasticsearch/repositories/VerifyNodeRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/repositories/VerifyNodeRepositoryAction.java @@ -8,9 +8,6 @@ package org.elasticsearch.repositories; -import com.carrotsearch.hppc.ObjectContainer; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -32,6 +29,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicInteger; @@ -68,10 +66,9 @@ public void verify(String repository, String verificationToken, final ActionList final DiscoveryNodes discoNodes = clusterService.state().nodes(); final DiscoveryNode localNode = discoNodes.getLocalNode(); - final ObjectContainer masterAndDataNodes = discoNodes.getMasterAndDataNodes().values(); + final Collection masterAndDataNodes = discoNodes.getMasterAndDataNodes().values(); final List nodes = new ArrayList<>(); - for (ObjectCursor cursor : masterAndDataNodes) { - DiscoveryNode node = cursor.value; + for (DiscoveryNode node : masterAndDataNodes) { if (RepositoriesService.isDedicatedVotingOnlyNode(node.getRoles()) == false) { nodes.add(node); } diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index f8514a50bdd74..192ab027ba814 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -827,11 +827,11 @@ private static RestoreInProgress.State overallState( ImmutableOpenMap shards ) { boolean hasFailed = false; - for (ObjectCursor status : shards.values()) { - if (status.value.state().completed() == false) { + for (RestoreInProgress.ShardRestoreStatus status : shards.values()) { + if (status.state().completed() == false) { return nonCompletedState; } - if (status.value.state() == RestoreInProgress.State.FAILURE) { + if (status.state() == RestoreInProgress.State.FAILURE) { hasFailed = true; } } @@ -843,8 +843,8 @@ private static RestoreInProgress.State overallState( } public static boolean completed(ImmutableOpenMap shards) { - for (ObjectCursor status : shards.values()) { - if (status.value.state().completed() == false) { + for (RestoreInProgress.ShardRestoreStatus status : shards.values()) { + if (status.state().completed() == false) { return false; } } @@ -853,8 +853,8 @@ public static boolean completed(ImmutableOpenMap shards) { int failedShards = 0; - for (ObjectCursor status : shards.values()) { - if (status.value.state() == RestoreInProgress.State.FAILURE) { + for (RestoreInProgress.ShardRestoreStatus status : shards.values()) { + if (status.state() == RestoreInProgress.State.FAILURE) { failedShards++; } } @@ -1266,8 +1266,8 @@ && isSystemIndex(snapshotIndexMetadata) == false) { indexMdBuilder.removeAllAliases(); } // Add existing aliases - for (ObjectCursor alias : currentIndexMetadata.getAliases().values()) { - indexMdBuilder.putAlias(alias.value); + for (AliasMetadata alias : currentIndexMetadata.getAliases().values()) { + indexMdBuilder.putAlias(alias); } } else { ensureNoAliasNameConflicts(snapshotIndexMetadata); @@ -1402,8 +1402,8 @@ private void applyGlobalStateRestore(ClusterState currentState, Metadata.Builder } if (metadata.templates() != null) { // TODO: Should all existing templates be deleted first? - for (ObjectCursor cursor : metadata.templates().values()) { - mdBuilder.put(cursor.value); + for (IndexTemplateMetadata cursor : metadata.templates().values()) { + mdBuilder.put(cursor); } } if (metadata.customs() != null) { diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 42e2a446cf2f0..0833f60e39dec 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -8,7 +8,6 @@ package org.elasticsearch.snapshots; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.logging.log4j.LogManager; @@ -1016,11 +1015,11 @@ private static boolean assertNoDanglingSnapshots(ClusterState state) { .collect(Collectors.toSet()); for (List repoEntry : snapshotsInProgress.entriesByRepo()) { final SnapshotsInProgress.Entry entry = repoEntry.get(0); - for (ObjectCursor value : entry.shardsByRepoShardId().values()) { - if (value.value.equals(ShardSnapshotStatus.UNASSIGNED_QUEUED)) { + for (ShardSnapshotStatus value : entry.shardsByRepoShardId().values()) { + if (value.equals(ShardSnapshotStatus.UNASSIGNED_QUEUED)) { assert reposWithRunningDelete.contains(entry.repository()) : "Found shard snapshot waiting to be assigned in [" + entry + "] but it is not blocked by any running delete"; - } else if (value.value.isActive()) { + } else if (value.isActive()) { assert reposWithRunningDelete.contains(entry.repository()) == false : "Found shard snapshot actively executing in [" + entry @@ -1380,8 +1379,7 @@ private static boolean removedNodesCleanupNeeded(SnapshotsInProgress snapshotsIn // nothing to do for already completed snapshots or clones that run on master anyways return false; } - for (ObjectCursor shardStatus : snapshot.shardsByRepoShardId().values()) { - final ShardSnapshotStatus shardSnapshotStatus = shardStatus.value; + for (ShardSnapshotStatus shardSnapshotStatus : snapshot.shardsByRepoShardId().values()) { if (shardSnapshotStatus.state().completed() == false && removedNodeIds.contains(shardSnapshotStatus.nodeId())) { // Snapshot had an incomplete shard running on a removed node so we need to adjust that shard's snapshot status return true; @@ -2248,8 +2246,8 @@ private static boolean isWritingToRepository(SnapshotsInProgress.Entry entry) { // Entry is writing to the repo because it's finalizing on master return true; } - for (ObjectCursor value : entry.shardsByRepoShardId().values()) { - if (value.value.isActive()) { + for (ShardSnapshotStatus value : entry.shardsByRepoShardId().values()) { + if (value.isActive()) { // Entry is writing to the repo because it's writing to a shard on a data node or waiting to do so for a concrete shard return true; } diff --git a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java index adfbe8b0d1061..0623b6df0c23d 100644 --- a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java @@ -311,7 +311,7 @@ private static class DataNodesOnlyTransportNodesAction @Override protected void resolveRequest(TestNodesRequest request, ClusterState clusterState) { - request.setConcreteNodes(clusterState.nodes().getDataNodes().values().toArray(DiscoveryNode.class)); + request.setConcreteNodes(clusterState.nodes().getDataNodes().values().toArray(DiscoveryNode[]::new)); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java index 5bb61e5f29058..234a3f8f96e07 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java @@ -8,8 +8,8 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.elasticsearch.Version; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.IndexGraveyard; @@ -31,7 +31,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -479,8 +478,8 @@ private static IndexMetadata createIndexMetadata(final Index index, final long v // Create the routing table for a cluster state. private static RoutingTable createRoutingTable(final long version, final Metadata metadata) { final RoutingTable.Builder builder = RoutingTable.builder().version(version); - for (ObjectCursor cursor : metadata.indices().values()) { - builder.addAsNew(cursor.value); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + builder.addAsNew(indexMetadata); } return builder.build(); } @@ -509,8 +508,8 @@ private static ClusterState executeIndicesChangesTest(final ClusterState previou final TombstoneDeletionQuantity deletionQuantity) { final int numAdd = randomIntBetween(0, 5); // add random # of indices to the next cluster state final List stateIndices = new ArrayList<>(); - for (Iterator iter = previousState.metadata().indices().valuesIt(); iter.hasNext();) { - stateIndices.add(iter.next().getIndex()); + for (IndexMetadata indexMetadata : previousState.metadata().indices().values()) { + stateIndices.add(indexMetadata.getIndex()); } final int numDel; switch (deletionQuantity) { diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 813035b5f629b..5386b478305a9 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -39,7 +39,7 @@ public class DiscoveryNodesTests extends ESTestCase { public void testResolveNodeByIdOrName() { DiscoveryNodes discoveryNodes = buildDiscoveryNodes(); - DiscoveryNode[] nodes = discoveryNodes.getNodes().values().toArray(DiscoveryNode.class); + DiscoveryNode[] nodes = discoveryNodes.getNodes().values().toArray(DiscoveryNode[]::new); DiscoveryNode node = randomFrom(nodes); DiscoveryNode resolvedNode = discoveryNodes.resolveNode(randomBoolean() ? node.getId() : node.getName()); assertThat(resolvedNode.getId(), equalTo(node.getId())); @@ -83,8 +83,7 @@ public void testAll() { assertThat(discoveryNodes.resolveNodes("_all"), arrayContainingInAnyOrder(allNodes)); final String[] nonMasterNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(n -> n.isMasterNode() == false) .map(DiscoveryNode::getId) .toArray(String[]::new); @@ -97,15 +96,13 @@ public void testCoordinatorOnlyNodes() { final DiscoveryNodes discoveryNodes = buildDiscoveryNodes(); final String[] coordinatorOnlyNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(n -> n.canContainData() == false && n.isIngestNode() == false && n.isMasterNode() == false) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] nonCoordinatorOnlyNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(n -> n.isMasterNode() || n.canContainData() || n.isIngestNode()) .map(DiscoveryNode::getId) .toArray(String[]::new); @@ -136,7 +133,7 @@ public void testResolveNodesIds() { expectedNodeIdsSet.add(nodeId); } int numNodeNames = randomIntBetween(0, 3); - DiscoveryNode[] nodes = discoveryNodes.getNodes().values().toArray(DiscoveryNode.class); + DiscoveryNode[] nodes = discoveryNodes.getNodes().values().toArray(DiscoveryNode[]::new); for (int i = 0; i < numNodeNames; i++) { DiscoveryNode discoveryNode = randomFrom(nodes); nodeSelectors.add(discoveryNode.getName()); @@ -330,24 +327,18 @@ Set matchingNodeIds(DiscoveryNodes nodes) { }, CUSTOM_ATTRIBUTE("attr:value") { @Override Set matchingNodeIds(DiscoveryNodes nodes) { - Set ids = new HashSet<>(); - nodes.getNodes().valuesIt().forEachRemaining(node -> { - if ("value".equals(node.getAttributes().get("attr"))) { - ids.add(node.getId()); - } - }); - return ids; + return nodes.getNodes().values().stream() + .filter(node -> "value".equals(node.getAttributes().get("attr"))) + .map(DiscoveryNode::getId) + .collect(Collectors.toSet()); } }, CUSTOM_ROLE("custom_role:true") { @Override Set matchingNodeIds(DiscoveryNodes nodes) { - Set ids = new HashSet<>(); - nodes.getNodes().valuesIt().forEachRemaining(node -> { - if (node.getRoles().stream().anyMatch(role -> role.roleName().equals("custom_role"))) { - ids.add(node.getId()); - } - }); - return ids; + return nodes.getNodes().values().stream() + .filter(node->node.getRoles().stream().anyMatch(role -> role.roleName().equals("custom_role"))) + .map(DiscoveryNode::getId) + .collect(Collectors.toSet()); } }; diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java index e1cbbe591bc0f..0252c286d5369 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java @@ -260,8 +260,8 @@ private ClusterState initCluster(AllocationService service, int numberOfNodes, i Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + routingTableBuilder.addAsNew(indexMetadata); } RoutingTable initialRoutingTable = routingTableBuilder.build(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java index fc7f3798c4a56..a82749ca53432 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java @@ -116,8 +116,8 @@ private ClusterState initCluster(AllocationService strategy) { Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + routingTableBuilder.addAsNew(indexMetadata); } RoutingTable initialRoutingTable = routingTableBuilder.build(); @@ -344,8 +344,8 @@ public ShardAllocationDecision decideShardAllocation(ShardRouting shard, Routing .settings(settings(Version.CURRENT)).numberOfShards(5).numberOfReplicas(1); metadataBuilder = metadataBuilder.put(indexMeta); Metadata metadata = metadataBuilder.build(); - for (ObjectCursor cursor : metadata.indices().values()) { - routingTableBuilder.addAsNew(cursor.value); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + routingTableBuilder.addAsNew(indexMetadata); } RoutingTable routingTable = routingTableBuilder.build(); DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java index 597dc5667886f..14bdfb857b7f2 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.routing.allocation; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; @@ -121,9 +120,9 @@ public void testRandomClusterPromotesNewestReplica() throws InterruptedException } // Log the node versions (for debugging if necessary) - for (ObjectCursor cursor : state.nodes().getDataNodes().values()) { - Version nodeVer = cursor.value.getVersion(); - logger.info("--> node [{}] has version [{}]", cursor.value.getId(), nodeVer); + for (DiscoveryNode discoveryNode : state.nodes().getDataNodes().values()) { + Version nodeVer = discoveryNode.getVersion(); + logger.info("--> node [{}] has version [{}]", discoveryNode.getId(), nodeVer); } // randomly create some indices diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java index 4b34a0e924d6f..2cdb8482d045f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.routing.allocation; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; @@ -642,13 +641,13 @@ public void testReplicaOnNewestVersionIsPromoted() { assertNotNull(replicaNodeVersion); logger.info("--> shard {} got assigned to node with version {}", startedReplica, replicaNodeVersion); - for (ObjectCursor cursor : clusterState.nodes().getDataNodes().values()) { - if ("node1".equals(cursor.value.getId())) { + for (DiscoveryNode discoveryNode : clusterState.nodes().getDataNodes().values()) { + if ("node1".equals(discoveryNode.getId())) { // Skip the node that the primary was on, it doesn't have a replica so doesn't need a version check continue; } - Version nodeVer = cursor.value.getVersion(); - assertTrue("expected node [" + cursor.value.getId() + "] with version " + nodeVer + Version nodeVer = discoveryNode.getVersion(); + assertTrue("expected node [" + discoveryNode.getId() + "] with version " + nodeVer + " to be before " + replicaNodeVersion, replicaNodeVersion.onOrAfter(nodeVer)); } @@ -671,14 +670,14 @@ public void testReplicaOnNewestVersionIsPromoted() { assertNotNull(replicaNodeVersion); logger.info("--> shard {} got assigned to node with version {}", startedReplica, replicaNodeVersion); - for (ObjectCursor cursor : clusterState.nodes().getDataNodes().values()) { - if (primaryShardToFail.currentNodeId().equals(cursor.value.getId()) || - secondPrimaryShardToFail.currentNodeId().equals(cursor.value.getId())) { + for (DiscoveryNode discoveryNode : clusterState.nodes().getDataNodes().values()) { + if (primaryShardToFail.currentNodeId().equals(discoveryNode.getId()) || + secondPrimaryShardToFail.currentNodeId().equals(discoveryNode.getId())) { // Skip the node that the primary was on, it doesn't have a replica so doesn't need a version check continue; } - Version nodeVer = cursor.value.getVersion(); - assertTrue("expected node [" + cursor.value.getId() + "] with version " + Version nodeVer = discoveryNode.getVersion(); + assertTrue("expected node [" + discoveryNode.getId() + "] with version " + nodeVer + " to be before " + replicaNodeVersion, replicaNodeVersion.onOrAfter(nodeVer)); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java index fb7933bc79c0f..1abc6bbcd3698 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -9,7 +9,7 @@ package org.elasticsearch.cluster.routing.allocation; import com.carrotsearch.hppc.IntHashSet; -import com.carrotsearch.hppc.cursors.ObjectCursor; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; @@ -338,9 +338,9 @@ private ClusterState createRecoveryStateAndInitializeAllocations( Snapshot snapshot = new Snapshot("repo", new SnapshotId("snap", "randomId")); Set snapshotIndices = new HashSet<>(); String restoreUUID = UUIDs.randomBase64UUID(); - for (ObjectCursor cursor: metadata.indices().values()) { - Index index = cursor.value.getIndex(); - IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(cursor.value); + for (IndexMetadata im : metadata.indices().values()) { + Index index = im.getIndex(); + IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(im); final int recoveryType = randomInt(5); if (recoveryType <= 4) { addInSyncAllocationIds(index, indexMetadataBuilder, gatewayAllocator, node1); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java index 3e35b69abedfc..a1b3d4f1e91fc 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationShortCircuitTests.java @@ -98,7 +98,7 @@ public void testRebalancingSkippedIfDisabled() { public void testRebalancingSkippedIfDisabledIncludingOnSpecificIndices() { ClusterState clusterState = createClusterStateWithAllShardsAssigned(); - final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(IndexMetadata.class)); + final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(IndexMetadata[]::new)); clusterState = ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()) .put(IndexMetadata.builder(indexMetadata).settings(Settings.builder().put(indexMetadata.getSettings()) .put(INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), EnableAllocationDecider.Rebalance.NONE.name()))).build()).build(); @@ -113,7 +113,7 @@ public void testRebalancingSkippedIfDisabledIncludingOnSpecificIndices() { public void testRebalancingAttemptedIfDisabledButOverridenOnSpecificIndices() { ClusterState clusterState = createClusterStateWithAllShardsAssigned(); - final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values().toArray(IndexMetadata.class)); + final IndexMetadata indexMetadata = randomFrom(clusterState.metadata().indices().values()); clusterState = ClusterState.builder(clusterState).metadata(Metadata.builder(clusterState.metadata()) .put(IndexMetadata.builder(indexMetadata).settings(Settings.builder().put(indexMetadata.getSettings()) .put(INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), diff --git a/server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java b/server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java index 1480bb0ddf902..034d5c18feaff 100644 --- a/server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java +++ b/server/src/test/java/org/elasticsearch/common/collect/ImmutableOpenMapTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.test.ESTestCase; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,8 +23,12 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Predicate; import java.util.stream.Collectors; +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; public class ImmutableOpenMapTests extends ESTestCase { @@ -36,9 +41,17 @@ public class ImmutableOpenMapTests extends ESTestCase { .fPut("Korea", "₩") .build(); + ImmutableOpenMap countryPopulations = ImmutableOpenMap.builder() + .fPut("Poland", 37_846_611) + .fPut("France", 65_273_511) + .fPut("Spain", 46_754_778) + .fPut("Germany", 83_783_942) + .fPut("Italy", 60_461_826) + .build(); + public void testStreamOperationsAreSupported() { assertThat(regionCurrencySymbols.stream().filter(e -> e.getKey().startsWith("U")).map(Map.Entry::getValue) - .collect(Collectors.toSet()), equalTo(Set.of("£", "$"))); + .collect(Collectors.toSet()), equalTo(Set.of("£", "$"))); } public void testSortedStream() { @@ -120,6 +133,56 @@ public void testEmptyKeySetWorks() { assertThat(ImmutableOpenMap.of().keySet().size(), equalTo(0)); } + public void testEmptyValuesIsCollection() { + assertThat(ImmutableOpenMap.of().values(), empty()); + } + + public void testValuesIsCollection() { + assertThat(countryPopulations.values(), containsInAnyOrder(37_846_611, 46_754_778, 60_461_826, 65_273_511, 83_783_942)); + } + + public void testValuesToArray() { + Integer[] populations = countryPopulations.values().toArray(Integer[]::new); + + assertThat(populations, arrayContainingInAnyOrder(37_846_611, 46_754_778, 60_461_826, 65_273_511, 83_783_942)); + } + + public void testStreamOperationOnValues() { + assertThat(countryPopulations.values().stream() + .filter(e -> e > 60_000_000) + .sorted(Comparator.reverseOrder()) + .limit(2).collect(Collectors.toList()), + equalTo(List.of(83_783_942, 65_273_511))); + } + + public void testStreamOperationsOnRandomMapValues() { + ImmutableOpenMap map = randomImmutableOpenMap(); + + int limit = randomIntBetween(0, map.size()); + List collectedViaStream = map.values() + .stream() + .filter(Predicate.not(e -> e.contains("ab") || e.contains("cd") || e.contains("ef"))) + .sorted() + .limit(limit) + .collect(Collectors.toList()); + + SortedSet filteredSortedStrings = new TreeSet<>(); + for (ObjectObjectCursor cursor : map) { + if ((cursor.value.contains("ab") || cursor.value.contains("cd") || cursor.value.contains("ef")) == false) { + filteredSortedStrings.add(cursor.value); + } + } + int i = 0; + List collectedIteratively = new ArrayList<>(); + for (String s : filteredSortedStrings) { + if (i++ >= limit) { + break; + } + collectedIteratively.add(s); + } + assertThat(collectedViaStream, equalTo(collectedIteratively)); + } + private static ImmutableOpenMap randomImmutableOpenMap() { return Randomness.get().longs(randomIntBetween(1, 1000)) .mapToObj(e -> Tuple.tuple(e, randomAlphaOfLength(8))) diff --git a/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java b/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java index 94639adbd27c1..722383adad858 100644 --- a/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java @@ -26,11 +26,9 @@ import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; -import java.util.Arrays; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.metadata.MetadataIndexStateServiceTests.addClosedIndex; import static org.elasticsearch.cluster.metadata.MetadataIndexStateServiceTests.addOpenedIndex; @@ -116,7 +114,7 @@ public void testValidateShardLimitUpdateReplicas() { } public Index[] getIndices(ClusterState state) { - return Arrays.stream(state.metadata().indices().values().toArray(IndexMetadata.class)) + return state.metadata().indices().values().stream() .map(IndexMetadata::getIndex) .collect(Collectors.toList()) .toArray(Index.EMPTY_ARRAY); @@ -201,8 +199,8 @@ private static DiscoveryNode createNode(String group) { } private static Metadata.Builder freezeMetadata(Metadata.Builder builder, Metadata metadata) { - StreamSupport.stream(metadata.indices().values().spliterator(), false) - .map(oc -> oc.value).map(imd -> IndexMetadata.builder(imd).settings(Settings.builder().put(imd.getSettings()) + metadata.indices().values().stream() + .map(imd -> IndexMetadata.builder(imd).settings(Settings.builder().put(imd.getSettings()) .put(ShardLimitValidator.INDEX_SETTING_SHARD_LIMIT_GROUP.getKey(), ShardLimitValidator.FROZEN_GROUP))) .forEach(builder::put); return builder; diff --git a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index b2d7ba31da13a..14628086b0910 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -441,7 +441,7 @@ public ClusterState randomlyUpdateClusterState(ClusterState state, } else { // remove node if (state.nodes().getDataNodes().size() > 3) { - DiscoveryNode discoveryNode = randomFrom(state.nodes().getNodes().values().toArray(DiscoveryNode.class)); + DiscoveryNode discoveryNode = randomFrom(state.nodes().getNodes().values()); if (discoveryNode.equals(state.nodes().getMasterNode()) == false) { state = cluster.removeNodes(state, Collections.singletonList(discoveryNode)); updateNodes(state, clusterStateServiceMap, indicesServiceSupplier); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java index 51d6305b6db72..11addd6a847cf 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java @@ -274,9 +274,7 @@ public void testMoveToEmpty() { } private Set allIndices() { - return StreamSupport.stream(state.metadata().getIndices().values().spliterator(), false) - .map(cursor -> cursor.value) - .collect(Collectors.toSet()); + return new HashSet<>(state.metadata().getIndices().values()); } private ClusterState moveToCold(Set candidates) { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index 1ef59857e7cc9..188c444f80794 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -6,8 +6,6 @@ */ package org.elasticsearch.xpack.ccr.action; -import com.carrotsearch.hppc.predicates.ObjectPredicate; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -51,7 +49,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -700,9 +697,9 @@ static Function cleanFollowedRemoteIndices( AutoFollowMetadata currentAutoFollowMetadata = currentState.metadata().custom(AutoFollowMetadata.TYPE); Map> autoFollowPatternNameToFollowedIndexUUIDs = new HashMap<>(currentAutoFollowMetadata.getFollowedLeaderIndexUUIDs()); - Set remoteIndexUUIDS = new HashSet<>(); - remoteMetadata.getIndices().values() - .forEach((ObjectPredicate) value -> remoteIndexUUIDS.add(value.getIndexUUID())); + Set remoteIndexUUIDS = remoteMetadata.getIndices().values().stream() + .map(IndexMetadata::getIndexUUID) + .collect(Collectors.toSet()); boolean requiresCSUpdate = false; for (String autoFollowPatternName : autoFollowPatternNames) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java index 6ff489bad3626..648e7b44c86e3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java @@ -7,8 +7,6 @@ package org.elasticsearch.xpack.cluster.routing.allocation; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; @@ -201,8 +199,8 @@ public static String[] parseTierList(String tiers) { static boolean tierNodesPresent(String singleTier, DiscoveryNodes nodes) { assert singleTier.equals(DiscoveryNodeRole.DATA_ROLE.roleName()) || DataTier.validTierName(singleTier) : "tier " + singleTier + " is an invalid tier name"; - for (ObjectCursor node : nodes.getNodes().values()) { - for (DiscoveryNodeRole discoveryNodeRole : node.value.getRoles()) { + for (DiscoveryNode node : nodes.getNodes().values()) { + for (DiscoveryNodeRole discoveryNodeRole : node.getRoles()) { String s = discoveryNodeRole.roleName(); if (s.equals(DiscoveryNodeRole.DATA_ROLE.roleName()) || s.equals(singleTier)) { return true; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java index 02bd034c6bf9a..3070dfa719b04 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java @@ -29,7 +29,6 @@ import java.io.InputStream; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; /** * A utility class used for index lifecycle policies @@ -92,8 +91,7 @@ private static void validate(BytesReference source) { */ public static ItemUsage calculateUsage(final IndexNameExpressionResolver indexNameExpressionResolver, final ClusterState state, final String policyName) { - final List indices = StreamSupport.stream(state.metadata().indices().values().spliterator(), false) - .map(cursor -> cursor.value) + final List indices = state.metadata().indices().values().stream() .filter(indexMetadata -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()))) .map(indexMetadata -> indexMetadata.getIndex().getName()) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java index bc45d73acc0c9..601aab492d5b2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java @@ -26,9 +26,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.Spliterators; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; @@ -135,7 +133,7 @@ public static boolean updateIndicesForPolicy(final Metadata.Builder mb, final Cl } final List indicesThatCanBeUpdated = - StreamSupport.stream(Spliterators.spliteratorUnknownSize(currentState.metadata().indices().valuesIt(), 0), false) + currentState.metadata().indices().values().stream() .filter(meta -> newPolicy.getName().equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) .filter(meta -> isIndexPhaseDefinitionUpdatable(xContentRegistry, client, meta, newPolicy.getPolicy(), licenseState)) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java index 5b738021b2a22..63cc99301b7a6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java @@ -13,7 +13,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; -import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.core.TimeValue; @@ -77,8 +76,7 @@ static void deleteSourceIndexAndTransferAliases(Client client, IndexMetadata sou .addAliasAction(IndicesAliasesRequest.AliasActions.removeIndex().index(sourceIndexName)) .addAliasAction(IndicesAliasesRequest.AliasActions.add().index(targetIndex).alias(sourceIndexName)); // copy over other aliases from source index - sourceIndex.getAliases().values().spliterator().forEachRemaining(aliasMetaDataObjectCursor -> { - AliasMetadata aliasMetaDataToAdd = aliasMetaDataObjectCursor.value; + sourceIndex.getAliases().values().forEach(aliasMetaDataToAdd -> { // inherit all alias properties except `is_write_index` aliasesRequest.addAliasAction(IndicesAliasesRequest.AliasActions.add() .index(targetIndex).alias(aliasMetaDataToAdd.alias()) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java index bdf611eac53a8..bfe7dda5175c1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/DataTierTests.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.StreamSupport; import static org.elasticsearch.xpack.core.DataTier.DATA_COLD; import static org.elasticsearch.xpack.core.DataTier.DATA_HOT; @@ -43,43 +42,37 @@ public void testNodeSelection() { DiscoveryNodes discoveryNodes = buildDiscoveryNodes(); final String[] dataNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DiscoveryNode::canContainData) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] contentNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DataTier::isContentNode) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] hotNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DataTier::isHotNode) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] warmNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DataTier::isWarmNode) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] coldNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DataTier::isColdNode) .map(DiscoveryNode::getId) .toArray(String[]::new); final String[] frozenNodes = - StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false) - .map(n -> n.value) + discoveryNodes.getNodes().values().stream() .filter(DataTier::isFrozenNode) .map(DiscoveryNode::getId) .toArray(String[]::new); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java index 94328df0b47cb..8846c96057556 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java @@ -66,7 +66,6 @@ import java.util.Set; import java.util.function.LongSupplier; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.xpack.core.ClientHelper.ENRICH_ORIGIN; @@ -137,10 +136,7 @@ public void run() { } private List> toMappings(GetIndexResponse response) { - return StreamSupport.stream(response.mappings().values().spliterator(), false) - .map(cursor -> cursor.value) - .map(MappingMetadata::getSourceAsMap) - .collect(Collectors.toList()); + return response.mappings().values().stream().map(MappingMetadata::getSourceAsMap).collect(Collectors.toList()); } private Map getMappings(final GetIndexResponse getIndexResponse, final String sourceIndexName) { diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorStatsAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorStatsAction.java index 4b71fd69a57e5..ab5f2289511d7 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorStatsAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorStatsAction.java @@ -154,7 +154,7 @@ public TransportAction( @Override protected void resolveRequest(Request request, ClusterState clusterState) { - DiscoveryNode[] ingestNodes = clusterState.getNodes().getIngestNodes().values().toArray(DiscoveryNode.class); + DiscoveryNode[] ingestNodes = clusterState.getNodes().getIngestNodes().values().toArray(DiscoveryNode[]::new); request.setConcreteNodes(ingestNodes); } diff --git a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java b/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java index 02520be6c691c..04b996b9adb32 100644 --- a/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java +++ b/x-pack/plugin/frozen-indices/src/internalClusterTest/java/org/elasticsearch/index/engine/frozen/FrozenIndexRecoveryTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; -import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; @@ -48,10 +47,7 @@ public void testRecoverExistingReplica() throws Exception { internalCluster().ensureAtLeastNumDataNodes(2); List dataNodes = randomSubsetOf( 2, - Sets.newHashSet(clusterService().state().nodes().getDataNodes().valuesIt()) - .stream() - .map(DiscoveryNode::getName) - .collect(Collectors.toSet()) + clusterService().state().nodes().getDataNodes().values().stream().map(DiscoveryNode::getName).collect(Collectors.toSet()) ); createIndex( indexName, diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java index 87bfe72079b64..8989598e36fec 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java @@ -42,10 +42,8 @@ import java.util.Map; import java.util.Objects; import java.util.SortedMap; -import java.util.Spliterators; import java.util.TreeMap; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_SETTING; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING; @@ -236,7 +234,7 @@ private static void refreshCachedPhaseForPhasesWithoutAllocateAction(Metadata.Bu XPackLicenseState licenseState) { String policyName = oldPolicy.getName(); final List managedIndices = - StreamSupport.stream(Spliterators.spliteratorUnknownSize(currentState.metadata().indices().valuesIt(), 0), false) + currentState.metadata().indices().values().stream() .filter(meta -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) .collect(Collectors.toList()); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index 1c879a623db1a..a9091276f63cd 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -6,8 +6,6 @@ */ package org.elasticsearch.xpack.ilm; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -166,8 +164,7 @@ void onMaster(ClusterState clusterState) { // If we just became master, we need to kick off any async actions that // may have not been run due to master rollover - for (ObjectCursor cursor : clusterState.metadata().indices().values()) { - IndexMetadata idxMeta = cursor.value; + for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); if (Strings.isNullOrEmpty(policyName) == false) { final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); @@ -334,8 +331,7 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) // loop through all indices in cluster state and filter for ones that are // managed by the Index Lifecycle Service they have a index.lifecycle.name setting // associated to a policy - for (ObjectCursor cursor : clusterState.metadata().indices().values()) { - IndexMetadata idxMeta = cursor.value; + for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); if (Strings.isNullOrEmpty(policyName) == false) { final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java index c0af59c8cb449..a43a35154602b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ilm.action; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; @@ -17,7 +16,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; -import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; @@ -32,10 +30,8 @@ import java.util.List; import java.util.SortedMap; -import java.util.Spliterator; import java.util.TreeMap; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_NAME_SETTING; @@ -54,12 +50,10 @@ protected void masterOperation(Task task, Request request, ClusterState state, A new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { - Spliterator> indicesIt = currentState.metadata().indices().values().spliterator(); String policyToDelete = request.getPolicyName(); - List indicesUsingPolicy = StreamSupport.stream(indicesIt, false) - .map(idxMeta -> idxMeta.value) - .filter((idxMeta) -> LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()).equals(policyToDelete)) - .map((idxMeta) -> idxMeta.getIndex().getName()) + List indicesUsingPolicy = currentState.metadata().indices().values().stream() + .filter(idxMeta -> LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()).equals(policyToDelete)) + .map(idxMeta -> idxMeta.getIndex().getName()) .collect(Collectors.toList()); if (indicesUsingPolicy.isEmpty() == false) { throw new IllegalArgumentException("Cannot delete policy [" + request.getPolicyName() diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/RunDataFrameAnalyticsIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/RunDataFrameAnalyticsIT.java index 2adbbfe16bdbb..1777c9d8ee604 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/RunDataFrameAnalyticsIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/RunDataFrameAnalyticsIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.WriteRequest; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexSettings; @@ -28,7 +27,6 @@ import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsState; import org.elasticsearch.xpack.core.ml.dataframe.analyses.OutlierDetection; import org.junit.After; -import org.junit.Before; import java.util.HashMap; import java.util.List; @@ -248,7 +246,7 @@ public void testOutlierDetectionWithMoreFieldsThanDocValueFieldLimit() throws Ex GetSettingsResponse docValueLimitSetting = client().admin().indices().getSettings(getSettingsRequest).actionGet(); int docValueLimit = IndexSettings.MAX_DOCVALUE_FIELDS_SEARCH_SETTING.get( - docValueLimitSetting.getIndexToSettings().values().iterator().next().value); + docValueLimitSetting.getIndexToSettings().valuesIt().next()); BulkRequestBuilder bulkRequestBuilder = client().prepareBulk(); bulkRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java index c11f0e602fde7..c487e565963f3 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java @@ -6,7 +6,6 @@ */ package org.elasticsearch.xpack.ml.integration; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.index.IndexRequest; @@ -162,9 +161,7 @@ public void testMigrateConfigs() throws InterruptedException, IOException { doAnswer(invocation -> { ClusterStateUpdateTask listener = (ClusterStateUpdateTask) invocation.getArguments()[1]; ClusterState result = listener.execute(clusterState); - for (ObjectCursor value : result.metadata().customs().values()){ - customs.add(value.value); - } + customs.addAll(result.metadata().customs().values()); listener.clusterStateProcessed("source", mock(ClusterState.class), mock(ClusterState.class)); return null; }).when(clusterService).submitStateUpdateTask(eq("remove-migrated-ml-configs"), any()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DestinationIndex.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DestinationIndex.java index c5477afe9868f..bb11a0e687b5a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DestinationIndex.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DestinationIndex.java @@ -41,7 +41,6 @@ import java.time.Clock; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -209,9 +208,7 @@ private static Settings settings(GetSettingsResponse settingsResponse) { @Nullable private static Integer findMaxSettingValue(GetSettingsResponse settingsResponse, String settingKey) { Integer maxValue = null; - Iterator settingsIterator = settingsResponse.getIndexToSettings().valuesIt(); - while (settingsIterator.hasNext()) { - Settings settings = settingsIterator.next(); + for (Settings settings : settingsResponse.getIndexToSettings().values()) { Integer indexValue = settings.getAsInt(settingKey, null); if (indexValue != null) { maxValue = maxValue == null ? indexValue : Math.max(indexValue, maxValue); diff --git a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java index 46c59ef1037ff..2c5322eea826c 100644 --- a/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java +++ b/x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java @@ -6,7 +6,6 @@ */ package org.elasticsearch.xpack.ql.index; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.ElasticsearchSecurityException; @@ -249,8 +248,8 @@ private void filterResults(String javaRegex, GetAliasesResponse aliases, GetInde Set result = new TreeSet<>(Comparator.comparing(IndexInfo::name)); // filter aliases (if present) if (aliases != null) { - for (ObjectCursor> cursor : aliases.getAliases().values()) { - for (AliasMetadata amd : cursor.value) { + for (List aliasList : aliases.getAliases().values()) { + for (AliasMetadata amd : aliasList) { String alias = amd.alias(); if (alias != null && (pattern == null || pattern.matcher(alias).matches())) { result.add(new IndexInfo(alias, IndexType.ALIAS)); diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/FrozenSearchableSnapshotsIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/FrozenSearchableSnapshotsIntegTests.java index 1fb4bdc079f05..1d3dc9224483b 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/FrozenSearchableSnapshotsIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/FrozenSearchableSnapshotsIntegTests.java @@ -62,7 +62,6 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.stream.StreamSupport; import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; @@ -377,10 +376,7 @@ public void testCreateAndRestorePartialSearchableSnapshot() throws Exception { internalCluster().ensureAtLeastNumDataNodes(2); final DiscoveryNode dataNode = randomFrom( - StreamSupport.stream( - client().admin().cluster().prepareState().get().getState().nodes().getDataNodes().values().spliterator(), - false - ).map(c -> c.value).toArray(DiscoveryNode[]::new) + client().admin().cluster().prepareState().get().getState().nodes().getDataNodes().values() ); assertAcked( diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java index 69d9f2f3e4491..4db3e0c5e74ec 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java @@ -71,7 +71,6 @@ import java.util.concurrent.CyclicBarrier; import java.util.stream.Collectors; import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING; @@ -298,10 +297,7 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception { internalCluster().ensureAtLeastNumDataNodes(2); final DiscoveryNode dataNode = randomFrom( - StreamSupport.stream( - client().admin().cluster().prepareState().get().getState().nodes().getDataNodes().values().spliterator(), - false - ).map(c -> c.value).toArray(DiscoveryNode[]::new) + client().admin().cluster().prepareState().get().getState().nodes().getDataNodes().values() ); assertAcked( diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/SearchableSnapshotsPersistentCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/SearchableSnapshotsPersistentCacheIntegTests.java index 5dddf0cebbe5c..32737e45e5193 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/SearchableSnapshotsPersistentCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/SearchableSnapshotsPersistentCacheIntegTests.java @@ -76,7 +76,7 @@ public void testCacheSurviveRestart() throws Exception { assertAcked(client().admin().indices().prepareDelete(indexName)); final DiscoveryNodes discoveryNodes = client().admin().cluster().prepareState().clear().setNodes(true).get().getState().nodes(); - final String dataNode = randomFrom(discoveryNodes.getDataNodes().values().toArray(DiscoveryNode.class)).getName(); + final String dataNode = randomFrom(discoveryNodes.getDataNodes().values()).getName(); mountSnapshot( fsRepoName, diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/recovery/SearchableSnapshotRecoveryStateIntegrationTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/recovery/SearchableSnapshotRecoveryStateIntegrationTests.java index 8b684138a9237..ad8805967e15c 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/recovery/SearchableSnapshotRecoveryStateIntegrationTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/recovery/SearchableSnapshotRecoveryStateIntegrationTests.java @@ -7,8 +7,6 @@ package org.elasticsearch.xpack.searchablesnapshots.recovery; -import com.carrotsearch.hppc.ObjectContainer; - import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -217,11 +215,11 @@ private RecoveryState getRecoveryState(String indexName) { @SuppressForbidden(reason = "Uses FileSystem APIs") private long getPhysicalCacheSize(Index index, String snapshotUUID) throws Exception { - final ObjectContainer dataNodes = getDiscoveryNodes().getDataNodes().values(); + final Collection dataNodes = getDiscoveryNodes().getDataNodes().values(); assertThat(dataNodes.size(), equalTo(1)); - final String dataNode = dataNodes.iterator().next().value.getName(); + final String dataNode = dataNodes.iterator().next().getName(); final IndexService indexService = internalCluster().getInstance(IndicesService.class, dataNode).indexService(index); final Path shardCachePath = CacheService.getShardCachePath(indexService.getShard(0).shardPath()); diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/TransportSearchableSnapshotsNodeCachesStatsAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/TransportSearchableSnapshotsNodeCachesStatsAction.java index 53300ed66e7ce..342266ec8613f 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/TransportSearchableSnapshotsNodeCachesStatsAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/cache/TransportSearchableSnapshotsNodeCachesStatsAction.java @@ -105,7 +105,7 @@ protected void resolveRequest(NodesRequest request, ClusterState clusterState) { final DiscoveryNode[] resolvedNodes; if (request.nodesIds() == null || request.nodesIds().length == 0) { - resolvedNodes = dataNodes.values().toArray(DiscoveryNode.class); + resolvedNodes = dataNodes.values().toArray(DiscoveryNode[]::new); } else { resolvedNodes = Arrays.stream(request.nodesIds()) .filter(dataNodes::containsKey) diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java index 0cefbf6597b3f..3490cd6315529 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java @@ -398,7 +398,7 @@ private AsyncShardFetch.FetchResult fetchData(ShardRouti ); final AsyncCacheStatusFetch asyncFetch = asyncFetchStore.computeIfAbsent(shardId, sid -> new AsyncCacheStatusFetch()); final DiscoveryNodes nodes = allocation.nodes(); - final DiscoveryNode[] dataNodes = asyncFetch.addFetches(nodes.getDataNodes().values().toArray(DiscoveryNode.class)); + final DiscoveryNode[] dataNodes = asyncFetch.addFetches(nodes.getDataNodes().values().toArray(DiscoveryNode[]::new)); if (dataNodes.length > 0) { client.execute( TransportSearchableSnapshotCacheStoresAction.TYPE, diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java index f7bb459d7b31b..9bc77792fb8fb 100644 --- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java +++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java @@ -40,7 +40,7 @@ public void testShrinkIndex() throws Exception { ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() .getDataNodes(); - DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode.class); + DiscoveryNode[] discoveryNodes = dataNodes.values().toArray(DiscoveryNode[]::new); final String mergeNode = discoveryNodes[0].getName(); ensureGreen(); // relocate all shards to one node such that we can merge it. diff --git a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java index b369d28be3eea..91767c982fe6c 100644 --- a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java +++ b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java @@ -7,9 +7,6 @@ package org.elasticsearch.repositories.blobstore.testkit; -import com.carrotsearch.hppc.ObjectContainer; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; @@ -59,6 +56,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -180,11 +178,11 @@ private static boolean isSnapshotNode(DiscoveryNode discoveryNode) { } private static List getSnapshotNodes(DiscoveryNodes discoveryNodes) { - final ObjectContainer nodesContainer = discoveryNodes.getMasterAndDataNodes().values(); - final List nodes = new ArrayList<>(nodesContainer.size()); - for (ObjectCursor cursor : nodesContainer) { - if (isSnapshotNode(cursor.value)) { - nodes.add(cursor.value); + final Collection nodesCollection = discoveryNodes.getMasterAndDataNodes().values(); + final List nodes = new ArrayList<>(nodesCollection.size()); + for (DiscoveryNode node : nodesCollection) { + if (isSnapshotNode(node)) { + nodes.add(node); } } return nodes; diff --git a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index c22d0eff4c174..9743587ba92b7 100644 --- a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -29,7 +29,6 @@ import org.junit.Before; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -158,9 +157,7 @@ public void testExceptionMapping() { // ensure that enabled is set to false List indexed = new ArrayList<>(); GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings(HistoryStoreField.INDEX_PREFIX + "*").get(); - Iterator iterator = mappingsResponse.getMappings().valuesIt(); - while (iterator.hasNext()) { - MappingMetadata mapping = iterator.next(); + for (MappingMetadata mapping : mappingsResponse.getMappings().values()) { Map docMapping = mapping.getSourceAsMap(); if (abortAtInput) { Boolean enabled = ObjectPath.eval("properties.result.properties.input.properties.error.enabled", docMapping); diff --git a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java index 5beb3b6de7c5f..2360275845d3b 100644 --- a/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java +++ b/x-pack/plugin/watcher/src/internalClusterTest/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java @@ -105,7 +105,7 @@ public void testFailedInputResultWithDotsInFieldNameGetsStored() throws Exceptio // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); XContentSource source = new XContentSource( - response.getMappings().values().iterator().next().value.source().uncompressed(), XContentType.JSON); + response.getMappings().valuesIt().next().source().uncompressed(), XContentType.JSON); // lets make sure the body fields are disabled if (useChained) { String chainedPath = SINGLE_MAPPING_NAME + @@ -146,7 +146,7 @@ public void testPayloadInputWithDotsInFieldNameWorks() throws Exception { // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); XContentSource source = new XContentSource( - response.getMappings().values().iterator().next().value.source().uncompressed(), XContentType.JSON); + response.getMappings().valuesIt().next().source().uncompressed(), XContentType.JSON); // lets make sure the body fields are disabled if (useChained) { @@ -203,7 +203,7 @@ public void testThatHistoryContainsStatus() throws Exception { // also ensure that the status field is disabled in the watch history GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); XContentSource mappingSource = - new XContentSource(response.getMappings().values().iterator().next().value.source().uncompressed(), XContentType.JSON); + new XContentSource(response.getMappings().valuesIt().next().source().uncompressed(), XContentType.JSON); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.enabled"), is(false)); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.properties.status"), is(nullValue())); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.properties.status.properties.active"), is(nullValue()));