@Test public void testSimple() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo1"); table.addCell("bar1"); table.endRow(); table.startRow(); table.addCell("foo2"); table.addCell("bar2"); table.endRow(); // Check headers List<Table.Cell> headers = table.getHeaders(); assertEquals(2, headers.size()); assertEquals("foo", headers.get(0).value.toString()); assertEquals(2, headers.get(0).attr.size()); assertEquals("f", headers.get(0).attr.get("alias")); assertEquals("foo", headers.get(0).attr.get("desc")); assertEquals("bar", headers.get(1).value.toString()); assertEquals(2, headers.get(1).attr.size()); assertEquals("b", headers.get(1).attr.get("alias")); assertEquals("bar", headers.get(1).attr.get("desc")); // Check rows List<List<Table.Cell>> rows = table.getRows(); assertEquals(2, rows.size()); List<Table.Cell> row = rows.get(0); assertEquals("foo1", row.get(0).value.toString()); assertEquals("bar1", row.get(1).value.toString()); row = rows.get(1); assertEquals("foo2", row.get(0).value.toString()); assertEquals("bar2", row.get(1).value.toString()); // Check getAsMap Map<String, List<Table.Cell>> map = table.getAsMap(); assertEquals(2, map.size()); row = map.get("foo"); assertEquals("foo1", row.get(0).value.toString()); assertEquals("foo2", row.get(1).value.toString()); row = map.get("bar"); assertEquals("bar1", row.get(0).value.toString()); assertEquals("bar2", row.get(1).value.toString()); // Check getHeaderMap Map<String, Table.Cell> headerMap = table.getHeaderMap(); assertEquals(2, headerMap.size()); Table.Cell cell = headerMap.get("foo"); assertEquals("foo", cell.value.toString()); cell = headerMap.get("bar"); assertEquals("bar", cell.value.toString()); // Check findHeaderByName cell = table.findHeaderByName("foo"); assertEquals("foo", cell.value.toString()); cell = table.findHeaderByName("missing"); assertNull(cell); }
@Test public void testOnLessCellsThanDeclaredUnchecked() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo"); table.endRow(false); }
@Test(expected = IllegalStateException.class) public void testFailOnLessCellsThanDeclared() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo"); table.endRow(true); }
public Table addColumn(String headerName, String attrs, List<Object> values) { Table t = new Table(); t.startHeaders().addCell(headerName, attrs).endHeaders(); for (Object val : values) { t.startRow().addCell(val).endRow(); } return this.addTable(t); }
private Table buildTable(RestRequest request, ClusterStateResponse state) { Table table = getTableWithHeader(request); DiscoveryNodes nodes = state.getState().nodes(); table.startRow(); DiscoveryNode master = nodes.get(nodes.masterNodeId()); if (master == null) { table.addCell("-"); table.addCell("-"); table.addCell("-"); table.addCell("-"); } else { table.addCell(master.getId()); table.addCell(master.getHostName()); table.addCell(master.getHostAddress()); table.addCell(master.getName()); } table.endRow(); return table; }
public Table addTable(Table t2) { Table t1 = this; Table t = new Table(); t.startHeaders(); for (Cell c : t1.getHeaders()) { t.addCell(c); } for (Cell c : t2.getHeaders()) { t.addCell(c); } t.endHeaders(); if (t1.rows.size() != t2.rows.size()) { StringBuilder sb = new StringBuilder(); sb.append("cannot add a table with "); sb.append(t2.rows.size()); sb.append(" rows to table with "); sb.append(t1.rows.size()); sb.append(" rows"); throw new ElasticSearchIllegalArgumentException(sb.toString()); } for (int i = 0; i < t1.rows.size(); i++) { t.startRow(); for (Cell c : t1.rows.get(i)) { t.addCell(c); } for (Cell c : t2.rows.get(i)) { t.addCell(c); } t.endRow(false); } return t; }
private Table buildTable( RestRequest req, ClusterStateResponse state, NodesInfoResponse nodesInfo, NodesStatsResponse nodesStats) { boolean fullId = req.paramAsBoolean("full_id", false); 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()); JvmInfo jvmInfo = info == null ? null : info.getJvm(); JvmStats jvmStats = stats == null ? null : stats.getJvm(); FsInfo fsInfo = stats == null ? null : stats.getFs(); OsStats osStats = stats == null ? null : stats.getOs(); ProcessStats processStats = stats == null ? null : stats.getProcess(); NodeIndicesStats indicesStats = stats == null ? null : stats.getIndices(); table.startRow(); table.addCell(fullId ? node.id() : Strings.substring(node.getId(), 0, 4)); table.addCell(info == null ? null : info.getProcess().getId()); 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().shortHash()); table.addCell(jvmInfo == null ? null : jvmInfo.version()); table.addCell(fsInfo == null ? null : fsInfo.getTotal().getAvailable()); table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsed()); table.addCell(jvmStats == null ? null : jvmStats.getMem().getHeapUsedPercent()); table.addCell(jvmInfo == null ? null : jvmInfo.getMem().getHeapMax()); table.addCell( osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsed()); table.addCell( osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getUsedPercent()); table.addCell( osStats == null ? null : osStats.getMem() == null ? null : osStats.getMem().getTotal()); table.addCell(processStats == null ? null : processStats.getOpenFileDescriptors()); table.addCell( processStats == null ? null : calculatePercentage( processStats.getOpenFileDescriptors(), processStats.getMaxFileDescriptors())); table.addCell(processStats == null ? null : processStats.getMaxFileDescriptors()); table.addCell( osStats == null ? null : String.format(Locale.ROOT, "%.2f", osStats.getLoadAverage())); table.addCell(jvmStats == null ? null : jvmStats.getUptime()); table.addCell(node.clientNode() ? "c" : node.dataNode() ? "d" : "-"); table.addCell( masterId == null ? "x" : masterId.equals(node.id()) ? "*" : node.masterNode() ? "m" : "-"); table.addCell(node.name()); CompletionStats completionStats = indicesStats == null ? null : stats.getIndices().getCompletion(); table.addCell(completionStats == null ? null : completionStats.getSize()); FieldDataStats fdStats = indicesStats == null ? null : stats.getIndices().getFieldData(); table.addCell(fdStats == null ? null : fdStats.getMemorySize()); table.addCell(fdStats == null ? null : fdStats.getEvictions()); QueryCacheStats fcStats = indicesStats == null ? null : indicesStats.getQueryCache(); table.addCell(fcStats == null ? null : fcStats.getMemorySize()); table.addCell(fcStats == null ? null : fcStats.getEvictions()); RequestCacheStats qcStats = indicesStats == null ? null : indicesStats.getRequestCache(); table.addCell(qcStats == null ? null : qcStats.getMemorySize()); table.addCell(qcStats == null ? null : qcStats.getEvictions()); table.addCell(qcStats == null ? null : qcStats.getHitCount()); table.addCell(qcStats == null ? null : qcStats.getMissCount()); FlushStats flushStats = indicesStats == null ? null : indicesStats.getFlush(); table.addCell(flushStats == null ? null : flushStats.getTotal()); table.addCell(flushStats == null ? null : flushStats.getTotalTime()); GetStats getStats = indicesStats == null ? null : indicesStats.getGet(); table.addCell(getStats == null ? null : getStats.current()); table.addCell(getStats == null ? null : getStats.getTime()); table.addCell(getStats == null ? null : getStats.getCount()); table.addCell(getStats == null ? null : getStats.getExistsTime()); table.addCell(getStats == null ? null : getStats.getExistsCount()); table.addCell(getStats == null ? null : getStats.getMissingTime()); table.addCell(getStats == null ? null : getStats.getMissingCount()); IndexingStats indexingStats = indicesStats == null ? null : indicesStats.getIndexing(); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCurrent()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteTime()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getDeleteCount()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCurrent()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexTime()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexCount()); table.addCell(indexingStats == null ? null : indexingStats.getTotal().getIndexFailedCount()); MergeStats mergeStats = indicesStats == null ? null : indicesStats.getMerge(); table.addCell(mergeStats == null ? null : mergeStats.getCurrent()); table.addCell(mergeStats == null ? null : mergeStats.getCurrentNumDocs()); table.addCell(mergeStats == null ? null : mergeStats.getCurrentSize()); table.addCell(mergeStats == null ? null : mergeStats.getTotal()); table.addCell(mergeStats == null ? null : mergeStats.getTotalNumDocs()); table.addCell(mergeStats == null ? null : mergeStats.getTotalSize()); table.addCell(mergeStats == null ? null : mergeStats.getTotalTime()); PercolateStats percolateStats = indicesStats == null ? null : indicesStats.getPercolate(); table.addCell(percolateStats == null ? null : percolateStats.getCurrent()); table.addCell(percolateStats == null ? null : percolateStats.getMemorySize()); table.addCell(percolateStats == null ? null : percolateStats.getNumQueries()); table.addCell(percolateStats == null ? null : percolateStats.getTime()); table.addCell(percolateStats == null ? null : percolateStats.getCount()); RefreshStats refreshStats = indicesStats == null ? null : indicesStats.getRefresh(); table.addCell(refreshStats == null ? null : refreshStats.getTotal()); table.addCell(refreshStats == null ? null : refreshStats.getTotalTime()); ScriptStats scriptStats = stats == null ? null : stats.getScriptStats(); table.addCell(scriptStats == null ? null : scriptStats.getCompilations()); table.addCell(scriptStats == null ? null : scriptStats.getCacheEvictions()); SearchStats searchStats = indicesStats == null ? null : indicesStats.getSearch(); table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCurrent()); table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchTime()); table.addCell(searchStats == null ? null : searchStats.getTotal().getFetchCount()); table.addCell(searchStats == null ? null : searchStats.getOpenContexts()); table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCurrent()); table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryTime()); table.addCell(searchStats == null ? null : searchStats.getTotal().getQueryCount()); table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCurrent()); table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollTime()); table.addCell(searchStats == null ? null : searchStats.getTotal().getScrollCount()); SegmentsStats segmentsStats = indicesStats == null ? null : indicesStats.getSegments(); table.addCell(segmentsStats == null ? null : segmentsStats.getCount()); table.addCell(segmentsStats == null ? null : segmentsStats.getMemory()); table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMemory()); table.addCell(segmentsStats == null ? null : segmentsStats.getIndexWriterMaxMemory()); table.addCell(segmentsStats == null ? null : segmentsStats.getVersionMapMemory()); table.addCell(segmentsStats == null ? null : segmentsStats.getBitsetMemory()); SuggestStats suggestStats = indicesStats == null ? null : indicesStats.getSuggest(); table.addCell(suggestStats == null ? null : suggestStats.getCurrent()); table.addCell(suggestStats == null ? null : suggestStats.getTime()); table.addCell(suggestStats == null ? null : suggestStats.getCount()); table.endRow(); } return table; }
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); 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; }
@Test(expected = IllegalStateException.class) public void testFailOnStartRowWithoutHeader() { Table table = new Table(); table.startRow(); }