Search in sources :

Example 1 with TestrigSettings

use of org.batfish.config.Settings.TestrigSettings in project batfish by batfish.

the class Batfish method getNodeRoleSpecifier.

/* Gets the NodeRoleSpecifier that specifies the roles for each node.
     If inferred is true, it returns the inferred roles;
     otherwise it prefers the user-specified roles if they exist.
  */
@Override
public NodeRoleSpecifier getNodeRoleSpecifier(boolean inferred) {
    NodeRoleSpecifier result;
    boolean inferredRoles = false;
    TestrigSettings settings = _settings.getActiveTestrigSettings();
    Path nodeRolesPath = settings.getNodeRolesPath();
    if (!Files.exists(nodeRolesPath) || inferred) {
        inferredRoles = true;
        nodeRolesPath = settings.getInferredNodeRolesPath();
        if (!Files.exists(nodeRolesPath)) {
            return new NodeRoleSpecifier();
        }
    }
    result = parseNodeRoles(nodeRolesPath);
    result.setInferred(inferredRoles);
    return result;
}
Also used : Path(java.nio.file.Path) TestrigSettings(org.batfish.config.Settings.TestrigSettings) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier)

Example 2 with TestrigSettings

use of org.batfish.config.Settings.TestrigSettings in project batfish by batfish.

the class Batfish method initTestrigSettings.

public static void initTestrigSettings(Settings settings) {
    String testrig = settings.getTestrig();
    String envName = settings.getEnvironmentName();
    Path containerDir = settings.getContainerDir();
    if (testrig != null) {
        applyBaseDir(settings.getBaseTestrigSettings(), containerDir, testrig, envName);
        String deltaTestrig = settings.getDeltaTestrig();
        String deltaEnvName = settings.getDeltaEnvironmentName();
        TestrigSettings deltaTestrigSettings = settings.getDeltaTestrigSettings();
        if (deltaTestrig != null && deltaEnvName == null) {
            deltaEnvName = envName;
            settings.setDeltaEnvironmentName(envName);
        } else if (deltaTestrig == null && deltaEnvName != null) {
            deltaTestrig = testrig;
            settings.setDeltaTestrig(testrig);
        }
        if (deltaTestrig != null) {
            applyBaseDir(deltaTestrigSettings, containerDir, deltaTestrig, deltaEnvName);
        }
        if (settings.getDiffActive()) {
            settings.setActiveTestrigSettings(settings.getDeltaTestrigSettings());
        } else {
            settings.setActiveTestrigSettings(settings.getBaseTestrigSettings());
        }
        initQuestionSettings(settings);
    } else if (containerDir != null) {
        throw new CleanBatfishException("Must supply argument to -" + BfConsts.ARG_TESTRIG);
    }
}
Also used : Path(java.nio.file.Path) CleanBatfishException(org.batfish.common.CleanBatfishException) TestrigSettings(org.batfish.config.Settings.TestrigSettings)

Example 3 with TestrigSettings

use of org.batfish.config.Settings.TestrigSettings in project batfish by batfish.

the class Batfish method saveDataPlane.

/* Write the dataplane to disk and cache, and write the answer element to disk.
   */
private void saveDataPlane(DataPlane dataPlane, DataPlaneAnswerElement answerElement, boolean compressed) {
    Path dataPlanePath = compressed ? _testrigSettings.getEnvironmentSettings().getCompressedDataPlanePath() : _testrigSettings.getEnvironmentSettings().getDataPlanePath();
    Path answerElementPath = compressed ? _testrigSettings.getEnvironmentSettings().getCompressedDataPlaneAnswerPath() : _testrigSettings.getEnvironmentSettings().getDataPlaneAnswerPath();
    Cache<TestrigSettings, DataPlane> cache = compressed ? _cachedCompressedDataPlanes : _cachedDataPlanes;
    cache.put(_testrigSettings, dataPlane);
    _logger.resetTimer();
    newBatch("Writing data plane to disk", 0);
    try (ActiveSpan writeDataplane = GlobalTracer.get().buildSpan("Writing data plane").startActive()) {
        // avoid unused warning
        assert writeDataplane != null;
        serializeObject(dataPlane, dataPlanePath);
        serializeObject(answerElement, answerElementPath);
    }
    _logger.printElapsedTime();
}
Also used : Path(java.nio.file.Path) DataPlane(org.batfish.datamodel.DataPlane) ActiveSpan(io.opentracing.ActiveSpan) TestrigSettings(org.batfish.config.Settings.TestrigSettings)

Example 4 with TestrigSettings

use of org.batfish.config.Settings.TestrigSettings in project batfish by batfish.

the class Batfish method loadDataPlane.

private DataPlane loadDataPlane(boolean compressed) {
    Cache<TestrigSettings, DataPlane> cache = compressed ? _cachedCompressedDataPlanes : _cachedDataPlanes;
    Path path = compressed ? _testrigSettings.getEnvironmentSettings().getCompressedDataPlanePath() : _testrigSettings.getEnvironmentSettings().getDataPlanePath();
    DataPlane dp = cache.getIfPresent(_testrigSettings);
    if (dp == null) {
        /*
       * Data plane should exist after loading answer element, as it triggers
       * repair if necessary. However, it might not be cached if it was not
       * repaired, so we still might need to load it from disk.
       */
        loadDataPlaneAnswerElement(compressed);
        dp = cache.getIfPresent(_testrigSettings);
        if (dp == null) {
            newBatch("Loading data plane from disk", 0);
            dp = deserializeObject(path, DataPlane.class);
            cache.put(_testrigSettings, dp);
        }
    }
    return dp;
}
Also used : DataPlane(org.batfish.datamodel.DataPlane) Path(java.nio.file.Path) TestrigSettings(org.batfish.config.Settings.TestrigSettings)

Aggregations

Path (java.nio.file.Path)4 TestrigSettings (org.batfish.config.Settings.TestrigSettings)4 DataPlane (org.batfish.datamodel.DataPlane)2 ActiveSpan (io.opentracing.ActiveSpan)1 CleanBatfishException (org.batfish.common.CleanBatfishException)1 NodeRoleSpecifier (org.batfish.datamodel.NodeRoleSpecifier)1