-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow hostInterfaces to be specified as list in json #5291
Allow hostInterfaces to be specified as list in json #5291
Conversation
arifogel
commented
Dec 20, 2019
- prevents mismatch between key and name
- retain support for hostInterfaces specified as object (map)
- remove unused serialization support
- prevents mismatch between key and name - retain support for hostInterfaces specified as object (map) - remove unused serialization support
Codecov Report
@@ Coverage Diff @@
## master #5291 +/- ##
============================================
- Coverage 73.39% 73.39% -0.01%
- Complexity 31956 31962 +6
============================================
Files 2624 2624
Lines 128893 128926 +33
Branches 15499 15503 +4
============================================
+ Hits 94602 94625 +23
- Misses 26802 26812 +10
Partials 7489 7489
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-reviewer:@progwriter
Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @arifogel and @dhalperi)
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 129 at r2 (raw file):
Quoted 22 lines of code…
if (hostInterfacesNode == null) { hostInterfaces = ImmutableMap.of(); } else if (hostInterfacesNode instanceof ObjectNode) { hostInterfaces = BatfishObjectMapper.mapper() .convertValue(hostInterfacesNode, new TypeReference<Map<String, HostInterface>>() {}); hostInterfaces.forEach( (name, hostInterface) -> checkArgument( name.equals(hostInterface.getName()), "Mismatch between hostInterface key '%s' and name '%s'", name, hostInterface.getName())); } else { assert hostInterfacesNode instanceof ArrayNode; List<HostInterface> hostInterfacesList = BatfishObjectMapper.mapper() .convertValue(hostInterfacesNode, new TypeReference<List<HostInterface>>() {}); hostInterfaces = hostInterfacesList.stream() .collect(ImmutableMap.toImmutableMap(HostInterface::getName, Function.identity())); }
refactor into unit-testable function (JsonNode
-> List<HI>
), and test that function directly.
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 144 at r2 (raw file):
} @JsonIgnore
defer not-directly-related changes to a separate PR with an explanation of why you're making them. May want to ship that one first, if you need to do some complicated reorganization here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 3 files reviewed, 2 unresolved discussions (waiting on @dhalperi)
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 129 at r2 (raw file):
Previously, dhalperi (Dan Halperin) wrote…
if (hostInterfacesNode == null) { hostInterfaces = ImmutableMap.of(); } else if (hostInterfacesNode instanceof ObjectNode) { hostInterfaces = BatfishObjectMapper.mapper() .convertValue(hostInterfacesNode, new TypeReference<Map<String, HostInterface>>() {}); hostInterfaces.forEach( (name, hostInterface) -> checkArgument( name.equals(hostInterface.getName()), "Mismatch between hostInterface key '%s' and name '%s'", name, hostInterface.getName())); } else { assert hostInterfacesNode instanceof ArrayNode; List<HostInterface> hostInterfacesList = BatfishObjectMapper.mapper() .convertValue(hostInterfacesNode, new TypeReference<List<HostInterface>>() {}); hostInterfaces = hostInterfacesList.stream() .collect(ImmutableMap.toImmutableMap(HostInterface::getName, Function.identity())); }
refactor into unit-testable function (
JsonNode
->List<HI>
), and test that function directly.
better now, or want more granularity?
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 144 at r2 (raw file):
Previously, dhalperi (Dan Halperin) wrote…
defer not-directly-related changes to a separate PR with an explanation of why you're making them. May want to ship that one first, if you need to do some complicated reorganization here.
Went simpler route and skipped unrelated changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, 2 of 2 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @arifogel)
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 304 at r3 (raw file):
hostInterfaces = hostInterfacesList.stream() .collect(ImmutableMap.toImmutableMap(HostInterface::getName, Function.identity()));
I believe this will crash if the same interface name is given twice. Is that your intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @dhalperi)
projects/batfish/src/main/java/org/batfish/representation/host/HostConfiguration.java, line 304 at r3 (raw file):
Previously, dhalperi (Dan Halperin) wrote…
I believe this will crash if the same interface name is given twice. Is that your intent?
Good catch.
Now just using last definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4.
Reviewable status: complete! all files reviewed, all discussions resolved