Search in sources :

Example 91 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.

the class RestThreadPoolAction method buildTable.

private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) {
    final String[] threadPools = req.paramAsStringArray("thread_pool_patterns", new String[] { "*" });
    final DiscoveryNodes nodes = state.getState().nodes();
    final Table table = getTableWithHeader(req);
    // collect all thread pool names that we see across the nodes
    final Set<String> candidates = new HashSet<>();
    for (final NodeStats nodeStats : nodesStats.getNodes()) {
        for (final ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) {
            candidates.add(threadPoolStats.getName());
        }
    }
    // collect all thread pool names that match the specified thread pool patterns
    final Set<String> included = new HashSet<>();
    for (final String candidate : candidates) {
        if (Regex.simpleMatch(threadPools, candidate)) {
            included.add(candidate);
        }
    }
    for (final DiscoveryNode node : nodes) {
        final NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
        final NodeStats stats = nodesStats.getNodesMap().get(node.getId());
        final Map<String, ThreadPoolStats.Stats> poolThreadStats;
        final Map<String, ThreadPool.Info> poolThreadInfo;
        if (stats == null) {
            poolThreadStats = Collections.emptyMap();
            poolThreadInfo = Collections.emptyMap();
        } else {
            // we use a sorted map to ensure that thread pools are sorted by name
            poolThreadStats = new TreeMap<>();
            poolThreadInfo = new HashMap<>();
            ThreadPoolStats threadPoolStats = stats.getThreadPool();
            for (ThreadPoolStats.Stats threadPoolStat : threadPoolStats) {
                poolThreadStats.put(threadPoolStat.getName(), threadPoolStat);
            }
            if (info != null) {
                for (ThreadPool.Info threadPoolInfo : info.getThreadPool()) {
                    poolThreadInfo.put(threadPoolInfo.getName(), threadPoolInfo);
                }
            }
        }
        for (Map.Entry<String, ThreadPoolStats.Stats> entry : poolThreadStats.entrySet()) {
            if (!included.contains(entry.getKey()))
                continue;
            table.startRow();
            table.addCell(node.getName());
            table.addCell(node.getId());
            table.addCell(node.getEphemeralId());
            table.addCell(info == null ? null : info.getProcess().getId());
            table.addCell(node.getHostName());
            table.addCell(node.getHostAddress());
            table.addCell(node.getAddress().address().getPort());
            final ThreadPoolStats.Stats poolStats = entry.getValue();
            final ThreadPool.Info poolInfo = poolThreadInfo.get(entry.getKey());
            Long maxQueueSize = null;
            String keepAlive = null;
            Integer minThreads = null;
            Integer maxThreads = null;
            if (poolInfo != null) {
                if (poolInfo.getQueueSize() != null) {
                    maxQueueSize = poolInfo.getQueueSize().singles();
                }
                if (poolInfo.getKeepAlive() != null) {
                    keepAlive = poolInfo.getKeepAlive().toString();
                }
                if (poolInfo.getMin() >= 0) {
                    minThreads = poolInfo.getMin();
                }
                if (poolInfo.getMax() >= 0) {
                    maxThreads = poolInfo.getMax();
                }
            }
            table.addCell(entry.getKey());
            table.addCell(poolInfo == null ? null : poolInfo.getThreadPoolType().getType());
            table.addCell(poolStats == null ? null : poolStats.getActive());
            table.addCell(poolStats == null ? null : poolStats.getThreads());
            table.addCell(poolStats == null ? null : poolStats.getQueue());
            table.addCell(maxQueueSize == null ? -1 : maxQueueSize);
            table.addCell(poolStats == null ? null : poolStats.getRejected());
            table.addCell(poolStats == null ? null : poolStats.getLargest());
            table.addCell(poolStats == null ? null : poolStats.getCompleted());
            table.addCell(minThreads);
            table.addCell(maxThreads);
            table.addCell(keepAlive);
            table.endRow();
        }
    }
    return table;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Table(org.elasticsearch.common.Table) ThreadPool(org.elasticsearch.threadpool.ThreadPool) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet)

Example 92 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.

the class RestPluginsAction method buildTable.

private Table buildTable(RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo) {
    DiscoveryNodes nodes = state.getState().nodes();
    Table table = getTableWithHeader(req);
    for (DiscoveryNode node : nodes) {
        NodeInfo info = nodesInfo.getNodesMap().get(node.getId());
        for (PluginInfo pluginInfo : info.getPlugins().getPluginInfos()) {
            table.startRow();
            table.addCell(node.getId());
            table.addCell(node.getName());
            table.addCell(pluginInfo.getName());
            table.addCell(pluginInfo.getVersion());
            table.addCell(pluginInfo.getDescription());
            table.endRow();
        }
    }
    return table;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Table(org.elasticsearch.common.Table) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) PluginInfo(org.elasticsearch.plugins.PluginInfo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 93 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.

the class RestTasksAction method buildGroups.

private void buildGroups(Table table, boolean fullId, boolean detailed, List<TaskGroup> taskGroups) {
    DiscoveryNodes discoveryNodes = nodesInCluster.get();
    List<TaskGroup> sortedGroups = new ArrayList<>(taskGroups);
    sortedGroups.sort((o1, o2) -> Long.compare(o1.getTaskInfo().getStartTime(), o2.getTaskInfo().getStartTime()));
    for (TaskGroup taskGroup : sortedGroups) {
        buildRow(table, fullId, detailed, discoveryNodes, taskGroup.getTaskInfo());
        buildGroups(table, fullId, detailed, taskGroup.getChildTasks());
    }
}
Also used : ArrayList(java.util.ArrayList) TaskGroup(org.elasticsearch.action.admin.cluster.node.tasks.list.TaskGroup) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 94 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.

the class ClusterStateTests method testSupersedes.

public void testSupersedes() {
    final Version version = Version.CURRENT;
    final DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    final DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version);
    final DiscoveryNodes nodes = DiscoveryNodes.builder().add(node1).add(node2).build();
    ClusterName name = ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY);
    ClusterState noMaster1 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build();
    ClusterState noMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(nodes).build();
    ClusterState withMaster1a = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build();
    ClusterState withMaster1b = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node1.getId())).build();
    ClusterState withMaster2 = ClusterState.builder(name).version(randomInt(5)).nodes(DiscoveryNodes.builder(nodes).masterNodeId(node2.getId())).build();
    // states with no master should never supersede anything
    assertFalse(noMaster1.supersedes(noMaster2));
    assertFalse(noMaster1.supersedes(withMaster1a));
    // states should never supersede states from another master
    assertFalse(withMaster1a.supersedes(withMaster2));
    assertFalse(withMaster1a.supersedes(noMaster1));
    // state from the same master compare by version
    assertThat(withMaster1a.supersedes(withMaster1b), equalTo(withMaster1a.version() > withMaster1b.version()));
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Version(org.elasticsearch.Version) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 95 with DiscoveryNodes

use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.

the class DiscoveryWithServiceDisruptionsIT method testClusterJoinDespiteOfPublishingIssues.

/**
     * Test cluster join with issues in cluster state publishing *
     */
public void testClusterJoinDespiteOfPublishingIssues() throws Exception {
    List<String> nodes = startCluster(2, 1);
    String masterNode = internalCluster().getMasterName();
    String nonMasterNode;
    if (masterNode.equals(nodes.get(0))) {
        nonMasterNode = nodes.get(1);
    } else {
        nonMasterNode = nodes.get(0);
    }
    DiscoveryNodes discoveryNodes = internalCluster().getInstance(ClusterService.class, nonMasterNode).state().nodes();
    TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.getMasterNode().getName());
    logger.info("blocking requests from non master [{}] to master [{}]", nonMasterNode, masterNode);
    MockTransportService nonMasterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nonMasterNode);
    nonMasterTransportService.addFailToSendNoConnectRule(masterTranspotService);
    assertNoMaster(nonMasterNode);
    logger.info("blocking cluster state publishing from master [{}] to non master [{}]", masterNode, nonMasterNode);
    MockTransportService masterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, masterNode);
    TransportService localTransportService = internalCluster().getInstance(TransportService.class, discoveryNodes.getLocalNode().getName());
    if (randomBoolean()) {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublishClusterStateAction.SEND_ACTION_NAME);
    } else {
        masterTransportService.addFailToSendNoConnectRule(localTransportService, PublishClusterStateAction.COMMIT_ACTION_NAME);
    }
    logger.info("allowing requests from non master [{}] to master [{}], waiting for two join request", nonMasterNode, masterNode);
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    nonMasterTransportService.addDelegate(masterTranspotService, new MockTransportService.DelegateTransport(nonMasterTransportService.original()) {

        @Override
        protected void sendRequest(Connection connection, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException {
            if (action.equals(MembershipAction.DISCOVERY_JOIN_ACTION_NAME)) {
                countDownLatch.countDown();
            }
            super.sendRequest(connection, requestId, action, request, options);
        }

        @Override
        public Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws IOException {
            return super.openConnection(node, profile);
        }
    });
    countDownLatch.await();
    logger.info("waiting for cluster to reform");
    masterTransportService.clearRule(localTransportService);
    nonMasterTransportService.clearRule(localTransportService);
    ensureStableCluster(2);
    // shutting down the nodes, to avoid the leakage check tripping
    // on the states associated with the commit requests we may have dropped
    internalCluster().stopRandomNonMasterNode();
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) TransportRequest(org.elasticsearch.transport.TransportRequest) MockTransportService(org.elasticsearch.test.transport.MockTransportService) ConnectionProfile(org.elasticsearch.transport.ConnectionProfile) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) TransportService(org.elasticsearch.transport.TransportService) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Aggregations

DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)129 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)74 ClusterState (org.elasticsearch.cluster.ClusterState)45 Settings (org.elasticsearch.common.settings.Settings)37 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)27 HashSet (java.util.HashSet)25 List (java.util.List)24 Map (java.util.Map)23 TransportService (org.elasticsearch.transport.TransportService)23 Version (org.elasticsearch.Version)22 HashMap (java.util.HashMap)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)20 Set (java.util.Set)19 TransportException (org.elasticsearch.transport.TransportException)19 Collections (java.util.Collections)18 ThreadPool (org.elasticsearch.threadpool.ThreadPool)18 CountDownLatch (java.util.concurrent.CountDownLatch)16 Collectors (java.util.stream.Collectors)16