use of org.batfish.common.BatfishException in project batfish by batfish.
the class Batfish method loadParseEnvironmentBgpTablesAnswerElement.
private ParseEnvironmentBgpTablesAnswerElement loadParseEnvironmentBgpTablesAnswerElement(boolean firstAttempt) {
Path answerPath = _testrigSettings.getEnvironmentSettings().getParseEnvironmentBgpTablesAnswerPath();
if (!Files.exists(answerPath)) {
repairEnvironmentBgpTables();
}
ParseEnvironmentBgpTablesAnswerElement ae = deserializeObject(answerPath, ParseEnvironmentBgpTablesAnswerElement.class);
if (!Version.isCompatibleVersion("Service", "Old processed environment BGP tables", ae.getVersion())) {
if (firstAttempt) {
repairEnvironmentRoutingTables();
return loadParseEnvironmentBgpTablesAnswerElement(false);
} else {
throw new BatfishException("Version error repairing environment BGP tables for parse environment BGP tables " + "answer element");
}
} else {
return ae;
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class Batfish method loadDataPlaneAnswerElement.
private DataPlaneAnswerElement loadDataPlaneAnswerElement(boolean compressed, boolean firstAttempt) {
Path answerPath = compressed ? _testrigSettings.getEnvironmentSettings().getCompressedDataPlaneAnswerPath() : _testrigSettings.getEnvironmentSettings().getDataPlaneAnswerPath();
DataPlaneAnswerElement bae = deserializeObject(answerPath, DataPlaneAnswerElement.class);
if (!Version.isCompatibleVersion("Service", "Old data plane", bae.getVersion())) {
if (firstAttempt) {
repairDataPlane(compressed);
return loadDataPlaneAnswerElement(compressed, false);
} else {
throw new BatfishException("Version error repairing data plane for data plane answer element");
}
} else {
return bae;
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class Batfish method readIptableFiles.
/**
* Read Iptable Files for each host in the keyset of {@code hostConfigurations}, and store the
* contents in {@code iptablesDate}. Each task fails if the Iptable file specified by host is not
* under {@code testRigPath} or does not exist.
*
* @throws BatfishException if there is a failed task and either {@link
* Settings#getExitOnFirstError()} or {@link Settings#getHaltOnParseError()} is set.
*/
void readIptableFiles(Path testRigPath, SortedMap<String, VendorConfiguration> hostConfigurations, SortedMap<Path, String> iptablesData, ParseVendorConfigurationAnswerElement answerElement) {
List<BatfishException> failureCauses = new ArrayList<>();
for (VendorConfiguration vc : hostConfigurations.values()) {
HostConfiguration hostConfig = (HostConfiguration) vc;
if (hostConfig.getIptablesFile() != null) {
Path path = Paths.get(testRigPath.toString(), hostConfig.getIptablesFile());
// testrig
try {
if (!path.toFile().getCanonicalPath().contains(testRigPath.toFile().getCanonicalPath()) || !path.toFile().exists()) {
String failureMessage = String.format("Iptables file %s for host %s is not contained within the testrig", hostConfig.getIptablesFile(), hostConfig.getHostname());
BatfishException bfc;
if (answerElement.getErrors().containsKey(hostConfig.getHostname())) {
bfc = new BatfishException(failureMessage, answerElement.getErrors().get(hostConfig.getHostname()).getException());
answerElement.getErrors().put(hostConfig.getHostname(), bfc.getBatfishStackTrace());
} else {
bfc = new BatfishException(failureMessage);
if (_settings.getExitOnFirstError()) {
throw bfc;
} else {
failureCauses.add(bfc);
answerElement.getErrors().put(hostConfig.getHostname(), bfc.getBatfishStackTrace());
answerElement.getParseStatus().put(hostConfig.getHostname(), ParseStatus.FAILED);
}
}
} else {
String fileText = CommonUtil.readFile(path);
iptablesData.put(path, fileText);
}
} catch (IOException e) {
throw new BatfishException("Could not get canonical path", e);
}
}
}
if (_settings.getHaltOnParseError() && !failureCauses.isEmpty()) {
BatfishException e = new BatfishException("Fatal exception due to at least one Iptables file is" + " not contained within the testrig");
failureCauses.forEach(e::addSuppressed);
throw e;
}
}
use of org.batfish.common.BatfishException 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;
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class Batfish method loadConvertConfigurationAnswerElementOrReparse.
@Override
public ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse() {
ConvertConfigurationAnswerElement ccae = _storage.loadConvertConfigurationAnswerElement(_testrigSettings.getName());
if (ccae != null && Version.isCompatibleVersion("Service", "Old processed configurations", ccae.getVersion())) {
return ccae;
}
repairConfigurations();
ccae = _storage.loadConvertConfigurationAnswerElement(_testrigSettings.getName());
if (ccae != null && Version.isCompatibleVersion("Service", "Old processed configurations", ccae.getVersion())) {
return ccae;
} else {
throw new BatfishException("Version error repairing configurations for convert configuration answer element");
}
}
Aggregations