use of org.batfish.representation.aws.AwsConfiguration 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.representation.aws.AwsConfiguration in project batfish by batfish.
the class Batfish method serializeAwsConfigs.
private Answer serializeAwsConfigs(Path testRigPath, Path outputPath) {
Answer answer = new Answer();
Map<Path, String> configurationData = readConfigurationFiles(testRigPath, BfConsts.RELPATH_AWS_CONFIGS_DIR);
AwsConfiguration config;
try (ActiveSpan parseAwsConfigsSpan = GlobalTracer.get().buildSpan("Parse AWS configs").startActive()) {
// avoid unused warning
assert parseAwsConfigsSpan != null;
config = parseAwsConfigurations(configurationData);
}
_logger.info("\n*** SERIALIZING AWS CONFIGURATION STRUCTURES ***\n");
_logger.resetTimer();
outputPath.toFile().mkdirs();
Path currentOutputPath = outputPath.resolve(BfConsts.RELPATH_AWS_CONFIGS_FILE);
_logger.debugf("Serializing AWS to \"%s\"...", currentOutputPath);
serializeObject(config, currentOutputPath);
_logger.debug("OK\n");
_logger.printElapsedTime();
return answer;
}
use of org.batfish.representation.aws.AwsConfiguration in project batfish by batfish.
the class Batfish method parseAwsConfigurations.
private AwsConfiguration parseAwsConfigurations(Map<Path, String> configurationData) {
AwsConfiguration config = new AwsConfiguration();
for (Entry<Path, String> configFile : configurationData.entrySet()) {
Path file = configFile.getKey();
String fileText = configFile.getValue();
// parent dir name
String regionName = file.getName(file.getNameCount() - 2).toString();
// processing
if (file.toString().contains("classic-link")) {
_logger.errorf("%s has classic link configuration\n", file);
continue;
}
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(fileText);
} catch (JSONException e) {
_logger.errorf("%s does not have valid json\n", file);
}
if (jsonObj != null) {
try {
config.addConfigElement(regionName, jsonObj, _logger);
} catch (JSONException e) {
throw new BatfishException("Problems parsing JSON in " + file, e);
}
}
}
return config;
}
Aggregations