Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Conversation

@kevin-zhonghao
Copy link
Contributor

@kevin-zhonghao kevin-zhonghao commented Sep 8, 2020

Implement VPC Router in Route Manager:

  • CRUD APIs for VPC router
  • CRUD APIs for VPC route table
  • CRUD APIs for Subnet route table

@xieus xieus requested review from cj-chung and xieus September 8, 2020 23:19
@xieus xieus added enhancement New feature or request feature feature development labels Sep 8, 2020
@xieus xieus added this to the Version 0.9.2020.09.30 milestone Sep 8, 2020
Comment on lines 127 to 136
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();
}
}
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Comment on lines 177 to 188
// 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);
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

Comment on lines 202 to 210
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;
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

return new ArrayList<RouteTable>();
}
return router.getVpcRouteTable();
}
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@cj-chung
Copy link
Contributor

LGTM

@xieus xieus changed the title Feature/Vpc_Route_APIs [Microservice] Route Manager Supports VPC Routing Sep 21, 2020
Copy link
Contributor

@xieus xieus left a 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"),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

routeTable.setId(routeTableId);
routeTable.setRouteEntities(routeEntities);
routeTable.setRouteTableType(RouteTableType.NEUTRON);
routeTable.setRouteTableType(RouteTableType.NEUTRON_ROUTER.getRouteTableType());
Copy link
Contributor

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()

Copy link
Contributor Author

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();
Copy link
Contributor

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")){
Copy link
Contributor

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.

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());}});}});
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep RouteTableType if possible.

Copy link
Contributor Author

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

@xieus xieus merged commit 1f9d405 into futurewei-cloud:master Sep 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request feature feature development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants