use of org.batfish.common.BatfishException.BatfishStackTrace in project batfish by batfish.
the class Batfish method mergeInitStepAnswer.
private void mergeInitStepAnswer(InitInfoAnswerElement initInfoAnswerElement, InitStepAnswerElement initStepAnswerElement, boolean summary, boolean verboseError) {
if (!summary) {
if (verboseError) {
SortedMap<String, List<BatfishStackTrace>> errors = initInfoAnswerElement.getErrors();
initStepAnswerElement.getErrors().forEach((hostname, initStepErrors) -> {
errors.computeIfAbsent(hostname, k -> new ArrayList<>()).add(initStepErrors);
});
}
SortedMap<String, Warnings> warnings = initInfoAnswerElement.getWarnings();
initStepAnswerElement.getWarnings().forEach((hostname, initStepWarnings) -> {
Warnings combined = warnings.computeIfAbsent(hostname, h -> buildWarnings(_settings));
combined.getPedanticWarnings().addAll(initStepWarnings.getPedanticWarnings());
combined.getRedFlagWarnings().addAll(initStepWarnings.getRedFlagWarnings());
combined.getUnimplementedWarnings().addAll(initStepWarnings.getUnimplementedWarnings());
});
}
}
use of org.batfish.common.BatfishException.BatfishStackTrace in project batfish by batfish.
the class InitInfoAnswerElement method prettyPrint.
@Override
public String prettyPrint() {
final StringBuilder sb = new StringBuilder();
int pedanticCount = 0;
int redFlagCount = 0;
int unimplementedCount = 0;
int emptyCount = 0;
int failedCount = 0;
int ignoredCount = 0;
int orphanedCount = 0;
int passedCount = 0;
int unknownCount = 0;
int unrecognizedCount = 0;
int unsupportedCount = 0;
if (!_warnings.isEmpty()) {
sb.append("DETAILED WARNINGS\n");
for (String name : _warnings.keySet()) {
sb.append(" " + name + ":\n");
for (Warning warning : _warnings.get(name).getRedFlagWarnings()) {
sb.append(" RedFlag " + warning.getTag() + " : " + warning.getText() + "\n");
redFlagCount++;
}
for (Warning warning : _warnings.get(name).getUnimplementedWarnings()) {
sb.append(" Unimplemented " + warning.getTag() + " : " + warning.getText() + "\n");
unimplementedCount++;
}
for (Warning warning : _warnings.get(name).getPedanticWarnings()) {
sb.append(" Pedantic " + warning.getTag() + " : " + warning.getText() + "\n");
pedanticCount++;
}
}
}
sb.append("PARSING SUMMARY\n");
for (Entry<String, ParseStatus> e : _parseStatus.entrySet()) {
String hostname = e.getKey();
ParseStatus status = e.getValue();
switch(status) {
case FAILED:
sb.append(" " + hostname + ": failed to parse\n");
failedCount++;
break;
case PARTIALLY_UNRECOGNIZED:
sb.append(" " + hostname + ": contained at least one unrecognized line\n");
unrecognizedCount++;
break;
case PASSED:
passedCount++;
break;
case EMPTY:
sb.append(" " + hostname + ": empty file\n");
emptyCount++;
break;
case IGNORED:
sb.append(" " + hostname + ": explicitly ignored by user\n");
ignoredCount++;
break;
case ORPHANED:
sb.append(" " + hostname + ": is an orphaned overlay configuration\n");
orphanedCount++;
break;
case UNKNOWN:
sb.append(" " + hostname + ": unknown configuration format\n");
unknownCount++;
break;
case UNSUPPORTED:
sb.append(" " + hostname + ": known but unsupported configuration format\n");
unsupportedCount++;
break;
default:
break;
}
}
if (!_errors.isEmpty()) {
sb.append("DETAILED ERRORS\n");
for (String name : _errors.keySet()) {
sb.append(" Failed to parse " + name + ":\n");
for (BatfishStackTrace stackTrace : _errors.get(name)) {
for (String line : stackTrace.getLineMap()) {
sb.append(" " + line + "\n");
}
}
}
}
sb.append("STATISTICS\n");
if (!_warnings.isEmpty()) {
sb.append(" Total warnings:\n");
if (redFlagCount > 0) {
sb.append(" Red Flag: " + redFlagCount + "\n");
}
if (unimplementedCount > 0) {
sb.append(" Unimplemented: " + unimplementedCount + "\n");
}
if (pedanticCount > 0) {
sb.append(" Pedantic: " + pedanticCount + "\n");
}
}
sb.append(" Parsing results:\n");
if (passedCount > 0) {
sb.append(" Parsed successfully: " + passedCount + "\n");
}
if (unrecognizedCount > 0) {
sb.append(" Contained unrecognized line(s): " + unrecognizedCount + "\n");
}
if (emptyCount > 0) {
sb.append(" Empty file: " + emptyCount + "\n");
}
if (ignoredCount > 0) {
sb.append(" Explicitly ignored by user: " + ignoredCount + "\n");
}
if (orphanedCount > 0) {
sb.append(" Is an orphaned overlay configuration: " + orphanedCount + "\n");
}
if (failedCount > 0) {
sb.append(" Failed to parse: " + failedCount + "\n");
}
if (unknownCount > 0) {
sb.append(" Unknown configuration format: " + unknownCount + "\n");
}
if (unsupportedCount > 0) {
sb.append(" Known but unsupported configuration format: " + unsupportedCount + "\n");
}
return sb.toString();
}
use of org.batfish.common.BatfishException.BatfishStackTrace in project batfish by batfish.
the class InitInfoAnswerElementTest method testPrettyPrint.
@Test
public void testPrettyPrint() {
String errorMessage = "message is: parser: SampleParser: line 50, sample error\n";
BatfishException exception = new BatfishException(errorMessage);
BatfishStackTrace stackTrace = new BatfishStackTrace(exception);
List<BatfishStackTrace> errors = new ArrayList<>();
errors.add(stackTrace);
_element.getErrors().put("sampleError", errors);
StringBuilder expected = new StringBuilder();
expected.append("PARSING SUMMARY\n");
expected.append("DETAILED ERRORS\n");
for (BatfishStackTrace trace : _element.getErrors().get("sampleError")) {
expected.append(" Failed to parse sampleError:\n");
for (String line : trace.getLineMap()) {
expected.append(" " + line + "\n");
}
}
expected.append("STATISTICS\n");
expected.append(" Parsing results:\n");
assertThat(_element.prettyPrint(), equalTo(expected.toString()));
}
use of org.batfish.common.BatfishException.BatfishStackTrace in project batfish by batfish.
the class ParseVendorConfigurationAnswerElementTest method testGetErrors.
@Test
public void testGetErrors() {
BatfishException exception = new BatfishException("sample exception");
BatfishStackTrace stackTrace = new BatfishStackTrace(exception);
_element.getErrors().put("error", stackTrace);
assertThat(_element.getErrors().get("error"), is(stackTrace));
}
use of org.batfish.common.BatfishException.BatfishStackTrace in project batfish by batfish.
the class ParseVendorConfigurationAnswerElementTest method testPrettyPrint.
@Test
public void testPrettyPrint() {
BatfishException exception = new BatfishException("sample exception");
BatfishStackTrace stackTrace = new BatfishStackTrace(exception);
_element.getErrors().put("sampleError", stackTrace);
StringBuilder expected = new StringBuilder();
expected.append("Results of parsing vendor configurations\n");
expected.append("\n sampleError[Parser errors]\n");
for (String line : _element.getErrors().get("sampleError").getLineMap()) {
expected.append(" " + line + "\n");
}
assertThat(_element.prettyPrint(), equalTo(expected.toString()));
}
Aggregations