Search in sources :

Example 1 with FlattenVendorConfigurationJob

use of org.batfish.job.FlattenVendorConfigurationJob in project batfish by batfish.

the class Batfish method flatten.

private void flatten(Path inputPath, Path outputPath) {
    Map<Path, String> configurationData = readConfigurationFiles(inputPath, BfConsts.RELPATH_CONFIGURATIONS_DIR);
    Map<Path, String> outputConfigurationData = new TreeMap<>();
    Path outputConfigDir = outputPath.resolve(BfConsts.RELPATH_CONFIGURATIONS_DIR);
    CommonUtil.createDirectories(outputConfigDir);
    _logger.info("\n*** FLATTENING TEST RIG ***\n");
    _logger.resetTimer();
    List<FlattenVendorConfigurationJob> jobs = new ArrayList<>();
    for (Entry<Path, String> configFile : configurationData.entrySet()) {
        Path inputFile = configFile.getKey();
        String fileText = configFile.getValue();
        Warnings warnings = buildWarnings(_settings);
        String name = inputFile.getFileName().toString();
        Path outputFile = outputConfigDir.resolve(name);
        FlattenVendorConfigurationJob job = new FlattenVendorConfigurationJob(_settings, fileText, inputFile, outputFile, warnings);
        jobs.add(job);
    }
    BatfishJobExecutor.runJobsInExecutor(_settings, _logger, jobs, outputConfigurationData, new FlattenVendorConfigurationAnswerElement(), _settings.getFlatten() || _settings.getHaltOnParseError(), "Flatten configurations");
    _logger.printElapsedTime();
    for (Entry<Path, String> e : outputConfigurationData.entrySet()) {
        Path outputFile = e.getKey();
        String flatConfigText = e.getValue();
        String outputFileAsString = outputFile.toString();
        _logger.debugf("Writing config to \"%s\"...", outputFileAsString);
        CommonUtil.writeFile(outputFile, flatConfigText);
        _logger.debug("OK\n");
    }
    Path inputTopologyPath = inputPath.resolve(TOPOLOGY_FILENAME);
    Path outputTopologyPath = outputPath.resolve(TOPOLOGY_FILENAME);
    if (Files.isRegularFile(inputTopologyPath)) {
        String topologyFileText = CommonUtil.readFile(inputTopologyPath);
        CommonUtil.writeFile(outputTopologyPath, topologyFileText);
    }
}
Also used : Path(java.nio.file.Path) FlattenVendorConfigurationAnswerElement(org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement) ArrayList(java.util.ArrayList) FlattenVendorConfigurationJob(org.batfish.job.FlattenVendorConfigurationJob) TreeMap(java.util.TreeMap) Warnings(org.batfish.common.Warnings)

Aggregations

Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 Warnings (org.batfish.common.Warnings)1 FlattenVendorConfigurationAnswerElement (org.batfish.datamodel.answers.FlattenVendorConfigurationAnswerElement)1 FlattenVendorConfigurationJob (org.batfish.job.FlattenVendorConfigurationJob)1