@Test public void testFlattenVendorConfigurationJobUnknown() { String unknownFileText = "unknown config format {\ntest;\n}\n"; FlattenVendorConfigurationJob job = new FlattenVendorConfigurationJob( new Settings(), unknownFileText, Paths.get("input"), Paths.get("output"), new Warnings()); assertThat(job.call().getFlattenedText(), equalTo(unknownFileText)); }
@Override public FlattenVendorConfigurationResult call() { long startTime = System.currentTimeMillis(); long elapsedTime; String inputFileAsString = _inputFile.toAbsolutePath().toString(); ConfigurationFormat format = VendorConfigurationFormatDetector.identifyConfigurationFormat(_fileText); if (format == ConfigurationFormat.JUNIPER || format == ConfigurationFormat.PALO_ALTO_NESTED || format == ConfigurationFormat.VYOS) { String header = null; if (format == ConfigurationFormat.JUNIPER) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_JUNIPER_HEADER; } if (format == ConfigurationFormat.PALO_ALTO_NESTED) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_PALO_ALTO_HEADER; } if (format == ConfigurationFormat.VYOS) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_VYOS_HEADER; } _logger.debugf("Flattening config: \"%s\"...", _inputFile); String flatConfigText; try { flatConfigText = Batfish.flatten(_fileText, _logger, _settings, _warnings, format, header) .getFlattenedConfigurationText(); } catch (ParserBatfishException e) { String error = "Error parsing configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } catch (Exception e) { String error = "Error post-processing parse tree of configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } finally { Batfish.logWarnings(_logger, _warnings); } elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } else if (!_settings.ignoreUnsupported() && format == ConfigurationFormat.UNKNOWN) { elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException("Unknown configuration format for: \"" + _inputFile + "\"")); } else { _logger.debugf("Skipping: \"%s\"\n", _inputFile); String flatConfigText = _fileText; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } }
FlattenVendorConfigurationJob extends BatfishJob<FlattenVendorConfigurationResult> { @Override public FlattenVendorConfigurationResult call() { long startTime = System.currentTimeMillis(); long elapsedTime; String inputFileAsString = _inputFile.toAbsolutePath().toString(); ConfigurationFormat format = VendorConfigurationFormatDetector.identifyConfigurationFormat(_fileText); if (format == ConfigurationFormat.JUNIPER || format == ConfigurationFormat.PALO_ALTO_NESTED || format == ConfigurationFormat.VYOS) { String header = null; if (format == ConfigurationFormat.JUNIPER) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_JUNIPER_HEADER; } if (format == ConfigurationFormat.PALO_ALTO_NESTED) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_PALO_ALTO_HEADER; } if (format == ConfigurationFormat.VYOS) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_VYOS_HEADER; } _logger.debugf("Flattening config: \"%s\"...", _inputFile); String flatConfigText; try { flatConfigText = Batfish.flatten(_fileText, _logger, _settings, _warnings, format, header) .getFlattenedConfigurationText(); } catch (ParserBatfishException e) { String error = "Error parsing configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } catch (Exception e) { String error = "Error post-processing parse tree of configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } finally { Batfish.logWarnings(_logger, _warnings); } elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } else if (!_settings.ignoreUnsupported() && format == ConfigurationFormat.UNKNOWN) { elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException("Unknown configuration format for: \"" + _inputFile + "\"")); } else { _logger.debugf("Skipping: \"%s\"\n", _inputFile); String flatConfigText = _fileText; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } } }
FlattenVendorConfigurationJob extends BatfishJob<FlattenVendorConfigurationResult> { @Override public FlattenVendorConfigurationResult call() { long startTime = System.currentTimeMillis(); long elapsedTime; String inputFileAsString = _inputFile.toAbsolutePath().toString(); ConfigurationFormat format = VendorConfigurationFormatDetector.identifyConfigurationFormat(_fileText); if (format == ConfigurationFormat.JUNIPER || format == ConfigurationFormat.PALO_ALTO_NESTED || format == ConfigurationFormat.VYOS) { String header = null; if (format == ConfigurationFormat.JUNIPER) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_JUNIPER_HEADER; } if (format == ConfigurationFormat.PALO_ALTO_NESTED) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_PALO_ALTO_HEADER; } if (format == ConfigurationFormat.VYOS) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_VYOS_HEADER; } _logger.debugf("Flattening config: \"%s\"...", _inputFile); String flatConfigText; try { flatConfigText = Batfish.flatten(_fileText, _logger, _settings, _warnings, format, header) .getFlattenedConfigurationText(); } catch (ParserBatfishException e) { String error = "Error parsing configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } catch (Exception e) { String error = "Error post-processing parse tree of configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } finally { Batfish.logWarnings(_logger, _warnings); } elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } else if (!_settings.ignoreUnsupported() && format == ConfigurationFormat.UNKNOWN) { elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException("Unknown configuration format for: \"" + _inputFile + "\"")); } else { _logger.debugf("Skipping: \"%s\"\n", _inputFile); String flatConfigText = _fileText; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } } FlattenVendorConfigurationJob(
      Settings settings, String fileText, Path inputFile, Path outputFile, Warnings warnings); }
FlattenVendorConfigurationJob extends BatfishJob<FlattenVendorConfigurationResult> { @Override public FlattenVendorConfigurationResult call() { long startTime = System.currentTimeMillis(); long elapsedTime; String inputFileAsString = _inputFile.toAbsolutePath().toString(); ConfigurationFormat format = VendorConfigurationFormatDetector.identifyConfigurationFormat(_fileText); if (format == ConfigurationFormat.JUNIPER || format == ConfigurationFormat.PALO_ALTO_NESTED || format == ConfigurationFormat.VYOS) { String header = null; if (format == ConfigurationFormat.JUNIPER) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_JUNIPER_HEADER; } if (format == ConfigurationFormat.PALO_ALTO_NESTED) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_PALO_ALTO_HEADER; } if (format == ConfigurationFormat.VYOS) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_VYOS_HEADER; } _logger.debugf("Flattening config: \"%s\"...", _inputFile); String flatConfigText; try { flatConfigText = Batfish.flatten(_fileText, _logger, _settings, _warnings, format, header) .getFlattenedConfigurationText(); } catch (ParserBatfishException e) { String error = "Error parsing configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } catch (Exception e) { String error = "Error post-processing parse tree of configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } finally { Batfish.logWarnings(_logger, _warnings); } elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } else if (!_settings.ignoreUnsupported() && format == ConfigurationFormat.UNKNOWN) { elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException("Unknown configuration format for: \"" + _inputFile + "\"")); } else { _logger.debugf("Skipping: \"%s\"\n", _inputFile); String flatConfigText = _fileText; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } } FlattenVendorConfigurationJob(
      Settings settings, String fileText, Path inputFile, Path outputFile, Warnings warnings); @Override FlattenVendorConfigurationResult call(); }
FlattenVendorConfigurationJob extends BatfishJob<FlattenVendorConfigurationResult> { @Override public FlattenVendorConfigurationResult call() { long startTime = System.currentTimeMillis(); long elapsedTime; String inputFileAsString = _inputFile.toAbsolutePath().toString(); ConfigurationFormat format = VendorConfigurationFormatDetector.identifyConfigurationFormat(_fileText); if (format == ConfigurationFormat.JUNIPER || format == ConfigurationFormat.PALO_ALTO_NESTED || format == ConfigurationFormat.VYOS) { String header = null; if (format == ConfigurationFormat.JUNIPER) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_JUNIPER_HEADER; } if (format == ConfigurationFormat.PALO_ALTO_NESTED) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_PALO_ALTO_HEADER; } if (format == ConfigurationFormat.VYOS) { header = VendorConfigurationFormatDetector.BATFISH_FLATTENED_VYOS_HEADER; } _logger.debugf("Flattening config: \"%s\"...", _inputFile); String flatConfigText; try { flatConfigText = Batfish.flatten(_fileText, _logger, _settings, _warnings, format, header) .getFlattenedConfigurationText(); } catch (ParserBatfishException e) { String error = "Error parsing configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } catch (Exception e) { String error = "Error post-processing parse tree of configuration file: \"" + inputFileAsString + "\""; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException(error, e)); } finally { Batfish.logWarnings(_logger, _warnings); } elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } else if (!_settings.ignoreUnsupported() && format == ConfigurationFormat.UNKNOWN) { elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, new BatfishException("Unknown configuration format for: \"" + _inputFile + "\"")); } else { _logger.debugf("Skipping: \"%s\"\n", _inputFile); String flatConfigText = _fileText; elapsedTime = System.currentTimeMillis() - startTime; return new FlattenVendorConfigurationResult( elapsedTime, _logger.getHistory(), _outputFile, flatConfigText); } } FlattenVendorConfigurationJob(
      Settings settings, String fileText, Path inputFile, Path outputFile, Warnings warnings); @Override FlattenVendorConfigurationResult call();  }