Package org.elasticsearch.action.admin.cluster.node.info

Examples of org.elasticsearch.action.admin.cluster.node.info.NodeInfo


    public List<NodeInfo> getAllNodes() {
        return Lists.newArrayList(c.admin().cluster().nodesInfo(new NodesInfoRequest().all()).actionGet().getNodes());
    }

    public String nodeIdToName(String nodeId) {
        final NodeInfo nodeInfo = getNodeInfo(nodeId);
        return nodeInfo == null ? "UNKNOWN" : nodeInfo.getNode().getName();

    }
View Full Code Here


        return nodeInfo == null ? "UNKNOWN" : nodeInfo.getNode().getName();

    }

    public String nodeIdToHostName(String nodeId) {
        final NodeInfo nodeInfo = getNodeInfo(nodeId);
        return nodeInfo == null ? "UNKNOWN" : nodeInfo.getHostname();
    }
View Full Code Here

public class NodePortExpressionTest {

    @Test
    public void testNoHttpServerAvailable() throws Exception {
        NodeService nodeService = mock(NodeService.class);
        NodeInfo nodeInfo = mock(NodeInfo.class);
        when(nodeService.info()).thenReturn(nodeInfo);
        when(nodeInfo.getHttp()).thenReturn(null);


        NodePortExpression nodePortExpression = new NodePortExpression(nodeService);
        Object value = nodePortExpression.getChildImplementation(NodePortExpression.HTTP).value();
        assertThat(value, Matchers.nullValue());
View Full Code Here

            ProcessStats processStats = mock(ProcessStats.class);
            when(nodeStats.getProcess()).thenReturn(processStats);
            when(processStats.getOpenFileDescriptors()).thenReturn(42L);

            NodeInfo nodeInfo = mock(NodeInfo.class);
            when(nodeService.info()).thenReturn(nodeInfo);

            ProcessInfo processInfo = mock(ProcessInfo.class);
            when(nodeInfo.getProcess()).thenReturn(processInfo);
            when(processInfo.getMaxFileDescriptors()).thenReturn(1000L);

            Discovery discovery = mock(Discovery.class);
            bind(Discovery.class).toInstance(discovery);
            when(discovery.localNode()).thenReturn(node);
            when(node.getId()).thenReturn("node-id-1");
            when(node.getName()).thenReturn("node 1");
            TransportAddress transportAddress = new InetSocketTransportAddress("localhost", 44300);
            when(node.address()).thenReturn(transportAddress);

            NetworkStats.Tcp tcp = mock(NetworkStats.Tcp.class, new Answer<Long>() {
                @Override
                public Long answer(InvocationOnMock invocation) throws Throwable {
                    return 42L;
                }
            });
            NetworkStats networkStats = mock(NetworkStats.class);
            when(networkStats.tcp()).thenReturn(tcp);
            NetworkService networkService = mock(NetworkService.class);
            when(networkService.stats()).thenReturn(networkStats);
            bind(NetworkService.class).toInstance(networkService);

            bind(NodeService.class).toInstance(nodeService);

            NodeEnvironment nodeEnv = mock(NodeEnvironment.class);
            File[] dataLocations = new File[]{ new File("/foo"), new File("/bar") };
            when(nodeEnv.hasNodeFile()).then(new Answer<Boolean>() {
                @Override
                public Boolean answer(InvocationOnMock invocation) throws Throwable {
                    return isDataNode;
                }
            });
            when(nodeEnv.nodeDataLocations()).thenReturn(dataLocations);
            bind(NodeEnvironment.class).toInstance(nodeEnv);

            Sigar sigar = mock(Sigar.class);
            SigarService sigarService = mock(SigarService.class);
            when(sigarService.sigarAvailable()).then(new Answer<Boolean>() {
                @Override
                public Boolean answer(InvocationOnMock invocation) throws Throwable {
                    return sigarAvailable;
                }
            });

            FileSystem fsFoo = mock(FileSystem.class);
            when(fsFoo.getDevName()).thenReturn("/dev/sda1");
            when(fsFoo.getDirName()).thenReturn("/foo");
            when(fsFoo.getType()).thenReturn(FileSystem.TYPE_LOCAL_DISK);

            FileSystem fsBar = mock(FileSystem.class);
            when(fsBar.getDevName()).thenReturn("/dev/sda2");
            when(fsBar.getDirName()).thenReturn("/bar");
            when(fsBar.getType()).thenReturn(FileSystem.TYPE_LOCAL_DISK);


            FileSystem fsFiltered = mock(FileSystem.class);
            when(fsFiltered.getType()).thenReturn(FileSystem.TYPE_UNKNOWN);
            when(fsFiltered.getDevName()).thenReturn(("/dev/filtered"));
            when(fsFiltered.getDirName()).thenReturn(("/filtered"));

            FileSystemMap map = mock(FileSystemMap.class);
            when(map.getMountPoint("/foo")).thenReturn(fsFoo);
            when(map.getMountPoint("/bar")).thenReturn(fsBar);
            when(map.getMountPoint("/filtered")).thenReturn(fsFiltered);
            FileSystemUsage usage = mock(FileSystemUsage.class, new Answer<Long>() {
                @Override
                public Long answer(InvocationOnMock invocation) throws Throwable {
                    return 42L;
                }
            });

            try {
                when(sigar.getFileSystemList()).thenReturn(new FileSystem[]{fsFoo, fsBar, fsFiltered});
                when(sigar.getFileSystemMap()).thenReturn(map);
                when(sigar.getFileSystemUsage(anyString())).thenReturn(usage);
                assertThat(sigar.getFileSystemUsage("/"), is(usage));
            } catch (SigarException e) {
                e.printStackTrace();
            }
            when(sigarService.sigar()).thenReturn(sigar);
            bind(SigarService.class).toInstance(sigarService);
            try {
                assertThat(sigarService.sigar().getFileSystemMap(), is(map));
            } catch (SigarException e) {
                e.printStackTrace();
            }

            HttpInfo httpInfo = mock(HttpInfo.class);
            when(nodeInfo.getHttp()).thenReturn(httpInfo);
            BoundTransportAddress boundTransportAddress = new BoundTransportAddress(
                    new InetSocketTransportAddress("localhost", 44200),
                    new InetSocketTransportAddress("localhost", 44200)
            );
            when(httpInfo.address()).thenReturn(boundTransportAddress);
View Full Code Here

        boolean fullId = req.paramAsBoolean("full_id", false);
        DiscoveryNodes nodes = state.getState().nodes();
        Table table = getTableWithHeader(req);

        for (DiscoveryNode node : nodes) {
            NodeInfo info = nodesInfo.getNodesMap().get(node.id());
            NodeStats stats = nodesStats.getNodesMap().get(node.id());
            table.startRow();

            table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
            table.addCell(info == null ? null : info.getProcess().id());
            table.addCell(node.getHostName());
            table.addCell(node.getHostAddress());
            if (node.address() instanceof InetSocketTransportAddress) {
                table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
            } else {
                table.addCell("-");
            }

            final Map<String, ThreadPoolStats.Stats> poolThreadStats;
            final Map<String, ThreadPool.Info> poolThreadInfo;

            if (stats == null) {
                poolThreadStats = Collections.emptyMap();
                poolThreadInfo = Collections.emptyMap();
            } else {
                poolThreadStats = new HashMap<>(14);
                poolThreadInfo = new HashMap<>(14);

                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 (String pool : SUPPORTED_NAMES) {
View Full Code Here

    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.id());

            for (PluginInfo pluginInfo : info.getPlugins().getInfos()) {
                table.startRow();
                table.addCell(node.name());
                table.addCell(pluginInfo.getName());
                table.addCell(pluginInfo.getVersion());
                String type;
View Full Code Here

        DiscoveryNodes nodes = state.getState().nodes();
        String masterId = nodes.masterNodeId();
        Table table = getTableWithHeader(req);

        for (DiscoveryNode node : nodes) {
            NodeInfo info = nodesInfo.getNodesMap().get(node.id());
            NodeStats stats = nodesStats.getNodesMap().get(node.id());

            table.startRow();

            table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4));
            table.addCell(info == null ? null : info.getProcess().id());
            table.addCell(node.getHostName());
            table.addCell(node.getHostAddress());
            if (node.address() instanceof InetSocketTransportAddress) {
                table.addCell(((InetSocketTransportAddress) node.address()).address().getPort());
            } else {
                table.addCell("-");
            }

            table.addCell(node.getVersion().number());
            table.addCell(info == null ? null : info.getBuild().hashShort());
            table.addCell(info == null ? null : info.getJvm().version());
            table.addCell(stats == null ? null : stats.getFs() == null ? null : stats.getFs().total().getAvailable());
            table.addCell(stats == null ? null : stats.getJvm().getMem().getHeapUsed());
            table.addCell(stats == null ? null : stats.getJvm().getMem().getHeapUsedPrecent());
            table.addCell(info == null ? null : info.getJvm().getMem().getHeapMax());
            table.addCell(stats == null ? null : stats.getOs().mem() == null ? null : stats.getOs().mem().used());
            table.addCell(stats == null ? null : stats.getOs().mem() == null ? null : stats.getOs().mem().usedPercent());
            table.addCell(info == null ? null : info.getOs().mem() == null ? null : info.getOs().mem().total()); // sigar fails to load in IntelliJ
            table.addCell(stats == null ? null : stats.getProcess().getOpenFileDescriptors());
            table.addCell(stats == null || info == null ? null :
                          calculatePercentage(stats.getProcess().getOpenFileDescriptors(), info.getProcess().getMaxFileDescriptors()));
            table.addCell(info == null ? null : info.getProcess().getMaxFileDescriptors());

            table.addCell(stats == null ? null : stats.getOs() == null ? null : stats.getOs().getLoadAverage().length < 1 ? null : String.format(Locale.ROOT, "%.2f", stats.getOs().getLoadAverage()[0]));
            table.addCell(stats == null ? null : stats.getJvm().uptime());
            table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : "-");
            table.addCell(masterId == null ? "x" : masterId.equals(node.id()) ? "*" : node.masterNode() ? "m" : "-");
View Full Code Here

    public void sendRequest(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) throws IOException, TransportException {

        //we make sure that nodes get added to the connected ones when calling addTransportAddress, by returning proper nodes info
        if (connectMode) {
            TransportResponseHandler transportResponseHandler = transportServiceAdapter.remove(requestId);
            NodeInfo nodeInfo = new NodeInfo(Version.CURRENT, Build.CURRENT, node, null, null, null, null, null, null, null, null, null, null);
            NodesInfoResponse nodesInfoResponse = new NodesInfoResponse(ClusterName.DEFAULT, new NodeInfo[]{nodeInfo});
            transportResponseHandler.handleResponse(nodesInfoResponse);
            return;
        }
View Full Code Here

    public ImmutableMap<String, String> attributes() {
        return this.serviceAttributes;
    }

    public NodeInfo info() {
        return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes,
                settings,
                monitorService.osService().info(),
                monitorService.processService().info(),
                monitorService.jvmService().info(),
                threadPool.info(),
View Full Code Here

        );
    }

    public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean threadPool,
                         boolean network, boolean transport, boolean http, boolean plugin) {
        return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes,
                settings ? this.settings : null,
                os ? monitorService.osService().info() : null,
                process ? monitorService.processService().info() : null,
                jvm ? monitorService.jvmService().info() : null,
                threadPool ? this.threadPool.info() : null,
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.cluster.node.info.NodeInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.