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");
}
}
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);
}
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());
}
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")));
}
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;
}
Aggregations