Search in sources :

Example 1 with ClusterStateApplier

use of org.elasticsearch.cluster.ClusterStateApplier in project elasticsearch by elastic.

the class TransportBulkActionIngestTests method setupAction.

@Before
public void setupAction() {
    // initialize captors, which must be members to use @Capture because of generics
    MockitoAnnotations.initMocks(this);
    // setup services that will be called by action
    transportService = mock(TransportService.class);
    clusterService = mock(ClusterService.class);
    localIngest = true;
    // setup nodes for local and remote
    DiscoveryNode localNode = mock(DiscoveryNode.class);
    when(localNode.isIngestNode()).thenAnswer(stub -> localIngest);
    when(clusterService.localNode()).thenReturn(localNode);
    remoteNode1 = mock(DiscoveryNode.class);
    remoteNode2 = mock(DiscoveryNode.class);
    nodes = mock(DiscoveryNodes.class);
    ImmutableOpenMap<String, DiscoveryNode> ingestNodes = ImmutableOpenMap.<String, DiscoveryNode>builder(2).fPut("node1", remoteNode1).fPut("node2", remoteNode2).build();
    when(nodes.getIngestNodes()).thenReturn(ingestNodes);
    ClusterState state = mock(ClusterState.class);
    when(state.getNodes()).thenReturn(nodes);
    when(clusterService.state()).thenReturn(state);
    doAnswer(invocation -> {
        ClusterChangedEvent event = mock(ClusterChangedEvent.class);
        when(event.state()).thenReturn(state);
        ((ClusterStateApplier) invocation.getArguments()[0]).applyClusterState(event);
        return null;
    }).when(clusterService).addStateApplier(any(ClusterStateApplier.class));
    // setup the mocked ingest service for capturing calls
    ingestService = mock(IngestService.class);
    executionService = mock(PipelineExecutionService.class);
    when(ingestService.getPipelineExecutionService()).thenReturn(executionService);
    action = new TestTransportBulkAction();
    singleItemBulkWriteAction = new TestSingleItemBulkWriteAction(action);
    // call on construction of action
    reset(transportService);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IngestService(org.elasticsearch.ingest.IngestService) PipelineExecutionService(org.elasticsearch.ingest.PipelineExecutionService) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterService(org.elasticsearch.cluster.service.ClusterService) TransportService(org.elasticsearch.transport.TransportService) ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Before(org.junit.Before)

Example 2 with ClusterStateApplier

use of org.elasticsearch.cluster.ClusterStateApplier in project elasticsearch by elastic.

the class ClusterService method callClusterStateAppliers.

private void callClusterStateAppliers(ClusterState newClusterState, ClusterChangedEvent clusterChangedEvent) {
    for (ClusterStateApplier applier : clusterStateAppliers) {
        try {
            logger.trace("calling [{}] with change to version [{}]", applier, newClusterState.version());
            applier.applyClusterState(clusterChangedEvent);
        } catch (Exception ex) {
            logger.warn("failed to notify ClusterStateApplier", ex);
        }
    }
}
Also used : ClusterStateApplier(org.elasticsearch.cluster.ClusterStateApplier) ProcessClusterEventTimeoutException(org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Aggregations

ClusterStateApplier (org.elasticsearch.cluster.ClusterStateApplier)2 ClusterChangedEvent (org.elasticsearch.cluster.ClusterChangedEvent)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ProcessClusterEventTimeoutException (org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1 IngestService (org.elasticsearch.ingest.IngestService)1 PipelineExecutionService (org.elasticsearch.ingest.PipelineExecutionService)1 TransportService (org.elasticsearch.transport.TransportService)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Before (org.junit.Before)1