Skip to content

Commit

Permalink
[Backport to main]Fix build. (#1018) (#1263)
Browse files Browse the repository at this point in the history
* Fix build. (#1018)

* Fix build.

Signed-off-by: Yury-Fridlyand <[email protected]>

* Remove unused import.

Signed-off-by: Yury-Fridlyand <[email protected]>

---------

Signed-off-by: Yury-Fridlyand <[email protected]>

* fix format issue

Signed-off-by: zane-neo <[email protected]>

---------

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: zane-neo <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
zane-neo and Yury-Fridlyand authored Aug 29, 2023
1 parent 7c54864 commit adb7ed3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.collect.ImmutableMap;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -437,17 +438,19 @@ private ClusterState setupTestClusterState() {
new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()),
new HashMap<>(), roleSet,
Version.CURRENT);
Settings.Builder indexSettings = Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("index.version.created", Version.CURRENT.id);
IndexMetadata indexMetaData = IndexMetadata.builder("test").settings(indexSettings).build();
final Map<String, IndexMetadata> indices = Collections.unmodifiableMap(Map.of(indexName, indexMetaData));
Metadata metadata = new Metadata.Builder().indices(indices).build();

Metadata metadata = new Metadata.Builder()
.indices(ImmutableMap
.<String, IndexMetadata>builder()
.put(indexName, IndexMetadata.builder("test")
.settings(Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("index.version.created", Version.CURRENT.id))
.build())
.build()).build();
return new ClusterState(new ClusterName(clusterName), 123l, "111111",
metadata, null, DiscoveryNodes.builder().add(node).build(),
null, new HashMap<>(), 0, false);
null, Map.of(), 0, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import org.apache.lucene.search.TotalHits;
import org.junit.Before;
Expand Down Expand Up @@ -103,18 +103,7 @@ public void setup() {

Metadata metadata = mock(Metadata.class);
when(metadata.hasIndex(anyString())).thenReturn(true);
ClusterState testState = new ClusterState(
new ClusterName("mock"),
123l,
"111111",
metadata,
null,
null,
null,
Collections.singletonMap("key", null),
0,
false
);
ClusterState testState = new ClusterState(new ClusterName("mock"), 123l, "111111", metadata, null, null, null, Map.of(), 0, false);
when(clusterService.state()).thenReturn(testState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -129,7 +129,7 @@ public void setup() throws IOException {
.add(mlNode1)
.add(mlNode2)
.build();
clusterState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, new HashMap<>(), 0, false);
clusterState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, Map.of(), 0, false);

when(clusterService.state()).thenReturn(clusterState);
discoveryNodeHelper = new DiscoveryNodeHelper(clusterService, settings);
Expand Down Expand Up @@ -158,7 +158,7 @@ public void testGetEligibleNodes_DataNode() {
mockSettings(false, nonExistingNodeName);
DiscoveryNodeHelper discoveryNodeHelper = new DiscoveryNodeHelper(clusterService, settings);
DiscoveryNodes nodes = DiscoveryNodes.builder().add(clusterManagerNode).add(dataNode1).add(dataNode2).add(warmDataNode1).build();
clusterState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, new HashMap<>(), 0, false);
clusterState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, Map.of(), 0, false);
when(clusterService.state()).thenReturn(clusterState);

DiscoveryNode[] eligibleNodes = discoveryNodeHelper.getEligibleNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.opensearch.client.Client;
import org.opensearch.cluster.ClusterName;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodeRole;
Expand Down Expand Up @@ -99,8 +98,7 @@ public void setup() throws IOException {
}

public void testRun_NoMLModelIndex() {
final Map<String, IndexMetadata> indices = new HashMap<>();
Metadata metadata = new Metadata.Builder().indices(indices).build();
Metadata metadata = new Metadata.Builder().indices(Map.of()).build();
DiscoveryNode node = new DiscoveryNode(
"node",
new TransportAddress(TransportAddress.META_ADDRESS, new AtomicInteger().incrementAndGet()),
Expand All @@ -116,7 +114,7 @@ public void testRun_NoMLModelIndex() {
null,
DiscoveryNodes.builder().add(node).build(),
null,
new HashMap<>(),
Map.of(),
0,
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void setup() {
Set<DiscoveryNodeRole> mlRoleSet = ImmutableSet.of(ML_ROLE);
mlNode = new DiscoveryNode("mlNode", buildNewFakeTransportAddress(), new HashMap<>(), mlRoleSet, Version.CURRENT);
DiscoveryNodes nodes = DiscoveryNodes.builder().add(dataNode1).add(dataNode2).build();
testState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, null, 0, false);
testState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, Map.of(), 0, false);
when(clusterService.state()).thenReturn(testState);

doAnswer(invocation -> {
Expand Down Expand Up @@ -145,7 +145,7 @@ public void testGetEligibleNodes_DataNodeOnly() {
@Ignore
public void testGetEligibleNodes_MlAndDataNodes() {
DiscoveryNodes nodes = DiscoveryNodes.builder().add(dataNode1).add(dataNode2).add(mlNode).build();
testState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, null, 0, false);
testState = new ClusterState(new ClusterName(clusterName), 123l, "111111", null, null, nodes, null, Map.of(), 0, false);
when(clusterService.state()).thenReturn(testState);

DiscoveryNode[] eligibleNodes = nodeHelper.getEligibleNodes();
Expand Down
36 changes: 24 additions & 12 deletions plugin/src/test/java/org/opensearch/ml/utils/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ public static ClusterState state(
.build();
final Settings.Builder existingSettings = Settings.builder().put(indexSettings).put(IndexMetadata.SETTING_INDEX_UUID, "test2UUID");
IndexMetadata indexMetaData = IndexMetadata.builder(indexName).settings(existingSettings).putMapping(mapping).build();
final Map<String, IndexMetadata> indices = Collections.unmodifiableMap(Map.of(indexName, indexMetaData));
ClusterState clusterState = ClusterState.builder(name).metadata(Metadata.builder().indices(indices).build()).build();

return clusterState;
final Map<String, IndexMetadata> indices = Map.of(indexName, indexMetaData);

return ClusterState.builder(name).metadata(Metadata.builder().indices(indices).build()).build();
}

public static ClusterState state(int numDataNodes, String indexName, String mapping) throws IOException {
Expand Down Expand Up @@ -359,14 +359,26 @@ public static ClusterState setupTestClusterState() {
roleSet,
Version.CURRENT
);
final Settings.Builder indexSettings = Settings
.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("index.version.created", Version.CURRENT.id);
IndexMetadata indexMetaData = IndexMetadata.builder("test").settings(indexSettings).build();
final Map<String, IndexMetadata> indices = Map.of(ML_MODEL_INDEX, indexMetaData);
Metadata metadata = new Metadata.Builder().indices(indices).build();
Metadata metadata = new Metadata.Builder()
.indices(
ImmutableMap
.<String, IndexMetadata>builder()
.put(
ML_MODEL_INDEX,
IndexMetadata
.builder("test")
.settings(
Settings
.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 1)
.put("index.version.created", Version.CURRENT.id)
)
.build()
)
.build()
)
.build();
return new ClusterState(
new ClusterName("test cluster"),
123l,
Expand All @@ -375,7 +387,7 @@ public static ClusterState setupTestClusterState() {
null,
DiscoveryNodes.builder().add(node).build(),
null,
new HashMap<>(),
Map.of(),
0,
false
);
Expand Down

0 comments on commit adb7ed3

Please sign in to comment.