Search in sources :

Example 11 with ClusterName

use of org.opensearch.cluster.ClusterName 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 12 with ClusterName

use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.

the class ADClusterEventListenerTests method testNotRecovered.

public void testNotRecovered() {
    ClusterState blockedClusterState = ClusterState.builder(new ClusterName(clusterName)).nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)).blocks(ClusterBlocks.builder().addGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)).build();
    listener.clusterChanged(new ClusterChangedEvent("foo", blockedClusterState, oldClusterState));
    assertTrue(testAppender.containsMessage(ADClusterEventListener.NOT_RECOVERED_MSG));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes)

Example 13 with ClusterName

use of org.opensearch.cluster.ClusterName 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 14 with ClusterName

use of org.opensearch.cluster.ClusterName in project anomaly-detection by opensearch-project.

the class HourlyCronTests method templateHourlyCron.

@SuppressWarnings("unchecked")
public void templateHourlyCron(HourlyCronTestExecutionMode mode) {
    super.setUpLog4jForJUnit(HourlyCron.class);
    ClusterService clusterService = mock(ClusterService.class);
    ClusterState state = ClusterCreation.state(1);
    when(clusterService.state()).thenReturn(state);
    HashMap<String, String> ignoredAttributes = new HashMap<String, String>();
    ignoredAttributes.put(CommonName.BOX_TYPE_KEY, CommonName.WARM_BOX_TYPE);
    DiscoveryNodeFilterer nodeFilter = new DiscoveryNodeFilterer(clusterService);
    Client client = mock(Client.class);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        assertTrue(String.format("The size of args is %d.  Its content is %s", args.length, Arrays.toString(args)), args.length == 3);
        assertTrue(args[2] instanceof ActionListener);
        ActionListener<CronResponse> listener = (ActionListener<CronResponse>) args[2];
        if (mode == HourlyCronTestExecutionMode.NODE_FAIL) {
            listener.onResponse(new CronResponse(new ClusterName("test"), Collections.singletonList(new CronNodeResponse(state.nodes().getLocalNode())), Collections.singletonList(new FailedNodeException("foo0", "blah", new OpenSearchException("bar")))));
        } else if (mode == HourlyCronTestExecutionMode.ALL_FAIL) {
            listener.onFailure(new OpenSearchException("bar"));
        } else {
            CronNodeResponse nodeResponse = new CronNodeResponse(state.nodes().getLocalNode());
            BytesStreamOutput nodeResponseOut = new BytesStreamOutput();
            nodeResponseOut.setVersion(Version.CURRENT);
            nodeResponse.writeTo(nodeResponseOut);
            StreamInput siNode = nodeResponseOut.bytes().streamInput();
            CronNodeResponse nodeResponseRead = new CronNodeResponse(siNode);
            CronResponse response = new CronResponse(new ClusterName("test"), Collections.singletonList(nodeResponseRead), Collections.EMPTY_LIST);
            BytesStreamOutput out = new BytesStreamOutput();
            out.setVersion(Version.CURRENT);
            response.writeTo(out);
            StreamInput si = out.bytes().streamInput();
            CronResponse responseRead = new CronResponse(si);
            listener.onResponse(responseRead);
        }
        return null;
    }).when(client).execute(eq(CronAction.INSTANCE), any(), any());
    HourlyCron cron = new HourlyCron(client, nodeFilter);
    cron.run();
    Logger LOG = LogManager.getLogger(HourlyCron.class);
    LOG.info(testAppender.messages);
    if (mode == HourlyCronTestExecutionMode.NODE_FAIL) {
        assertTrue(testAppender.containsMessage(HourlyCron.NODE_EXCEPTION_LOG_MSG));
    } else if (mode == HourlyCronTestExecutionMode.ALL_FAIL) {
        assertTrue(testAppender.containsMessage(HourlyCron.EXCEPTION_LOG_MSG));
    } else {
        assertTrue(testAppender.containsMessage(HourlyCron.SUCCEEDS_LOG_MSG));
    }
    super.tearDownLog4jForJUnit();
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) HashMap(java.util.HashMap) CronResponse(org.opensearch.ad.transport.CronResponse) Logger(org.apache.logging.log4j.Logger) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) CronNodeResponse(org.opensearch.ad.transport.CronNodeResponse) StreamInput(org.opensearch.common.io.stream.StreamInput) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException) OpenSearchException(org.opensearch.OpenSearchException) Client(org.opensearch.client.Client)

Example 15 with ClusterName

use of org.opensearch.cluster.ClusterName 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

ClusterName (org.opensearch.cluster.ClusterName)224 ClusterState (org.opensearch.cluster.ClusterState)176 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)73 Matchers.containsString (org.hamcrest.Matchers.containsString)57 Settings (org.opensearch.common.settings.Settings)53 Metadata (org.opensearch.cluster.metadata.Metadata)45 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)43 ClusterService (org.opensearch.cluster.service.ClusterService)42 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)36 ClusterChangedEvent (org.opensearch.cluster.ClusterChangedEvent)33 ClusterSettings (org.opensearch.common.settings.ClusterSettings)32 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)32 Version (org.opensearch.Version)31 HashMap (java.util.HashMap)30 ThreadPool (org.opensearch.threadpool.ThreadPool)29 Index (org.opensearch.index.Index)27 Before (org.junit.Before)26 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)25 BytesArray (org.opensearch.common.bytes.BytesArray)24 AtomicReference (java.util.concurrent.atomic.AtomicReference)23