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

[Hotfix] Fix Issue #506 and Issue #505 #511

Merged
merged 30 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
24b9b76
commit message
kevin-zhonghao Oct 7, 2020
08ec421
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 7, 2020
2507b8f
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 15, 2020
8cab6bf
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 15, 2020
d9d2a58
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 16, 2020
daba98e
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 20, 2020
b813735
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 22, 2020
fd9a984
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 28, 2020
e44875a
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 29, 2020
98dcf0d
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Oct 30, 2020
a9c3a47
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Nov 3, 2020
f058bd1
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Nov 5, 2020
08d4a6f
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Nov 5, 2020
ef0b4fe
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Nov 18, 2020
bf29fc7
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 2, 2020
b23608a
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 3, 2020
d2e742c
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 4, 2020
7b1f333
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 8, 2020
0599937
update
kevin-zhonghao Dec 9, 2020
487948d
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 17, 2020
1e62759
Merge branch 'new_master' into fix/issue_506_505
kevin-zhonghao Dec 17, 2020
602c7f9
update
kevin-zhonghao Dec 18, 2020
ce19ed1
update
kevin-zhonghao Dec 18, 2020
4358c99
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 19, 2020
fb907ee
Merge branch 'new_master' into fix/issue_506_505
kevin-zhonghao Dec 19, 2020
b61fcc1
update
kevin-zhonghao Dec 22, 2020
e851cce
Merge branch 'master' of https://github.com/futurewei-cloud/alcor int…
kevin-zhonghao Dec 22, 2020
fc24c1f
Merge branch 'new_master' into fix/issue_506_505
kevin-zhonghao Dec 22, 2020
8af5732
update
kevin-zhonghao Dec 23, 2020
bf4b11d
Merge branch 'master' into fix/issue_506_505
Jan 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@ public RouterInterfaceResponse addInterfaceToNeutronRouter(@PathVariable String

// TODO: return all connected subnet-ids to Port Manager. The algorithm as follow:
//1. get ports array from the router.
//2. get subnet-ids from the mapping table of port-subnet for all ports.
//3. call Port Manager's /project/{project_id}/update-l3-neighbors/{new_subnet_id} with BODY {operation_type, vpcid, [old_subnet_ids]}.
Router router = this.routerDatabaseService.getByRouterId(routerid);
List<String> gatewayPorts = router.getGatewayPorts();
//2. call Port Manager's /project/{project_id}/update-l3-neighbors/{new_subnet_id} with BODY {operation_type, vpcid, [old_subnet_ids]}.
//Need to check if there is only one gateway port exists in the current router, we don't need to request PM for update-l3-neighbors. This operation only happen when there are more than 2 ports exist in the router.
if (gatewayPorts != null && gatewayPorts.size() > 1) {
// TODO: waiting for PM new API
this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "add", gatewayPorts);
}

return routerInterfaceResponse;

Expand All @@ -314,6 +319,17 @@ public RouterInterfaceResponse removeInterfaceToNeutronRouter(@PathVariable Stri

RouterInterfaceResponse routerInterfaceResponse = this.neutronRouterService.removeAnInterfaceToNeutronRouter(projectid, portId, subnetId, routerid);

// TODO: return all connected subnet-ids to Port Manager. The algorithm as follow:
//1. get ports array from the router.
Router router = this.routerDatabaseService.getByRouterId(routerid);
List<String> gatewayPorts = router.getGatewayPorts();
//2. call Port Manager's /project/{project_id}/update-l3-neighbors/{new_subnet_id} with BODY {operation_type, vpcid, [old_subnet_ids]}.
//Need to check if there is only one gateway port exists in the current router, we don't need to request PM for update-l3-neighbors. This operation only happen when there are more than 2 ports exist in the router.
if (gatewayPorts != null && gatewayPorts.size() > 1) {
// TODO: waiting for PM new API
this.routerToPMService.updateL3Neighbors(projectid, router.getOwner(), subnetId, "delete", gatewayPorts);
}

return routerInterfaceResponse;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,34 +430,35 @@ public RouteTableWebJson updateSubnetRouteTable(@PathVariable String projectid,
}

routetable = this.routerService.updateSubnetRouteTable(projectid, subnetid, resource);

// sub-level routing rule update
List<RouteEntry> routeEntities = routetable.getRouteEntities();
NewRoutesWebRequest newRoutes = new NewRoutesWebRequest();
List<NewRoutesRequest> routes = new ArrayList<>();
for (RouteEntry routeEntry : routeEntities) {
String destination = routeEntry.getDestination();
String target = routeEntry.getTarget();
NewRoutesRequest newRoutesRequest = new NewRoutesRequest(destination, target);
routes.add(newRoutesRequest);
}
newRoutes.setRoutes(routes);

UpdateRoutingRuleResponse updateRoutingRuleResponse = this.neutronRouterService.updateRoutingRule(subnetid, newRoutes, false);
InternalSubnetRoutingTable internalSubnetRoutingTable = updateRoutingRuleResponse.getInternalSubnetRoutingTable();
List<InternalSubnetRoutingTable> internalSubnetRoutingTables = new ArrayList<>();
internalSubnetRoutingTables.add(internalSubnetRoutingTable);
InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(internalSubnetRoutingTables);
List<HostRoute> hostRouteToSubnet = updateRoutingRuleResponse.getHostRouteToSubnet();

// send InternalRouterInfo contract to DPM
// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);

// update routes in subnet manager
if (hostRouteToSubnet == null) {
throw new HostRoutesToSubnetIsNull();
if (routetable != null) {
// sub-level routing rule update
List<RouteEntry> routeEntities = routetable.getRouteEntities();
NewRoutesWebRequest newRoutes = new NewRoutesWebRequest();
List<NewRoutesRequest> routes = new ArrayList<>();
for (RouteEntry routeEntry : routeEntities) {
String destination = routeEntry.getDestination();
String target = routeEntry.getTarget();
NewRoutesRequest newRoutesRequest = new NewRoutesRequest(destination, target);
routes.add(newRoutesRequest);
}
newRoutes.setRoutes(routes);

UpdateRoutingRuleResponse updateRoutingRuleResponse = this.neutronRouterService.updateRoutingRule(subnetid, newRoutes, false);
InternalSubnetRoutingTable internalSubnetRoutingTable = updateRoutingRuleResponse.getInternalSubnetRoutingTable();
List<InternalSubnetRoutingTable> internalSubnetRoutingTables = new ArrayList<>();
internalSubnetRoutingTables.add(internalSubnetRoutingTable);
InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(internalSubnetRoutingTables);
List<HostRoute> hostRouteToSubnet = updateRoutingRuleResponse.getHostRouteToSubnet();

// send InternalRouterInfo contract to DPM
//this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);

// update routes in subnet manager
if (hostRouteToSubnet == null) {
throw new HostRoutesToSubnetIsNull();
}
this.vpcRouterToSubnetService.updateRoutingRuleInSubnetManager(projectid, subnetid, hostRouteToSubnet);
}
this.vpcRouterToSubnetService.updateRoutingRuleInSubnetManager(projectid, subnetid, hostRouteToSubnet);

} catch (ParameterNullOrEmptyException | HostRoutesToSubnetIsNull e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ public RouteTable updateSubnetRouteTable(String projectId, String subnetId, Rout
RouteTable inRoutetable = resource.getRoutetable();
// Get or create a router for a Subnet
routeTable = getSubnetRouteTable(projectId, subnetId);
if (routeTable != null) {
RouteManagerUtil.copyPropertiesIgnoreNull(inRoutetable, routeTable);
this.routeTableDatabaseService.addRouteTable(routeTable);

RouteManagerUtil.copyPropertiesIgnoreNull(inRoutetable, routeTable);
this.routeTableDatabaseService.addRouteTable(routeTable);
// TODO: notify Subnet Manager to update L3 neighbor for all ports in the same subnet

// TODO: notify Subnet Manager to update L3 neighbor for all ports in the same subnet
}

return routeTable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.futurewei.alcor.web.entity.port.PortEntity;
import com.futurewei.alcor.web.entity.port.PortWebBulkJson;
import com.futurewei.alcor.web.entity.port.PortWebJson;
import com.futurewei.alcor.web.entity.route.RouterUpdateInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -81,4 +82,17 @@ public void updatePort(String projectid, String portId, PortEntity portEntity) {
HttpEntity<PortWebJson> request = new HttpEntity<>(new PortWebJson(portEntity));
restTemplate.put(portManagerServiceUrl, request, PortWebJson.class);
}

@Override
public void updateL3Neighbors(String projectid, String vpcId, String subnetId, String operationType, List<String> gatewayPorts) {
String portManagerServiceUrl = portUrl + "/project/" + projectid + "/update-l3-neighbors";
RouterUpdateInfo routerUpdateInfo = new RouterUpdateInfo();
routerUpdateInfo.setGatewayPortIds(gatewayPorts);
routerUpdateInfo.setSubnetId(subnetId);
routerUpdateInfo.setOperationType(operationType);
routerUpdateInfo.setVpcId(vpcId);

HttpEntity<RouterUpdateInfo> request = new HttpEntity<>(routerUpdateInfo);
restTemplate.put(portManagerServiceUrl, request, RouterUpdateInfo.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ public interface RouterToPMService {

public List<String> getSubnetIdsFromPM (String projectid, List<String> gatewayPorts) throws PortWebBulkJsonOrPortEntitiesListIsNull;
public void updatePort (String projectid, String portId, PortEntity portEntity);
public void updateL3Neighbors (String projectid, String vpcId, String subnetId, String operationType, List<String> gatewayPorts);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import com.futurewei.alcor.subnet.utils.SubnetManagementUtil;
import com.futurewei.alcor.subnet.utils.ThreadPoolExecutorUtils;
import com.futurewei.alcor.web.entity.ip.IpAddrRequest;
import com.futurewei.alcor.web.entity.mac.MacState;
import com.futurewei.alcor.web.entity.mac.MacStateJson;
import com.futurewei.alcor.web.entity.port.PortEntity;
import com.futurewei.alcor.web.entity.route.InternalRouterInfo;
import com.futurewei.alcor.web.entity.route.RouteEntity;
import com.futurewei.alcor.web.entity.subnet.*;
import com.futurewei.alcor.web.entity.vpc.VpcWebJson;
Expand Down Expand Up @@ -208,6 +206,8 @@ public SubnetWebJson createSubnetState(@PathVariable String projectId, @RequestB
String vpcId = inSubnetEntity.getVpcId();
String cidr = inSubnetEntity.getCidr();
String gatewayIp = inSubnetEntity.getGatewayIp();
// TODO: if it didn't give gateway ip, we should allocate the first ip in cidr as gateway ip

boolean gatewayIpIsValid = SubnetManagementUtil.checkGatewayIpInputSupported(gatewayIp, cidr);
if (!gatewayIpIsValid) {
throw new GatewayIpUnsupported();
Expand Down Expand Up @@ -413,6 +413,7 @@ public SubnetWebJson updateSubnetState(@PathVariable String projectId, @PathVari
RestPreconditionsUtil.verifyParameterNotNullorEmpty(subnetId);

SubnetWebRequest inSubnetWebResponseObject = resource.getSubnet();
List<HostRoute> hostRoutes = inSubnetWebResponseObject.getHostRoutes();
Preconditions.checkNotNull(inSubnetWebResponseObject, "Empty resource");
// RestPreconditionsUtil.verifyResourceNotNull(inSubnetWebResponseObject);
RestPreconditionsUtil.populateResourceProjectId(inSubnetWebResponseObject, projectId);
Expand Down Expand Up @@ -477,7 +478,10 @@ public SubnetWebJson updateSubnetState(@PathVariable String projectId, @PathVari
}

// update subnet routing rule in route manager
this.subnetService.updateSubnetRoutingRuleInRM(projectId, subnetId, subnetEntity);
if (hostRoutes != null && hostRoutes.size() > 0) {
this.subnetService.updateSubnetRoutingRuleInRM(projectId, subnetId, subnetEntity);
}


this.subnetDatabaseService.addSubnet(subnetEntity);
subnetEntity = this.subnetDatabaseService.getBySubnetId(subnetId);
Expand Down Expand Up @@ -514,7 +518,6 @@ public ResponseId deleteSubnetState(@PathVariable String projectId, @PathVariabl
return new ResponseId();
}

// check if there is any port in this subnet
String rangeId = null;
String ipV4RangeId = subnetEntity.getIpV4RangeId();
String ipV6RangeId = subnetEntity.getIpV6RangeId();
Expand All @@ -523,19 +526,18 @@ public ResponseId deleteSubnetState(@PathVariable String projectId, @PathVariabl
} else {
rangeId = ipV6RangeId;
}
// Boolean checkIfAnyPortInSubnet = this.subnetService.checkIfAnyPortInSubnet(rangeId);
// if (checkIfAnyPortInSubnet) {
// throw new HavePortInSubnet();
// }

// check if subnet bind any routes
Boolean checkIfSubnetBindAnyRoutes = this.subnetService.checkIfSubnetBindAnyRoutes(subnetEntity);
if (checkIfSubnetBindAnyRoutes) {
throw new SubnetBindRoutes();
// TODO: check if there is any gateway / non-gateway port for the subnet, waiting for PM new API
Boolean checkIfAnyNoneGatewayPortInSubnet = this.subnetService.checkIfAnyPortInSubnet(projectId, subnetId);
if (checkIfAnyNoneGatewayPortInSubnet) {
throw new HavePortInSubnet();
}

// delete subnet id in vpc
this.subnetService.deleteSubnetIdInVpc(subnetId, projectId, subnetEntity.getVpcId());
// check if subnet bind any router
Boolean checkIfSubnetBindAnyRouter = this.subnetService.checkIfSubnetBindAnyRouter(subnetEntity);
if (checkIfSubnetBindAnyRouter) {
throw new SubnetBindRouter();
}

// delete subnet routing rule in route manager
this.subnetService.deleteSubnetRoutingRuleInRM(projectId, subnetId);
Expand All @@ -546,9 +548,15 @@ public ResponseId deleteSubnetState(@PathVariable String projectId, @PathVariabl
this.subnetToPortManagerService.deleteGatewayPort(projectId, gatewayPortDetail.getGatewayPortId());
}

// delete subnet id in vpc
this.subnetService.deleteSubnetIdInVpc(subnetId, projectId, subnetEntity.getVpcId());

// delete ip range in Private IP Manager
this.subnetService.deleteIPRangeInPIM(rangeId);

this.subnetDatabaseService.deleteSubnet(subnetId);

} catch (ParameterNullOrEmptyException | HavePortInSubnet | SubnetBindRoutes e) {
} catch (ParameterNullOrEmptyException | HavePortInSubnet | SubnetBindRouter e) {
logger.error(e.getMessage());
throw new Exception(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code= HttpStatus.CONFLICT, reason="Subnet bind routes, we can Not delete subnet")
public class SubnetBindRoutes extends Exception {
public class SubnetBindRouter extends Exception {
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void fallbackOperation (AtomicReference<RouteWebJson> routeResponseAtomic
public void deleteSubnetIdInVpc (String subnetId, String projectId, String vpcId) throws Exception;

// check if there is any port in this subnet
public boolean checkIfAnyPortInSubnet (String rangeId) throws RangeIdIsNullOrEmpty;
public boolean checkIfAnyPortInSubnet (String projectId, String subnetId) throws SubnetIdIsNull;

// check if subnet bind any routes
public boolean checkIfSubnetBindAnyRoutes (SubnetEntity subnetEntity);
public boolean checkIfSubnetBindAnyRouter(SubnetEntity subnetEntity);

// check if cidr overlap
public boolean checkIfCidrOverlap (String cidr,String projectId, String vpcId) throws FallbackException, ResourceNotFoundException, ResourcePersistenceException, CidrNotWithinNetworkCidr, CidrOverlapWithOtherSubnets;
Expand All @@ -85,4 +85,7 @@ public void fallbackOperation (AtomicReference<RouteWebJson> routeResponseAtomic

// construct port entity passed in PM
public PortEntity constructPortEntity (String portId, String vpcId, String subnetId, String gatewayIP, String deviceOwner);

// delete ip range in Private IP Manager
public void deleteIPRangeInPIM (String rangeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class SubnetServiceImp implements SubnetService {
@Value("${microservices.ip.service.url}")
private String ipUrl;

@Value("${microservices.port.service.url}")
private String portUrl;

private RestTemplate restTemplate = new RestTemplate();

@Async
Expand Down Expand Up @@ -365,27 +368,21 @@ public void deleteSubnetIdInVpc(String subnetId, String projectId, String vpcId)
}

@Override
public boolean checkIfAnyPortInSubnet(String rangeId) throws RangeIdIsNullOrEmpty {
if (rangeId == null) {
throw new RangeIdIsNullOrEmpty();
public boolean checkIfAnyPortInSubnet(String projectId, String subnetId) throws SubnetIdIsNull {
if (subnetId == null) {
throw new SubnetIdIsNull();
}
String ipManagerServiceUrl = ipUrl + "range/" + rangeId;
IpAddrRangeRequest ipAddrRangeRequest = restTemplate.getForObject(ipManagerServiceUrl, IpAddrRangeRequest.class);
if (ipAddrRangeRequest == null) {
String portManagerServiceUrl = portUrl + "project/" + projectId + "/subnet-port-count/" + subnetId;
int portCount = restTemplate.getForObject(portManagerServiceUrl, Integer.class);
if (portCount == 0) {
return false;
}

// check usedIps
long usedIps = ipAddrRangeRequest.getUsedIps();
if (usedIps > ConstantsConfig.UsedIpThreshold) {
return true;
}

return false;
return true;
}

@Override
public boolean checkIfSubnetBindAnyRoutes(SubnetEntity subnetEntity) {
public boolean checkIfSubnetBindAnyRouter(SubnetEntity subnetEntity) {

String attachedRouterId = subnetEntity.getAttachedRouterId();
if (attachedRouterId == null || attachedRouterId.equals("")){
Expand Down Expand Up @@ -614,4 +611,14 @@ public PortEntity constructPortEntity(String portId, String vpcId, String subnet
return portEntity;
}

@Override
public void deleteIPRangeInPIM(String rangeId) {
if (rangeId == null) {
return;
}

String ipManagerCreateRangeUrl = ipUrl + "range/"+ rangeId;
restTemplate.delete(ipManagerCreateRangeUrl);
}

}