Search in sources :

Example 26 with DiscoveryNode

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());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode)

Example 27 with DiscoveryNode

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());
}
Also used : NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) ArrayList(java.util.ArrayList)

Example 28 with DiscoveryNode

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);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterName(org.opensearch.cluster.ClusterName) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Before(org.junit.Before)

Example 29 with DiscoveryNode

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"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ClusterName(org.opensearch.cluster.ClusterName) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 30 with DiscoveryNode

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());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) ProfileAction(org.opensearch.ad.transport.ProfileAction) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) ActionListener(org.opensearch.action.ActionListener) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException)

Aggregations

DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)673 ClusterState (org.opensearch.cluster.ClusterState)164 Settings (org.opensearch.common.settings.Settings)152 ArrayList (java.util.ArrayList)137 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)123 ThreadPool (org.opensearch.threadpool.ThreadPool)103 ClusterService (org.opensearch.cluster.service.ClusterService)100 CountDownLatch (java.util.concurrent.CountDownLatch)98 HashSet (java.util.HashSet)93 TransportService (org.opensearch.transport.TransportService)92 IOException (java.io.IOException)89 ActionListener (org.opensearch.action.ActionListener)88 Matchers.containsString (org.hamcrest.Matchers.containsString)84 ClusterName (org.opensearch.cluster.ClusterName)82 Version (org.opensearch.Version)80 List (java.util.List)78 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)78 HashMap (java.util.HashMap)77 TimeValue (org.opensearch.common.unit.TimeValue)77 ShardId (org.opensearch.index.shard.ShardId)76