-
Notifications
You must be signed in to change notification settings - Fork 34
[Microservice] Route Manager Supports VPC Routing #380
[Microservice] Route Manager Supports VPC Routing #380
Conversation
services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java
Outdated
Show resolved
Hide resolved
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Outdated
Show resolved
Hide resolved
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Show resolved
Hide resolved
| List<RouteTable> vpcRouteTable = router.getVpcRouteTable(); | ||
| if (vpcRouteTable == null || vpcRouteTable.size() == 0) { | ||
| return null; | ||
| } | ||
| for (RouteTable routeTable : vpcRouteTable) { | ||
| String routeTableType = routeTable.getRouteTableType().getRouteTableType(); | ||
| if (RouteTableType.PRIVATE_SUBNET.getRouteTableType().equals(routeTableType) || RouteTableType.PUBLIC_SUBNET.getRouteTableType().equals(routeTableType)) { | ||
| throw new VpcRouterContainsSubnetRoutingTables(); | ||
| } | ||
| } |
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.
The logic here is not correct! We shouldn't block the updating for VPC default routing table when there are subnets using it. So, I think we don't need to check 'if the VPC router contains subnet routing table' 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.
Instead, we need to check if there is any subnet exists in the VPC. If VPC contains subnet, we cannot delete VPC router and VPC default routing table.
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.
Yeah you are right, I'll modify the checking process
| // create a VPC routing table and pump-in the VPC default routing rules | ||
| RouteEntry routeEntry = new RouteEntry(projectId, routeEntryId, "default_vpc_routeEntry", "", null, RouteConstant.DEFAULT_TARGET, RouteConstant.DEFAULT_PRIORITY, routeTableId, null); | ||
| routeEntities.add(routeEntry); | ||
| this.routeEntryDatabaseService.addRouteEntry(routeEntry); | ||
|
|
||
| RouteTable routeTable = new RouteTable(projectId, routeTableId, "default_vpc_routeTable", "", routeEntities, RouteTableType.VPC, owner); | ||
| vpcRouteTables.add(routeTable); | ||
| this.routeTableDatabaseService.addRouteTable(routeTable); | ||
|
|
||
| vpcRouteTables.add(routeTable); | ||
| router.setVpcRouteTable(vpcRouteTables); | ||
| this.routerDatabaseService.addRouter(router); |
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.
These lines of code same as the lines in the getOrCreateVpcRouter function. Since one VPC has only one router and default routing table. Should we merge createDefaultVpcRouteTable into getOrCreateVpcRouter ?
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.
Although some codes here are same as createDefaultVpcRouter, it is not convenient to merge them. They are used for different method and the parameters passed in are dfferent, either
| List<RouteTable> vpcRouteTables = router.getVpcRouteTable(); | ||
| for (RouteTable vpcRouteTable : vpcRouteTables) { | ||
| String routeTableType = vpcRouteTable.getRouteTableType().getRouteTableType(); | ||
| if (RouteTableType.VPC.getRouteTableType().equals(routeTableType)) { | ||
| routeTable = vpcRouteTable; | ||
| vpcRouteTables.remove(vpcRouteTable); | ||
| break; | ||
| } | ||
| } |
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.
VPC default route table has only one for each VPC. We shouldn't look-up all routing tables to get it.
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.
Already add a field "vpcDefaultRouteTableId" in Router to map vpc default route table
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Outdated
Show resolved
Hide resolved
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Show resolved
Hide resolved
| return new ArrayList<RouteTable>(); | ||
| } | ||
| return router.getVpcRouteTable(); | ||
| } |
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.
I am not quite understand the logic here. Why you return new ArrayList<RouteTable>() when you cannot find router?
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.
I changed here return null, is it correct?
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Outdated
Show resolved
Hide resolved
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Outdated
Show resolved
Hide resolved
|
LGTM |
xieus
left a comment
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.
Look good. Left a few comments, mostly minor. Please take a look. @kevin-zhonghao
| PRIVATE_SUBNET("private_subnet"), | ||
| VPC("vpc"), | ||
| NEUTRON("neutron"); | ||
| NEUTRON_ROUTER("neutron_router"), |
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.
@kevin-zhonghao @cj-chung We might want to describe each enum value a bit more, either in the code or in the design doc.
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.
Agree
...manager/src/main/java/com/futurewei/alcor/route/exception/ExistMultipleSubnetRouteTable.java
Outdated
Show resolved
Hide resolved
.../route_manager/src/main/java/com/futurewei/alcor/route/exception/ExistMultipleVpcRouter.java
Outdated
Show resolved
Hide resolved
services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcContainsSubnet.java
Outdated
Show resolved
Hide resolved
| routeTable.setId(routeTableId); | ||
| routeTable.setRouteEntities(routeEntities); | ||
| routeTable.setRouteTableType(RouteTableType.NEUTRON); | ||
| routeTable.setRouteTableType(RouteTableType.NEUTRON_ROUTER.getRouteTableType()); |
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.
Why do we need getRouteTableType()
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.
Because I changed the RouteTableType field class type
| return null; | ||
| } | ||
| RouteTableType routeTableType = routeTable.getRouteTableType(); | ||
| String routeTableType = routeTable.getRouteTableType(); |
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.
Should stick to RouteTableType.
| if (routeTableType == null) { | ||
| return null; | ||
| } else if(routeTableType.getRouteTableType().equals("neutron")){ | ||
| } else if(routeTableType.equals("neutron")){ |
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.
Enum can do comparison easier. No need to convert it to String.
...es/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java
Outdated
Show resolved
Hide resolved
| Mockito.when(routerDatabaseService.getByRouterId(UnitTestConfig.routerId)) | ||
| .thenReturn(new Router(){{setId(UnitTestConfig.routerId);setPorts(new ArrayList<>()); | ||
| setNeutronRouteTable(new RouteTable(){{setRouteEntities(new ArrayList<>());setRouteTableType(RouteTableType.NEUTRON);}});}}); | ||
| setNeutronRouteTable(new RouteTable(){{setRouteEntities(new ArrayList<>());setRouteTableType(RouteTableType.NEUTRON_ROUTER.getRouteTableType());}});}}); |
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.
Same. Should get rid of getRouteTableType() here.
|
|
||
| @JsonProperty("route_table_type") | ||
| private RouteTableType routeTableType; | ||
| private String routeTableType; |
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.
Keep RouteTableType if possible.
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.
If I keep RouteTableType, it is difficult to mock requestBody in UTs
Implement VPC Router in Route Manager: