From 04cbb1e6d7368bbaeb351841edf6cc9c5352c68d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 12:06:50 -0700 Subject: [PATCH 01/18] Update router manager api --- .../route/controller/RouterController.java | 102 +++++++++++++++--- .../route/exception/CanNotFindRouter.java | 20 ++++ .../route/service/Impl/RouterServiceImpl.java | 51 +++++---- .../alcor/route/service/RouterService.java | 6 +- .../futurewei/alcor/route/VpcRouterTests.java | 30 ++++-- 5 files changed, 167 insertions(+), 42 deletions(-) create mode 100644 services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 4d94690d7..548e155dd 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -22,10 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.logging.Logger; import com.futurewei.alcor.common.logging.LoggerFactory; import com.futurewei.alcor.common.stats.DurationStatistics; -import com.futurewei.alcor.route.exception.CanNotFindVpc; -import com.futurewei.alcor.route.exception.HostRoutesToSubnetIsNull; -import com.futurewei.alcor.route.exception.OwnMultipleSubnetRouteTablesException; -import com.futurewei.alcor.route.exception.VpcNonEmptyException; +import com.futurewei.alcor.route.exception.*; import com.futurewei.alcor.route.service.*; import com.futurewei.alcor.route.utils.RestPreconditionsUtil; import com.futurewei.alcor.route.utils.RouteManagerUtil; @@ -70,7 +67,7 @@ public class RouterController { private RouterToDPMService routerToDPMService; /** - * Get or Create VPC router + * Get VPC router * @param projectid * @param vpcid * @return @@ -80,7 +77,7 @@ public class RouterController { method = GET, value = {"/project/{projectid}/vpcs/{vpcid}/router"}) @DurationStatistics - public RouterWebJson getOrCreateVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + public RouterWebJson getVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { Router router = null; @@ -89,7 +86,46 @@ public RouterWebJson getOrCreateVpcRouter(@PathVariable String projectid, @PathV RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); RestPreconditionsUtil.verifyResourceFound(projectid); - router = this.routerService.getOrCreateVpcRouter(projectid, vpcid); + router = this.routerService.getVpcRouter(projectid, vpcid); + + } catch (ParameterNullOrEmptyException e) { + throw e; + } catch (CanNotFindVpc e) { + logger.log(Level.WARNING, e.getMessage() + " : " + vpcid); + throw e; + } catch (DatabasePersistenceException e) { + throw e; + } + + if (router == null) + { + throw new CanNotFindRouter(); + } + + return new RouterWebJson(router); + } + + /** + * Create VPC router + * @param projectid + * @param vpcid + * @return + * @throws Exception + */ + @RequestMapping( + method = POST, + value = {"/project/{projectid}/vpcs/{vpcid}/router"}) + @DurationStatistics + public RouterWebJson createVpcRouter(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + + Router router = null; + + try { + RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); + RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); + RestPreconditionsUtil.verifyResourceFound(projectid); + + router = this.routerService.createVpcRouter(projectid, vpcid); } catch (ParameterNullOrEmptyException e) { throw e; @@ -139,7 +175,7 @@ public ResponseId deleteVpcRouter(@PathVariable String projectid, @PathVariable } /** - * Get or Create VPC default route table + * Get VPC default route table * @param projectid * @param vpcid * @return @@ -149,7 +185,7 @@ public ResponseId deleteVpcRouter(@PathVariable String projectid, @PathVariable method = GET, value = {"/project/{projectid}/vpcs/{vpcid}/vpcroutetable"}) @DurationStatistics - public RouteTableWebJson getOrCreateVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + public RouteTableWebJson getVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { RouteTable routetable = null; @@ -158,7 +194,41 @@ public RouteTableWebJson getOrCreateVpcRouteTable(@PathVariable String projectid RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); RestPreconditionsUtil.verifyResourceFound(projectid); - routetable = this.routerService.getOrCreateVpcRouteTable(projectid, vpcid); + routetable = this.routerService.getVpcRouteTable(projectid, vpcid); + + } catch (ParameterNullOrEmptyException e) { + throw e; + } catch (CanNotFindVpc e) { + logger.log(Level.WARNING, e.getMessage() + " : " + vpcid); + throw e; + } catch (DatabasePersistenceException e) { + throw e; + } + + return new RouteTableWebJson(routetable); + } + + /** + * Create VPC default route table + * @param projectid + * @param vpcid + * @return + * @throws Exception + */ + @RequestMapping( + method = POST, + value = {"/project/{projectid}/vpcs/{vpcid}/vpcroutetable"}) + @DurationStatistics + public RouteTableWebJson createVpcRouteTable(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { + + RouteTable routetable = null; + + try { + RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); + RestPreconditionsUtil.verifyParameterNotNullorEmpty(projectid); + RestPreconditionsUtil.verifyResourceFound(projectid); + + routetable = this.routerService.createVpcRouteTable(projectid, vpcid); } catch (ParameterNullOrEmptyException e) { throw e; @@ -217,7 +287,11 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa newRouteEntry.setRoutes(routes); // find subnets related to this vpc (getVpcRouteTables) - Router router = this.routerService.getOrCreateVpcRouter(projectid, vpcid); + Router router = this.routerService.getVpcRouter(projectid, vpcid); + if (router == null) + { + throw new CanNotFindRouter(); + } List vpcRouteTables = router.getVpcRouteTables(); // sub-level routing rule update @@ -305,7 +379,7 @@ public RouteTableWebJson getVpcRouteTableById(@PathVariable String projectid, @P } /** - * Show Subnet route table or Create Subnet route table + * Show Subnet route table * @param projectid * @param subnetid * @return @@ -315,7 +389,7 @@ public RouteTableWebJson getVpcRouteTableById(@PathVariable String projectid, @P method = GET, value = {"/project/{projectid}/subnets/{subnetid}/routetable"}) @DurationStatistics - public RouteTableWebJson getOrCreateSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid) throws Exception { + public RouteTableWebJson getSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid) throws Exception { RouteTable routeTable = null; @@ -350,7 +424,7 @@ public RouteTableWebJson getOrCreateSubnetRouteTable(@PathVariable String projec method = POST, value = {"/project/{projectid}/subnets/{subnetid}/routetable"}) @DurationStatistics - public RouteTableWebJson createNeutronSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid, @RequestBody RouteTableWebJson resource) throws Exception { + public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, @PathVariable String subnetid, @RequestBody RouteTableWebJson resource) throws Exception { RouteTable routeTable = resource.getRoutetable(); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java new file mode 100644 index 000000000..9d67f9a39 --- /dev/null +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/CanNotFindRouter.java @@ -0,0 +1,20 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package com.futurewei.alcor.route.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code= HttpStatus.NOT_FOUND, reason="can not find router") +public class CanNotFindRouter extends Exception { +} \ No newline at end of file diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 230da2ff6..3fb8bcae4 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -61,14 +61,14 @@ public class RouterServiceImpl implements RouterService { @Override - public Router getOrCreateVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { Router router = null; // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); Object[] values = new Object[1]; - values[0] = vpcId; + values[0] = "VPC:" + vpcId; queryParams.put("owner", values); routerMap = this.routerDatabaseService.getAllRouters(queryParams); @@ -84,19 +84,19 @@ public Router getOrCreateVpcRouter(String projectId, String vpcId) throws CanNot router = (Router)entry.getValue(); return router; } - } else { - // get vpc entity to create default route table and route route rule - VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); - VpcEntity vpcEntity = vpcResponse.getNetwork(); - - - // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules - router = createDefaultVpcRouter(projectId, vpcEntity); } return router; } + @Override + public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + VpcEntity vpcEntity = vpcResponse.getNetwork(); + // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules + return createDefaultVpcRouter(projectId, vpcEntity); + } + @Override public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException { String routerId = UUID.randomUUID().toString(); @@ -126,7 +126,7 @@ public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) thro @Override public String deleteVpcRouter(String projectId, String vpcId) throws Exception { - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); if (router == null) { return null; } @@ -154,11 +154,11 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { } @Override - public RouteTable getOrCreateVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { RouteTable routeTable = null; // Get or create a router for a Vpc - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); @@ -169,12 +169,19 @@ public RouteTable getOrCreateVpcRouteTable(String projectId, String vpcId) throw } } - // If VPC doesn’t have a VPC routing table, this operation will create a VPC routing table and pump-in the VPC default routing rules. - routeTable = createDefaultVpcRouteTable(projectId, router); - return routeTable; } + @Override + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } + return createDefaultVpcRouteTable(projectId, router); + } + @Override public RouteTable createDefaultVpcRouteTable(String projectId, Router router) throws DatabasePersistenceException { String routeTableId = UUID.randomUUID().toString(); @@ -203,7 +210,11 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable RouteTable inRoutetable = resource.getRoutetable(); // Get or create a router for a Vpc - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } // check if there is a vpc default routetable List vpcRouteTables = router.getVpcRouteTables(); @@ -265,7 +276,11 @@ public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws // create a subnet route table SubnetWebJson subnetWebJson = this.vpcRouterToSubnetService.getSubnet(projectId, subnetId); String vpcId = subnetWebJson.getSubnet().getVpcId(); - Router router = getOrCreateVpcRouter(projectId, vpcId); + Router router = getVpcRouter(projectId, vpcId); + if (router == null) + { + return null; + } String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index c42d2a22a..6ae25b7d3 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -27,10 +27,12 @@ free of charge, to any person obtaining a copy of this software and associated d public interface RouterService { - public Router getOrCreateVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; - public RouteTable getOrCreateVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index 4409af69c..b801fa6a6 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -83,7 +83,7 @@ public class VpcRouterTests { private String subnetRouteTableUri = "/project/" + UnitTestConfig.projectId + "/subnets/" + UnitTestConfig.subnetId + "/routetable"; @Test - public void getOrCreateVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { + public void getVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); @@ -96,7 +96,7 @@ public void getOrCreateVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { } @Test - public void getOrCreateVpcRouter_notHaveVpcRouter_pass () throws Exception { + public void getVpcRouter_notHaveVpcRouter_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); @@ -108,12 +108,11 @@ public void getOrCreateVpcRouter_notHaveVpcRouter_pass () throws Exception { .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouterUri)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.router.name").value(UnitTestConfig.vpcRouterName)); + .andExpect(status().isNotFound()); } @Test - public void getOrCreateVpcRouter_ExistMultipleVpcRouter_notPass () throws Exception { + public void getVpcRouter_ExistMultipleVpcRouter_notPass () throws Exception { Router router1 = new Router(); router1.setId(UnitTestConfig.routerId); Router router2 = new Router(); @@ -188,7 +187,7 @@ public void deleteVpcRouter_VpcRouterContainsSubnetRoutingTables_notPass () thro } @Test - public void getOrCreateVpcRouteTable_pass () throws Exception { + public void getVpcRouteTable_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); @@ -209,6 +208,21 @@ public void getOrCreateVpcRouteTable_pass () throws Exception { .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); } + @Test + public void getVpcRouteTable_notpass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + + Mockito.when(routerDatabaseService.getAllRouters(anyMap())) + .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); + + this.mockMvc.perform(get(vpcRouteTableUri)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); + } + @Test public void updateVpcRouteTable_pass () throws Exception { VpcWebJson vpcWebJson = new VpcWebJson(); @@ -290,7 +304,7 @@ public void getVpcRouteTableById_pass () throws Exception { } @Test - public void getOrCreateSubnetRouteTable_pass () throws Exception { + public void getSubnetRouteTable_pass () throws Exception { RouteTable routetable = new RouteTable(); routetable.setId(UnitTestConfig.routeTableId); @@ -303,7 +317,7 @@ public void getOrCreateSubnetRouteTable_pass () throws Exception { } @Test - public void getOrCreateSubnetRouteTable_ExistMultipleSubnetRouteTable_notPass () throws Exception { + public void getSubnetRouteTable_ExistMultipleSubnetRouteTable_notPass () throws Exception { RouteTable routetable1 = new RouteTable(); routetable1.setId(UnitTestConfig.routeTableId); RouteTable routetable2 = new RouteTable(); From 4c100e5cdcde8559f943cd5eca06c054a6fadc77 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 16:21:28 -0700 Subject: [PATCH 02/18] Update code --- .../route/controller/RouterController.java | 4 +- .../Impl/NeutronRouterServiceImpl.java | 4 +- .../route/service/Impl/RouterServiceImpl.java | 60 ++++++++----------- .../alcor/route/service/RouterService.java | 11 ++-- .../futurewei/alcor/route/VpcRouterTests.java | 20 +++++-- 5 files changed, 48 insertions(+), 51 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 548e155dd..d3fa6dba1 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -333,7 +333,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = new ArrayList<>(); + List routetables = null; try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); @@ -405,8 +405,6 @@ public RouteTableWebJson getSubnetRouteTable(@PathVariable String projectid, @Pa } catch (OwnMultipleSubnetRouteTablesException e) { logger.log(Level.WARNING, e.getMessage() + " , subnetId: " + subnetid); throw e; - } catch (DatabasePersistenceException e) { - throw e; } return new RouteTableWebJson(routeTable); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java index 0ada663b9..28415fb03 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/NeutronRouterServiceImpl.java @@ -813,9 +813,7 @@ private void PopulateInternalRouterInfo(Router router, Map gwPor RouteTable subnetRouteTable = null; try { subnetRouteTable = this.routerService.getSubnetRouteTable(router.getProjectId(), entry.getValue()); - } catch (CanNotFindSubnet | CacheException | OwnMultipleSubnetRouteTablesException | - DatabasePersistenceException | ResourceNotFoundException | ResourcePersistenceException | - OwnMultipleVpcRouterException | CanNotFindVpc canNotFindSubnet) { + } catch (Exception e) { logger.log(Level.WARNING, "Subnet" + entry.getValue() + "'s routing table is empty!");; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 3fb8bcae4..2eaf66584 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -68,7 +68,7 @@ public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, Map routerMap = null; Map queryParams = new HashMap<>(); Object[] values = new Object[1]; - values[0] = "VPC:" + vpcId; + values[0] = vpcId; queryParams.put("owner", values); routerMap = this.routerDatabaseService.getAllRouters(queryParams); @@ -118,7 +118,7 @@ public Router createDefaultVpcRouter(String projectId, VpcEntity vpcEntity) thro this.routeTableDatabaseService.addRouteTable(routeTable); Router router = new Router(projectId, routerId, "default_vpc_router", "", - null, vpcRouteTables, "VPC:" + owner, ports, projectId, true, null, null, routeTableId); + null, vpcRouteTables, owner, ports, projectId, true, null, null, routeTableId); this.routerDatabaseService.addRouter(router); return router; @@ -154,11 +154,18 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { } @Override - public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { RouteTable routeTable = null; - - // Get or create a router for a Vpc - Router router = getVpcRouter(projectId, vpcId); + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + VpcEntity vpcEntity = vpcResponse.getNetwork(); + if (vpcEntity == null) + { + throw new CanNotFindVpc(); + } + Router router = vpcEntity.getRouter(); + if (router == null) { + throw new CanNotFindRouter(); + } // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); @@ -173,11 +180,11 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa } @Override - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException { + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { Router router = getVpcRouter(projectId, vpcId); if (router == null) { - return null; + throw new CanNotFindRouter(); } return createDefaultVpcRouteTable(projectId, router); } @@ -205,15 +212,15 @@ public RouteTable createDefaultVpcRouteTable(String projectId, Router router) th } @Override - public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException { + public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter { RouteTable routeTable = null; RouteTable inRoutetable = resource.getRoutetable(); - // Get or create a router for a Vpc + // Get router Router router = getVpcRouter(projectId, vpcId); if (router == null) { - return null; + throw new CanNotFindRouter(); } // check if there is a vpc default routetable @@ -258,7 +265,7 @@ public List getVpcRouteTables(String projectId, String vpcId) throws } @Override - public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, OwnMultipleSubnetRouteTablesException, DatabasePersistenceException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindSubnet, OwnMultipleVpcRouterException, CanNotFindVpc { + public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException { RouteTable routeTable = null; Map routeTableMap = null; @@ -268,36 +275,21 @@ public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws queryParams.put("owner", values); routeTableMap = this.routeTableDatabaseService.getAllRouteTables(queryParams); - if (routeTableMap == null) { - routeTableMap = new HashMap<>(); - } - if (routeTableMap.size() == 0) { - // create a subnet route table - SubnetWebJson subnetWebJson = this.vpcRouterToSubnetService.getSubnet(projectId, subnetId); - String vpcId = subnetWebJson.getSubnet().getVpcId(); - Router router = getVpcRouter(projectId, vpcId); - if (router == null) - { - return null; - } + if (routeTableMap == null || routeTableMap.size() == 0) { + throw new CanNotFindRouteTableByOwner(); + } - String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); - routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); - return routeTable; - } else if (routeTableMap.size() > 1) { + if (routeTableMap.size() > 1) + { throw new OwnMultipleSubnetRouteTablesException(); - } else { - for (Map.Entry entry : routeTableMap.entrySet()) { - routeTable = (RouteTable)entry.getValue(); - } } - return routeTable; + return routeTableMap.values().stream().findFirst().get(); } @Override - public RouteTable updateSubnetRouteTable(String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindVpc, CanNotFindSubnet, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException { + public RouteTable updateSubnetRouteTable(String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner { InternalSubnetRoutingTable inRoutetable = resource.getInternalSubnetRoutingTable(); List inHostRoutes = resource.getHostRouteToSubnet(); // Get or create a router for a Subnet diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 6ae25b7d3..3a71f9420 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -20,6 +20,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.exception.ResourceNotFoundException; import com.futurewei.alcor.common.exception.ResourcePersistenceException; import com.futurewei.alcor.route.exception.*; +import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.route.*; import com.futurewei.alcor.web.entity.vpc.VpcEntity; @@ -31,13 +32,13 @@ public interface RouterService { public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; - public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException; + public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; - public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException; + public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; - public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CanNotFindSubnet, CacheException, OwnMultipleSubnetRouteTablesException, DatabasePersistenceException, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException, CanNotFindVpc; - public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindVpc, CanNotFindSubnet, ResourceNotFoundException, ResourcePersistenceException, OwnMultipleVpcRouterException; + public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; + public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index b801fa6a6..35f6f7c9d 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -188,15 +188,16 @@ public void deleteVpcRouter_VpcRouterContainsSubnetRoutingTables_notPass () thro @Test public void getVpcRouteTable_pass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Router router = new Router(); - router.setId(UnitTestConfig.routerId); - router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) @@ -210,17 +211,24 @@ public void getVpcRouteTable_pass () throws Exception { @Test public void getVpcRouteTable_notpass () throws Exception { + Router router = new Router(); router.setId(UnitTestConfig.routerId); router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); + VpcEntity vpcEntity = new VpcEntity(); + vpcEntity.setId(UnitTestConfig.vpcId); + vpcWebJson.setNetwork(vpcEntity); + Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); + Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) + .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouteTableUri)) .andDo(print()) - .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.routetable.id").value(UnitTestConfig.routeTableId)); + .andExpect(status().isNotFound()); } @Test From e38bcf902198b4dcea707a159fb8ef2923e49ddd Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 16:42:53 -0700 Subject: [PATCH 03/18] Update code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ++-- .../futurewei/alcor/route/service/Impl/RouterServiceImpl.java | 4 ++-- .../java/com/futurewei/alcor/route/service/RouterService.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index d3fa6dba1..4c3b5379c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -306,7 +306,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa InternalRouterInfo internalRouterInfo = this.neutronRouterService.constructInternalRouterInfo(router.getId(), internalSubnetRoutingTableList); // send InternalRouterInfo contract to DPM -// this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo); + this.routerToDPMService.sendInternalRouterInfoToDPM(internalRouterInfo); } catch (ParameterNullOrEmptyException e) { throw e; @@ -333,7 +333,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = null; + List routetables = new ArrayList<>(); try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 2eaf66584..300dbe516 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -254,12 +254,12 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable } @Override - public List getVpcRouteTables(String projectId, String vpcId) throws CanNotFindVpc { + public List getVpcRouteTables(String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter { VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); Router router = vpcEntity.getRouter(); if (router == null) { - return null; + throw new CanNotFindRouter(); } return router.getVpcRouteTables(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 3a71f9420..653d7752c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -36,7 +36,7 @@ public interface RouterService { public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; - public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc; + public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter; public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; From 067a9886cf8b768314214791a1a57f08366939fa Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 20:57:39 -0700 Subject: [PATCH 04/18] Update router manager --- .../route/service/Impl/RouterServiceImpl.java | 23 ++++++++++++------- .../alcor/route/service/RouterService.java | 2 +- .../futurewei/alcor/route/VpcRouterTests.java | 17 ++++++++------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 300dbe516..035f1427c 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -64,6 +64,8 @@ public class RouterServiceImpl implements RouterService { public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { Router router = null; + VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); + // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); @@ -155,7 +157,6 @@ public String deleteVpcRouter(String projectId, String vpcId) throws Exception { @Override public RouteTable getVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { - RouteTable routeTable = null; VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); if (vpcEntity == null) @@ -169,23 +170,29 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa // If VPC has a VPC routing table, return the routing table’s state List vpcRouteTables = router.getVpcRouteTables(); - for (RouteTable vpcRouteTable : vpcRouteTables) { - String routeTableType = vpcRouteTable.getRouteTableType(); - if (RouteTableType.VPC.getRouteTableType().equals(routeTableType)) { - return vpcRouteTable; - } + if (vpcRouteTables != null) + { + return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().get(); } - return routeTable; + return null; } @Override - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exception { + Router router = getVpcRouter(projectId, vpcId); if (router == null) { throw new CanNotFindRouter(); } + + String defaultRouteTableId = router.getVpcDefaultRouteTableId(); + if (defaultRouteTableId.isEmpty() || this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) + { + throw new RouteTableNotUnique(); + } + return createDefaultVpcRouteTable(projectId, router); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 653d7752c..9d01944da 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -33,7 +33,7 @@ public interface RouterService { public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; - public RouteTable createVpcRouteTable(String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exception; public RouteTable createDefaultVpcRouteTable (String projectId, Router router) throws DatabasePersistenceException; public RouteTable updateVpcRouteTable (String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter; public List getVpcRouteTables (String projectId, String vpcId) throws CanNotFindVpc, CanNotFindRouter; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index 35f6f7c9d..f567be2a9 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -198,8 +198,6 @@ public void getVpcRouteTable_pass () throws Exception { vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) - .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); @@ -214,21 +212,20 @@ public void getVpcRouteTable_notpass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); - router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); - Mockito.when(routerDatabaseService.getAllRouters(anyMap())) - .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); this.mockMvc.perform(get(vpcRouteTableUri)) .andDo(print()) - .andExpect(status().isNotFound()); + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetable").doesNotExist()); } @Test @@ -286,16 +283,22 @@ public void updateVpcRouteTable_ResourceNotValid_notPass () throws Exception { @Test public void getVpcRouteTables_pass () throws Exception { + Router router = new Router(); + router.setId(UnitTestConfig.routerId); + router.setVpcRouteTables(new ArrayList<>(){{add(new RouteTable(){{setRouteTableType(RouteTableType.VPC.getRouteTableType());setId(UnitTestConfig.routeTableId);}});}}); + VpcWebJson vpcWebJson = new VpcWebJson(); VpcEntity vpcEntity = new VpcEntity(); vpcEntity.setId(UnitTestConfig.vpcId); + vpcEntity.setRouter(router); vpcWebJson.setNetwork(vpcEntity); Mockito.when(vpcRouterToVpcService.getVpcWebJson(UnitTestConfig.projectId, UnitTestConfig.vpcId)) .thenReturn(vpcWebJson); this.mockMvc.perform(get(getVpcRouteTablesUri)) .andDo(print()) - .andExpect(status().isOk()); + .andExpect(status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.routetables.length()").value(1)); } @Test From dd5dafdeb0959bcc0573de7014647886a048643f Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 15:04:48 -0700 Subject: [PATCH 05/18] Update router manager --- .../exception/VpcRouterAlreadyExist.java | 23 ++++++++++++++++ .../route/service/Impl/RouterServiceImpl.java | 27 +++++++++---------- .../alcor/route/service/RouterService.java | 4 +-- .../futurewei/alcor/route/VpcRouterTests.java | 4 ++- 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java new file mode 100644 index 000000000..404285289 --- /dev/null +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/exception/VpcRouterAlreadyExist.java @@ -0,0 +1,23 @@ +/* +MIT License +Copyright(c) 2020 Futurewei Cloud + + Permission is hereby granted, + free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons + to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package com.futurewei.alcor.route.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(code= HttpStatus.CONFLICT, reason="Vpc router already exist.") +public class VpcRouterAlreadyExist extends Exception { +} diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index 035f1427c..b4b0e7053 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -61,11 +61,7 @@ public class RouterServiceImpl implements RouterService { @Override - public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { - Router router = null; - - VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); - + public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter { // If VPC already has a router, return the router state Map routerMap = null; Map queryParams = new HashMap<>(); @@ -75,26 +71,29 @@ public Router getVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, routerMap = this.routerDatabaseService.getAllRouters(queryParams); - if (routerMap == null) { - routerMap = new HashMap<>(); + if (routerMap == null || routerMap.size() == 0) { + throw new CanNotFindRouter(); } if (routerMap.size() > 1) { throw new OwnMultipleVpcRouterException(); - } else if (routerMap.size() == 1) { - for (Map.Entry entry : routerMap.entrySet()) { - router = (Router)entry.getValue(); - return router; - } } + Router router = routerMap.values().stream().findFirst().get(); + return router; } @Override - public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException { + public Router createVpcRouter(String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, VpcRouterAlreadyExist { VpcWebJson vpcResponse = this.vpcRouterToVpcService.getVpcWebJson(projectId, vpcId); VpcEntity vpcEntity = vpcResponse.getNetwork(); + + if (vpcEntity.getRouter() != null) + { + throw new VpcRouterAlreadyExist(); + } + // If VPC doesn’t have a router, create a new router, create a VPC routing table and pump-in the VPC default routing rules return createDefaultVpcRouter(projectId, vpcEntity); } @@ -188,7 +187,7 @@ public RouteTable createVpcRouteTable(String projectId, String vpcId) throws Exc } String defaultRouteTableId = router.getVpcDefaultRouteTableId(); - if (defaultRouteTableId.isEmpty() || this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) + if (!defaultRouteTableId.isEmpty() && this.routeTableDatabaseService.getByRouteTableId(defaultRouteTableId) != null) { throw new RouteTableNotUnique(); } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 9d01944da..020647ab6 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -28,8 +28,8 @@ free of charge, to any person obtaining a copy of this software and associated d public interface RouterService { - public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; - public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException; + public Router getVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; + public Router createVpcRouter (String projectId, String vpcId) throws CanNotFindVpc, DatabasePersistenceException, CacheException, VpcRouterAlreadyExist; public Router createDefaultVpcRouter (String projectId, VpcEntity vpcEntity) throws DatabasePersistenceException; public String deleteVpcRouter (String projectId, String vpcId) throws Exception; public RouteTable getVpcRouteTable (String projectId, String vpcId) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, CanNotFindRouter; diff --git a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java index f567be2a9..436869298 100644 --- a/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java +++ b/services/route_manager/src/test/java/com/futurewei/alcor/route/VpcRouterTests.java @@ -86,13 +86,15 @@ public class VpcRouterTests { public void getVpcRouter_alreadyHaveVpcRouter_pass () throws Exception { Router router = new Router(); router.setId(UnitTestConfig.routerId); + router.setOwner(UnitTestConfig.vpcId); Mockito.when(routerDatabaseService.getAllRouters(anyMap())) .thenReturn(new HashMap(){{put(UnitTestConfig.routerId, router);}}); this.mockMvc.perform(get(vpcRouterUri)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(MockMvcResultMatchers.jsonPath("$.router.id").value(UnitTestConfig.routerId)); + .andExpect(MockMvcResultMatchers.jsonPath("$.router.id").value(UnitTestConfig.routerId)) + .andExpect(MockMvcResultMatchers.jsonPath("$.router.owner").value(UnitTestConfig.vpcId)); } @Test From aa765625d20083bade7e36fcd886e20591b64c8d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 17:09:34 -0700 Subject: [PATCH 06/18] Merge router manager service api code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ++-- .../alcor/route/service/Impl/RouterServiceImpl.java | 7 +++---- .../com/futurewei/alcor/route/service/RouterService.java | 2 +- .../com/futurewei/alcor/route/utils/RouteManagerUtil.java | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 4c3b5379c..2fc9ddc65 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -432,7 +432,7 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, RestPreconditionsUtil.verifyResourceFound(projectid); // check resource - if (!RouteManagerUtil.checkCreateNeutronSubnetRouteTableWebJsonResourceIsValid(resource)) { + if (!RouteManagerUtil.checkCreateSubnetRouteTableWebJsonResourceIsValid(resource)) { throw new ResourceNotValidException("request resource is invalid"); } @@ -450,7 +450,7 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, "0.0.0.0/0", null, 100, null, "192.168.0.1"); routes.add(defaultRoute); - routeTable = this.routerService.createNeutronSubnetRouteTable(projectid, subnetid, resource, routes); + routeTable = this.routerService.createSubnetRouteTable(projectid, subnetid, resource, routes); } catch (ParameterNullOrEmptyException e) { throw e; diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index b4b0e7053..d8af03973 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -219,7 +219,6 @@ public RouteTable createDefaultVpcRouteTable(String projectId, Router router) th @Override public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTableWebJson resource) throws DatabasePersistenceException, CanNotFindVpc, CacheException, OwnMultipleVpcRouterException, ResourceNotFoundException, ResourcePersistenceException, CanNotFindRouter { - RouteTable routeTable = null; RouteTable inRoutetable = resource.getRoutetable(); // Get router @@ -232,7 +231,7 @@ public RouteTable updateVpcRouteTable(String projectId, String vpcId, RouteTable // check if there is a vpc default routetable List vpcRouteTables = router.getVpcRouteTables(); String vpcDefaultRouteTableId = router.getVpcDefaultRouteTableId(); - routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); + RouteTable routeTable = this.routeTableDatabaseService.getByRouteTableId(vpcDefaultRouteTableId); if (routeTable == null) { String routeTableId = inRoutetable.getId(); @@ -352,7 +351,7 @@ public String deleteSubnetRouteTable(String projectId, String subnetId) throws E } @Override - public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException { + public RouteTable createSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException { // configure a new route table RouteTable routeTable = new RouteTable(); @@ -361,7 +360,7 @@ public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetI routeTable.setDescription(""); routeTable.setName("subnet-" + id + "-routetable"); routeTable.setProjectId(projectId); - routeTable.setRouteTableType(RouteTableType.NEUTRON_SUBNET.getRouteTableType()); + routeTable.setRouteTableType(resource.getRoutetable().getRouteTableType()); routeTable.setOwner(subnetId); routeTable.setRouteEntities(routes); diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java index 020647ab6..2b21311ef 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/RouterService.java @@ -40,6 +40,6 @@ public interface RouterService { public RouteTable getSubnetRouteTable(String projectId, String subnetId) throws CacheException, CanNotFindRouteTableByOwner, OwnMultipleSubnetRouteTablesException; public RouteTable updateSubnetRouteTable (String projectId, String subnetId, UpdateRoutingRuleResponse resource) throws CacheException, DatabasePersistenceException, OwnMultipleSubnetRouteTablesException, CanNotFindRouteTableByOwner; public String deleteSubnetRouteTable (String projectId, String subnetId) throws Exception; - public RouteTable createNeutronSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; + public RouteTable createSubnetRouteTable(String projectId, String subnetId, RouteTableWebJson resource, List routes) throws DatabasePersistenceException; } diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java index 5e2db38a4..8d089c3e6 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/utils/RouteManagerUtil.java @@ -158,13 +158,13 @@ public static boolean checkSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJ return true; } - public static boolean checkCreateNeutronSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJson resource) { + public static boolean checkCreateSubnetRouteTableWebJsonResourceIsValid(RouteTableWebJson resource) { if (resource == null) { return false; } RouteTable routetable = resource.getRoutetable(); - if (routetable == null) { + if (routetable == null || routetable.getRouteTableType() == null || routetable.getRouteTableType().trim().isEmpty()) { return false; } From 8ae37db45367ec861508a1ff4c5939ac50b1960a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 18:36:40 -0700 Subject: [PATCH 07/18] Fix getVpcRouteTables --- .../futurewei/alcor/route/controller/RouterController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 2fc9ddc65..c55bf8dc1 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -342,6 +342,11 @@ public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @Pat routetables = this.routerService.getVpcRouteTables(projectid, vpcid); + if (routetables == null) + { + throw new RouterUnavailable(); + } + } catch (Exception e) { throw e; } From f0462ae5cb0fa5dc13d7d34df8079bce1d61ed09 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 1 Jul 2021 19:00:50 -0700 Subject: [PATCH 08/18] Fix getVpcRouteTable --- .../futurewei/alcor/route/service/Impl/RouterServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java index d8af03973..da8cf818e 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/service/Impl/RouterServiceImpl.java @@ -171,7 +171,7 @@ public RouteTable getVpcRouteTable(String projectId, String vpcId) throws Databa List vpcRouteTables = router.getVpcRouteTables(); if (vpcRouteTables != null) { - return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().get(); + return vpcRouteTables.stream().filter(vpcRouteTable -> RouteTableType.VPC.getRouteTableType().equals(vpcRouteTable.getRouteTableType())).findFirst().orElse(null); } return null; From 976883f581abc7d5128bee0a584c7f07cb519c65 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 6 Jul 2021 14:18:32 -0700 Subject: [PATCH 09/18] Update RouterController --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index c55bf8dc1..bb7a2dcbb 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -344,7 +344,7 @@ public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @Pat if (routetables == null) { - throw new RouterUnavailable(); + throw new RouterTableNotExist(); } } catch (Exception e) { From ef7a2d2f366e87b54b5ebf2222bd1ba234d62337 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 6 Jul 2021 16:13:01 -0700 Subject: [PATCH 10/18] Update code --- .../futurewei/alcor/route/controller/RouterController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index bb7a2dcbb..a95af55f4 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -450,10 +450,6 @@ public RouteTableWebJson createSubnetRouteTable(@PathVariable String projectid, routeEntry.getDestination(), null, 100, null, routeEntry.getNexthop()); routes.add(newRoute); } - String d_uuid = UUID.randomUUID().toString(); - RouteEntry defaultRoute = new RouteEntry(projectid, d_uuid, "default-route-" + d_uuid, "Default Routing Rule", - "0.0.0.0/0", null, 100, null, "192.168.0.1"); - routes.add(defaultRoute); routeTable = this.routerService.createSubnetRouteTable(projectid, subnetid, resource, routes); From 670dcc630dad29b0bfee1d91ea8e7be1461b84b2 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 16:21:28 -0700 Subject: [PATCH 11/18] Update code --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index 9fdb4f11d..bec3dfce3 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -334,7 +334,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = new ArrayList<>(); + List routetables = null; try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); From 59a65f0dac6ddf384fbe5332f6d43e0db3ba18a8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Jun 2021 16:42:53 -0700 Subject: [PATCH 12/18] Update code --- .../com/futurewei/alcor/route/controller/RouterController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java index bec3dfce3..9fdb4f11d 100644 --- a/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java +++ b/services/route_manager/src/main/java/com/futurewei/alcor/route/controller/RouterController.java @@ -334,7 +334,7 @@ public RouteTableWebJson updateVpcRouteTable(@PathVariable String projectid, @Pa @DurationStatistics public RouteTablesWebJson getVpcRouteTables(@PathVariable String projectid, @PathVariable String vpcid) throws Exception { - List routetables = null; + List routetables = new ArrayList<>(); try { RestPreconditionsUtil.verifyParameterNotNullorEmpty(vpcid); From d11ae656c2321bfb20d81ecc8bc0262d9fa144bb Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 11:08:13 -0800 Subject: [PATCH 13/18] Update code --- .../client/gRPC/GoalStateClientImpl.java | 18 ++++-------------- .../impl/GoalStatePersistenceServiceImpl.java | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index 8dc0eb0aa..fd034fd59 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -128,9 +128,8 @@ public List sendGoalStates(Map hostGoalStates) th logger.log(Level.INFO, "Host goal states size: " + hostGoalStates.values().size()); List replies = new ArrayList<>(); - boolean isAttache = !hostGoalStates.values().parallelStream().anyMatch(hostGoalState -> hostGoalState.getGoalState().getPortStatesCount() > 0); for (HostGoalState hostGoalState : hostGoalStates.values()) { - doSendGoalState(hostGoalState, finishLatch, replies, isAttache); + doSendGoalState(hostGoalState, finishLatch, replies); } if (!finishLatch.await(5, TimeUnit.MINUTES)) { @@ -256,7 +255,7 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp) { } - private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, List replies, boolean isAttache) throws InterruptedException { + private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, List replies) throws InterruptedException { String hostIp = hostGoalState.getHostIp(); logger.log(Level.FINE, "Setting up a channel to ACA on: " + hostIp); long start = System.currentTimeMillis(); @@ -302,19 +301,10 @@ public void onCompleted() { try { long before_get_goalState = System.currentTimeMillis(); Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); - Set resourceIds = goalState.getHostResourcesMap().get(hostIp).getResourcesList().stream().filter(resourceIdType -> resourceIdType.getType().equals(Common.ResourceType.NEIGHBOR)).map(resourceIdType -> resourceIdType.getId()).collect(Collectors.toSet()); - Goalstate.GoalStateV2.Builder goalstateBuilder = Goalstate.GoalStateV2.newBuilder(); - goalstateBuilder.mergeFrom(goalState); - if (isAttache || goalstateBuilder.getPortStatesCount() > 0) { - Map neighborStateMap = resourceInfo.getNeighborStates(resourceIds); - if (neighborStateMap.size() > 0) { - goalstateBuilder.putAllNeighborStates(neighborStateMap); - } - } long after_get_goalState = System.currentTimeMillis(); - logger.log(Level.FINE, "Sending GS with size " + goalState.getSerializedSize() + " to Host " + hostIp + " as follows | " + goalstateBuilder.build()); + logger.log(Level.FINE, "Sending GS with size " + goalState.getSerializedSize() + " to Host " + hostIp + " as follows | " + goalState); - requestObserver.onNext(goalstateBuilder.build()); + requestObserver.onNext(goalState); long after_onNext = System.currentTimeMillis(); logger.log(Level.FINE, "[doSendGoalState] Get goalstatev2 from HostGoalState in milliseconds: " + (after_get_goalState - before_get_goalState)); logger.log(Level.FINE, "[doSendGoalState] Call onNext in milliseconds: " + (after_onNext - after_get_goalState)); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java index aac7b91a2..a37811dc2 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java @@ -34,6 +34,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; @Service @ComponentScan(value = "com.futurewei.alcor.netwconfigmanager.cache") @@ -85,8 +86,22 @@ public Map updateGoalStates(Goalstate.GoalStateV2 goalSta return hostGoalStates; } - public Map getNeighborStates(Set resourceIds) throws Exception { - return resourceStateCache.getResourceStates(resourceIds); + public void patchNeighbors(Map hostGoalStates) throws Exception { + boolean isAttache = !hostGoalStates.values().parallelStream().anyMatch(hostGoalState -> hostGoalState.getGoalState().getPortStatesCount() > 0); + for (HostGoalState hostGoalState : hostGoalStates.values()) { + if (isAttache || hostGoalState.getGoalState().getPortStatesCount() > 0) { + String hostIp = hostGoalState.getHostIp(); + Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); + Set resourceIds = goalState.getHostResourcesMap().get(hostIp).getResourcesList().stream().filter(resourceIdType -> resourceIdType.getType().equals(Common.ResourceType.NEIGHBOR)).map(resourceIdType -> resourceIdType.getId()).collect(Collectors.toSet()); + Goalstate.GoalStateV2.Builder goalstateBuilder = Goalstate.GoalStateV2.newBuilder(); + goalstateBuilder.mergeFrom(goalState); + Map neighborStateMap = resourceStateCache.getResourceStates(resourceIds); + if (neighborStateMap.size() > 0) { + goalstateBuilder.putAllNeighborStates(neighborStateMap); + } + hostGoalStates.put(hostIp, new HostGoalState(hostIp, goalstateBuilder.build())); + } + } } @Override From 677e4a25af2534a64cbb9991e8877bdfb034e67f Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 11:26:58 -0800 Subject: [PATCH 14/18] Update code --- .../server/grpc/GoalStateProvisionerServer.java | 4 +--- .../service/GoalStatePersistenceService.java | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java index 53e24b6b0..65d70d80a 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java @@ -214,7 +214,6 @@ public void onNext(Goalstate.GoalStateV2 value) { Span storeGsSpan = tracer.buildSpan(serverStoreGsSpanName).asChildOf(span.context()).start(); Scope storageCscope = tracer.scopeManager().activate(storeGsSpan); - //store the goal state in cache Map hostGoalStates = new HashMap<>(); try { @@ -225,9 +224,7 @@ public void onNext(Goalstate.GoalStateV2 value) { } storeGsSpan.finish(); - Set processedResourceIds = new HashSet<>(); - long end = System.currentTimeMillis(); logger.log(Level.FINE, "pushGoalStatesStream : finished putting GS into cache, elapsed time in milliseconds: " + + (end-start)); Span filterSendGsSpan = tracer.buildSpan(serverFilterSendGsSpanName).asChildOf(span.context()).start(); @@ -238,6 +235,7 @@ public void onNext(Goalstate.GoalStateV2 value) { Map filteredGoalStates = NetworkConfigManagerUtil.filterNeighbors(hostGoalStates); //TODO use filteredGoalStates + goalStatePersistenceService.patchNeighbors(hostGoalStates); grpcGoalStateClient.sendGoalStates(hostGoalStates); } catch (Exception e) { e.printStackTrace(); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java index d82a979ea..f602769df 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/GoalStatePersistenceService.java @@ -36,4 +36,6 @@ public interface GoalStatePersistenceService { Map updateGoalStates(Goalstate.GoalStateV2 goalStateV2) throws Exception; + void patchNeighbors(Map hostGoalStates) throws Exception; + } From a0d4925ff94cd1c892d8d6fb1bf8d4808f0f0b2a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 11:28:42 -0800 Subject: [PATCH 15/18] Update code --- .../client/gRPC/GoalStateClientImpl.java | 18 +-------------- .../service/ResourceInfo.java | 10 --------- .../service/impl/ResourceInfoImpl.java | 22 ------------------- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java delete mode 100644 services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index fd034fd59..e948ee870 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -18,33 +18,20 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.logging.Logger; import com.futurewei.alcor.common.logging.LoggerFactory; import com.futurewei.alcor.common.stats.DurationStatistics; -import com.futurewei.alcor.netwconfigmanager.cache.ResourceStateCache; import com.futurewei.alcor.netwconfigmanager.client.GoalStateClient; import com.futurewei.alcor.netwconfigmanager.config.Config; import com.futurewei.alcor.netwconfigmanager.entity.HostGoalState; -import com.futurewei.alcor.netwconfigmanager.service.ResourceInfo; import com.futurewei.alcor.schema.*; import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder; -import io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoopGroup; -import io.grpc.netty.shaded.io.netty.channel.epoll.EpollSocketChannel; -import io.grpc.stub.ClientCallStreamObserver; -import io.grpc.stub.ServerCallStreamObserver; import io.grpc.stub.StreamObserver; import io.jaegertracing.Configuration; -import io.jaegertracing.internal.JaegerTracer; import io.jaegertracing.internal.samplers.ConstSampler; -import io.lettuce.core.dynamic.annotation.Param; import io.netty.util.concurrent.DefaultThreadFactory; -import io.opentracing.Scope; -import io.opentracing.Span; -import io.opentracing.contrib.tracerresolver.TracerResolver; import io.opentracing.util.GlobalTracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Service; import java.util.*; import java.util.concurrent.*; @@ -60,10 +47,7 @@ public class GoalStateClientImpl implements GoalStateClient { private int hostAgentPort; private final ExecutorService executor; - - @Autowired - private ResourceInfo resourceInfo; - + // each host_ip should have this amount of gRPC channels @Value("${grpc.number-of-channels-per-host:1}") private int numberOfGrpcChannelPerHost; diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java deleted file mode 100644 index 49958357f..000000000 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/ResourceInfo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.futurewei.alcor.netwconfigmanager.service; - -import com.futurewei.alcor.schema.Neighbor; - -import java.util.Map; -import java.util.Set; - -public interface ResourceInfo { - Map getNeighborStates (Set resourceIds) throws Exception; -} diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java deleted file mode 100644 index 6bb49d544..000000000 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/ResourceInfoImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.futurewei.alcor.netwconfigmanager.service.impl; - -import com.futurewei.alcor.netwconfigmanager.cache.ResourceStateCache; -import com.futurewei.alcor.netwconfigmanager.service.ResourceInfo; -import com.futurewei.alcor.schema.Neighbor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Service; - -import java.util.Map; -import java.util.Set; - -@Service -@ComponentScan(value = "com.futurewei.alcor.netwconfigmanager.cache") -public class ResourceInfoImpl implements ResourceInfo { - @Autowired - private ResourceStateCache resourceStateCache; - - public Map getNeighborStates (Set resourceIds) throws Exception { - return resourceStateCache.getResourceStates(resourceIds); - } -} From d00983fde555d72c8e38272841ea276d21d3e94a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 13:08:49 -0800 Subject: [PATCH 16/18] Update code --- .../client/gRPC/GoalStateClientImpl.java | 2 +- .../server/grpc/GoalStateProvisionerServer.java | 1 - .../service/impl/GoalStatePersistenceServiceImpl.java | 11 ++++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java index e948ee870..5ddf7e8b7 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java @@ -47,7 +47,7 @@ public class GoalStateClientImpl implements GoalStateClient { private int hostAgentPort; private final ExecutorService executor; - + // each host_ip should have this amount of gRPC channels @Value("${grpc.number-of-channels-per-host:1}") private int numberOfGrpcChannelPerHost; diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java index 65d70d80a..4a7aeda7f 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/server/grpc/GoalStateProvisionerServer.java @@ -235,7 +235,6 @@ public void onNext(Goalstate.GoalStateV2 value) { Map filteredGoalStates = NetworkConfigManagerUtil.filterNeighbors(hostGoalStates); //TODO use filteredGoalStates - goalStatePersistenceService.patchNeighbors(hostGoalStates); grpcGoalStateClient.sendGoalStates(hostGoalStates); } catch (Exception e) { e.printStackTrace(); diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java index a37811dc2..0dfe9ed38 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/service/impl/GoalStatePersistenceServiceImpl.java @@ -82,16 +82,17 @@ public Map updateGoalStates(Goalstate.GoalStateV2 goalSta } } hostResourceMetadataCache.commit(); + patchNeighbors(hostGoalStates); } return hostGoalStates; } public void patchNeighbors(Map hostGoalStates) throws Exception { boolean isAttache = !hostGoalStates.values().parallelStream().anyMatch(hostGoalState -> hostGoalState.getGoalState().getPortStatesCount() > 0); - for (HostGoalState hostGoalState : hostGoalStates.values()) { - if (isAttache || hostGoalState.getGoalState().getPortStatesCount() > 0) { - String hostIp = hostGoalState.getHostIp(); - Goalstate.GoalStateV2 goalState = hostGoalState.getGoalState(); + for (Map.Entry hostGoalState : hostGoalStates.entrySet()) { + if (isAttache || hostGoalState.getValue().getGoalState().getPortStatesCount() > 0) { + String hostIp = hostGoalState.getValue().getHostIp(); + Goalstate.GoalStateV2 goalState = hostGoalState.getValue().getGoalState(); Set resourceIds = goalState.getHostResourcesMap().get(hostIp).getResourcesList().stream().filter(resourceIdType -> resourceIdType.getType().equals(Common.ResourceType.NEIGHBOR)).map(resourceIdType -> resourceIdType.getId()).collect(Collectors.toSet()); Goalstate.GoalStateV2.Builder goalstateBuilder = Goalstate.GoalStateV2.newBuilder(); goalstateBuilder.mergeFrom(goalState); @@ -99,7 +100,7 @@ public void patchNeighbors(Map hostGoalStates) throws Exc if (neighborStateMap.size() > 0) { goalstateBuilder.putAllNeighborStates(neighborStateMap); } - hostGoalStates.put(hostIp, new HostGoalState(hostIp, goalstateBuilder.build())); + hostGoalStates.put(hostGoalState.getKey(), new HostGoalState(hostIp, goalstateBuilder.build())); } } } From 12dc66dd307c35f89c78471c5236ffcaad66a868 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 14:02:38 -0800 Subject: [PATCH 17/18] Update code --- .../futurewei/alcor/dataplane/service/impl/NeighborService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index a448091c2..2538354d3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -451,8 +451,10 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni e.printStackTrace(); } }); + unicastHostResourceBuilder.addAllResources(unicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).getResourcesList()); unicastGoalStateV2.getGoalStateBuilder().putHostResources(unicastGoalStateV2.getHostIp(), unicastHostResourceBuilder.build()); for (String hostIp : multicastGoalStateV2.getHostIps()) { + multicastHostResourceBuilder.addAllResources(multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp).getResourcesList()); multicastGoalStateV2.getGoalStateBuilder().putHostResources(hostIp, multicastHostResourceBuilder.build()); } unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap); From 676bbba0f5452108c41e36a0b9d99066c4eab4f8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 3 Feb 2022 14:37:18 -0800 Subject: [PATCH 18/18] Update code --- .../alcor/dataplane/service/impl/NeighborService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java index 2538354d3..0b6a52b8a 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/NeighborService.java @@ -454,7 +454,9 @@ public void buildNeighborStatesL3(NetworkConfiguration networkConfiguration, Uni unicastHostResourceBuilder.addAllResources(unicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).getResourcesList()); unicastGoalStateV2.getGoalStateBuilder().putHostResources(unicastGoalStateV2.getHostIp(), unicastHostResourceBuilder.build()); for (String hostIp : multicastGoalStateV2.getHostIps()) { - multicastHostResourceBuilder.addAllResources(multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp).getResourcesList()); + if (multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap(). containsKey(hostIp) && multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp) != null) { + multicastHostResourceBuilder.addAllResources(multicastGoalStateV2.getGoalStateBuilder().getHostResourcesMap().get(hostIp).getResourcesList()); + } multicastGoalStateV2.getGoalStateBuilder().putHostResources(hostIp, multicastHostResourceBuilder.build()); } unicastGoalStateV2.getGoalStateBuilder().putAllNeighborStates(neighborStateMap);