Search in sources :

Example 1 with PathAnalyzer

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

the class ExplorerResource method analyze.

@POST
@Path("analyze")
@Consumes("application/json")
@Produces("application/json")
public Response analyze(List<PathAnalysisRequest> paths) throws Exception {
    context.getExhibitor().getLog().add(ActivityLog.Type.INFO, "Starting analysis");
    List<PathAndMax> pathAndMaxes = Lists.transform(paths, new Function<PathAnalysisRequest, PathAndMax>() {

        @Override
        public PathAndMax apply(PathAnalysisRequest request) {
            return new PathAndMax(request.getPath(), request.getMax());
        }
    });
    PathAnalyzer analyzer = new PathAnalyzer(context.getExhibitor(), pathAndMaxes);
    Analysis analysis = analyzer.analyze();
    Iterable<PathAnalysisNode> transformed = Iterables.transform(analysis.getCompleteData(), new Function<PathComplete, PathAnalysisNode>() {

        @Override
        public PathAnalysisNode apply(PathComplete pathComplete) {
            return new PathAnalysisNode(pathComplete.getPath(), pathComplete.getMax(), pathComplete.getChildIds());
        }
    });
    Iterable<IdList> transformedPossibleCycles = Iterables.transform(analysis.getPossibleCycles(), new Function<Set<String>, IdList>() {

        @Override
        public IdList apply(Set<String> s) {
            return new IdList(Lists.newArrayList(s));
        }
    });
    String error = analysis.getError();
    PathAnalysis response;
    try {
        response = new PathAnalysis((error != null) ? error : "", Lists.newArrayList(transformed), Lists.newArrayList(transformedPossibleCycles));
    } catch (Exception e) {
        context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "Error performing analysis", e);
        throw e;
    }
    return Response.ok(response).header("content-disposition", "attachment; filename=analysis.txt").build();
}
Also used : PathAnalyzer(com.netflix.exhibitor.core.analyze.PathAnalyzer) PathComplete(com.netflix.exhibitor.core.analyze.PathComplete) Set(java.util.Set) PathAnalysisNode(com.netflix.exhibitor.core.entities.PathAnalysisNode) PathAndMax(com.netflix.exhibitor.core.analyze.PathAndMax) PathAnalysis(com.netflix.exhibitor.core.entities.PathAnalysis) IdList(com.netflix.exhibitor.core.entities.IdList) KeeperException(org.apache.zookeeper.KeeperException) PathAnalysis(com.netflix.exhibitor.core.entities.PathAnalysis) Analysis(com.netflix.exhibitor.core.analyze.Analysis) PathAnalysisRequest(com.netflix.exhibitor.core.entities.PathAnalysisRequest)

Aggregations

Analysis (com.netflix.exhibitor.core.analyze.Analysis)1 PathAnalyzer (com.netflix.exhibitor.core.analyze.PathAnalyzer)1 PathAndMax (com.netflix.exhibitor.core.analyze.PathAndMax)1 PathComplete (com.netflix.exhibitor.core.analyze.PathComplete)1 IdList (com.netflix.exhibitor.core.entities.IdList)1 PathAnalysis (com.netflix.exhibitor.core.entities.PathAnalysis)1 PathAnalysisNode (com.netflix.exhibitor.core.entities.PathAnalysisNode)1 PathAnalysisRequest (com.netflix.exhibitor.core.entities.PathAnalysisRequest)1 Set (java.util.Set)1 KeeperException (org.apache.zookeeper.KeeperException)1