Search in sources :

Example 11 with BatfishStackTrace

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());
        });
    }
}
Also used : JuniperFlattener(org.batfish.grammar.juniper.JuniperFlattener) TreeMultiSet(org.batfish.datamodel.collections.TreeMultiSet) BfConsts(org.batfish.common.BfConsts) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) Topology(org.batfish.datamodel.Topology) Map(java.util.Map) RoutesByVrf(org.batfish.datamodel.collections.RoutesByVrf) Pair(org.batfish.common.Pair) Path(java.nio.file.Path) TopologyExtractor(org.batfish.grammar.topology.TopologyExtractor) ConfigurationFormat(org.batfish.datamodel.ConfigurationFormat) GenericConfigObject(org.batfish.datamodel.GenericConfigObject) AnswerSummary(org.batfish.datamodel.answers.AnswerSummary) ReachabilityQuerySynthesizer(org.batfish.z3.ReachabilityQuerySynthesizer) AssertionCombinedParser(org.batfish.grammar.assertion.AssertionCombinedParser) ParseEnvironmentBgpTableJob(org.batfish.job.ParseEnvironmentBgpTableJob) Serializable(java.io.Serializable) Environment(org.batfish.datamodel.pojo.Environment) AssertionExtractor(org.batfish.grammar.assertion.AssertionExtractor) Stream(java.util.stream.Stream) NamedStructureEquivalenceSets(org.batfish.datamodel.collections.NamedStructureEquivalenceSets) RoleQuestion(org.batfish.datamodel.questions.smt.RoleQuestion) BatfishCompressor(org.batfish.symbolic.abstraction.BatfishCompressor) CoordConsts(org.batfish.common.CoordConsts) AssertionContext(org.batfish.grammar.assertion.AssertionParser.AssertionContext) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) AnswerElement(org.batfish.datamodel.answers.AnswerElement) JuniperCombinedParser(org.batfish.grammar.juniper.JuniperCombinedParser) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) InitInfoAnswerElement(org.batfish.datamodel.answers.InitInfoAnswerElement) QuerySynthesizer(org.batfish.z3.QuerySynthesizer) NodJob(org.batfish.z3.NodJob) RipNeighbor(org.batfish.datamodel.RipNeighbor) SerializationUtils(org.apache.commons.lang3.SerializationUtils) HostConfiguration(org.batfish.representation.host.HostConfiguration) AclLine(org.batfish.z3.AclLine) DataPlanePlugin(org.batfish.common.plugin.DataPlanePlugin) ParseStatus(org.batfish.datamodel.answers.ParseStatus) Lists(com.google.common.collect.Lists) RunAnalysisAnswerElement(org.batfish.datamodel.answers.RunAnalysisAnswerElement) DeviceType(org.batfish.datamodel.DeviceType) AclReachabilityQuerySynthesizer(org.batfish.z3.AclReachabilityQuerySynthesizer) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Directory(org.batfish.common.Directory) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) IOException(java.io.IOException) InterfaceType(org.batfish.datamodel.InterfaceType) ReachabilitySettings(org.batfish.datamodel.questions.ReachabilitySettings) JSONArray(org.codehaus.jettison.json.JSONArray) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier) AnswerStatus(org.batfish.datamodel.answers.AnswerStatus) ExecutionException(java.util.concurrent.ExecutionException) ParseEnvironmentRoutingTableJob(org.batfish.job.ParseEnvironmentRoutingTableJob) BlacklistDstIpQuerySynthesizer(org.batfish.z3.BlacklistDstIpQuerySynthesizer) CleanBatfishException(org.batfish.common.CleanBatfishException) TreeMap(java.util.TreeMap) JSONException(org.codehaus.jettison.json.JSONException) Snapshot(org.batfish.common.Snapshot) IpsecVpn(org.batfish.datamodel.IpsecVpn) SortedSet(java.util.SortedSet) DataPlaneAnswerElement(org.batfish.datamodel.answers.DataPlaneAnswerElement) BiFunction(java.util.function.BiFunction) FlowTrace(org.batfish.datamodel.FlowTrace) BgpTableFormat(org.batfish.grammar.BgpTableFormat) FlowHistory(org.batfish.datamodel.FlowHistory) Edge(org.batfish.datamodel.Edge) ForwardingAnalysisImpl(org.batfish.datamodel.ForwardingAnalysisImpl) OspfProcess(org.batfish.datamodel.OspfProcess) Collectors.toMap(java.util.stream.Collectors.toMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PropertyChecker(org.batfish.symbolic.smt.PropertyChecker) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) NodFirstUnsatJob(org.batfish.z3.NodFirstUnsatJob) VyosFlattener(org.batfish.grammar.vyos.VyosFlattener) Vrf(org.batfish.datamodel.Vrf) ImmutableSet(com.google.common.collect.ImmutableSet) ParseVendorConfigurationJob(org.batfish.job.ParseVendorConfigurationJob) RipProcess(org.batfish.datamodel.RipProcess) StandardReachabilityQuerySynthesizer(org.batfish.z3.StandardReachabilityQuerySynthesizer) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InferRoles(org.batfish.role.InferRoles) AclLinesAnswerElement(org.batfish.datamodel.answers.AclLinesAnswerElement) ParseEnvironmentRoutingTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentRoutingTablesAnswerElement) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) Settings(org.batfish.config.Settings) BatfishCombinedParser(org.batfish.grammar.BatfishCombinedParser) Entry(java.util.Map.Entry) BatfishJobExecutor(org.batfish.job.BatfishJobExecutor) Ip(org.batfish.datamodel.Ip) NodeInterfacePair(org.batfish.datamodel.collections.NodeInterfacePair) ForwardingAnalysis(org.batfish.datamodel.ForwardingAnalysis) BatfishException(org.batfish.common.BatfishException) IpAccessList(org.batfish.datamodel.IpAccessList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) TestrigSettings(org.batfish.config.Settings.TestrigSettings) BgpAdvertisementsByVrf(org.batfish.datamodel.collections.BgpAdvertisementsByVrf) ImmutableList(com.google.common.collect.ImmutableList) Version(org.batfish.common.Version) BatfishObjectMapper(org.batfish.common.util.BatfishObjectMapper) NamedStructureEquivalenceSet(org.batfish.datamodel.collections.NamedStructureEquivalenceSet) Configuration(org.batfish.datamodel.Configuration) ComputeDataPlaneResult(org.batfish.common.plugin.DataPlanePlugin.ComputeDataPlaneResult) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) Nonnull(javax.annotation.Nonnull) ConvertConfigurationJob(org.batfish.job.ConvertConfigurationJob) Answerer(org.batfish.common.Answerer) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) NodAnswerElement(org.batfish.datamodel.answers.NodAnswerElement) NodFirstUnsatAnswerElement(org.batfish.datamodel.answers.NodFirstUnsatAnswerElement) InitStepAnswerElement(org.batfish.datamodel.answers.InitStepAnswerElement) NodSatAnswerElement(org.batfish.datamodel.answers.NodSatAnswerElement) ParseAnswerElement(org.batfish.datamodel.answers.ParseAnswerElement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) FileVisitOption(java.nio.file.FileVisitOption) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) Cache(com.google.common.cache.Cache) HeaderLocationQuestion(org.batfish.datamodel.questions.smt.HeaderLocationQuestion) AssertionAst(org.batfish.datamodel.assertion.AssertionAst) Interface(org.batfish.datamodel.Interface) CompositeNodJob(org.batfish.z3.CompositeNodJob) DirectoryStream(java.nio.file.DirectoryStream) Flow(org.batfish.datamodel.Flow) FlattenVendorConfigurationAnswerElement(org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement) InvalidReachabilitySettingsException(org.batfish.datamodel.questions.InvalidReachabilitySettingsException) GrammarSettings(org.batfish.grammar.GrammarSettings) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) Verify(com.google.common.base.Verify) DataPlane(org.batfish.datamodel.DataPlane) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Set(java.util.Set) EnvironmentSettings(org.batfish.config.Settings.EnvironmentSettings) IBatfish(org.batfish.common.plugin.IBatfish) Question(org.batfish.datamodel.questions.Question) Roles(org.batfish.symbolic.abstraction.Roles) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ForwardingAction(org.batfish.datamodel.ForwardingAction) CommonUtil(org.batfish.common.util.CommonUtil) EarliestMoreGeneralReachableLineQuerySynthesizer(org.batfish.z3.EarliestMoreGeneralReachableLineQuerySynthesizer) AclReachabilityEntry(org.batfish.datamodel.answers.AclLinesAnswerElement.AclReachabilityEntry) PluginClientType(org.batfish.common.plugin.PluginClientType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BgpAdvertisement(org.batfish.datamodel.BgpAdvertisement) BgpTablePlugin(org.batfish.common.plugin.BgpTablePlugin) ParseTreePrettyPrinter(org.batfish.grammar.ParseTreePrettyPrinter) ReachEdgeQuerySynthesizer(org.batfish.z3.ReachEdgeQuerySynthesizer) ValidateEnvironmentAnswerElement(org.batfish.datamodel.answers.ValidateEnvironmentAnswerElement) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) BgpAdvertisementType(org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType) Files(java.nio.file.Files) JSONObject(org.codehaus.jettison.json.JSONObject) ExternalBgpAdvertisementPlugin(org.batfish.common.plugin.ExternalBgpAdvertisementPlugin) File(java.io.File) ParseEnvironmentBgpTablesAnswerElement(org.batfish.datamodel.answers.ParseEnvironmentBgpTablesAnswerElement) Paths(java.nio.file.Paths) ActiveSpan(io.opentracing.ActiveSpan) HeaderSpace(org.batfish.datamodel.HeaderSpace) SynthesizerInputImpl(org.batfish.z3.SynthesizerInputImpl) MultiSet(org.batfish.datamodel.collections.MultiSet) NodesSpecifier(org.batfish.datamodel.questions.NodesSpecifier) Answer(org.batfish.datamodel.answers.Answer) NodSatJob(org.batfish.z3.NodSatJob) FlattenVendorConfigurationJob(org.batfish.job.FlattenVendorConfigurationJob) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PatternSyntaxException(java.util.regex.PatternSyntaxException) ImmutableMap(com.google.common.collect.ImmutableMap) Sets(com.google.common.collect.Sets) List(java.util.List) GNS3TopologyExtractor(org.batfish.grammar.topology.GNS3TopologyExtractor) Warnings(org.batfish.common.Warnings) Pattern(java.util.regex.Pattern) Synthesizer(org.batfish.z3.Synthesizer) PluginConsumer(org.batfish.common.plugin.PluginConsumer) SortedMap(java.util.SortedMap) MultipathInconsistencyQuerySynthesizer(org.batfish.z3.MultipathInconsistencyQuerySynthesizer) BatfishLogger(org.batfish.common.BatfishLogger) HashMap(java.util.HashMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) AbstractRoute(org.batfish.datamodel.AbstractRoute) SubRange(org.batfish.datamodel.SubRange) VyosCombinedParser(org.batfish.grammar.vyos.VyosCombinedParser) Warning(org.batfish.common.Warning) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GlobalTracer(io.opentracing.util.GlobalTracer) GNS3TopologyCombinedParser(org.batfish.grammar.topology.GNS3TopologyCombinedParser) ParseVendorConfigurationAnswerElement(org.batfish.datamodel.answers.ParseVendorConfigurationAnswerElement) DataPlanePluginSettings(org.batfish.common.plugin.DataPlanePluginSettings) ReportAnswerElement(org.batfish.datamodel.answers.ReportAnswerElement) Collections(java.util.Collections) ArrayList(java.util.ArrayList) IpAccessList(org.batfish.datamodel.IpAccessList) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) Warnings(org.batfish.common.Warnings)

Example 12 with BatfishStackTrace

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();
}
Also used : Warning(org.batfish.common.Warning) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace)

Example 13 with BatfishStackTrace

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()));
}
Also used : BatfishException(org.batfish.common.BatfishException) ArrayList(java.util.ArrayList) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) Test(org.junit.Test)

Example 14 with BatfishStackTrace

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));
}
Also used : BatfishException(org.batfish.common.BatfishException) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) Test(org.junit.Test)

Example 15 with BatfishStackTrace

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()));
}
Also used : BatfishException(org.batfish.common.BatfishException) BatfishStackTrace(org.batfish.common.BatfishException.BatfishStackTrace) Test(org.junit.Test)

Aggregations

BatfishStackTrace (org.batfish.common.BatfishException.BatfishStackTrace)15 BatfishException (org.batfish.common.BatfishException)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)4 TreeMap (java.util.TreeMap)3 List (java.util.List)2 Warning (org.batfish.common.Warning)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Verify (com.google.common.base.Verify)1 Cache (com.google.common.cache.Cache)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 ActiveSpan (io.opentracing.ActiveSpan)1