use of org.opensearch.cluster.node.DiscoveryNode in project anomaly-detection by opensearch-project.
the class HashRingTests method testGetOwningNodeWithEmptyResult.
public void testGetOwningNodeWithEmptyResult() throws UnknownHostException {
DiscoveryNode node1 = createNode(Integer.toString(1), "127.0.0.4", 9204, emptyMap());
doReturn(node1).when(clusterService).localNode();
Optional<DiscoveryNode> node = hashRing.getOwningNodeWithSameLocalAdVersionForRealtimeAD("http-latency-rcf-1");
assertFalse(node.isPresent());
}
use of org.opensearch.cluster.node.DiscoveryNode in project anomaly-detection by opensearch-project.
the class HashRingTests method setupClusterAdminClient.
private void setupClusterAdminClient(DiscoveryNode... nodes) {
doAnswer(invocation -> {
ActionListener<NodesInfoResponse> listener = invocation.getArgument(1);
List<NodeInfo> nodeInfos = new ArrayList<>();
for (DiscoveryNode node : nodes) {
nodeInfos.add(createNodeInfo(node, "1.1.0.0"));
}
NodesInfoResponse nodesInfoResponse = new NodesInfoResponse(ClusterName.DEFAULT, nodeInfos, ImmutableList.of());
listener.onResponse(nodesInfoResponse);
return null;
}).when(clusterAdminClient).nodesInfo(any(), any());
}
use of org.opensearch.cluster.node.DiscoveryNode in project anomaly-detection by opensearch-project.
the class ADClusterEventListenerTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
super.setUpLog4jForJUnit(ADClusterEventListener.class);
clusterService = createClusterService(threadPool);
hashRing = mock(HashRing.class);
masterNode = new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT);
oldClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(masterNodeId).add(masterNode)).build();
newClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)).build();
listener = new ADClusterEventListener(clusterService, hashRing);
}
use of org.opensearch.cluster.node.DiscoveryNode in project anomaly-detection by opensearch-project.
the class ADClusterEventListenerTests method testNodeRemoved.
public void testNodeRemoved() {
ClusterState twoDataNodeClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)).add(dataNode1).add(new DiscoveryNode("dataNode2", buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT))).build();
listener.clusterChanged(new ClusterChangedEvent("foo", newClusterState, twoDataNodeClusterState));
assertTrue(testAppender.containsMessage(ADClusterEventListener.NODE_CHANGED_MSG));
assertTrue(testAppender.containsMessage("node removed: true, node added: true"));
}
use of org.opensearch.cluster.node.DiscoveryNode in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method setUpClientExecuteProfileAction.
@SuppressWarnings("unchecked")
private void setUpClientExecuteProfileAction() {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<ProfileResponse> listener = (ActionListener<ProfileResponse>) args[2];
node1 = "node1";
nodeName1 = "nodename1";
discoveryNode1 = new DiscoveryNode(nodeName1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
node2 = "node2";
nodeName2 = "nodename2";
discoveryNode2 = new DiscoveryNode(nodeName2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), Version.CURRENT);
modelSize = 4456448L;
model1Id = "Pl536HEBnXkDrah03glg_model_rcf_1";
model0Id = "Pl536HEBnXkDrah03glg_model_rcf_0";
shingleSize = 6;
String clusterName = "test-cluster-name";
Map<String, Long> modelSizeMap1 = new HashMap<String, Long>() {
{
put(model1Id, modelSize);
}
};
Map<String, Long> modelSizeMap2 = new HashMap<String, Long>() {
{
put(model0Id, modelSize);
}
};
ProfileNodeResponse profileNodeResponse1 = new ProfileNodeResponse(discoveryNode1, modelSizeMap1, shingleSize, 0L, 0L, new ArrayList<>(), modelSizeMap1.size());
ProfileNodeResponse profileNodeResponse2 = new ProfileNodeResponse(discoveryNode2, modelSizeMap2, -1, 0L, 0L, new ArrayList<>(), modelSizeMap2.size());
List<ProfileNodeResponse> profileNodeResponses = Arrays.asList(profileNodeResponse1, profileNodeResponse2);
List<FailedNodeException> failures = Collections.emptyList();
ProfileResponse profileResponse = new ProfileResponse(new ClusterName(clusterName), profileNodeResponses, failures);
listener.onResponse(profileResponse);
return null;
}).when(client).execute(any(ProfileAction.class), any(), any());
}
Aggregations