static void toXContent(XContentBuilder builder, Accountable tree) throws IOException { builder.startObject(); builder.field(Fields.DESCRIPTION, tree.toString()); builder.byteSizeField( Fields.SIZE_IN_BYTES, Fields.SIZE, new ByteSizeValue(tree.ramBytesUsed())); Collection<Accountable> children = tree.getChildResources(); if (children.isEmpty() == false) { builder.startArray(Fields.CHILDREN); for (Accountable child : children) { toXContent(builder, child); } builder.endArray(); } builder.endObject(); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.INDICES); for (IndexSegments indexSegments : getIndices().values()) { builder.startObject(indexSegments.getIndex(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject(Fields.SHARDS); for (IndexShardSegments indexSegment : indexSegments) { builder.startArray(Integer.toString(indexSegment.getShardId().id())); for (ShardSegments shardSegments : indexSegment) { builder.startObject(); builder.startObject(Fields.ROUTING); builder.field(Fields.STATE, shardSegments.getShardRouting().state()); builder.field(Fields.PRIMARY, shardSegments.getShardRouting().primary()); builder.field(Fields.NODE, shardSegments.getShardRouting().currentNodeId()); if (shardSegments.getShardRouting().relocatingNodeId() != null) { builder.field( Fields.RELOCATING_NODE, shardSegments.getShardRouting().relocatingNodeId()); } builder.endObject(); builder.field(Fields.NUM_COMMITTED_SEGMENTS, shardSegments.getNumberOfCommitted()); builder.field(Fields.NUM_SEARCH_SEGMENTS, shardSegments.getNumberOfSearch()); builder.startObject(Fields.SEGMENTS); for (Segment segment : shardSegments) { builder.startObject(segment.getName()); builder.field(Fields.GENERATION, segment.getGeneration()); builder.field(Fields.NUM_DOCS, segment.getNumDocs()); builder.field(Fields.DELETED_DOCS, segment.getDeletedDocs()); builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, segment.getSizeInBytes()); builder.byteSizeField( Fields.MEMORY_IN_BYTES, Fields.MEMORY, segment.getMemoryInBytes()); builder.field(Fields.COMMITTED, segment.isCommitted()); builder.field(Fields.SEARCH, segment.isSearch()); if (segment.getVersion() != null) { builder.field(Fields.VERSION, segment.getVersion()); } if (segment.isCompound() != null) { builder.field(Fields.COMPOUND, segment.isCompound()); } if (segment.getMergeId() != null) { builder.field(Fields.MERGE_ID, segment.getMergeId()); } if (segment.ramTree != null) { builder.startArray(Fields.RAM_TREE); for (Accountable child : segment.ramTree.getChildResources()) { toXContent(builder, child); } builder.endArray(); } builder.endObject(); } builder.endObject(); builder.endObject(); } builder.endArray(); } builder.endObject(); builder.endObject(); } builder.endObject(); return builder; }