Search in sources :

Example 1 with ConvertConfigurationAnswerElement

use of org.batfish.datamodel.answers.ConvertConfigurationAnswerElement in project batfish by batfish.

the class Batfish method loadConvertConfigurationAnswerElementOrReparse.

@Override
public ConvertConfigurationAnswerElement loadConvertConfigurationAnswerElementOrReparse() {
    ConvertConfigurationAnswerElement ccae = _storage.loadConvertConfigurationAnswerElement(_testrigSettings.getName());
    if (ccae != null && Version.isCompatibleVersion("Service", "Old processed configurations", ccae.getVersion())) {
        return ccae;
    }
    repairConfigurations();
    ccae = _storage.loadConvertConfigurationAnswerElement(_testrigSettings.getName());
    if (ccae != null && Version.isCompatibleVersion("Service", "Old processed configurations", ccae.getVersion())) {
        return ccae;
    } else {
        throw new BatfishException("Version error repairing configurations for convert configuration answer element");
    }
}
Also used : CleanBatfishException(org.batfish.common.CleanBatfishException) BatfishException(org.batfish.common.BatfishException) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement)

Example 2 with ConvertConfigurationAnswerElement

use of org.batfish.datamodel.answers.ConvertConfigurationAnswerElement in project batfish by batfish.

the class ConvertConfigurationJob method call.

@Override
public ConvertConfigurationResult call() {
    long startTime = System.currentTimeMillis();
    long elapsedTime;
    _logger.infof("Processing: \"%s\"", _name);
    Map<String, Configuration> configurations = new HashMap<>();
    Map<String, Warnings> warningsByHost = new HashMap<>();
    ConvertConfigurationAnswerElement answerElement = new ConvertConfigurationAnswerElement();
    try {
        // We have only two options: AWS VPCs or router configs
        if (VendorConfiguration.class.isInstance(_configObject)) {
            Warnings warnings = Batfish.buildWarnings(_settings);
            VendorConfiguration vendorConfiguration = ((VendorConfiguration) _configObject);
            vendorConfiguration.setWarnings(warnings);
            vendorConfiguration.setAnswerElement(answerElement);
            Configuration configuration = vendorConfiguration.toVendorIndependentConfiguration();
            if (configuration.getDefaultCrossZoneAction() == null) {
                throw new BatfishException("Implementation error: missing default cross-zone action for host: '" + configuration.getHostname() + "'");
            }
            if (configuration.getDefaultInboundAction() == null) {
                throw new BatfishException("Implementation error: missing default inbound action for host: '" + configuration.getHostname() + "'");
            }
            // get iptables if applicable
            IptablesVendorConfiguration iptablesConfig = null;
            VendorConfiguration ov = vendorConfiguration.getOverlayConfiguration();
            if (ov != null) {
                // apply overlay
                HostConfiguration oh = (HostConfiguration) ov;
                iptablesConfig = oh.getIptablesVendorConfig();
            } else if (vendorConfiguration instanceof HostConfiguration) {
            // TODO: To enable below, we need to reconcile overlay and non-overlay iptables semantics.
            // HostConfiguration oh = (HostConfiguration)vendorConfiguration;
            // iptablesConfig = oh.getIptablesVendorConfig();
            }
            if (iptablesConfig != null) {
                iptablesConfig.addAsIpAccessLists(configuration, vendorConfiguration, warnings);
                iptablesConfig.applyAsOverlay(configuration, warnings);
            }
            configurations.put(_name, configuration);
            warningsByHost.put(_name, warnings);
        } else {
            configurations = ((AwsConfiguration) _configObject).toConfigurations(_settings, warningsByHost);
        }
        _logger.info(" ...OK\n");
    } catch (Exception e) {
        String error = "Conversion error for node with hostname '" + _name + "'";
        elapsedTime = System.currentTimeMillis() - startTime;
        return new ConvertConfigurationResult(elapsedTime, _logger.getHistory(), _name, new BatfishException(error, e));
    } finally {
        warningsByHost.forEach((hostname, warnings) -> Batfish.logWarnings(_logger, warnings));
        ;
    }
    elapsedTime = System.currentTimeMillis() - startTime;
    return new ConvertConfigurationResult(elapsedTime, _logger.getHistory(), warningsByHost, _name, configurations, answerElement);
}
Also used : BatfishException(org.batfish.common.BatfishException) VendorConfiguration(org.batfish.vendor.VendorConfiguration) Configuration(org.batfish.datamodel.Configuration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) HostConfiguration(org.batfish.representation.host.HostConfiguration) HashMap(java.util.HashMap) HostConfiguration(org.batfish.representation.host.HostConfiguration) BatfishException(org.batfish.common.BatfishException) VendorConfiguration(org.batfish.vendor.VendorConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) Warnings(org.batfish.common.Warnings) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration)

Example 3 with ConvertConfigurationAnswerElement

use of org.batfish.datamodel.answers.ConvertConfigurationAnswerElement in project batfish by batfish.

the class BatfishStorageTest method loadOldConfigurationsReturnsNull.

@Test
public void loadOldConfigurationsReturnsNull() {
    ConvertConfigurationAnswerElement oldConvertAnswer = new ConvertConfigurationAnswerElement();
    oldConvertAnswer.setVersion(INCOMPATIBLE_VERSION);
    assertThat("should not be compatible with current code", Version.isCompatibleVersion("current", "old test", oldConvertAnswer.getVersion()), equalTo(false));
    String trname = "sometr";
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS));
    _storage.storeConfigurations(configs, oldConvertAnswer, trname);
    assertThat(_storage.loadConfigurations(trname), nullValue());
}
Also used : Configuration(org.batfish.datamodel.Configuration) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with ConvertConfigurationAnswerElement

use of org.batfish.datamodel.answers.ConvertConfigurationAnswerElement in project batfish by batfish.

the class BatfishStorageTest method roundTripConfigurationsSucceeds.

@Test
public void roundTripConfigurationsSucceeds() {
    Map<String, Configuration> configs = new HashMap<>();
    configs.put("node1", new Configuration("node1", ConfigurationFormat.CISCO_IOS));
    _storage.storeConfigurations(configs, new ConvertConfigurationAnswerElement(), "sometr");
    Map<String, Configuration> deserialized = _storage.loadConfigurations("sometr");
    assertThat(deserialized, not(nullValue()));
    assertThat(deserialized.keySet(), equalTo(Sets.newHashSet("node1")));
}
Also used : Configuration(org.batfish.datamodel.Configuration) HashMap(java.util.HashMap) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) Test(org.junit.Test)

Example 5 with ConvertConfigurationAnswerElement

use of org.batfish.datamodel.answers.ConvertConfigurationAnswerElement in project batfish by batfish.

the class Batfish method serializeIndependentConfigs.

private Answer serializeIndependentConfigs(Path vendorConfigPath) {
    Answer answer = new Answer();
    ConvertConfigurationAnswerElement answerElement = new ConvertConfigurationAnswerElement();
    answerElement.setVersion(Version.getVersion());
    if (_settings.getVerboseParse()) {
        answer.addAnswerElement(answerElement);
    }
    Map<String, Configuration> configurations = getConfigurations(vendorConfigPath, answerElement);
    Topology testrigTopology = computeTestrigTopology(_testrigSettings.getTestRigPath(), configurations);
    serializeAsJson(_testrigSettings.getTopologyPath(), testrigTopology, "testrig topology");
    checkTopology(configurations, testrigTopology);
    org.batfish.datamodel.pojo.Topology pojoTopology = org.batfish.datamodel.pojo.Topology.create(_testrigSettings.getName(), configurations, testrigTopology);
    serializeAsJson(_testrigSettings.getPojoTopologyPath(), pojoTopology, "testrig pojo topology");
    _storage.storeConfigurations(configurations, answerElement, _testrigSettings.getName());
    applyEnvironment(configurations);
    Topology envTopology = computeEnvironmentTopology(configurations);
    serializeAsJson(_testrigSettings.getEnvironmentSettings().getSerializedTopologyPath(), envTopology, "environment topology");
    NodeRoleSpecifier roleSpecifier = inferNodeRoles(configurations);
    serializeAsJson(_testrigSettings.getInferredNodeRolesPath(), roleSpecifier, "inferred node roles");
    return answer;
}
Also used : Answer(org.batfish.datamodel.answers.Answer) HostConfiguration(org.batfish.representation.host.HostConfiguration) Configuration(org.batfish.datamodel.Configuration) ImmutableConfiguration(org.apache.commons.configuration2.ImmutableConfiguration) AwsConfiguration(org.batfish.representation.aws.AwsConfiguration) IptablesVendorConfiguration(org.batfish.representation.iptables.IptablesVendorConfiguration) VendorConfiguration(org.batfish.vendor.VendorConfiguration) ConvertConfigurationAnswerElement(org.batfish.datamodel.answers.ConvertConfigurationAnswerElement) Topology(org.batfish.datamodel.Topology) NodeRoleSpecifier(org.batfish.datamodel.NodeRoleSpecifier)

Aggregations

ConvertConfigurationAnswerElement (org.batfish.datamodel.answers.ConvertConfigurationAnswerElement)7 Configuration (org.batfish.datamodel.Configuration)4 HashMap (java.util.HashMap)3 BatfishException (org.batfish.common.BatfishException)2 AwsConfiguration (org.batfish.representation.aws.AwsConfiguration)2 HostConfiguration (org.batfish.representation.host.HostConfiguration)2 IptablesVendorConfiguration (org.batfish.representation.iptables.IptablesVendorConfiguration)2 VendorConfiguration (org.batfish.vendor.VendorConfiguration)2 Test (org.junit.Test)2 ImmutableConfiguration (org.apache.commons.configuration2.ImmutableConfiguration)1 CleanBatfishException (org.batfish.common.CleanBatfishException)1 Warnings (org.batfish.common.Warnings)1 NodeRoleSpecifier (org.batfish.datamodel.NodeRoleSpecifier)1 Topology (org.batfish.datamodel.Topology)1 Answer (org.batfish.datamodel.answers.Answer)1 Before (org.junit.Before)1