use of org.batfish.common.BatfishException in project batfish by batfish.
the class PluginConsumer method serializeToLz4Data.
/**
* Serializes the given object to the given stream, using LZ4 compression.
*/
private void serializeToLz4Data(Serializable object, OutputStream out) {
// This is a hack:
// XStream requires that its streams be closed to properly finish serialization,
// but we do not actually want to close the passed-in output stream.
out = new CloseIgnoringOutputStream(out);
try (Closer closer = Closer.create()) {
OutputStream los = closer.register(new LZ4FrameOutputStream(out));
ObjectOutputStream oos;
if (_serializeToText) {
XStream xstream = new XStream(new DomDriver("UTF-8"));
oos = closer.register(xstream.createObjectOutputStream(los));
} else {
oos = closer.register(new ObjectOutputStream(los));
}
oos.writeObject(object);
} catch (IOException e) {
throw new BatfishException("Failed to convert object to LZ4 data", e);
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class NodeRoleSpecifier method addToRoleNodesMap.
private void addToRoleNodesMap(SortedMap<String, SortedSet<String>> roleNodesMap, Set<String> nodes) {
List<Pattern> patList = new ArrayList<>();
for (String regex : _roleRegexes) {
try {
patList.add(Pattern.compile(regex));
} catch (PatternSyntaxException e) {
throw new BatfishException("Supplied regex is not a valid Java regex: \"" + regex + "\"", e);
}
}
for (String node : nodes) {
for (Pattern pattern : patList) {
Matcher matcher = pattern.matcher(node);
int numGroups = matcher.groupCount();
if (matcher.matches()) {
try {
List<String> roleParts = IntStream.range(1, numGroups + 1).mapToObj(matcher::group).collect(Collectors.toList());
String role = String.join("-", roleParts);
SortedSet<String> currNodes = roleNodesMap.computeIfAbsent(role, k -> new TreeSet<>());
currNodes.add(node);
} catch (IndexOutOfBoundsException e) {
throw new BatfishException("Supplied regex does not contain a group: \"" + pattern.pattern() + "\"", e);
}
}
}
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class ConjunctionChain method evaluate.
@Override
public Result evaluate(Environment environment) {
Result subroutineResult = new Result();
subroutineResult.setFallThrough(true);
for (BooleanExpr subroutine : _subroutines) {
subroutineResult = subroutine.evaluate(environment);
if (subroutineResult.getExit()) {
return subroutineResult;
} else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) {
subroutineResult.setReturn(false);
return subroutineResult;
}
}
if (!subroutineResult.getFallThrough()) {
return subroutineResult;
} else {
String defaultPolicy = environment.getDefaultPolicy();
if (defaultPolicy != null) {
CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy());
Result defaultPolicyResult = callDefaultPolicy.evaluate(environment);
return defaultPolicyResult;
} else {
throw new BatfishException("Default policy not set");
}
}
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class Prefix method parse.
@JsonCreator
public static Prefix parse(String text) {
String[] parts = text.split("/");
if (parts.length != 2) {
throw new BatfishException("Invalid prefix string: \"" + text + "\"");
}
Ip ip = new Ip(parts[0]);
int prefixLength;
try {
prefixLength = Integer.parseInt(parts[1]);
} catch (NumberFormatException e) {
throw new BatfishException("Invalid prefix length: \"" + parts[1] + "\"", e);
}
return new Prefix(ip, prefixLength);
}
use of org.batfish.common.BatfishException in project batfish by batfish.
the class Answer method append.
public void append(Answer answer) {
if (answer._question != null) {
_question = answer._question;
}
_answerElements.addAll(answer._answerElements);
_status = answer._status;
_summary.combine(answer.getSummary());
for (AnswerElement answerElement : answer._answerElements) {
if (answerElement instanceof BatfishStackTrace) {
BatfishException e = ((BatfishStackTrace) answerElement).getException();
throw new QuestionException("Exception answering question", e, this);
}
}
}
Aggregations