Skip to content

Commit

Permalink
Refactored ImmutableMap coming from OpenSearch
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Apr 27, 2023
1 parent 5ddb5af commit dc993ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ private void updateJobIndexSettingIfNecessary(IndexState jobIndexState, ActionLi

private static Integer getIntegerSetting(GetSettingsResponse settingsResponse, String settingKey) {
Integer value = null;
Iterator<Settings> iter = settingsResponse.getIndexToSettings().valuesIt();
Iterator<Settings> iter = settingsResponse.getIndexToSettings().values().iterator();
while (iter.hasNext()) {
Settings settings = iter.next();
value = settings.getAsInt(settingKey, null);
Expand All @@ -1166,7 +1166,7 @@ private static Integer getIntegerSetting(GetSettingsResponse settingsResponse, S

private static String getStringSetting(GetSettingsResponse settingsResponse, String settingKey) {
String value = null;
Iterator<Settings> iter = settingsResponse.getIndexToSettings().valuesIt();
Iterator<Settings> iter = settingsResponse.getIndexToSettings().values().iterator();
while (iter.hasNext()) {
Settings settings = iter.next();
value = settings.get(settingKey, null);
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/org/opensearch/ad/ADIntegTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.opensearch.client.node.NodeClient;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.query.MatchAllQueryBuilder;
Expand All @@ -65,7 +64,6 @@
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.transport.MockTransportService;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableMap;

public abstract class ADIntegTestCase extends OpenSearchIntegTestCase {
Expand Down Expand Up @@ -252,7 +250,7 @@ public ClusterUpdateSettingsResponse updateTransientSettings(Map<String, ?> sett
return clusterAdmin().updateSettings(updateSettingsRequest).actionGet(timeout);
}

public ImmutableOpenMap<String, DiscoveryNode> getDataNodes() {
public Map<String, DiscoveryNode> getDataNodes() {
DiscoveryNodes nodes = clusterService().state().getNodes();
return nodes.getDataNodes();
}
Expand All @@ -268,10 +266,10 @@ public Client getDataNodeClient() {

public DiscoveryNode[] getDataNodesArray() {
DiscoveryNodes nodes = clusterService().state().getNodes();
Iterator<ObjectObjectCursor<String, DiscoveryNode>> iterator = nodes.getDataNodes().iterator();
Iterator<DiscoveryNode> iterator = nodes.getDataNodes().values().iterator();
List<DiscoveryNode> dataNodes = new ArrayList<>();
while (iterator.hasNext()) {
dataNodes.add(iterator.next().value);
dataNodes.add(iterator.next());
}
return dataNodes.toArray(new DiscoveryNode[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.opensearch.Version;
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodes;
import org.opensearch.common.collect.ImmutableOpenMap;
import org.opensearch.common.transport.TransportAddress;

public class ClusterCreation {
Expand Down Expand Up @@ -66,12 +67,12 @@ public static ClusterState state(
*
* TODO: ModelManagerTests has the same method. Refactor.
*/
public static ImmutableOpenMap<String, DiscoveryNode> createDataNodes(int numDataNodes) {
ImmutableOpenMap.Builder<String, DiscoveryNode> dataNodes = ImmutableOpenMap.builder();
public static Map<String, DiscoveryNode> createDataNodes(int numDataNodes) {
final Map<String, DiscoveryNode> dataNodes = new HashMap<>();
for (int i = 0; i < numDataNodes; i++) {
dataNodes.put("foo" + i, mock(DiscoveryNode.class));
}
return dataNodes.build();
return dataNodes;
}

/**
Expand Down

0 comments on commit dc993ca

Please sign in to comment.