use of com.netflix.exhibitor.core.entities.PathAnalysis 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();
}
Aggregations