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

Commit 977ac09

Browse files
[Hotfix] Short-term Solution to GW Port Issues (#504)
1 parent 053018d commit 977ac09

9 files changed

Lines changed: 44 additions & 36 deletions

File tree

services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/FixedIpsProcessor.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void allocateRandomIpCallback(IRestRequest request) throws Exception {
284284
subnetIds.add(fixedIp.getSubnetId());
285285
}
286286

287-
//getSubnetAndRoute(context, new ArrayList<>(subnetIds));
287+
getSubnetAndRoute(context, new ArrayList<>(subnetIds));
288288
}
289289

290290
private void allocateFixedIpsProcess(PortContext context, List<PortEntity> portEntities, CallbackFunction fetchSubnetCallback) {
@@ -297,9 +297,7 @@ private void allocateFixedIpsProcess(PortContext context, List<PortEntity> portE
297297

298298
for (PortEntity portEntity: portEntities){
299299
List<PortEntity.FixedIp> fixedIps = portEntity.getFixedIps();
300-
if (portEntity.isGatewayPort()) {
301-
continue;
302-
}
300+
303301
if (fixedIps != null) {
304302
for (PortEntity.FixedIp fixedIp: fixedIps) {
305303
if (fixedIp.getSubnetId() != null) {
@@ -330,13 +328,13 @@ private void allocateFixedIpsProcess(PortContext context, List<PortEntity> portE
330328
context.setHasSubnetFixedIps(hasSubnetFixedIps);
331329
context.setUnassignedIpPorts(noAssignedIpPorts);
332330

333-
if (subnetIds.size() > 0) {
334-
//Get subnet
335-
getSubnetEntities(context, new ArrayList<>(subnetIds), true, this::fetchSubnetForAddCallBack);
336331

337-
//Get subnet route
338-
getSubnetRoutes(context, new ArrayList<>(subnetIds));
339-
}
332+
//Get subnet
333+
getSubnetEntities(context, new ArrayList<>(subnetIds), true, this::fetchSubnetForAddCallBack);
334+
335+
//Get subnet route
336+
getSubnetRoutes(context, new ArrayList<>(subnetIds));
337+
340338

341339
//Allocate fixed ip addresses
342340
allocateIpAddresses(context, fixedIpAddresses, this::allocateFixedIpCallback);

services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa
230230
InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(internalSubnetRoutingTableList);
231231

232232
// send InternalRouterInfo contract to DPM
233-
this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
233+
// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
234234

235235
} catch (ParameterNullOrEmptyException e) {
236236
throw e;
@@ -451,7 +451,7 @@ public RouteTableWebJson updateSubnetRouteTable(@PathVariable String projectid,
451451
List<HostRoute> hostRouteToSubnet = updateRoutingRuleResponse.getHostRouteToSubnet();
452452

453453
// send InternalRouterInfo contract to DPM
454-
this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
454+
// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
455455

456456
// update routes in subnet manager
457457
if (hostRouteToSubnet == null) {
@@ -491,8 +491,6 @@ public ResponseId deleteSubnetRouteTable(@PathVariable String projectid, @PathVa
491491
RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid);
492492
RestPreconditionsUtil.verifyResourceFound(projectid);
493493

494-
routerId = this.routerService.deleteSubnetRouteTable(projectid, subnetid);
495-
496494
// sub-level routing rule update
497495
NewRoutesWebRequest newRoutes = new NewRoutesWebRequest();
498496
List<NewRoutesRequest> routes = new ArrayList<>();
@@ -505,14 +503,16 @@ public ResponseId deleteSubnetRouteTable(@PathVariable String projectid, @PathVa
505503
List<HostRoute> hostRouteToSubnet = updateRoutingRuleResponse.getHostRouteToSubnet();
506504

507505
// send InternalRouterInfo contract to DPM
508-
this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
506+
// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo);
509507

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

514+
routerId = this.routerService.deleteSubnetRouteTable(projectid, subnetid);
515+
516516
} catch (ParameterNullOrEmptyException | HostRoutesToSubnetIsNull e) {
517517
throw e;
518518
}

services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,11 @@ public UpdateRoutingRuleResponse updateRoutingRule (String owner, NewRoutesWebRe
479479
}
480480

481481
// find routeTable
482-
Map<String, String[]> requestParams = new HashMap<>();
483-
String[] value = new String[1];
482+
Map<String, Object[]> queryParams = new HashMap<>();
483+
Object[] value = new Object[1];
484484
value[0] = owner;
485-
requestParams.put("owner", value);
485+
queryParams.put("owner", value);
486486

487-
Map<String, Object[]> queryParams =
488-
ControllerUtil.transformUrlPathParams(requestParams, RouteTable.class);
489487
Map<String, RouteTable> routeTableMap = this.routeTableDatabaseService.getAllRouteTables(queryParams);
490488
List<RouteTable> routeTables = new ArrayList<>(routeTableMap.values());
491489
if (routeTables == null || routeTables.size() == 0) {

services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterToSubnetServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public SubnetWebJson getSubnet(String projectid, String subnetId) {
4444

4545
@Override
4646
public SubnetsWebJson getSubnetsByPortId(String projectid, String portId) {
47-
String subnetManagerServiceUrl = subnetUrl + "/project/" + projectid + "/subnets?port_id=" + portId;
47+
String subnetManagerServiceUrl = subnetUrl + "/project/" + projectid + "/subnets?gatewayPortId=" + portId;
4848
SubnetsWebJson response = restTemplate.getForObject(subnetManagerServiceUrl, SubnetsWebJson.class);
4949
return response;
5050
}

services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static boolean checkSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJ
148148

149149
// routeTableType
150150
String routeTableTypeStr = resource.getRoutetable().getRouteTableType();
151-
if (routeTableTypeStr != null && !routeTableTypeStr.equals("public_subnet") && !routeTableTypeStr.equals("private_subnet")) {
151+
if (routeTableTypeStr != null && !routeTableTypeStr.equals("public_subnet") && !routeTableTypeStr.equals("private_subnet") && !routeTableTypeStr.equals("neutron_subnet")) {
152152
return false;
153153
}
154154

services/subnet_manager/src/main/java/com/futurewei/alcor/subnet/controller/SubnetController.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ public SubnetWebJson createSubnetState(@PathVariable String projectId, @RequestB
296296
// if (macState != null) {
297297
// inSubnetEntity.setGatewayMacAddress(macState.getMacAddress());
298298
// }
299+
this.subnetDatabaseService.addSubnet(inSubnetEntity);
300+
299301
if (gatewayIpIsInAllocatedRange) {
300302
PortEntity portEntity = this.subnetService.constructPortEntity(portId, vpcId, subnetId, ipResponse.getIp(), ConstantsConfig.DeviceOwner);
301303
GatewayPortDetail gatewayPortDetail = this.subnetToPortManagerService.createGatewayPort(projectId, portEntity);
302304

303305
inSubnetEntity.setGatewayIp(ipResponse.getIp());
304306
inSubnetEntity.setGatewayPortDetail(gatewayPortDetail);
307+
inSubnetEntity.setGatewayPortId(gatewayPortDetail.getGatewayPortId());
305308
} else {
306309
String gatewayIP = SubnetManagementUtil.setGatewayIpValue(gatewayIp, cidr);
307310
if (gatewayIp != null) {
@@ -310,8 +313,10 @@ public SubnetWebJson createSubnetState(@PathVariable String projectId, @RequestB
310313

311314
inSubnetEntity.setGatewayIp(gatewayIP);
312315
inSubnetEntity.setGatewayPortDetail(gatewayPortDetail);
316+
inSubnetEntity.setGatewayPortId(gatewayPortDetail.getGatewayPortId());
313317
}
314318
}
319+
315320
if (ipResponse != null && ipResponse.getIpVersion() == 4) {
316321
inSubnetEntity.setIpV4RangeId(ipResponse.getRangeId());
317322
}else if (ipResponse != null && ipResponse.getIpVersion() == 6) {
@@ -441,6 +446,7 @@ public SubnetWebJson updateSubnetState(@PathVariable String projectId, @PathVari
441446
GatewayPortDetail gatewayPortDetail = this.subnetToPortManagerService.createGatewayPort(projectId, portEntity);
442447
subnetEntity.setGatewayPortDetail(gatewayPortDetail);
443448
subnetEntity.setGatewayIp(newGatewayIp);
449+
subnetEntity.setGatewayPortId(gatewayPortDetail.getGatewayPortId()); // -tem
444450

445451
// delete port with old gateway port IP & port Id
446452
this.subnetToPortManagerService.deleteGatewayPort(projectId,oldPortId);
@@ -457,13 +463,12 @@ public SubnetWebJson updateSubnetState(@PathVariable String projectId, @PathVari
457463
subnetEntity.setRevisionNumber(revisionNumber + 1);
458464
}
459465

466+
// update subnet routing rule in route manager
467+
this.subnetService.updateSubnetRoutingRuleInRM(projectId, subnetId, subnetEntity);
460468

461469
this.subnetDatabaseService.addSubnet(subnetEntity);
462470
subnetEntity = this.subnetDatabaseService.getBySubnetId(subnetId);
463471

464-
// update subnet routing rule in route manager
465-
this.subnetService.updateSubnetRoutingRuleInRM(projectId, subnetId, subnetEntity);
466-
467472
} catch (ParameterNullOrEmptyException e) {
468473
logger.error(e.getMessage());
469474
throw new Exception(e);
@@ -516,19 +521,19 @@ public ResponseId deleteSubnetState(@PathVariable String projectId, @PathVariabl
516521
throw new SubnetBindRoutes();
517522
}
518523

519-
this.subnetDatabaseService.deleteSubnet(subnetId);
520-
521524
// delete subnet id in vpc
522525
this.subnetService.deleteSubnetIdInVpc(subnetId, projectId, subnetEntity.getVpcId());
523526

524527
// delete subnet routing rule in route manager
525528
this.subnetService.deleteSubnetRoutingRuleInRM(projectId, subnetId);
526529

527-
// delete gateway port in port manager
528-
GatewayPortDetail gatewayPortDetail = subnetEntity.getGatewayPortDetail();
529-
if (gatewayPortDetail != null) {
530-
this.subnetToPortManagerService.deleteGatewayPort(projectId, gatewayPortDetail.getGatewayPortId());
531-
}
530+
// TODO: delete gateway port in port manager. Temporary solution, need PM fix issue
531+
// GatewayPortDetail gatewayPortDetail = subnetEntity.getGatewayPortDetail();
532+
// if (gatewayPortDetail != null) {
533+
// this.subnetToPortManagerService.deleteGatewayPort(projectId, gatewayPortDetail.getGatewayPortId());
534+
// }
535+
536+
this.subnetDatabaseService.deleteSubnet(subnetId);
532537

533538
} catch (ParameterNullOrEmptyException | HavePortInSubnet | SubnetBindRoutes e) {
534539
logger.error(e.getMessage());

services/subnet_manager/src/test/java/com/futurewei/alcor/subnet/SubnetControllerTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.futurewei.alcor.common.exception.FallbackException;
1010
import com.futurewei.alcor.common.exception.ResourceNotFoundException;
11+
import com.futurewei.alcor.subnet.config.ConstantsConfig;
1112
import com.futurewei.alcor.subnet.config.UnitTestConfig;
1213
import com.futurewei.alcor.subnet.service.SubnetDatabaseService;
1314
import com.futurewei.alcor.subnet.service.SubnetService;
@@ -116,6 +117,8 @@ public void createSubnetState_create_pass () throws Exception {
116117
.thenReturn(new String[2]);
117118
Mockito.when(subnetToPortManagerService.createGatewayPort(anyString(), any(PortEntity.class)))
118119
.thenReturn(new GatewayPortDetail(UnitTestConfig.macAddress, UnitTestConfig.gatewayPortId));
120+
Mockito.when(subnetService.constructPortEntity(anyString(), anyString(), anyString(), anyString(), anyString()))
121+
.thenReturn(new PortEntity());
119122

120123
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
121124
.content(UnitTestConfig.resource))
@@ -268,6 +271,8 @@ public void createSubnetState_canNotFindIP_notPass () throws Exception {
268271
.thenThrow(new FallbackException("fallback request"));
269272
Mockito.when(subnetToPortManagerService.createGatewayPort(anyString(), any(PortEntity.class)))
270273
.thenReturn(new GatewayPortDetail(UnitTestConfig.macAddress, UnitTestConfig.gatewayPortId));
274+
Mockito.when(subnetService.constructPortEntity(anyString(), anyString(), anyString(), anyString(), anyString()))
275+
.thenReturn(new PortEntity());
271276
try {
272277
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
273278
.content(UnitTestConfig.resource))
@@ -311,6 +316,8 @@ public void createSubnetState_invalidCidr_notPass () throws Exception {
311316
.thenReturn(new String[2]);
312317
Mockito.when(subnetToPortManagerService.createGatewayPort(anyString(), any(PortEntity.class)))
313318
.thenReturn(new GatewayPortDetail(UnitTestConfig.macAddress, UnitTestConfig.gatewayPortId));
319+
Mockito.when(subnetService.constructPortEntity(anyString(), anyString(), anyString(), anyString(), anyString()))
320+
.thenReturn(new PortEntity());
314321
try {
315322
this.mockMvc.perform(post(createUri).contentType(MediaType.APPLICATION_JSON)
316323
.content(UnitTestConfig.invalidCidrResource))

web/src/main/java/com/futurewei/alcor/web/entity/port/PortEntity.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ public class PortEntity extends CustomerResource {
119119
@JsonProperty("mac_learning_enabled")
120120
private boolean macLearningEnabled;
121121

122-
public boolean isGatewayPort () {
123-
return deviceOwner != null;
124-
}
125-
126122
public PortEntity() {
127123
}
128124

web/src/main/java/com/futurewei/alcor/web/entity/subnet/SubnetEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public class SubnetEntity extends CustomerResource {
4141
@JsonProperty("gateway_ip")
4242
private String gatewayIp = "";
4343

44+
// subnet_gateway_port_id
45+
@JsonProperty("gatewayPortId")
46+
private String gatewayPortId;
47+
4448
@JsonProperty("gateway_port_detail")
4549
private GatewayPortDetail gatewayPortDetail;
4650

0 commit comments

Comments
 (0)