-
Notifications
You must be signed in to change notification settings - Fork 34
[Microservice] Route Manager Refactor to Support Neutron Routers #361
[Microservice] Route Manager Refactor to Support Neutron Routers #361
Conversation
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.
@kevin-zhonghao Some early feedback, mostly on AlcorWeb change.
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.futurewei.alcor.web.entity.port.PortEntity; | ||
|
|
||
| public class FixedIp { |
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.
FixedIp is also defined in PortEntity
| public static class FixedIp { |
Could you check if we could reuse 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.
Yes ~ I see the FixedIp is the internal class in PortEntity, could we move the entity to the general directory? Because some other class also need it
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Data | ||
| public class RouteEntry extends CustomerResource { |
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 found there are two files, both named RouteEntity in this PR. Very unusual. Could you pls double check?
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.
One is the RouteEntity, it's used for our previous version of route manager; the other one is RouteEntry, it's used for our new version.
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.
Got it. Looked so similar, time to upgrade my glass :-)
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 @xieus Should we remove the previous version of APIs from this PR if we don't need it?
web/src/main/java/com/futurewei/alcor/web/entity/route/RouteTable.java
Outdated
Show resolved
Hide resolved
|
|
||
| public class RouterState { | ||
| private String tenantId; | ||
| import lombok.Data; |
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 Forgot to mention this to you earlier. Going forward, let us not use lombok.Data, instead, let us write setter and getter explicitly.
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.
NP ~ I will remember that and use setter and getter directorly, but in this PR, most of web class used @DaTa. Should I fix them all?
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 It is okay. Plan to change it when you get bored :-)
| @JsonProperty("routes") | ||
| private List<RouteEntity> routeEntities; | ||
|
|
||
| @JsonProperty("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.
For VPCEntity, could use extract the common fields of VPCEntity and NetworkEntity (not existed yet) to a common class? VPCEntity and NetworkEntity could inherit this common class. This way, we could clearly see the differences in two different scenarios.
Not high priority for this PR. We could discuss and plan in next PR.
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.
That's a good idea ~ we could discuss later
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 @xieus Agree, this is a fundamental change, we should wait until next PR.
web/src/main/java/com/futurewei/alcor/web/entity/route/NeutronRouterWebRequestObject.java
Outdated
Show resolved
Hide resolved
services/vpc_manager/src/main/java/com/futurewei/alcor/vpcmanager/service/VpcService.java
Outdated
Show resolved
Hide resolved
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.
@kevin-zhonghao Completed review of NeutronRouterController. The web layer is well written for db access. As discussed, next step is to close the contract with PM.
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
| // RouterExtraAttribute routerExtraAttribute = null; | ||
|
|
||
| try { | ||
| RestPreconditionsUtil.verifyParameterNotNullorEmpty(routerid); |
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 maybe it is time to start thinking about a generic validator for all microservices.
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.
Yes I think so
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.
we could put all validator of microservices into one Util class
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.
Correct. @kevin-zhonghao
That is one way - putting all the util methods together in a utii class, and those methods are set as static methods.
Alternative is to use OOD for validator - a base validator class defining the validate() interface, and a few more child classes inheriting from the base and implement the actual validate method.
Each child class is responsible of one specific class that it wants to validate.
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.
Yes ~ could we do this in next PR?
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 This is not urgent. Instead, we will need design the validator for the ground up and apply it to the web layers of all microservices (of course, starting with small, e.g., from vpc mgr).
Tracking the item in an issue #374 and assign to you and me :-)
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
| neutronRouterWebRequestObject = resource.getRouter(); | ||
| String id = neutronRouterWebRequestObject.getId(); | ||
|
|
||
| if (id == null || StringUtils.isEmpty(id)) { |
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.
Could we consolidate the validation into one?
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.
we may do this in next PR
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
| RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); | ||
|
|
||
| // check resource | ||
| if (!RouteManagerUtil.checkNeutronRouterWebResourceIsValid(resource)) { |
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.
what if the resource.getid() != routerid?
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.
User are not allowed to change the router_id
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.
Some more minor comments.
web/src/main/java/com/futurewei/alcor/web/entity/subnet/SubnetEntity.java
Show resolved
Hide resolved
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Data | ||
| public class RouteEntry extends CustomerResource { |
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.
Got it. Looked so similar, time to upgrade my glass :-)
services/vpc_manager/src/main/java/com/futurewei/alcor/vpcmanager/service/VpcService.java
Outdated
Show resolved
Hide resolved
services/vpc_manager/src/main/java/com/futurewei/alcor/vpcmanager/controller/VpcController.java
Outdated
Show resolved
Hide resolved
# Conflicts: # services/vpc_manager/src/main/java/com/futurewei/alcor/vpcmanager/controller/VpcController.java
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.
@kevin-zhonghao A few more comments. Major comment is about four empty controllers, do we plan to implement something there?
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
| // RouterExtraAttribute routerExtraAttribute = null; | ||
|
|
||
| try { | ||
| RestPreconditionsUtil.verifyParameterNotNullorEmpty(routerid); |
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.
Correct. @kevin-zhonghao
That is one way - putting all the util methods together in a utii class, and those methods are set as static methods.
Alternative is to use OOD for validator - a base validator class defining the validate() interface, and a few more child classes inheriting from the base and implement the actual validate method.
Each child class is responsible of one specific class that it wants to validate.
services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouteController.java
Outdated
Show resolved
Hide resolved
...s/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouteEntryController.java
Outdated
Show resolved
Hide resolved
...s/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouteEntryController.java
Outdated
Show resolved
Hide resolved
| if (routerExtraAttribute != null) { | ||
| BeanUtils.copyProperties(routerExtraAttribute, neutronRouterWebRequestObject); | ||
| neutronRouterWebRequestObject.setId(routerId); | ||
| } |
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 you need to set routerID when routerExtraAttribute != null?
The routerID should be set when the router has or has not extra attribute.
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 ID of NeutronRouterWebRequestObject should be router_id, but I used the BeanUtils.copyProperties method twice. The first time I used it, NeutronRouterWebRequestObject_id = router_id; But the second time I used it, route_extra_attribute_id would overwrite the previous value, so I had to change it set back
web/src/main/java/com/futurewei/alcor/web/entity/route/NeutronRouterWebRequestObject.java
Show resolved
Hide resolved
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| @Data | ||
| public class RouteEntry extends CustomerResource { |
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 @xieus Should we remove the previous version of APIs from this PR if we don't need it?
| @Data | ||
| public class Router extends CustomerResource { | ||
|
|
||
| @JsonProperty("routetable") |
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 There are multiple routetables for a router. It's better rename 'routetable' to 'routetables'
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.
Actually our vpc and subnet still use the previous APIs of route manager, is that correct?
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.
'routetable' to 'routetables' issue has been fixed
| @JsonProperty("routes") | ||
| private List<RouteEntity> routeEntities; | ||
|
|
||
| @JsonProperty("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 @xieus Agree, this is a fundamental change, we should wait until next PR.
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Outdated
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Show resolved
Hide resolved
...oute_manager/src/main/java/com/futurewei/alcor/route/controller/NeutronRouterController.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
...e_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java
Show resolved
Hide resolved
cj-chung
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.
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 great! Thanks @kevin-zhonghao and @cj-chung
| } | ||
|
|
||
| @Test | ||
| public void getConnectedSubnets_pass () throws Exception { |
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.
Really like the comprehensive set of tests in this file 💯
Implement Neutron routers in route manager: