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 94ed6e72fb83a..ab0e6813aa6c1 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 @@ -30,7 +30,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; @@ -107,10 +106,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++) { @@ -192,8 +191,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 a3862d1cca5a4..b2b7d90419789 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,12 +16,13 @@ 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.core.Set; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.core.Set; import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.core.TimeValue; import org.elasticsearch.env.Environment; @@ -47,7 +48,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; @@ -370,10 +370,9 @@ private void putPipeline() throws IOException { } private List getGeoIpTmpDirs() throws IOException { - final java.util.Set ids = - StreamSupport.stream(clusterService().state().nodes().getDataNodes().values().spliterator(), false) - .map(c -> c.value.getId()) - .collect(Collectors.toSet()); + final java.util.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"); assertThat(Files.exists(geoipBaseTmpDir), is(true)); 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 84839345fce83..6a2251b12adea 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 @@ -39,8 +39,8 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.engine.SegmentsStats; @@ -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(new DiscoveryNode[0]); 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(new DiscoveryNode[0]); 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(new DiscoveryNode[0]); // 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(new DiscoveryNode[0]); 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(new DiscoveryNode[0]); 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(new DiscoveryNode[0]); // 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 e70a54bd514b2..80e2f5312c81d 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 51ea8795d3d40..44a1fac7222bb 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 6f82f32fa20f0..2a0bae2fa2839 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; @@ -134,8 +133,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 6c115743c7810..66c421a3dacb7 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(new DiscoveryNode[0]); 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 f33c418caca2a..170c86e77148a 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; @@ -382,8 +381,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 94c48495e8816..2c3793c2be361 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/routing/PartitionedRoutingIT.java @@ -85,7 +85,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(new DiscoveryNode[0])[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 3ccb6d20d66f6..87e800184e6c2 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; @@ -687,8 +685,8 @@ public void testStartCloneDuringRunningDelete() throws Exception { for (SnapshotsInProgress.Entry entry : state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY).entries()) { 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 1ed7665cbfe4b..f1fbcb6127546 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; @@ -1932,8 +1930,8 @@ private void createIndexWithContent(String indexName, String nodeInclude, String private static boolean snapshotHasCompletedShard(String snapshot, SnapshotsInProgress snapshotsInProgress) { for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) { 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 bb42461104180..f07070c70cc54 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; @@ -132,9 +131,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 84aab50123547..29fc61f93df57 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; @@ -211,8 +210,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 3221b9266e04f..cc7ba6d49a50d 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; @@ -23,7 +24,6 @@ import org.elasticsearch.transport.TransportService; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class TransportGetIndexTemplatesAction extends @@ -49,7 +49,7 @@ protected void masterOperation(GetIndexTemplatesRequest request, ClusterState st // 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..908ed891ef030 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/IngestActionForwarder.java @@ -8,10 +8,10 @@ package org.elasticsearch.action.ingest; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionType; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterStateApplier; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -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(new DiscoveryNode[0]); } } diff --git a/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index 7348283322ba1..4eefa66de8001 100644 --- a/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/server/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -8,7 +8,6 @@ package org.elasticsearch.client.transport; -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; @@ -542,8 +541,8 @@ public void handleException(TransportException e) { newFilteredNodes.add(entry.getKey()); continue; } - for (ObjectCursor cursor : entry.getValue().getState().nodes().getDataNodes().values()) { - newNodes.add(cursor.value); + for (DiscoveryNode node : entry.getValue().getState().nodes().getDataNodes().values()) { + newNodes.add(node); } } diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java b/server/src/main/java/org/elasticsearch/cluster/ClusterChangedEvent.java index cc372d80aa7c7..0ff3fd44b911a 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/ClusterState.java b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java index bf70a0cdad34a..f012bf42dcf16 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.Version; @@ -721,15 +720,15 @@ public void writeTo(StreamOutput out) throws IOException { blocks.writeTo(out); // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + for (final Custom custom : customs.values()) { + if (FeatureAware.shouldSerialize(out, custom)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { - out.writeNamedWriteable(cursor.value); + for (final Custom custom : customs.values()) { + if (FeatureAware.shouldSerialize(out, custom)) { + out.writeNamedWriteable(custom); } } if (out.getVersion().onOrAfter(Version.V_6_7_0)) { diff --git a/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java b/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java index 44fdeba4c46cf..3291bc36536c4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java +++ b/server/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster; -import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.Version; @@ -443,8 +442,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()) { if (out.getVersion().onOrAfter(Version.V_6_6_0)) { out.writeString(entry.uuid); } @@ -458,8 +456,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 1044057aa3604..7a9d6cb39cabf 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; @@ -36,6 +35,7 @@ import org.elasticsearch.snapshots.SnapshotsService; import java.io.IOException; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -215,9 +215,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; } } @@ -225,8 +225,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 a4468e618f005..3ac413bba1095 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; @@ -105,8 +105,7 @@ protected void processNodePaths(Terminal terminal, Path[] dataPaths, int nodeLoc .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 e346742fe298b..0d96d4061b9a5 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.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; @@ -101,8 +100,8 @@ private OptionalInt getDesiredNumberOfReplicas(IndexMetadata indexMetadata, Rout int numMatchingDataNodes = 0; // Only start using new logic once all nodes are migrated to 7.6.0, avoiding disruption during an upgrade if (allocation.nodes().getMinNodeVersion().onOrAfter(Version.V_7_6_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 c790b4e496306..c6bf2ca56d375 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -634,9 +634,9 @@ public Index getResizeSourceIndex() { @Nullable public MappingMetadata mappingOrDefault() { MappingMetadata mapping = null; - for (ObjectCursor m : mappings.values()) { + for (MappingMetadata m : mappings.values()) { if (mapping == null || mapping.type().equals(MapperService.DEFAULT_MAPPING)) { - mapping = m.value; + mapping = m; } } @@ -992,12 +992,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); } if (out.getVersion().onOrAfter(Version.V_6_5_0)) { out.writeVInt(customData.size()); @@ -1015,8 +1015,8 @@ public void writeTo(StreamOutput out) throws IOException { } if (out.getVersion().onOrAfter(Version.V_6_4_0)) { 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)) { @@ -1482,8 +1482,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(); @@ -1518,8 +1518,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 b1bd5d7274509..b513ca2aa35c0 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -48,11 +48,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); @@ -563,8 +561,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 58037038fd40a..62cf033c4f8f7 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.Version; import org.elasticsearch.cluster.AbstractDiffable; @@ -232,8 +232,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); } if (out.getVersion().before(Version.V_6_5_0)) { out.writeVInt(0); @@ -445,8 +445,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 b13a01858f20c..40f1438255187 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -29,16 +29,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; @@ -50,6 +40,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; @@ -212,10 +212,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; @@ -279,8 +279,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; @@ -367,10 +366,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) { @@ -382,7 +380,7 @@ private ImmutableOpenMap> findAliases(final String[] } } if (matched) { - filteredValues.add(value); + filteredValues.add(aliasMetadata); } } if (filteredValues.isEmpty() == false) { @@ -413,8 +411,7 @@ public boolean hasAliases(final String[] aliases, String[] concreteIndices) { for (String index : intersection) { IndexMetadata indexMetadata = indices.get(index); List filteredValues = new ArrayList<>(); - for (ObjectCursor cursor : indexMetadata.getAliases().values()) { - AliasMetadata value = cursor.value; + for (AliasMetadata value : indexMetadata.getAliases().values()) { if (Regex.simpleMatch(aliases, value.alias())) { filteredValues.add(value); } @@ -924,8 +921,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++; } } @@ -1116,20 +1113,20 @@ 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); } // filter out custom states not supported by the other node int numberOfCustoms = 0; - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { + for (final Custom custom : customs.values()) { + if (FeatureAware.shouldSerialize(out, custom)) { numberOfCustoms++; } } out.writeVInt(numberOfCustoms); - for (final ObjectCursor cursor : customs.values()) { - if (FeatureAware.shouldSerialize(out, cursor.value)) { - out.writeNamedWriteable(cursor.value); + for (final Custom custom : customs.values()) { + if (FeatureAware.shouldSerialize(out, custom)) { + out.writeNamedWriteable(custom); } } } @@ -1802,8 +1799,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 bb51ca550e87f..048fb9ebab831 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; @@ -872,8 +873,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 f53a848441a8b..00994cd04559e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -260,8 +260,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 1438b8387e184..e8e75eefabd79 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 b713a690a9aa3..ad99d471604e4 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; @@ -432,9 +431,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 4b956ea0ba0d7..718642764b8fd 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/discovery/PeerFinder.java b/server/src/main/java/org/elasticsearch/discovery/PeerFinder.java index 1fb5afd65d467..eb0297e8cde13 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; @@ -264,8 +263,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/discovery/zen/ElectMasterService.java b/server/src/main/java/org/elasticsearch/discovery/zen/ElectMasterService.java index b99f514a63cc0..c819e3edc2f81 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/ElectMasterService.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/ElectMasterService.java @@ -8,7 +8,6 @@ package org.elasticsearch.discovery.zen; -import com.carrotsearch.hppc.ObjectContainer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.CollectionUtil; @@ -20,7 +19,6 @@ import org.elasticsearch.common.util.CollectionUtils; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; @@ -172,8 +170,8 @@ static List sortByMasterLikelihood(Iterable nodes) /** * Returns a list of the next possible masters. */ - public DiscoveryNode[] nextPossibleMasters(ObjectContainer nodes, int numberOfPossibleMasters) { - List sortedNodes = sortedMasterNodes(Arrays.asList(nodes.toArray(DiscoveryNode.class))); + public DiscoveryNode[] nextPossibleMasters(Collection nodes, int numberOfPossibleMasters) { + List sortedNodes = sortedMasterNodes(new ArrayList<>(nodes)); if (sortedNodes == null) { return new DiscoveryNode[0]; } diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java index 7e06e382bf755..85858e85eb781 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java @@ -8,7 +8,6 @@ package org.elasticsearch.discovery.zen; -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; @@ -192,8 +191,8 @@ protected void ping(final Consumer resultsConsumer, seedAddresses.addAll(hostsProvider.getSeedAddresses(createHostsResolver())); final DiscoveryNodes nodes = contextProvider.clusterState().nodes(); // add all possible master nodes that were active in the last known cluster configuration - for (ObjectCursor masterNode : nodes.getMasterNodes().values()) { - seedAddresses.add(masterNode.value.getAddress()); + for (DiscoveryNode masterNode : nodes.getMasterNodes().values()) { + seedAddresses.add(masterNode.getAddress()); } final ConnectionProfile connectionProfile = diff --git a/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java b/server/src/main/java/org/elasticsearch/env/NodeRepurposeCommand.java index a8683058b99c8..cb731781ba145 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; @@ -94,8 +95,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 2cf71a0f3d202..b1d224d374b2f 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.action.ActionListener; @@ -158,8 +157,8 @@ void findNewAndAddDanglingIndices(final Metadata metadata) { */ public Map findNewDanglingIndices(Map existingDanglingIndices, final Metadata metadata) { final Set excludeIndexPathIds = new HashSet<>(metadata.indices().size() + danglingIndices.size()); - for (ObjectCursor cursor : metadata.indices().values()) { - excludeIndexPathIds.add(cursor.value.getIndex().getUUID()); + for (IndexMetadata indexMetadata : metadata.indices().values()) { + excludeIndexPathIds.add(indexMetadata.getIndex().getUUID()); } for (Index index : existingDanglingIndices.keySet()) { excludeIndexPathIds.add(index.getUUID()); diff --git a/server/src/main/java/org/elasticsearch/gateway/Gateway.java b/server/src/main/java/org/elasticsearch/gateway/Gateway.java index d522cb1a584c2..a0bbfe9ddd308 100644 --- a/server/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/server/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -9,7 +9,6 @@ package org.elasticsearch.gateway; import com.carrotsearch.hppc.ObjectFloatHashMap; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.action.FailedNodeException; @@ -67,8 +66,8 @@ public void performStateRecovery(final GatewayStateRecoveredListener listener) { } else if (nodeState.metadata().version() > electedGlobalState.version()) { electedGlobalState = nodeState.metadata(); } - for (final ObjectCursor cursor : nodeState.metadata().indices().values()) { - indices.addTo(cursor.value.getIndex(), 1); + for (final IndexMetadata indexMetadata : nodeState.metadata().indices().values()) { + indices.addTo(indexMetadata.getIndex(), 1); } } if (found < requiredAllocation) { diff --git a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java index 0f0aefbd481e1..3eb3681825cbd 100644 --- a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java +++ b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java @@ -7,7 +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; @@ -676,8 +675,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; @@ -685,8 +683,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 [{}]", @@ -742,8 +739,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 624fcd16a062b..4599d6d23d388 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; @@ -338,8 +338,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/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 8df2c9d5caff0..5b855fc765287 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -8,7 +8,6 @@ package org.elasticsearch.index.mapper; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -231,8 +230,7 @@ public void updateMapping(final IndexMetadata currentIndexMetadata, final IndexM final Map updatedEntries; try { Map map = new LinkedHashMap<>(); - for (ObjectCursor cursor : newIndexMetadata.getMappings().values()) { - MappingMetadata mappingMetadata = cursor.value; + for (MappingMetadata mappingMetadata : newIndexMetadata.getMappings().values()) { map.put(mappingMetadata.type(), mappingMetadata.source()); } Mappings mappings = parseMappings(map, MergeReason.MAPPING_RECOVERY); @@ -340,8 +338,7 @@ public void merge(String type, Map mappings, MergeReason reason) public void merge(IndexMetadata indexMetadata, MergeReason reason) { assert reason != MergeReason.MAPPING_UPDATE_PREFLIGHT; Map map = new LinkedHashMap<>(); - for (ObjectCursor cursor : indexMetadata.getMappings().values()) { - MappingMetadata mappingMetadata = cursor.value; + for (MappingMetadata mappingMetadata : indexMetadata.getMappings().values()) { map.put(mappingMetadata.type(), mappingMetadata.source()); } mergeAndApplyMappings(map, reason); 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 a572a5cf8d958..936ee640dfd2a 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; @@ -138,9 +137,9 @@ protected void findAndProcessShardPath(OptionSet options, Environment environmen shardId = Integer.parseInt(shardIdFileName); fromNodeId = Integer.parseInt(nodeIdFileName); toNodeId = fromNodeId + 1; - 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 076ec26903ea2..5091ab5ba712b 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; @@ -194,7 +193,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 [" + @@ -206,9 +205,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 c615930bd54e4..4717b7414af28 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/rest/action/admin/indices/RestGetMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java index fdad5824e2d8a..b7e2734f08fc3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java @@ -171,8 +171,8 @@ private static SortedSet getMissingTypes(String[] types, return Collections.emptySortedSet(); } final Set typeNames = new HashSet<>(); - for (final ObjectCursor> cursor : mappingsByIndex.values()) { - for (final ObjectCursor inner : cursor.value.keys()) { + for (final ImmutableOpenMap value : mappingsByIndex.values()) { + for (final ObjectCursor inner : value.keys()) { typeNames.add(inner.value); } } diff --git a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java index eb20529e9ea7c..8b4c500a6823d 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/RestoreService.java @@ -824,11 +824,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; } } @@ -840,8 +840,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; } } @@ -850,8 +850,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++; } } @@ -1254,8 +1254,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); @@ -1385,8 +1385,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 95eab2d06dd82..e90a1c3cfd918 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; @@ -1504,11 +1503,11 @@ private static boolean assertNoDanglingSnapshots(ClusterState state) { final Set reposSeen = new HashSet<>(); for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) { if (reposSeen.add(entry.repository())) { - 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 @@ -1809,8 +1808,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; @@ -2615,11 +2613,11 @@ public ClusterState execute(ClusterState currentState) throws Exception { } else { boolean hasUncompletedShards = false; // Cleanup in case a node gone missing and snapshot wasn't updated for some reason - for (ObjectCursor shardStatus : snapshotEntry.shards().values()) { + for (ShardSnapshotStatus shardStatus : snapshotEntry.shards().values()) { // Check if we still have shard running on existing nodes - if (shardStatus.value.state().completed() == false - && shardStatus.value.nodeId() != null - && currentState.nodes().get(shardStatus.value.nodeId()) != null) { + if (shardStatus.state().completed() == false + && shardStatus.nodeId() != null + && currentState.nodes().get(shardStatus.nodeId()) != null) { hasUncompletedShards = true; break; } @@ -2923,8 +2921,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 8f3efbd82b361..ace9143f6db32 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 @@ -310,7 +310,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(new DiscoveryNode[0])); } } 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 97c36cc6a1c7c..fcca4bd43f00d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -40,7 +40,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(new DiscoveryNode[0]); DiscoveryNode node = randomFrom(nodes); DiscoveryNode resolvedNode = discoveryNodes.resolveNode(randomBoolean() ? node.getId() : node.getName()); assertThat(resolvedNode.getId(), equalTo(node.getId())); @@ -84,8 +84,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); @@ -98,15 +97,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); @@ -137,7 +134,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(new DiscoveryNode[0]); for (int i = 0; i < numNodeNames; i++) { DiscoveryNode discoveryNode = randomFrom(nodes); nodeSelectors.add(discoveryNode.getName()); @@ -338,24 +335,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 a273a605b0090..7dbd689381903 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 93721a9843872..155c857f06938 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; @@ -640,13 +639,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)); } @@ -669,14 +668,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..e769ec81f4b07 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(new IndexMetadata[0])); 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 9fddce24affe3..ebc7aaf0449c4 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; @@ -24,6 +25,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +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,6 +40,14 @@ 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(Stream.of("£", "$").collect(Collectors.toSet()))); @@ -120,6 +132,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(new Integer[0]); + + 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(org.elasticsearch.core.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(e -> (e.contains("ab") || e.contains("cd") || e.contains("ef")) == false) + .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 9bf44c795776c..38f9ede2e60bb 100644 --- a/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java +++ b/server/src/test/java/org/elasticsearch/indices/ShardLimitValidatorTests.java @@ -27,10 +27,8 @@ import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; -import java.util.Arrays; import java.util.Optional; 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 be40b98d7fc1d..c302bcc6606f1 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -440,7 +440,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 42006cce663b3..a895fa1dabb3f 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 @@ -290,9 +290,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 7db799cb27272..51adb501ab285 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; @@ -53,7 +51,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; @@ -712,9 +709,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 0c5e94d2a3706..325d63d547f6b 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; @@ -309,8 +307,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 38f3034845c54..2a808e61e02a3 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 @@ -25,7 +25,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; @@ -44,43 +43,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/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index bc6ce6d21befc..dd43fd740b16b 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -7,8 +7,6 @@ package org.elasticsearch.xpack.deprecation; -import com.carrotsearch.hppc.cursors.ObjectCursor; - import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.MappingMetadata; @@ -48,9 +46,9 @@ public class IndexDeprecationChecks { private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsumer> checker) { - for (ObjectCursor mappingMetadata : indexMetadata.getMappings().values()) { - Map sourceAsMap = mappingMetadata.value.sourceAsMap(); - checker.accept(mappingMetadata.value, sourceAsMap); + for (MappingMetadata mappingMetadata : indexMetadata.getMappings().values()) { + Map sourceAsMap = mappingMetadata.sourceAsMap(); + checker.accept(mappingMetadata, sourceAsMap); } } 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 4f1389e591b4b..4dfdb426475d9 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,10 @@ public void run() { } private List> toMappings(GetIndexResponse response) { - return StreamSupport.stream(response.mappings().values().spliterator(), false) - .map(cursor -> cursor.value) - .flatMap(k -> StreamSupport.stream(k.values().spliterator(), false)) - .map(cursor -> cursor.value) + return response.mappings() + .values() + .stream() + .flatMap(k -> k.values().stream()) .map(MappingMetadata::getSourceAsMap) .collect(Collectors.toList()); } 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 00a889166ee25..ff7cd47d68863 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 @@ -178,7 +178,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(new DiscoveryNode[0]); 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 779ba59d953c6..ae29253f922f8 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; @@ -53,10 +52,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 1bb3cdd02816b..7b0c1ee055b51 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; @@ -167,8 +165,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); @@ -335,8 +332,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 614ab68260274..33cb7cee781ce 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; @@ -31,10 +29,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; @@ -53,12 +49,10 @@ protected void masterOperation(Request request, ClusterState state, ActionListen 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 35d6b404d9007..570f857137ef7 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 @@ -15,7 +15,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; @@ -29,7 +28,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; @@ -249,7 +247,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 cba034f4705e4..d2d658c06c610 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; @@ -161,9 +160,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 ca342e7f19140..b43b48e0039bd 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 @@ -44,7 +44,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; @@ -216,9 +215,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 08249a64d7b79..bd3375ac7af4b 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 0e68e086aa45e..e8a25c7bb7854 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 @@ -72,7 +72,6 @@ import java.util.concurrent.CyclicBarrier; import java.util.stream.Collectors; import java.util.stream.IntStream; -import java.util.stream.StreamSupport; import static java.util.Collections.singletonList; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING; @@ -300,10 +299,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 2eee41a356da2..c5f2fc6d5ccd7 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 6591a9826aaf6..74cafab648e58 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 @@ -103,7 +103,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(new DiscoveryNode[0]); } 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 d17cc4d72b86b..eb2766bb8d9f6 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(new DiscoveryNode[0])); 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 c0511df6e7339..c84562b000ab3 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(new DiscoveryNode[0]); 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 49d16c24afe77..61b9f34e937fe 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 @@ -28,7 +28,6 @@ import org.junit.Before; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -157,9 +156,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()) { - ImmutableOpenMap mapping = iterator.next(); + for (ImmutableOpenMap mapping : mappingsResponse.getMappings().values()) { assertThat(mapping.containsKey(SINGLE_MAPPING_NAME), is(true)); Map docMapping = mapping.get(SINGLE_MAPPING_NAME).getSourceAsMap(); if (abortAtInput) { 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 3fd077e1bb289..bff0df2a7b73f 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 @@ -102,7 +102,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*") .addTypes(SINGLE_MAPPING_NAME).get(); - XContentSource source = new XContentSource(response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME) + XContentSource source = new XContentSource(response.getMappings().valuesIt().next().get(SINGLE_MAPPING_NAME) .source().uncompressed(), XContentType.JSON); // lets make sure the body fields are disabled if (useChained) { @@ -144,7 +144,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*") .addTypes(SINGLE_MAPPING_NAME).get(); - XContentSource source = new XContentSource(response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME) + XContentSource source = new XContentSource(response.getMappings().valuesIt().next().get(SINGLE_MAPPING_NAME) .source().uncompressed(), XContentType.JSON); // lets make sure the body fields are disabled @@ -202,7 +202,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*") .addTypes(SINGLE_MAPPING_NAME).get(); - XContentSource mappingSource = new XContentSource(response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME) + XContentSource mappingSource = new XContentSource(response.getMappings().valuesIt().next().get(SINGLE_MAPPING_NAME) .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()));