@Override public TableAnswerElement answer() { UndefinedReferencesQuestion question = (UndefinedReferencesQuestion) _question; // Find all the filenames that produced the queried nodes. This might have false positives if // a file produced multiple nodes, but that was already mis-handled before. Need to rewrite // this question as a TableAnswerElement. Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream() .filter(e -> includeNodes.contains(e.getKey())) .map(Entry::getValue) .collect(Collectors.toSet()); Multiset<Row> rows = LinkedHashMultiset.create(); SortedMap<String, SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>>> undefinedReferences = _batfish.loadConvertConfigurationAnswerElementOrReparse().getUndefinedReferences(); undefinedReferences.entrySet().stream() .filter(e -> includeFiles.contains(e.getKey())) .forEach(e -> rows.addAll(processEntryToRows(e))); TableAnswerElement table = new TableAnswerElement(createMetadata()); table.postProcessAnswer(_question, rows); return table; }
@Override public TableAnswerElement answer() { UnusedStructuresQuestion question = (UnusedStructuresQuestion) _question; // Find all the filenames that produced the queried nodes. This might have false positives if // a file produced multiple nodes, but that was already mis-handled before. Need to rewrite // this question as a TableAnswerElement. Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream() .filter(e -> includeNodes.contains(e.getKey())) .map(Entry::getValue) .collect(Collectors.toSet()); Multiset<Row> rows = LinkedHashMultiset.create(); SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> definedStructures = _batfish.loadConvertConfigurationAnswerElementOrReparse().getDefinedStructures(); definedStructures.entrySet().stream() .filter(e -> includeFiles.contains(e.getKey())) .forEach(e -> rows.addAll(processEntryToRows(e))); TableAnswerElement table = new TableAnswerElement(createMetadata(question)); table.postProcessAnswer(_question, rows); return table; }
@VisibleForTesting public static AwsConfiguration parseAwsConfigurations( Map<Path, String> configurationData, ParseVendorConfigurationAnswerElement pvcae) { AwsConfiguration config = new AwsConfiguration(); for (Entry<Path, String> configFile : configurationData.entrySet()) { Path path = configFile.getKey(); int pathLength = configFile.getKey().getNameCount(); String fileText = configFile.getValue(); String regionName = path.getName(pathLength - 2).toString(); // parent dir name String fileName = path.subpath(pathLength - 3, pathLength).toString(); pvcae.getFileMap().put(BfConsts.RELPATH_AWS_CONFIGS_FILE, fileName); JSONObject jsonObj = null; try { jsonObj = new JSONObject(fileText); } catch (JSONException e) { pvcae.addRedFlagWarning( BfConsts.RELPATH_AWS_CONFIGS_FILE, new Warning(String.format("AWS file %s is not valid JSON", fileName), "AWS")); } if (jsonObj != null) { try { config.addConfigElement(regionName, jsonObj, fileName, pvcae); } catch (JSONException e) { throw new BatfishException("Problems parsing JSON in " + fileName, e); } } } return config; }
Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream()
@Override public TableAnswerElement answer() { ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(); Map<String, ParseStatus> statusMap = pvcae.getParseStatus(); Rows rows = new Rows(); Multimap<String, String> fileToHost = TreeMultimap.create(); pvcae.getFileMap().forEach((hostname, filename) -> fileToHost.put(filename, hostname)); statusMap.forEach( (filename, status) -> rows.add(getRow(filename, status, fileToHost.get(filename)))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; }
Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream()
answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(hostname, _warnings);