use of org.apache.accumulo.monitor.rest.tservers.TabletServers in project accumulo by apache.
the class TablesResource method getParticipatingTabletServers.
/**
* Generates a list of participating tservers for a table
*
* @param tableIdStr
* Table ID to find participating tservers
* @return List of participating tservers
*/
@Path("{tableId}")
@GET
public TabletServers getParticipatingTabletServers(@PathParam("tableId") @NotNull @Pattern(regexp = ALPHA_NUM_REGEX_TABLE_ID) String tableIdStr) {
Instance instance = Monitor.getContext().getInstance();
Table.ID tableId = Table.ID.of(tableIdStr);
TabletServers tabletServers = new TabletServers(Monitor.getMmi().tServerInfo.size());
if (StringUtils.isBlank(tableIdStr)) {
return tabletServers;
}
TreeSet<String> locs = new TreeSet<>();
if (RootTable.ID.equals(tableId)) {
locs.add(instance.getRootTabletLocation());
} else {
String systemTableName = MetadataTable.ID.equals(tableId) ? RootTable.NAME : MetadataTable.NAME;
MetaDataTableScanner scanner = new MetaDataTableScanner(Monitor.getContext(), new Range(KeyExtent.getMetadataEntry(tableId, new Text()), KeyExtent.getMetadataEntry(tableId, null)), systemTableName);
while (scanner.hasNext()) {
TabletLocationState state = scanner.next();
if (state.current != null) {
try {
locs.add(state.current.hostPort());
} catch (Exception ex) {
scanner.close();
return tabletServers;
}
}
}
scanner.close();
}
List<TabletServerStatus> tservers = new ArrayList<>();
if (Monitor.getMmi() != null) {
for (TabletServerStatus tss : Monitor.getMmi().tServerInfo) {
try {
if (tss.name != null && locs.contains(tss.name))
tservers.add(tss);
} catch (Exception ex) {
return tabletServers;
}
}
}
// Adds tservers to the list
for (TabletServerStatus status : tservers) {
if (status == null)
status = NO_STATUS;
TableInfo summary = TableInfoUtil.summarizeTableStats(status);
if (tableId != null)
summary = status.tableMap.get(tableId.canonicalID());
if (summary == null)
continue;
TabletServer tabletServerInfo = new TabletServer();
tabletServerInfo.updateTabletServerInfo(status, summary);
tabletServers.addTablet(tabletServerInfo);
}
return tabletServers;
}
Aggregations