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 Aug 21, 2020

Implement Neutron routers in route manager:

  • CRUD APIs
  • Add/remove interface to Neutron routers
  • Add/remove routes to Neutron routers
  • Get connected subnets

@xieus xieus requested review from cj-chung and xieus August 24, 2020 17:58
@xieus xieus self-assigned this Aug 24, 2020
@xieus xieus added enhancement New feature or request feature feature development labels Aug 24, 2020
@xieus xieus added this to the Version 0.8.2020.08.30 milestone Aug 24, 2020
@xieus xieus changed the title Feature/refactor route manager [Microservice] Route Manager Refactor to Support Neutron Routers Aug 24, 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.

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

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

Could you check if we could reuse 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.

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

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

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 @xieus Should we remove the previous version of APIs from this PR if we don't need it?


public class RouterState {
private String tenantId;
import lombok.Data;
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 Forgot to mention this to you earlier. Going forward, let us not use lombok.Data, instead, let us write setter and getter explicitly.

Copy link
Contributor Author

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?

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 It is okay. Plan to change it when you get bored :-)

@JsonProperty("routes")
private List<RouteEntity> routeEntities;

@JsonProperty("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

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.

Copy link
Contributor Author

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

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 @xieus Agree, this is a fundamental change, we should wait until next PR.

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.

@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.

// RouterExtraAttribute routerExtraAttribute = null;

try {
RestPreconditionsUtil.verifyParameterNotNullorEmpty(routerid);
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 maybe it is time to start thinking about a generic validator for all microservices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think so

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

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

neutronRouterWebRequestObject = resource.getRouter();
String id = neutronRouterWebRequestObject.getId();

if (id == null || StringUtils.isEmpty(id)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid);

// check resource
if (!RouteManagerUtil.checkNeutronRouterWebResourceIsValid(resource)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

Some more minor comments.

import org.jetbrains.annotations.NotNull;

@Data
public class RouteEntry extends CustomerResource {
Copy link
Contributor

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

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.

@kevin-zhonghao A few more comments. Major comment is about four empty controllers, do we plan to implement something there?

// RouterExtraAttribute routerExtraAttribute = null;

try {
RestPreconditionsUtil.verifyParameterNotNullorEmpty(routerid);
Copy link
Contributor

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.

if (routerExtraAttribute != null) {
BeanUtils.copyProperties(routerExtraAttribute, neutronRouterWebRequestObject);
neutronRouterWebRequestObject.setId(routerId);
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

import org.jetbrains.annotations.NotNull;

@Data
public class RouteEntry extends CustomerResource {
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 @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")
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 There are multiple routetables for a router. It's better rename 'routetable' to 'routetables'

Copy link
Contributor Author

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?

Copy link
Contributor Author

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")
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 @xieus Agree, this is a fundamental change, we should wait until next PR.

Copy link
Contributor

@cj-chung cj-chung left a comment

Choose a reason for hiding this comment

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

LGTM

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 great! Thanks @kevin-zhonghao and @cj-chung

}

@Test
public void getConnectedSubnets_pass () throws Exception {
Copy link
Contributor

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 💯

@xieus xieus merged commit 1a478a5 into futurewei-cloud:master Sep 4, 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