Search in sources :

Example 6 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project crate by crate.

the class NodeDisconnectJobMonitorServiceTest method testOnParticipatingNodeDisconnectedKillsJob.

@Test
public void testOnParticipatingNodeDisconnectedKillsJob() throws Exception {
    JobContextService jobContextService = jobContextService();
    DiscoveryNode coordinator_node = new DiscoveryNode("coordinator_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNode data_node = new DiscoveryNode("data_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().localNodeId("coordinator_node_id").put(coordinator_node).put(data_node).build();
    JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID(), coordinator_node.getId(), Arrays.asList(coordinator_node.getId(), data_node.getId()));
    builder.addSubContext(new DummySubContext());
    jobContextService.createContext(builder);
    TransportKillJobsNodeAction killAction = mock(TransportKillJobsNodeAction.class);
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, mock(ThreadPool.class), jobContextService, mock(TransportService.class), killAction);
    monitorService.onNodeDisconnected(discoveryNodes.get("data_node_id"));
    verify(killAction, times(1)).broadcast(any(KillJobsRequest.class), any(ActionListener.class), eq(Arrays.asList(discoveryNodes.get("data_node_id").getId())));
}
Also used : TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) DummySubContext(io.crate.jobs.DummySubContext) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) KillJobsRequest(io.crate.executor.transport.kill.KillJobsRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobExecutionContext(io.crate.jobs.JobExecutionContext) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project crate by crate.

the class CreateAlterTableStatementAnalyzerTest method init.

@Before
public void init() throws Exception {
    String analyzerSettings = FulltextAnalyzerResolver.encodeSettings(Settings.builder().put("search", "foobar").build()).toUtf8();
    MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("crate.analysis.custom.analyzer.ft_search", analyzerSettings).build()).build();
    ClusterState state = ClusterState.builder(ClusterName.DEFAULT).nodes(DiscoveryNodes.builder().put(new DiscoveryNode("n1", DummyTransportAddress.INSTANCE, org.elasticsearch.Version.CURRENT)).put(new DiscoveryNode("n2", DummyTransportAddress.INSTANCE, org.elasticsearch.Version.CURRENT)).put(new DiscoveryNode("n3", DummyTransportAddress.INSTANCE, org.elasticsearch.Version.CURRENT)).localNodeId("n1")).metaData(metaData).build();
    e = SQLExecutor.builder(new NoopClusterService(state)).enableDefaultTables().build();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MetaData(org.elasticsearch.cluster.metadata.MetaData) DocIndexMetaData(io.crate.metadata.doc.DocIndexMetaData) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 8 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project crate by crate.

the class NodeStatsContextFieldResolverTest method setup.

@Before
public void setup() {
    DiscoveryNode discoveryNode = mock(DiscoveryNode.class);
    when(discoveryNode.getId()).thenReturn("node_id");
    when(discoveryNode.name()).thenReturn("node_name");
    when(clusterService.localNode()).thenReturn(discoveryNode);
    resolver = new NodeStatsContextFieldResolver(clusterService, osService, nodeService, jvmService, threadPool, extendedNodeInfo, postgresNetty);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Before(org.junit.Before)

Example 9 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project crate by crate.

the class NodeStatsCollectSourceTest method filterNodes.

private List<DiscoveryNode> filterNodes(String where) throws NoSuchFieldException, IllegalAccessException {
    // build where clause with id = ?
    SysNodesTableInfo tableInfo = mock(SysNodesTableInfo.class);
    when(tableInfo.ident()).thenReturn(new TableIdent("sys", "nodes"));
    when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("sys", "nodes"), "id"), RowGranularity.DOC, DataTypes.STRING));
    when(tableInfo.getReference(SysNodesTableInfo.Columns.NAME)).thenReturn(new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.NAME), RowGranularity.DOC, DataTypes.STRING));
    when(tableInfo.getReference(SysNodesTableInfo.Columns.HOSTNAME)).thenReturn(new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName("sys.nodes"), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol(where)));
    List<DiscoveryNode> nodes = Lists.newArrayList(NodeStatsCollectSource.nodeIds(whereClause, discoveryNodes, getFunctions()));
    Collections.sort(nodes, new Comparator<DiscoveryNode>() {

        @Override
        public int compare(DiscoveryNode o1, DiscoveryNode o2) {
            return o1.getId().compareTo(o2.getId());
        }
    });
    return nodes;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) SysNodesTableInfo(io.crate.metadata.sys.SysNodesTableInfo) QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) SqlExpressions(io.crate.testing.SqlExpressions)

Example 10 with DiscoveryNode

use of org.elasticsearch.cluster.node.DiscoveryNode in project crate by crate.

the class Transports method sendRequest.

public <TRequest extends TransportRequest, TResponse extends TransportResponse> void sendRequest(String action, String node, TRequest request, ActionListener<TResponse> listener, TransportResponseHandler<TResponse> handler, TransportRequestOptions options) {
    DiscoveryNode discoveryNode = clusterService.state().nodes().get(node);
    if (discoveryNode == null) {
        listener.onFailure(new IllegalArgumentException(String.format(Locale.ENGLISH, "node \"%s\" not found in cluster state!", node)));
        return;
    }
    transportService.sendRequest(discoveryNode, action, request, options, handler);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode)

Aggregations

DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)352 ClusterState (org.elasticsearch.cluster.ClusterState)83 ArrayList (java.util.ArrayList)82 Settings (org.elasticsearch.common.settings.Settings)79 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)74 IOException (java.io.IOException)69 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)52 HashMap (java.util.HashMap)45 ShardId (org.elasticsearch.index.shard.ShardId)45 HashSet (java.util.HashSet)43 List (java.util.List)41 TransportAddress (org.elasticsearch.common.transport.TransportAddress)41 CountDownLatch (java.util.concurrent.CountDownLatch)39 MockTransportService (org.elasticsearch.test.transport.MockTransportService)39 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)37 Map (java.util.Map)35 ExecutionException (java.util.concurrent.ExecutionException)35 Version (org.elasticsearch.Version)35 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 ClusterName (org.elasticsearch.cluster.ClusterName)30