Search in sources :

Example 1 with UsageListing

use of com.netflix.exhibitor.core.analyze.UsageListing in project exhibitor by soabase.

the class ExplorerResource method usageListing.

@POST
@Path("usage-listing")
@Consumes("application/json")
@Produces("text/plain")
public Response usageListing(UsageListingRequest usageListingRequest) throws Exception {
    context.getExhibitor().getLog().add(ActivityLog.Type.INFO, "Starting usage listing");
    final UsageListing usageListing = new UsageListing(context.getExhibitor(), usageListingRequest.getStartPath(), usageListingRequest.getMaxChildrenForTraversal());
    usageListing.generate();
    final PipedInputStream in = new PipedInputStream();
    final PipedOutputStream pipedOutputStream = new PipedOutputStream(in);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            PrintStream out = null;
            try {
                out = new PrintStream(pipedOutputStream);
                out.println("Path\tCreateDate\tChildQty\tDeepChildQty");
                Iterator<String> iterator = usageListing.getPaths();
                while (iterator.hasNext()) {
                    String path = iterator.next();
                    UsageListing.NodeEntry details = usageListing.getNodeDetails(path);
                    out.println(path + "\t" + details.getCreationDate() + "\t" + details.getDirectChildQty() + "\t" + details.getDeepChildQty());
                }
            } catch (Exception e) {
                context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "Generating usage listing", e);
            } finally {
                CloseableUtils.closeQuietly(out);
            }
        }
    });
    return Response.ok(in).header("content-disposition", "attachment; filename=listing_tab_delimited.txt").build();
}
Also used : PrintStream(java.io.PrintStream) Iterator(java.util.Iterator) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) KeeperException(org.apache.zookeeper.KeeperException) UsageListing(com.netflix.exhibitor.core.analyze.UsageListing)

Aggregations

UsageListing (com.netflix.exhibitor.core.analyze.UsageListing)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 PrintStream (java.io.PrintStream)1 Iterator (java.util.Iterator)1 KeeperException (org.apache.zookeeper.KeeperException)1