use of org.batfish.datamodel.answers.RunAnalysisAnswerElement in project batfish by batfish.
the class Batfish method analyze.
private Answer analyze() {
Answer answer = new Answer();
AnswerSummary summary = new AnswerSummary();
String analysisName = _settings.getAnalysisName();
String containerName = _settings.getContainerDir().getFileName().toString();
Path analysisQuestionsDir = _settings.getContainerDir().resolve(Paths.get(BfConsts.RELPATH_ANALYSES_DIR, analysisName, BfConsts.RELPATH_QUESTIONS_DIR).toString());
if (!Files.exists(analysisQuestionsDir)) {
throw new BatfishException("Analysis questions dir does not exist: '" + analysisQuestionsDir + "'");
}
RunAnalysisAnswerElement ae = new RunAnalysisAnswerElement();
try (Stream<Path> questions = CommonUtil.list(analysisQuestionsDir)) {
questions.forEach(analysisQuestionDir -> {
String questionName = analysisQuestionDir.getFileName().toString();
Path analysisQuestionPath = analysisQuestionDir.resolve(BfConsts.RELPATH_QUESTION_FILE);
_settings.setQuestionPath(analysisQuestionPath);
Answer currentAnswer;
try (ActiveSpan analysisQuestionSpan = GlobalTracer.get().buildSpan(String.format("Getting answer to question %s from analysis %s", questionName, analysisName)).startActive()) {
// make span not show up as unused
assert analysisQuestionSpan != null;
currentAnswer = answer();
}
// Ensuring that question was parsed successfully
if (currentAnswer.getQuestion() != null) {
try {
// TODO: This can be represented much cleanly and easily with a Json
_logger.infof("Ran question:%s from analysis:%s in container:%s; work-id:%s, status:%s, " + "computed dataplane:%s, parameters:%s\n", questionName, analysisName, containerName, getTaskId(), currentAnswer.getSummary().getNumFailed() > 0 ? "failed" : "passed", currentAnswer.getQuestion().getDataPlane(), BatfishObjectMapper.writeString(currentAnswer.getQuestion().getInstance().getVariables()));
} catch (JsonProcessingException e) {
throw new BatfishException(String.format("Error logging question %s in analysis %s", questionName, analysisName), e);
}
}
initAnalysisQuestionPath(analysisName, questionName);
outputAnswer(currentAnswer);
ae.getAnswers().put(questionName, currentAnswer);
_settings.setQuestionPath(null);
summary.combine(currentAnswer.getSummary());
});
}
answer.addAnswerElement(ae);
answer.setSummary(summary);
return answer;
}
Aggregations