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

Conversation

@songxiaoyan
Copy link
Contributor

Current support CREATE,UPDATE,DELETE(for zeta gateway),continued development based on the design will follow

songxiaoyan and others added 29 commits December 8, 2020 19:12
# Conflicts:
#	services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/FixedIpsProcessor.java
#	services/port_manager/src/main/java/com/futurewei/alcor/portmanager/request/RequestManager.java
#	services/private_ip_manager/src/main/java/com/futurewei/alcor/privateipmanager/controller/IpAddrController.java
#	services/private_ip_manager/src/main/java/com/futurewei/alcor/privateipmanager/repo/IpAddrRangeRepo.java
#	services/private_ip_manager/src/main/java/com/futurewei/alcor/privateipmanager/service/implement/IpAddrServiceImpl.java
# Conflicts:
#	services/port_manager/src/main/java/com/futurewei/alcor/portmanager/request/UpdatePortIpAddressRequest.java
…to gateway_manager_micorservice

# Conflicts:
#	services/gateway_manager/src/main/java/com/futurewei/alcor/gatewaymanager/service/GatewayService.java
@codecov-io
Copy link

Codecov Report

Merging #541 (9232f36) into master (91e71bd) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #541      +/-   ##
============================================
- Coverage     34.95%   34.90%   -0.05%     
+ Complexity     1189     1183       -6     
============================================
  Files           473      473              
  Lines         11799    11799              
  Branches       1526     1526              
============================================
- Hits           4124     4119       -5     
- Misses         7112     7113       +1     
- Partials        563      567       +4     
Impacted Files Coverage Δ Complexity Δ
...nager/service/implement/NetworkAclServiceImpl.java 87.73% <ø> (ø) 29.00 <0.00> (ø)
...ewei/alcor/subnet/controller/SubnetController.java 54.18% <ø> (ø) 13.00 <0.00> (ø)
...cor/subnet/service/implement/SubnetServiceImp.java 1.10% <ø> (ø) 1.00 <0.00> (ø)
...com/futurewei/alcor/macmanager/utils/MacUtils.java 56.52% <0.00%> (-8.70%) 7.00% <0.00%> (-1.00%)
...i/alcor/portmanager/processor/RouterProcessor.java 79.41% <0.00%> (-5.89%) 9.00% <0.00%> (-1.00%)
...rewei/alcor/portmanager/processor/PortContext.java 68.91% <0.00%> (-2.71%) 31.00% <0.00%> (-2.00%)
...alcor/elasticipmanager/dao/ElasticIpAllocator.java 63.81% <0.00%> (+0.27%) 48.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91e71bd...9232f36. Read the comment docs.

@xieus xieus added the feature feature development label Jan 15, 2021
@xieus xieus added this to the Version 1.0.2021.02.28 milestone Jan 15, 2021
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.

@songxiaoyan I cannot find UT codes in this PR. Could you add UT in this PR to verify basic functionalities especially for DB (create/update/delete/query) operations?

Comment on lines 131 to 132
public void getGatewaysByVpcId(@PathVariable("projectid") String projectId) {

Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan The gateway here should be project-scope, not vpc-scope. So, it should be listed all available gateways in the current project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a reserved interface, which will be adjusted according to actual business in the future

Comment on lines +21 to +22
public class GWAttachmentRepository implements ICacheRepository<GWAttachment> {

Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan do we need cache for GWAttachment?

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 think we need to create the Cache Cache of GatewayEntity and GwAttachment in GM's DB for later interface query

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, agree.

Comment on lines +22 to +23
public class GatewayRepository implements ICacheRepository<GatewayEntity> {

Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan Same here. Do we need cache for Gateway?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree to have cache for GM's DB access.

Comment on lines 1 to 7
package com.futurewei.alcor.gatewaymanager.dao;

import org.springframework.stereotype.Repository;

@Repository
public class RouteTableRepository {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan We probably don't need 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.

ok, I can deleted reserved interface if don't need

Comment on lines 10 to 11
public class GatewayWebJson {

Copy link
Contributor

Choose a reason for hiding this comment

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

If this class is the return for "list all available gateway", it's better rename it "GatewaysWebJson"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines +1 to +2
server.port=9015

Copy link
Contributor

Choose a reason for hiding this comment

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

@xieus Does this port for GM? please confirm.

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 fine with 9015 and K8s cluster port of 30015. Keep in mind that 9014 remain available therefore we can keep it for other microservice.


//TODO check whether the project type is zeta by projectId

// create GatewayInfo entity in the DB
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan Please re-phrase the comment here. We are not creating a GatewayInfo enity in GM's DB.

<module>services/security_group_manager</module>
<module>services/elastic_ip_manager</module>
<module>services/quota_manager</module>
<module>services/network_acl_manager</module>
Copy link
Contributor

Choose a reason for hiding this comment

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

Irrelevant comment :-) Can we replace tab with space?

Comment on lines 9 to 10
public class GatewayIpJson {

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include "zeta" in the class name? since it's dedicated for zeta gateway only.

Comment on lines 64 to 65
log.info("update GatewayEntity status to READY failed, detail message: {}", e.getMessage());
//TODO how to handle this exception? rollback all?
Copy link
Contributor

Choose a reason for hiding this comment

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

If the execution goes to this far, that's mean DPM already has an gatewayinfo entry for zeta with status = PENDING. In that case, when port creation comes to DPM, DPM should wait for the status become READY for 30s. If the status still PENDING or FAILED, DPM will switch to OVS plugin. So, should we let the updateDPMCacheGateway try some times and if still failed rollback GM's DB and ask Zeta to remove the corresponding gateway resources.

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 update DPM's cache status to READY is fail,we need retry some times(3 times?),if still failed,we should rollback all the request resource, is this mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. that's what I think.

Comment on lines 72 to 73
//TODO if rollback failed,how we should handle it?
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan If rollback failed, we should raise an alarm or error.

Comment on lines +36 to 37
import com.futurewei.alcor.web.entity.route.RouteWebJson;
import com.futurewei.alcor.web.entity.subnet.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan why your code will touch the import in the SubnetController.java?

import com.futurewei.alcor.web.entity.route.InternalRouterInfo;
import com.futurewei.alcor.web.entity.route.RouteWebJson;
import com.futurewei.alcor.web.entity.subnet.NewHostRoutes;
import com.futurewei.alcor.web.entity.subnet.SubnetEntity;
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan Your IDE seems re-arrange the import statements in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merge code and resolve conflicts, it automatically import, I tried to turn it off.

private List<String> tags;
private String owner;
private Map<String, String> options;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@songxiaoyan Do we need constructor here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean it should be constructor in the GM entity package?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean such the code like this:

public GatewayEntity() {
    }

    public GatewayEntity(GatewayType type, String status, List<GatewayIp> ips, private List<String> attachments, List<String> 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.

oh,I get your mean,I use the set method to assign values, if necessary, I can add the construction method

@songxiaoyan
Copy link
Contributor Author

@songxiaoyan I cannot find UT codes in this PR. Could you add UT in this PR to verify basic functionalities especially for DB (create/update/delete/query) operations?

I'll make it up as soon as possible

* @param gatewayId
* @param gwAttachment
*/
@PostMapping("/project/{projectid}/gateways/{gateway_id}/attachments")
Copy link
Contributor

Choose a reason for hiding this comment

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

Underscore style is recommended: project_id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

if (!gatewayId.equals(attachment.getGatewayId())) {
throw new Exception(ExceptionMsgConfig.GATEWAY_NOT_ASSOCIATED_ATTACHMENT.getMsg());
}
gatewayEntity.getAttachments().removeIf(attachId::equals);
Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to persist the updated gatewayEntity to db here, linke this: gatewayRepository.addItem(gatewayEntity)

Copy link
Contributor Author

@songxiaoyan songxiaoyan Jan 19, 2021

Choose a reason for hiding this comment

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

Have updates in the code below

gatewayEntity.getAttachments().removeIf(attachId::equals);

//delete attachment and update GatewayEntity in the DB
gwAttachmentRepository.deleteItem(attachId,gatewayEntity);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is a transaction required to ensure the consistency of gatewayRepository and gwAttachmentRepository?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are transactions in the method



public List<GWAttachment> getAllAttachments(String gatewayId) throws CacheException {
Map<String, GWAttachment> attachmentMap = gwAttachmentRepository.findAllItems();
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest using findAllItems(Map < String, Object [] > queryParams) instead of findAllItems() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectId);
RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcId);
gatewayService.deleteGatewayInfoForZeta(projectId, vpcId);
log.info("GatewayInfo deleted success,the resource_id is: {}", vpcId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to initialize log with module class? linke this: private static final Logger log = LoggerFactory.getLogger(GatewayController.class);

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 used the @slf4j annotation,do don't need to initialize log.

//TODO check whether the project type is zeta by projectId

GatewayEntity gatewayEntity = null;
Map<String, GWAttachment> attachmentsMap = gwAttachmentRepository.findAllItems();
Copy link
Contributor

Choose a reason for hiding this comment

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

It is recommended to use the method of findAllItems (Map < String, Object [] > queryParams).

Map<String, GWAttachment> attachmentsMap = gwAttachmentRepository.findAllItems();
for (GatewayEntity newGatewayEntity : newGatewayInfo.getGatewayEntities()) {
for (GWAttachment attachment : attachmentsMap.values()) {
if (attachment.getResourceId().equals(newGatewayInfo.getResourceId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be attachment.getGatewayId() == newGatewayInfo.getResourceId() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

String parameters,I think use the equals to compare is better

Copy link
Contributor

Choose a reason for hiding this comment

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

attachment.getGatewayId(), not attachment.getResourceId() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

attachment.getGatewayId() is the gatewayId, attachment.getResourceId() and newGatewayInfo.getResourceId() is the vpcId

*/
@PutMapping("/project/{projectid}/gatewayinfo/{resource_id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public ResponseId updateGatewayInfoForZeta(@PathVariable("projectid") String projectId, @PathVariable("resource_id") String vpcId, @RequestBody GatewayInfoJson gatewayInfoJson) 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.

Who will call this interface? vpc-manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, now it’s just providing this interface

Copy link
Contributor

Choose a reason for hiding this comment

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

DPM will call this interface if there is no gatewayinfo entry in the DPM's cache for a vpc.

throw new Exception(ExceptionMsgConfig.GATEWAY_ENTITY_NOT_FOUND.getMsg());
}
if (gatewayEntity.getType().equals(newGatewayEntity.getType())) {
gatewayEntity.setStatus(newGatewayEntity.getStatus());
Copy link
Contributor

Choose a reason for hiding this comment

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

need gatewayRepository.addItem(gatewayEntity) here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have updates in the code below

Comment on lines +62 to +75
log.info("update GatewayEntity status to READY failed, detail message: {}", e.getMessage());
// rollback GM's DB and ask Zeta to remove the corresponding gateway resources
}

try {
rollback(result, gatewayInfo, gatewayEntity, projectId);
} catch (Exception e) {
log.info("rollback failed, detail message: {}", e.getMessage());
// If rollback failed, we should raise an alarm or error.
}
return null;
});
return gatewayInfo;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can leave rollback to another PR and figure out a better generic way for rollback.

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.

The current code looks good for zeta gateway integration. The rollback part can leave for another PR after we figure out a better generic way to handle the rollback.

@xieus xieus merged commit e07d52e into futurewei-cloud:master Jan 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature feature development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants