From 04cbb1e6d7368bbaeb351841edf6cc9c5352c68d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 12:06:50 -0700 Subject: [PATCH 01/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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 5b7e69f0aceebc3c0db56ef8b5bbe3f5cdadaa97 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 12 Nov 2021 14:38:06 -0800 Subject: [PATCH 13/48] DPM send goal state to NCM instead of ACA --- schema/proto3/common.proto | 17 +- .../client/grpc/DataPlaneClientImplV2.java | 160 +++++++++++++++--- .../dataplane/service/impl/DhcpService.java | 10 +- .../service/impl/NeighborService.java | 18 -- .../dataplane/service/impl/PortService.java | 8 - .../dataplane/service/impl/RouterService.java | 10 -- .../service/impl/SecurityGroupService.java | 8 - .../dataplane/service/impl/SubnetService.java | 10 -- .../dataplane/service/impl/VpcService.java | 8 - .../client/gRPC/GoalStateClientImpl.java | 45 ++--- .../grpc/GoalStateProvisionerServer.java | 5 +- 11 files changed, 163 insertions(+), 136 deletions(-) diff --git a/schema/proto3/common.proto b/schema/proto3/common.proto index 765fa781e..516341cb5 100644 --- a/schema/proto3/common.proto +++ b/schema/proto3/common.proto @@ -22,14 +22,15 @@ option java_package = "com.futurewei.alcor.schema"; option java_outer_classname = "Common"; enum ResourceType { - VPC = 0; - SUBNET = 1; - PORT = 2; - NEIGHBOR = 3; - SECURITYGROUP = 4; - DHCP = 5; - ROUTER = 6; - GATEWAY = 7; + DEFAULTTYPE = 0; + VPC = 1; + SUBNET = 2; + PORT = 3; + NEIGHBOR = 4; + SECURITYGROUP =5; + DHCP = 6; + ROUTER = 7; + GATEWAY = 8; } enum OperationType { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index ad5e81519..631017ac3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -22,9 +22,7 @@ import com.futurewei.alcor.dataplane.config.Config; import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; -import com.futurewei.alcor.schema.GoalStateProvisionerGrpc; -import com.futurewei.alcor.schema.Goalstate; -import com.futurewei.alcor.schema.Goalstateprovisioner; +import com.futurewei.alcor.schema.*; import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -37,6 +35,7 @@ import java.util.*; import java.util.concurrent.*; +import java.util.logging.Level; @Service("grpcDataPlaneClient") @ConditionalOnProperty(prefix = "protobuf.goal-state-message", name = "version", havingValue = "102") @@ -63,15 +62,24 @@ public class DataPlaneClientImplV2 implements DataPlaneClient sendGoalStates(List unicastGoalStates) throws Exception { + Goalstate.GoalStateV2.Builder goalStateBuilder = Goalstate.GoalStateV2.newBuilder(); + final CountDownLatch finishLatch = new CountDownLatch(1); + final CountDownLatch exceptionLatch = new CountDownLatch(1); List results = new ArrayList<>(); for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { - String resp = doSendGoalState(unicastGoalState); - if (resp != null) { - results.add(resp); - } + goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } + System.out.println(goalStateBuilder.build()); + doSendGoalState(goalStateBuilder.build(), finishLatch, exceptionLatch); - return results; + if (!finishLatch.await(1, TimeUnit.MINUTES) || !exceptionLatch.await(1, TimeUnit.MINUTES)) { + if (exceptionLatch.getCount() == 0) { + return Arrays.asList("Goal states not correct"); + } + LOG.warn("Send goal states can not finish within 1 minutes"); + return Arrays.asList("Send goal states can not finish within 1 minutes"); + } + return new ArrayList<>(); } public static DataPlaneClientImplV2 getInstance(Config globalConfig, ArrayList monitorHosts) { @@ -100,7 +108,7 @@ public DataPlaneClientImplV2(Config globalConfig, ArrayList monitorHosts LOG.info("Done printing out all monitorHosts"); this.numberOfGrpcChannelPerHost = globalConfig.numberOfGrpcChannelPerHost; this.numberOfWarmupsPerChannel = globalConfig.numberOfWarmupsPerChannel; - this.hostAgentPort = 50001; + this.hostAgentPort = 9016; this.executor = new ThreadPoolExecutor(100, 200, @@ -220,11 +228,9 @@ public void onCompleted() { return; } - private String doSendGoalState(UnicastGoalStateV2 unicastGoalState) { - String hostIp = unicastGoalState.getHostIp(); - LOG.info("Setting up a channel to ACA on: " + hostIp); + private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { + String hostIp = "10.97.182.147"; long start = System.currentTimeMillis(); - GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established channel, elapsed Time in milli seconds: " + (chan_established - start)); @@ -244,27 +250,19 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { @Override public void onError(Throwable t) { LOG.warn("Receive error from ACA@" + hostIp + " | " + t.getMessage()); + exceptionLatch.countDown(); } @Override public void onCompleted() { LOG.info("Complete receiving message from ACA@" + hostIp); + finishLatch.countDown(); } }; StreamObserver requestObserver = asyncStub.pushGoalStatesStream(responseObserver); try { - Goalstate.GoalStateV2 goalState = unicastGoalState.getGoalState(); - LOG.info("Sending GS to Host " + hostIp + " as follows | " + goalState.toString()); - requestObserver.onNext(goalState); - if (unicastGoalState.getGoalState().getNeighborStatesCount() == 1 && monitorHosts.contains(hostIp)) { - long sent_gs_time = System.currentTimeMillis(); - // If there's only one neighbor state and it is trying to send it to aca_node_one, the IP of which is now - // hardcoded) this send goalstate action is probably caused by on-demand workflow, need to record when it - // sends this goalState so what we can look into this and the ACA log to see how much time was spent. - String neighbor_id = unicastGoalState.getGoalState().getNeighborStatesMap().keySet().iterator().next(); - LOG.info("Sending neighbor ID: " + neighbor_id + " at: " + sent_gs_time); - } + requestObserver.onNext(goalStateV2); } catch (RuntimeException e) { // Cancel RPC LOG.warn("[doSendGoalState] Sending GS, but error happened | " + e.getMessage()); @@ -275,10 +273,7 @@ public void onCompleted() { LOG.info("Sending GS to Host " + hostIp + " is completed"); // comment out onCompleted so that the same channel/stub and keep sending next time. - // requestObserver.onCompleted(); - -// shutdown(channel); - + requestObserver.onCompleted(); return null; } @@ -291,4 +286,113 @@ public GrpcChannelStub(ManagedChannel channel, GoalStateProvisionerGrpc.GoalStat this.stub = stub; } } + + private Goalstate.GoalStateV2.Builder getGoalState(Goalstate.GoalStateV2.Builder goalStateBuilder, UnicastGoalStateV2 unicastGoalStateV2) { + Goalstate.GoalStateV2 goalStateV2 = unicastGoalStateV2.getGoalState(); + Goalstate.HostResources.Builder hostResourceBuilder = Goalstate.HostResources.newBuilder(); + if (goalStateV2.getSubnetStatesCount() > 0) { + goalStateV2.getSubnetStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType subnetResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.SUBNET) + .setId(key) + .build(); + hostResourceBuilder.addResources(subnetResourceIdType); + }); + goalStateBuilder.putAllSubnetStates(goalStateV2.getSubnetStatesMap()); + } + + if (goalStateV2.getDhcpStatesCount() > 0) { + goalStateV2.getDhcpStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType dhcpResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.DHCP) + .setId(key) + .build(); + hostResourceBuilder.addResources(dhcpResourceIdType); + }); + goalStateBuilder.putAllDhcpStates(goalStateV2.getDhcpStatesMap()); + } + + if (goalStateV2.getPortStatesCount() > 0) { + goalStateV2.getPortStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType portResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.PORT) + .setId(key) + .build(); + hostResourceBuilder.addResources(portResourceIdType); + }); + goalStateBuilder.putAllPortStates(goalStateV2.getPortStatesMap()); + } + + if (goalStateV2.getSecurityGroupStatesCount() > 0) { + goalStateV2.getSecurityGroupStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType securityGroupResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.SECURITYGROUP) + .setId(key) + .build(); + hostResourceBuilder.addResources(securityGroupResourceIdType); + }); + goalStateBuilder.putAllSecurityGroupStates(goalStateV2.getSecurityGroupStatesMap()); + } + + if (goalStateV2.getNeighborStatesCount() > 0) { + goalStateV2.getNeighborStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType neighborGroupResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.NEIGHBOR) + .setId(key) + .build(); + hostResourceBuilder.addResources(neighborGroupResourceIdType); + }); + goalStateBuilder.putAllNeighborStates(goalStateV2.getNeighborStatesMap()); + } + + if (goalStateV2.getRouterStatesCount() > 0) { + goalStateV2.getRouterStatesMap().entrySet().forEach(entry -> { + Goalstate.ResourceIdType routerResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.ROUTER) + .setId(unicastGoalStateV2.getHostIp() + "/" + entry.getKey()) + .build(); + hostResourceBuilder.addResources(routerResourceIdType); + + + if (goalStateBuilder.containsRouterStates(unicastGoalStateV2.getHostIp() + "/" + entry.getKey())) { + Router.RouterConfiguration.Builder routerConfigurationBuilder = goalStateBuilder.getRouterStatesMap().get(unicastGoalStateV2.getHostIp() + "/" + entry.getKey()).getConfiguration().toBuilder(); + routerConfigurationBuilder.addAllSubnetRoutingTables(entry.getValue().getConfiguration().getSubnetRoutingTablesList()); + Router.RouterState.Builder routerStateBuilder = goalStateBuilder.getRouterStatesMap().get(unicastGoalStateV2.getHostIp() + "/" + entry.getKey()).toBuilder(); + routerStateBuilder.setConfiguration(routerConfigurationBuilder); + } else { + goalStateBuilder.putRouterStates(unicastGoalStateV2.getHostIp() + "/" + entry.getKey(), entry.getValue()); + } + }); + } + + if (goalStateV2.getVpcStatesCount() > 0) { + goalStateV2.getVpcStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType vpcResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.VPC) + .setId(key) + .build(); + hostResourceBuilder.addResources(vpcResourceIdType); + }); + goalStateBuilder.putAllVpcStates(goalStateV2.getVpcStatesMap()); + } + + if (goalStateV2.getGatewayStatesCount() > 0) { + goalStateV2.getGatewayStatesMap().keySet().forEach(key -> { + Goalstate.ResourceIdType gatewayResourceIdType = Goalstate.ResourceIdType.newBuilder() + .setType(Common.ResourceType.GATEWAY) + .setId(key) + .build(); + hostResourceBuilder.addResources(gatewayResourceIdType); + }); + goalStateBuilder.putAllGatewayStates(goalStateV2.getGatewayStatesMap()); + } + + if (goalStateBuilder.containsHostResources(unicastGoalStateV2.getHostIp())) { + Goalstate.HostResources.Builder goalStateHostResourceBuilder = goalStateBuilder.getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).toBuilder(); + goalStateHostResourceBuilder.addAllResources(hostResourceBuilder.getResourcesList()); + } else { + goalStateBuilder.putHostResources(unicastGoalStateV2.getHostIp(), hostResourceBuilder.build()); + } + return goalStateBuilder; + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DhcpService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DhcpService.java index 3cdf905b8..13a6fedd8 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DhcpService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DhcpService.java @@ -26,6 +26,7 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.ArrayList; import java.util.List; +import java.util.UUID; @Service public class DhcpService extends ResourceService { @@ -72,6 +73,7 @@ public void buildDhcpStates(NetworkConfiguration networkConfig, UnicastGoalState DHCP.DHCPConfiguration.Builder dhcpConfigBuilder = DHCP.DHCPConfiguration.newBuilder(); dhcpConfigBuilder.setRevisionNumber(FORMAT_REVISION_NUMBER); dhcpConfigBuilder.setMacAddress(macAddress); + dhcpConfigBuilder.setId(UUID.randomUUID().toString()); dhcpConfigBuilder.setIpv4Address(fixedIp.getIpAddress()); dhcpConfigBuilder.setSubnetId(fixedIp.getSubnetId()); @@ -87,14 +89,6 @@ public void buildDhcpStates(NetworkConfiguration networkConfig, UnicastGoalState DHCP.DHCPState dhcpState = dhcpStateBuilder.build(); unicastGoalState.getGoalStateBuilder().putDhcpStates(dhcpState.getConfiguration().getId(), dhcpState); - - Goalstate.ResourceIdType dhcpResourceIdType = Goalstate.ResourceIdType.newBuilder() - .setType(Common.ResourceType.DHCP) - .setId(dhcpState.getConfiguration().getId()) - .build(); - Goalstate.HostResources.Builder hostResourceBuilder = Goalstate.HostResources.newBuilder(); - hostResourceBuilder.addResources(dhcpResourceIdType); - unicastGoalState.getGoalStateBuilder().putHostResources(unicastGoalState.getHostIp(), hostResourceBuilder.build()); } } } 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 b55a43537..ca8bbbea6 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 @@ -245,15 +245,6 @@ public void buildNeighborStates(NetworkConfiguration networkConfig, String hostI Neighbor.NeighborState neighborState = buildNeighborState(neighborEntry.getNeighborType(), neighborInfo, networkConfig.getOpType()); unicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - - Goalstate.ResourceIdType neighborResourceIdType = Goalstate.ResourceIdType.newBuilder() - .setType(Common.ResourceType.NEIGHBOR) - .setId(neighborState.getConfiguration().getId()) - .build(); - Goalstate.HostResources.Builder hostResourceBuilder = Goalstate.HostResources.newBuilder(); - hostResourceBuilder.addResources(neighborResourceIdType); - unicastGoalState.getGoalStateBuilder().putHostResources(unicastGoalState.getHostIp(), hostResourceBuilder.build()); - multicastNeighborEntries.add(neighborEntry); } } @@ -277,15 +268,6 @@ public void buildNeighborStates(NetworkConfiguration networkConfig, String hostI Neighbor.NeighborState neighborState = buildNeighborState(neighborEntry.getNeighborType(), neighborInfo1, networkConfig.getOpType()); multicastGoalState.getGoalStateBuilder().putNeighborStates(neighborState.getConfiguration().getId(), neighborState); - Goalstate.ResourceIdType neighborResourceIdType = Goalstate.ResourceIdType.newBuilder() - .setType(Common.ResourceType.NEIGHBOR) - .setId(neighborState.getConfiguration().getId()) - .build(); - Goalstate.HostResources.Builder hostResourceBuilder = Goalstate.HostResources.newBuilder(); - hostResourceBuilder.addResources(neighborResourceIdType); - // TODO: Change resource id - multicastGoalState.getGoalStateBuilder().putHostResources(unicastGoalState.getHostIp(), hostResourceBuilder.build()); - neighborInfoSet.add(neighborInfo1); } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/PortService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/PortService.java index a1343c1d4..8d1bb53d7 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/PortService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/PortService.java @@ -166,14 +166,6 @@ public void buildPortState(NetworkConfiguration networkConfig, List sendGoalStates(Map hostGoalStates) throws Exception { - List> - futures = new ArrayList<>(hostGoalStates.size()); + final CountDownLatch finishLatch = new CountDownLatch(hostGoalStates.size()); + final CountDownLatch exceptionLatch = new CountDownLatch(1); for (HostGoalState hostGoalState : hostGoalStates.values()) { - Future future = - executor.submit(() -> { - try { - doSendGoalState(hostGoalState); - } catch (InterruptedException e) { - e.printStackTrace(); - return hostGoalState; - } - - return new HostGoalState(); - }); - - futures.add(future); + doSendGoalState(hostGoalState, finishLatch, exceptionLatch); } - //Handle all failed hosts - return futures.parallelStream().filter(Objects::nonNull).map(future -> { - try { - return future.get().getHostIp(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + if (!finishLatch.await(1, TimeUnit.MINUTES) || !exceptionLatch.await(1, TimeUnit.MINUTES)) { + if (exceptionLatch.getCount() == 0) { + return Arrays.asList("Goal states not correct"); } - - return null; - }).collect(Collectors.toList()); + logger.log(Level.WARNING, "Send goal states can not finish within 1 minutes"); + return Arrays.asList("Send goal states can not finish within 1 minutes"); + } + return new ArrayList<>(); } private GrpcChannelStub getOrCreateGrpcChannel(String hostIp) { @@ -215,7 +199,7 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp) { return new GrpcChannelStub(channel, asyncStub); } - private void doSendGoalState(HostGoalState hostGoalState) throws InterruptedException { + private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, CountDownLatch exceptionLatch) throws InterruptedException { String hostIp = hostGoalState.getHostIp(); logger.log(Level.FINE, "Setting up a channel to ACA on: " + hostIp); @@ -235,16 +219,21 @@ private void doSendGoalState(HostGoalState hostGoalState) throws InterruptedExce public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); + if (reply.getOperationStatusesList().stream().filter(item -> !item.getOperationStatus().equals("SUCCESS")).collect(Collectors.toList()).size() > 0) { + exceptionLatch.countDown(); + } } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "Receive error from ACA@" + hostIp + " | " + t.getMessage()); + exceptionLatch.countDown(); } @Override public void onCompleted() { logger.log(Level.INFO, "Complete receiving message from ACA@" + hostIp); + finishLatch.countDown(); } }; @@ -271,7 +260,7 @@ public void onCompleted() { logger.log(Level.INFO, "Sending GS to Host " + hostIp + " is completed"); // comment out onCompleted so that the same channel/stub and keep sending next time. - // requestObserver.onCompleted(); + requestObserver.onCompleted(); // shutdown(channel); } 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 54faf5500..aadf98c34 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 @@ -162,6 +162,7 @@ public void onNext(Goalstate.GoalStateV2 value) { goalStatePersistenceService.updateGoalState(hostId, hostGoalState); } catch (Exception e) { e.printStackTrace(); + responseObserver.onError(e); } } long end = System.currentTimeMillis(); @@ -175,6 +176,7 @@ public void onNext(Goalstate.GoalStateV2 value) { grpcGoalStateClient.sendGoalStates(filteredGoalStates); } catch (Exception e) { e.printStackTrace(); + responseObserver.onError(e); } //consolidate response from ACA and send response to DPM @@ -182,7 +184,6 @@ public void onNext(Goalstate.GoalStateV2 value) { Goalstateprovisioner.GoalStateOperationReply.newBuilder() .setFormatVersion(100) .build(); - responseObserver.onNext(reply); long end1 = System.currentTimeMillis(); logger.log(Level.FINE, "pushGoalStatesStream : Replied to DPM, from received to replied, elapsed time in milliseconds: " + + (end1-end)); } @@ -191,7 +192,7 @@ public void onNext(Goalstate.GoalStateV2 value) { public void onError(Throwable t) { t.printStackTrace(); logger.log(Level.WARNING, "*** pushGoalStatesStream cancelled"); - responseObserver.onCompleted(); + responseObserver.onError(t); } @Override From 6b1fd3d21ea0120dc37614ad8b8447d52ab29fd9 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 12 Nov 2021 14:50:47 -0800 Subject: [PATCH 14/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 631017ac3..6d3b5b826 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -229,7 +229,7 @@ public void onCompleted() { } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { - String hostIp = "10.97.182.147"; + String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); From 43af049e58a69199de8a3692fe1ecfc2e86b049a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 15 Nov 2021 11:46:41 -0800 Subject: [PATCH 15/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 c1472e396..346a3b358 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 @@ -220,7 +220,9 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); if (reply.getOperationStatusesList().stream().filter(item -> !item.getOperationStatus().equals("SUCCESS")).collect(Collectors.toList()).size() > 0) { - exceptionLatch.countDown(); + this.onError(new Exception(reply.toString())); + } else { + this.onCompleted(); } } From db5f112a5b939d3ce12d5fb8308d5fc618797a60 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 16 Nov 2021 10:24:27 -0800 Subject: [PATCH 16/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 6d3b5b826..8b664cd23 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -229,7 +229,7 @@ public void onCompleted() { } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { - String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; + String hostIp = "netwconfigmanager-service.netwconfigmanager.svc.cluster.local"; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); From 872277287a5d6cd3432a0ade35e87b3b9bc6e146 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 16 Nov 2021 12:18:06 -0800 Subject: [PATCH 17/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 4 ++++ 1 file changed, 4 insertions(+) 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 346a3b358..e2e70fd3c 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 @@ -219,11 +219,15 @@ private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishL public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); + /* if (reply.getOperationStatusesList().stream().filter(item -> !item.getOperationStatus().equals("SUCCESS")).collect(Collectors.toList()).size() > 0) { this.onError(new Exception(reply.toString())); } else { this.onCompleted(); } + + */ + this.onCompleted(); } @Override From dda26786e638e06bdc3cfb14498cc961bd92a947 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 16 Nov 2021 12:21:39 -0800 Subject: [PATCH 18/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 8b664cd23..6d3b5b826 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -229,7 +229,7 @@ public void onCompleted() { } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { - String hostIp = "netwconfigmanager-service.netwconfigmanager.svc.cluster.local"; + String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); From 6bf77acf844b36582f2221db9f47a47033efc5b4 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 16 Nov 2021 15:42:31 -0800 Subject: [PATCH 19/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 2 +- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 6d3b5b826..d260e86c9 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -72,7 +72,7 @@ public List sendGoalStates(List unicastGoalStates) t System.out.println(goalStateBuilder.build()); doSendGoalState(goalStateBuilder.build(), finishLatch, exceptionLatch); - if (!finishLatch.await(1, TimeUnit.MINUTES) || !exceptionLatch.await(1, TimeUnit.MINUTES)) { + if (!finishLatch.await(1, TimeUnit.MINUTES) && !exceptionLatch.await(1, TimeUnit.MINUTES)) { if (exceptionLatch.getCount() == 0) { return Arrays.asList("Goal states not correct"); } 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 e2e70fd3c..71cd529d0 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 @@ -100,14 +100,16 @@ public GoalStateClientImpl(int numberOfGrpcChannelPerHost, int numberOfWarmupsPe @Override @DurationStatistics public List sendGoalStates(Map hostGoalStates) throws Exception { - final CountDownLatch finishLatch = new CountDownLatch(hostGoalStates.size()); + final CountDownLatch finishLatch = new CountDownLatch(hostGoalStates.values().size()); final CountDownLatch exceptionLatch = new CountDownLatch(1); + logger.log(Level.INFO, "Host goal states size: " + hostGoalStates.values().size()); + for (HostGoalState hostGoalState : hostGoalStates.values()) { doSendGoalState(hostGoalState, finishLatch, exceptionLatch); } - if (!finishLatch.await(1, TimeUnit.MINUTES) || !exceptionLatch.await(1, TimeUnit.MINUTES)) { + if (!finishLatch.await(1, TimeUnit.MINUTES) && !exceptionLatch.await(1, TimeUnit.MINUTES)) { if (exceptionLatch.getCount() == 0) { return Arrays.asList("Goal states not correct"); } From 410e50c16a230aa4c9cfa3366fb3617b0a22ad76 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 17 Nov 2021 13:31:21 -0800 Subject: [PATCH 20/48] Update code --- .../cache/ResourceStateCache.java | 12 ++++- .../service/GoalStatePersistenceService.java | 3 ++ .../impl/GoalStatePersistenceServiceImpl.java | 49 ++++++------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java index c5200f7af..e151c9285 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java @@ -18,13 +18,18 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.CacheFactory; import com.futurewei.alcor.common.db.ICache; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.schema.Subnet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + @Repository @ComponentScan(value = "com.futurewei.alcor.common.db") -public class ResourceStateCache { +public class ResourceStateCache { // Map private ICache hostResourceStates; @@ -45,6 +50,11 @@ public void addResourceState(String resourceId, Object resourceState) throws Exc this.hostResourceStates.put(resourceId, resourceState); } + @DurationStatistics + public void addResourceStates(SortedMap items) throws Exception { + this.hostResourceStates.putAll(items); + } + @DurationStatistics public void updateResourceState(String resourceId, Object resourceState) throws Exception { this.hostResourceStates.put(resourceId, resourceState); 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 a2f63d65f..ac3af8f6f 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 @@ -16,6 +16,9 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.netwconfigmanager.service; import com.futurewei.alcor.netwconfigmanager.entity.HostGoalState; +import com.futurewei.alcor.schema.Subnet; + +import java.util.SortedMap; public interface GoalStatePersistenceService { 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 196a8b021..883700699 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,8 @@ free of charge, to any person obtaining a copy of this software and associated d import java.util.HashMap; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.logging.Level; @Service @@ -118,59 +120,40 @@ private Map processVpcStates(HostGoalState hostGoalState) throw } private void processSubnetStates(HostGoalState hostGoalState) throws Exception { - Map subnetStatesMap = hostGoalState.getGoalState().getSubnetStatesMap(); + SortedMap subnetStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getSubnetStatesMap()); + resourceStateCache.addResourceStates(subnetStatesSortedMap); - for (String resourceId : subnetStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, subnetStatesMap.get(resourceId)); - } } private void processPortStates(HostGoalState hostGoalState) throws Exception { - Map portStatesMap = hostGoalState.getGoalState().getPortStatesMap(); + SortedMap portStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getPortStatesMap()); + resourceStateCache.addResourceStates(portStatesSortedMap); - for (String resourceId : portStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, portStatesMap.get(resourceId)); - } } private void processDhcpStates(HostGoalState hostGoalState) throws Exception { - Map dhcpStatesMap = hostGoalState.getGoalState().getDhcpStatesMap(); - - for (String resourceId : dhcpStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, dhcpStatesMap.get(resourceId)); - } + SortedMap portStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getDhcpStatesMap()); + resourceStateCache.addResourceStates(portStatesSortedMap); } private void processNeighborStates(HostGoalState hostGoalState) throws Exception { - Map neighborStatesMap = hostGoalState.getGoalState().getNeighborStatesMap(); - - for (String resourceId : neighborStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, neighborStatesMap.get(resourceId)); - } + SortedMap neighborStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getNeighborStatesMap()); + resourceStateCache.addResourceStates(neighborStatesSortedMap); } private void processSecurityGroupStates(HostGoalState hostGoalState) throws Exception { - Map securityGroupStatesMap = hostGoalState.getGoalState().getSecurityGroupStatesMap(); - - for (String resourceId : securityGroupStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, securityGroupStatesMap.get(resourceId)); - } + SortedMap securityGroupStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getSecurityGroupStatesMap()); + resourceStateCache.addResourceStates(securityGroupStatesSortedMap); } private void processRouterStates(HostGoalState hostGoalState) throws Exception { - Map routerStatesMap = hostGoalState.getGoalState().getRouterStatesMap(); - - for (String resourceId : routerStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, routerStatesMap.get(resourceId)); - } + SortedMap routerStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getRouterStatesMap()); + resourceStateCache.addResourceStates(routerStatesSortedMap); } private void processGatewayStates(HostGoalState hostGoalState) throws Exception { - Map gatewayStatesMap = hostGoalState.getGoalState().getGatewayStatesMap(); - - for (String resourceId : gatewayStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, gatewayStatesMap.get(resourceId)); - } + SortedMap gatewayStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getGatewayStatesMap()); + resourceStateCache.addResourceStates(gatewayStatesSortedMap); } private void populateVpcResourceCache(HostGoalState hostGoalState, Map vpcIdToVniMap) throws Exception { From ca741c7af25fcd06257c787773c37832a665ffe4 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 17 Nov 2021 14:40:50 -0800 Subject: [PATCH 21/48] Update code --- .../service/impl/GoalStatePersistenceServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 883700699..8b845e907 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 @@ -55,7 +55,7 @@ public class GoalStatePersistenceServiceImpl implements GoalStatePersistenceServ @Override @DurationStatistics - public boolean updateGoalState(String hostId, HostGoalState hostGoalState) throws Exception { + public synchronized boolean updateGoalState(String hostId, HostGoalState hostGoalState) throws Exception { // TODO: Use Ignite transaction here hostResourceMetadataCache.getTransaction(); From 7352b2482a60c8337d34f19facd7ed0c8ad9ffbf Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 17 Nov 2021 18:24:01 -0800 Subject: [PATCH 22/48] Update code --- .../client/gRPC/GoalStateClientImpl.java | 9 ++------- 1 file changed, 2 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 71cd529d0..d8316d759 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 @@ -21,6 +21,7 @@ free of charge, to any person obtaining a copy of this software and associated d 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.schema.Common; import com.futurewei.alcor.schema.GoalStateProvisionerGrpc; import com.futurewei.alcor.schema.Goalstate; import com.futurewei.alcor.schema.Goalstateprovisioner; @@ -221,15 +222,9 @@ private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishL public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); - /* - if (reply.getOperationStatusesList().stream().filter(item -> !item.getOperationStatus().equals("SUCCESS")).collect(Collectors.toList()).size() > 0) { + if (reply.getOperationStatusesList().stream().filter(item -> item.getOperationStatus().equals(Common.OperationStatus.FAILURE)).collect(Collectors.toList()).size() > 0) { this.onError(new Exception(reply.toString())); - } else { - this.onCompleted(); } - - */ - this.onCompleted(); } @Override From 2df153c1be9ab4a8b8accd797f84132ef419d7ec Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 17 Nov 2021 20:22:02 -0800 Subject: [PATCH 23/48] Update code --- .../client/gRPC/GoalStateClientImpl.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 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 d8316d759..8048942c9 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 @@ -102,21 +102,19 @@ public GoalStateClientImpl(int numberOfGrpcChannelPerHost, int numberOfWarmupsPe @DurationStatistics public List sendGoalStates(Map hostGoalStates) throws Exception { final CountDownLatch finishLatch = new CountDownLatch(hostGoalStates.values().size()); - final CountDownLatch exceptionLatch = new CountDownLatch(1); - logger.log(Level.INFO, "Host goal states size: " + hostGoalStates.values().size()); - + List replies = new ArrayList<>(); for (HostGoalState hostGoalState : hostGoalStates.values()) { - doSendGoalState(hostGoalState, finishLatch, exceptionLatch); + doSendGoalState(hostGoalState, finishLatch, replies); } - if (!finishLatch.await(1, TimeUnit.MINUTES) && !exceptionLatch.await(1, TimeUnit.MINUTES)) { - if (exceptionLatch.getCount() == 0) { - return Arrays.asList("Goal states not correct"); - } + if (!finishLatch.await(1, TimeUnit.MINUTES)) { logger.log(Level.WARNING, "Send goal states can not finish within 1 minutes"); return Arrays.asList("Send goal states can not finish within 1 minutes"); } + if (replies.size() > 0) { + return replies; + } return new ArrayList<>(); } @@ -202,8 +200,7 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp) { return new GrpcChannelStub(channel, asyncStub); } - private void doSendGoalState(HostGoalState hostGoalState, CountDownLatch finishLatch, CountDownLatch exceptionLatch) 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(); @@ -223,14 +220,16 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); if (reply.getOperationStatusesList().stream().filter(item -> item.getOperationStatus().equals(Common.OperationStatus.FAILURE)).collect(Collectors.toList()).size() > 0) { - this.onError(new Exception(reply.toString())); + replies.add(reply.toString()); + while (finishLatch.getCount() > 0) { + finishLatch.countDown(); + } } } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "Receive error from ACA@" + hostIp + " | " + t.getMessage()); - exceptionLatch.countDown(); } @Override From 40a3693ffb21a8907ed2cbb314bc86bf55dc7720 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 18 Nov 2021 16:32:03 -0800 Subject: [PATCH 24/48] Update code --- .../NetworkConfigManagerApplication.java | 15 +++--- .../cache/ResourceStateCache.java | 6 +++ .../grpc/GoalStateProvisionerServer.java | 21 +++----- .../service/GoalStatePersistenceService.java | 5 ++ .../impl/GoalStatePersistenceServiceImpl.java | 48 ++++++++++++++++--- 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java index 3f9398efe..d768e1c4d 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java @@ -37,12 +37,15 @@ public class NetworkConfigManagerApplication { @PostConstruct public void instantiateGrpcServer(){ - try { - networkConfigServer.start(); - networkConfigServer.blockUntilShutdown(); - } catch (Exception e) { - e.printStackTrace(); - } + Thread server = new Thread(() -> { + try { + networkConfigServer.start(); + networkConfigServer.blockUntilShutdown(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + server.start(); } public static void main(String[] args) { diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java index e151c9285..083e31d50 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/cache/ResourceStateCache.java @@ -18,6 +18,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.CacheFactory; import com.futurewei.alcor.common.db.ICache; import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.schema.Port; import com.futurewei.alcor.schema.Subnet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -45,6 +46,11 @@ public Object getResourceState(String resourceId) throws Exception { return resourceState; } + @DurationStatistics + public Map getResourceStates() throws Exception { + return this.hostResourceStates.getAll(); + } + @DurationStatistics public void addResourceState(String resourceId, Object resourceState) throws Exception { this.hostResourceStates.put(resourceId, resourceState); 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 aadf98c34..7ed264792 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 @@ -149,22 +149,15 @@ public void onNext(Goalstate.GoalStateV2 value) { logger.log(Level.INFO, "pushGoalStatesStream : receiving GS V2 message " + value.toString()); long start = System.currentTimeMillis(); - //prepare GS message based on host - Map hostGoalStates = NetworkConfigManagerUtil.splitClusterToHostGoalState(value); - //store the goal state in cache - Set processedResourceIds = new HashSet<>(); - for (Map.Entry entry : hostGoalStates.entrySet()) { - String hostId = entry.getKey(); - HostGoalState hostGoalState = entry.getValue(); - - try { - goalStatePersistenceService.updateGoalState(hostId, hostGoalState); - } catch (Exception e) { - e.printStackTrace(); - responseObserver.onError(e); - } + Map hostGoalStates = new HashMap<>(); + try { + hostGoalStates = goalStatePersistenceService.updateGoalStates(value); + } catch (Exception e) { + e.printStackTrace(); + responseObserver.onError(e); } + Set processedResourceIds = new HashSet<>(); long end = System.currentTimeMillis(); logger.log(Level.FINE, "pushGoalStatesStream : finished putting GS into cache, elapsed time in milliseconds: " + + (end-start)); // filter neighbor/SG update, and send them down to target ACA 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 ac3af8f6f..d82a979ea 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 @@ -16,8 +16,10 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.netwconfigmanager.service; import com.futurewei.alcor.netwconfigmanager.entity.HostGoalState; +import com.futurewei.alcor.schema.Goalstate; import com.futurewei.alcor.schema.Subnet; +import java.util.Map; import java.util.SortedMap; public interface GoalStatePersistenceService { @@ -31,4 +33,7 @@ public interface GoalStatePersistenceService { */ boolean updateGoalState(String hostId, HostGoalState hostGoalState) throws Exception; + + Map updateGoalStates(Goalstate.GoalStateV2 goalStateV2) throws Exception; + } 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 8b845e907..08e1af0e3 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 @@ -53,12 +53,46 @@ public class GoalStatePersistenceServiceImpl implements GoalStatePersistenceServ @Autowired private VpcResourceCache vpcResourceCache; + @Override + @DurationStatistics + public Map updateGoalStates(Goalstate.GoalStateV2 goalStateV2) throws Exception { + //prepare GS message based on host + Map hostGoalStates = NetworkConfigManagerUtil.splitClusterToHostGoalState(goalStateV2); + + SortedMap goalStates = new TreeMap<>(); + goalStates.putAll(goalStateV2.getSubnetStatesMap()); + goalStates.putAll(goalStateV2.getHostResourcesMap()); + goalStates.putAll(goalStateV2.getDhcpStatesMap()); + goalStates.putAll(goalStateV2.getGatewayStatesMap()); + goalStates.putAll(goalStateV2.getNeighborStatesMap()); + goalStates.putAll(goalStateV2.getPortStatesMap()); + goalStates.putAll(goalStateV2.getRouterStatesMap()); + goalStates.putAll(goalStateV2.getSecurityGroupStatesMap()); + synchronized (this) { + hostResourceMetadataCache.getTransaction(); + resourceStateCache.addResourceStates(goalStates); + for (Map.Entry entry : hostGoalStates.entrySet()) { + String hostId = entry.getKey(); + HostGoalState hostGoalState = entry.getValue(); + + try { + updateGoalState(hostId, hostGoalState); + } catch (Exception e) { + e.printStackTrace(); + } + } + hostResourceMetadataCache.commit(); + } + System.out.println(resourceStateCache.getResourceStates().size()); + resourceStateCache.getResourceStates().entrySet().forEach(item -> System.out.println(item)); + return hostGoalStates; + } + @Override @DurationStatistics public synchronized boolean updateGoalState(String hostId, HostGoalState hostGoalState) throws Exception { // TODO: Use Ignite transaction here - hostResourceMetadataCache.getTransaction(); // Step 1: Populate host resource metadata cache long t1 = System.currentTimeMillis(); @@ -86,6 +120,7 @@ public synchronized boolean updateGoalState(String hostId, HostGoalState hostGoa // Step 2: Populate resource state cache Map vpcIdToVniMap = processVpcStates(hostGoalState); + /* processSubnetStates(hostGoalState); processPortStates(hostGoalState); processDhcpStates(hostGoalState); @@ -93,6 +128,8 @@ public synchronized boolean updateGoalState(String hostId, HostGoalState hostGoa processSecurityGroupStates(hostGoalState); processRouterStates(hostGoalState); processGatewayStates(hostGoalState); + + */ long t5_plus = System.currentTimeMillis(); logger.log(Level.FINE, "updateGoalstate : hostId: "+hostId+", finished processing goalState, elapsed time in milliseconds: " + (t5_plus-t5)); @@ -102,20 +139,19 @@ public synchronized boolean updateGoalState(String hostId, HostGoalState hostGoa long t_total = (t6 - t5) + (t4 - t3) + (t2 - t1); logger.log(Level.FINE, "updateGoalstate : hostId: "+hostId+", finished populating vpc resource cache, elapsed time in milliseconds: " + (t6-t5_plus)); logger.log(Level.FINE, "updateGoalstate : hostId: "+hostId+", total time, elapsed time in milliseconds: " + t_total); - - hostResourceMetadataCache.commit(); return false; } private Map processVpcStates(HostGoalState hostGoalState) throws Exception { + /* + SortedMap vpcStatesSortedMap = new TreeMap<>(hostGoalState.getGoalState().getVpcStatesMap()); + resourceStateCache.addResourceStates(vpcStatesSortedMap); + */ Map vpcIdToVniMap = new HashMap<>(); Map vpsStatesMap = hostGoalState.getGoalState().getVpcStatesMap(); - for (String resourceId : vpsStatesMap.keySet()) { - resourceStateCache.addResourceState(resourceId, vpsStatesMap.get(resourceId)); vpcIdToVniMap.put(resourceId, vpsStatesMap.get(resourceId).getConfiguration().getTunnelId()); } - return vpcIdToVniMap; } From 2d6f74d61bfff9253b33c96b1ba3c1ea805c73a0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 18 Nov 2021 16:45:39 -0800 Subject: [PATCH 25/48] Update code --- .../service/impl/GoalStatePersistenceServiceImpl.java | 2 -- 1 file changed, 2 deletions(-) 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 08e1af0e3..c5c317673 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 @@ -83,8 +83,6 @@ public Map updateGoalStates(Goalstate.GoalStateV2 goalSta } hostResourceMetadataCache.commit(); } - System.out.println(resourceStateCache.getResourceStates().size()); - resourceStateCache.getResourceStates().entrySet().forEach(item -> System.out.println(item)); return hostGoalStates; } From e76fb1860954783e00c67cf96d1522b1d1dd3282 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 18 Nov 2021 17:34:42 -0800 Subject: [PATCH 26/48] Update code --- schema/proto3/common.proto | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/schema/proto3/common.proto b/schema/proto3/common.proto index 516341cb5..6ce48b96c 100644 --- a/schema/proto3/common.proto +++ b/schema/proto3/common.proto @@ -22,15 +22,14 @@ option java_package = "com.futurewei.alcor.schema"; option java_outer_classname = "Common"; enum ResourceType { - DEFAULTTYPE = 0; - VPC = 1; - SUBNET = 2; - PORT = 3; - NEIGHBOR = 4; - SECURITYGROUP =5; - DHCP = 6; - ROUTER = 7; - GATEWAY = 8; + VPC = 0; + SUBNET = 1; + PORT = 2; + NEIGHBOR = 3; + SECURITYGROUP =4; + DHCP = 5; + ROUTER = 6; + GATEWAY = 7; } enum OperationType { From e0a2fbbf5e58dae7c7c5508b42fec54870845bb0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 19 Nov 2021 14:59:38 -0800 Subject: [PATCH 27/48] Update code --- .../netwconfigmanager/util/NetworkConfigManagerUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/util/NetworkConfigManagerUtil.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/util/NetworkConfigManagerUtil.java index 566af5da4..92d62e877 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/util/NetworkConfigManagerUtil.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/util/NetworkConfigManagerUtil.java @@ -20,6 +20,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.netwconfigmanager.exception.UnexpectedHostNumException; import com.futurewei.alcor.schema.Common; import com.futurewei.alcor.schema.Goalstate; +import com.futurewei.alcor.schema.Router; import org.springframework.core.io.Resource; import java.util.HashMap; @@ -65,7 +66,12 @@ public static Map splitClusterToHostGoalState(Goalstate.G hostGoalState.getGoalStateBuilder().putDhcpStates(resourceId, goalState.getDhcpStatesOrThrow(resourceId)); break; case ROUTER: - hostGoalState.getGoalStateBuilder().putRouterStates(resourceId, goalState.getRouterStatesOrThrow(resourceId)); + Router.RouterState routerState = goalState.getRouterStatesOrThrow(resourceId); + String[] tokens = resourceId.split("/"); + if (tokens.length == 2) { + resourceId = tokens[1]; + } + hostGoalState.getGoalStateBuilder().putRouterStates(resourceId, routerState); break; case GATEWAY: hostGoalState.getGoalStateBuilder().putGatewayStates(resourceId, goalState.getGatewayStatesOrThrow(resourceId)); From 8ae12cfe24b7d92e9a501a9fe48724c5a4201785 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 19 Nov 2021 15:52:04 -0800 Subject: [PATCH 28/48] Update code --- .../server/grpc/GoalStateProvisionerServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7ed264792..9465e86df 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 @@ -166,7 +166,7 @@ public void onNext(Goalstate.GoalStateV2 value) { GoalStateClient grpcGoalStateClient = GoalStateClientImpl.getInstance(numberOfGrpcChannelPerHost, numberOfWarmupsPerChannel, monitorHosts); - grpcGoalStateClient.sendGoalStates(filteredGoalStates); + grpcGoalStateClient.sendGoalStates(hostGoalStates); } catch (Exception e) { e.printStackTrace(); responseObserver.onError(e); From 0ebf1f05eca86e5fb10701d3ad1b15050c0284a4 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 19 Nov 2021 16:49:34 -0800 Subject: [PATCH 29/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index d260e86c9..ba54ee68d 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -67,6 +67,7 @@ public List sendGoalStates(List unicastGoalStates) t final CountDownLatch exceptionLatch = new CountDownLatch(1); List results = new ArrayList<>(); for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { + System.out.println(unicastGoalState.getGoalState()); goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } System.out.println(goalStateBuilder.build()); From fa3433063ee5ba252ef56109f55829d59c0ada65 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 19 Nov 2021 17:22:43 -0800 Subject: [PATCH 30/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index ba54ee68d..de429dea1 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -67,7 +67,6 @@ public List sendGoalStates(List unicastGoalStates) t final CountDownLatch exceptionLatch = new CountDownLatch(1); List results = new ArrayList<>(); for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { - System.out.println(unicastGoalState.getGoalState()); goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } System.out.println(goalStateBuilder.build()); @@ -389,8 +388,10 @@ private Goalstate.GoalStateV2.Builder getGoalState(Goalstate.GoalStateV2.Builder } if (goalStateBuilder.containsHostResources(unicastGoalStateV2.getHostIp())) { - Goalstate.HostResources.Builder goalStateHostResourceBuilder = goalStateBuilder.getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).toBuilder(); - goalStateHostResourceBuilder.addAllResources(hostResourceBuilder.getResourcesList()); + Goalstate.HostResources.Builder hostResourceBuilder1 = Goalstate.HostResources.newBuilder(); + hostResourceBuilder1.addAllResources(hostResourceBuilder.getResourcesList()); + hostResourceBuilder1.addAllResources(goalStateBuilder.getHostResourcesMap().get(unicastGoalStateV2.getHostIp()).getResourcesList()); + goalStateBuilder.putHostResources(unicastGoalStateV2.getHostIp(), hostResourceBuilder1.build()); } else { goalStateBuilder.putHostResources(unicastGoalStateV2.getHostIp(), hostResourceBuilder.build()); } From 72a4b1e9f43e7007e8513cc2106faee50d3ee257 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Sat, 20 Nov 2021 11:08:55 -0800 Subject: [PATCH 31/48] Update code --- .../alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 1 + 1 file changed, 1 insertion(+) 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 8048942c9..da00b6f75 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 @@ -225,6 +225,7 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { finishLatch.countDown(); } } + finishLatch.countDown(); } @Override From 7c4a8b7dad3948244fb79472eb02b129331af257 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Sat, 20 Nov 2021 11:43:33 -0800 Subject: [PATCH 32/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 da00b6f75..f4b1f4b89 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 @@ -225,7 +225,7 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { finishLatch.countDown(); } } - finishLatch.countDown(); + this.onCompleted(); } @Override From a2b2397fc260190fa4f3de30c70c0bce94cb4a49 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 22 Nov 2021 19:13:55 -0800 Subject: [PATCH 33/48] Update code --- kubernetes/services/network_config_manager.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kubernetes/services/network_config_manager.yaml b/kubernetes/services/network_config_manager.yaml index 5703377e4..e0e6a9458 100644 --- a/kubernetes/services/network_config_manager.yaml +++ b/kubernetes/services/network_config_manager.yaml @@ -53,6 +53,8 @@ spec: replicas: 1 template: metadata: + annotations: + linkerd.io/inject: 1 enabled labels: app: netwconfigmanager spec: @@ -69,7 +71,8 @@ spec: imagePullPolicy: IfNotPresent command: ["java", "-jar", "/app/AlcorNetworkConfigManager-0.1.0.jar", "--spring.config.location=/etc/ncm/application.properties"] ports: - - containerPort: 8080 + - containerPort: 50001 + protocol: TCP volumeMounts: - name: ncm-volume mountPath: /etc/ncm @@ -84,10 +87,10 @@ metadata: labels: name: netwconfigmanager-service spec: - type: NodePort + type: ClusterIP ports: - - port: 9014 - targetPort: 8080 - nodePort: 30014 + - port: 50001 + protocol: TCP + targetPort: 50001 selector: app: netwconfigmanager From 76e08f2cc5d97e8b5b9176e5de8eda36d75e7872 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 22 Nov 2021 19:18:40 -0800 Subject: [PATCH 34/48] Update code --- .../alcor/dataplane/client/grpc/DataPlaneClientImplV2.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index de429dea1..54169f64b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -229,7 +229,8 @@ public void onCompleted() { } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { - String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; + String hostIp = "netwconfigmanager-service"; + //String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); From c5c1f0d1572490ed416a9ae47bfcde950d7462be Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 22 Nov 2021 19:43:23 -0800 Subject: [PATCH 35/48] Update code --- kubernetes/services/network_config_manager.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/services/network_config_manager.yaml b/kubernetes/services/network_config_manager.yaml index e0e6a9458..532d5a13a 100644 --- a/kubernetes/services/network_config_manager.yaml +++ b/kubernetes/services/network_config_manager.yaml @@ -54,7 +54,7 @@ spec: template: metadata: annotations: - linkerd.io/inject: 1 enabled + linkerd.io/inject: enabled labels: app: netwconfigmanager spec: From d3c5e0c4d493cc488074458d2e73a2af8670bbd2 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 22 Nov 2021 21:18:33 -0800 Subject: [PATCH 36/48] Update code --- kubernetes/services/dpm_manager.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kubernetes/services/dpm_manager.yaml b/kubernetes/services/dpm_manager.yaml index c647a149d..1199fe19d 100644 --- a/kubernetes/services/dpm_manager.yaml +++ b/kubernetes/services/dpm_manager.yaml @@ -71,6 +71,8 @@ spec: replicas: 5 template: metadata: + annotations: + linkerd.io/inject: enabled labels: app: dataplanemanager spec: From 55885e1ff17cf7ef2f708da4b33d54aeee4fc4c3 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 11:38:58 -0800 Subject: [PATCH 37/48] Update code --- kubernetes/services/dpm_manager.yaml | 1 + .../client/grpc/DataPlaneClientImplV2.java | 30 +++++++++++-------- .../alcor/dataplane/config/Config.java | 3 ++ .../src/main/resources/application.properties | 1 + .../client/gRPC/GoalStateClientImpl.java | 1 - 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/kubernetes/services/dpm_manager.yaml b/kubernetes/services/dpm_manager.yaml index 1199fe19d..76b58bc11 100644 --- a/kubernetes/services/dpm_manager.yaml +++ b/kubernetes/services/dpm_manager.yaml @@ -43,6 +43,7 @@ data: zetaGateway.enabled=false zetaGateway.node.mac=e0:97:96:02:45:53 microservices.node.service.url=http://nodemanager-service.default.svc.cluster.local:9007/nodes + microservices.netwconfigmanager.service.url=netwconfigmanager-service microservices.zeta.management.url=http://10.213.43.90 microservices.gateway.service.url=http://gatewaymanager-service.default.svc.cluster.local:9015 zetaGateway.check.timeout = 30 diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index 54169f64b..f61b7706b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -55,6 +55,8 @@ public class DataPlaneClientImplV2 implements DataPlaneClient monitorHosts; @@ -64,22 +66,17 @@ public class DataPlaneClientImplV2 implements DataPlaneClient sendGoalStates(List unicastGoalStates) throws Exception { Goalstate.GoalStateV2.Builder goalStateBuilder = Goalstate.GoalStateV2.newBuilder(); final CountDownLatch finishLatch = new CountDownLatch(1); - final CountDownLatch exceptionLatch = new CountDownLatch(1); List results = new ArrayList<>(); for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } - System.out.println(goalStateBuilder.build()); - doSendGoalState(goalStateBuilder.build(), finishLatch, exceptionLatch); + doSendGoalState(goalStateBuilder.build(), finishLatch, results); - if (!finishLatch.await(1, TimeUnit.MINUTES) && !exceptionLatch.await(1, TimeUnit.MINUTES)) { - if (exceptionLatch.getCount() == 0) { - return Arrays.asList("Goal states not correct"); - } + if (!finishLatch.await(1, TimeUnit.MINUTES)) { LOG.warn("Send goal states can not finish within 1 minutes"); return Arrays.asList("Send goal states can not finish within 1 minutes"); } - return new ArrayList<>(); + return results; } public static DataPlaneClientImplV2 getInstance(Config globalConfig, ArrayList monitorHosts) { @@ -100,6 +97,10 @@ public DataPlaneClientImplV2(Config globalConfig, ArrayList monitorHosts numberOfWarmupsPerChannel = 0; } + if (netwconfigmanagerHost == null || netwconfigmanagerHost.isEmpty()) { + netwconfigmanagerHost = globalConfig.netwconfigmanagerHost; + } + this.monitorHosts = monitorHosts; LOG.info("Printing out all monitorHosts"); for(String host : this.monitorHosts){ @@ -181,7 +182,8 @@ private ArrayList createGrpcChannelStubArrayList(String hostIp) ArrayList arr = new ArrayList<>(); for (int i = 0; i < numberOfGrpcChannelPerHost; i++) { GrpcChannelStub channelStub = createGrpcChannelStub(hostIp); - warmUpChannelStub(channelStub, hostIp); + // Using Linkerd load balance + //warmUpChannelStub(channelStub, hostIp); arr.add(channelStub); } long end = System.currentTimeMillis(); @@ -228,9 +230,8 @@ public void onCompleted() { return; } - private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, CountDownLatch exceptionLatch) { - String hostIp = "netwconfigmanager-service"; - //String hostIp = "netwconfigmanager-service.default.svc.cluster.local"; + private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, List replies) { + String hostIp = netwconfigmanagerHost; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); @@ -246,12 +247,15 @@ private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { LOG.info("Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); + replies.add(reply.toString()); + while (finishLatch.getCount() > 0) { + finishLatch.countDown(); + } } @Override public void onError(Throwable t) { LOG.warn("Receive error from ACA@" + hostIp + " | " + t.getMessage()); - exceptionLatch.countDown(); } @Override diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java index 703f4ad77..2e26d31c1 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java @@ -58,6 +58,9 @@ public class Config { @Value("${grpc.monitor-hosts}") public ArrayList monitorHosts; + @Value("${microservices.netwconfigmanager.service.url}") + public String netwconfigmanagerHost; + public static FileWriter TIME_STAMP_FILE; public static BufferedWriter TIME_STAMP_WRITER; public static String LOG_FILE_PATH = "timestamp.log"; diff --git a/services/data_plane_manager/src/main/resources/application.properties b/services/data_plane_manager/src/main/resources/application.properties index fedc40bd6..8584243dc 100644 --- a/services/data_plane_manager/src/main/resources/application.properties +++ b/services/data_plane_manager/src/main/resources/application.properties @@ -42,6 +42,7 @@ group.topic.to.multicast.topic.map=multicast-topic1:group-topic1,group-topic3 mu #####Microservice url configuration###### microservices.zeta.management.url=http://10.213.43.90 microservices.gateway.service.url=http://localhost:9015 +microservices.netwconfigmanager.service.url=netwconfigmanager-service #####ZetaGateway##### zetaGateway.node.mac=e0:97:96:02:45:53 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 f4b1f4b89..8048942c9 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 @@ -225,7 +225,6 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { finishLatch.countDown(); } } - this.onCompleted(); } @Override From a8a7673d1323b68d3a98d4d31b36e3201d95b29b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 12:09:24 -0800 Subject: [PATCH 38/48] Update code --- .../dataplane/client/grpc/DataPlaneClientImplV2.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index f61b7706b..ca1878804 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -36,6 +36,7 @@ import java.util.*; import java.util.concurrent.*; import java.util.logging.Level; +import java.util.stream.Collectors; @Service("grpcDataPlaneClient") @ConditionalOnProperty(prefix = "protobuf.goal-state-message", name = "version", havingValue = "102") @@ -247,9 +248,11 @@ private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { LOG.info("Receive response from ACA@" + hostIp + " | " + reply.toString()); result.put(hostIp, reply.getOperationStatusesList()); - replies.add(reply.toString()); - while (finishLatch.getCount() > 0) { - finishLatch.countDown(); + if (reply.getOperationStatusesList().stream().filter(item -> item.getOperationStatus().equals(Common.OperationStatus.FAILURE)).collect(Collectors.toList()).size() > 0) { + replies.add(reply.toString()); + while (finishLatch.getCount() > 0) { + finishLatch.countDown(); + } } } From 736bf1f4a89249e2d5d5401ecbc96ebfdde1f2cf Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 12:30:21 -0800 Subject: [PATCH 39/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8048942c9..1e1643234 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 @@ -224,6 +224,8 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { while (finishLatch.getCount() > 0) { finishLatch.countDown(); } + } else { + finishLatch.countDown(); } } @@ -235,7 +237,6 @@ public void onError(Throwable t) { @Override public void onCompleted() { logger.log(Level.INFO, "Complete receiving message from ACA@" + hostIp); - finishLatch.countDown(); } }; From b80033da300ccfff5c2d200150e3a71ed8820b81 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 12:33:02 -0800 Subject: [PATCH 40/48] Update code --- .../alcor/netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 1 + 1 file changed, 1 insertion(+) 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 1e1643234..d4cbcdbba 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 @@ -237,6 +237,7 @@ public void onError(Throwable t) { @Override public void onCompleted() { logger.log(Level.INFO, "Complete receiving message from ACA@" + hostIp); + finishLatch.countDown(); } }; From 7103bb399f5fb3c537a76207bd8dafa740824dad Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 13:26:23 -0800 Subject: [PATCH 41/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 2 -- 1 file changed, 2 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 d4cbcdbba..8048942c9 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 @@ -224,8 +224,6 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { while (finishLatch.getCount() > 0) { finishLatch.countDown(); } - } else { - finishLatch.countDown(); } } From a4462fe27b370f2849e4a4dfc856c70ae0364dbd Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 14:05:07 -0800 Subject: [PATCH 42/48] Update code --- .../NetworkConfigManagerApplication.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java index d768e1c4d..c135863ef 100644 --- a/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java +++ b/services/network_config_manager/src/main/java/com/futurewei/alcor/netwconfigmanager/NetworkConfigManagerApplication.java @@ -37,15 +37,14 @@ public class NetworkConfigManagerApplication { @PostConstruct public void instantiateGrpcServer(){ - Thread server = new Thread(() -> { - try { - networkConfigServer.start(); - networkConfigServer.blockUntilShutdown(); - } catch (Exception e) { - e.printStackTrace(); - } - }); - server.start(); + + try { + networkConfigServer.start(); + networkConfigServer.blockUntilShutdown(); + } catch (Exception e) { + e.printStackTrace(); + } + } public static void main(String[] args) { From 94417f0fb7ee6be761b2f9583143778c8faea67c Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 14:52:14 -0800 Subject: [PATCH 43/48] Update code --- .../server/grpc/GoalStateProvisionerServer.java | 1 + 1 file changed, 1 insertion(+) 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 9465e86df..66eb7da11 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 @@ -166,6 +166,7 @@ public void onNext(Goalstate.GoalStateV2 value) { GoalStateClient grpcGoalStateClient = GoalStateClientImpl.getInstance(numberOfGrpcChannelPerHost, numberOfWarmupsPerChannel, monitorHosts); + //TODO use filteredGoalStates grpcGoalStateClient.sendGoalStates(hostGoalStates); } catch (Exception e) { e.printStackTrace(); From 0f5949f85b036599a1478660529aafea7b348466 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 15:00:32 -0800 Subject: [PATCH 44/48] Update code --- .../server/grpc/GoalStateProvisionerServer.java | 2 +- .../service/impl/GoalStatePersistenceServiceImpl.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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 66eb7da11..b7d4a63af 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 @@ -166,7 +166,7 @@ public void onNext(Goalstate.GoalStateV2 value) { GoalStateClient grpcGoalStateClient = GoalStateClientImpl.getInstance(numberOfGrpcChannelPerHost, numberOfWarmupsPerChannel, monitorHosts); - //TODO use filteredGoalStates + //TODO use filteredGoalStates 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 c5c317673..958119e5c 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 @@ -59,6 +59,7 @@ public Map updateGoalStates(Goalstate.GoalStateV2 goalSta //prepare GS message based on host Map hostGoalStates = NetworkConfigManagerUtil.splitClusterToHostGoalState(goalStateV2); + //aggregate goal state SortedMap goalStates = new TreeMap<>(); goalStates.putAll(goalStateV2.getSubnetStatesMap()); goalStates.putAll(goalStateV2.getHostResourcesMap()); From a0d40af12eb4b7e96ae2657b1fc938a10e0b9a8b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 16:38:57 -0800 Subject: [PATCH 45/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 4 ++++ 1 file changed, 4 insertions(+) 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 8048942c9..9859c8d15 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 @@ -158,11 +158,13 @@ void warmUpChannelStub(GrpcChannelStub channelStub, String hostIp) { @Override public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { logger.log(Level.INFO, "Receive warmup response from ACA@" + hostIp + " | " + reply.toString()); + } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "Receive warmup error from ACA@" + hostIp + " | " + t.getMessage()); + } @Override @@ -224,6 +226,8 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { while (finishLatch.getCount() > 0) { finishLatch.countDown(); } + } else { + finishLatch.countDown(); } } From 3f0887207f37b9317690fe1cf4278c23718929ec Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 23 Nov 2021 17:30:25 -0800 Subject: [PATCH 46/48] Update code --- .../netwconfigmanager/client/gRPC/GoalStateClientImpl.java | 2 -- 1 file changed, 2 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 9859c8d15..02e8de496 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 @@ -226,8 +226,6 @@ public void onNext(Goalstateprovisioner.GoalStateOperationReply reply) { while (finishLatch.getCount() > 0) { finishLatch.countDown(); } - } else { - finishLatch.countDown(); } } From 140456b3aceb961faf3de7960a1b2e03969a0fd8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 24 Nov 2021 12:17:13 -0800 Subject: [PATCH 47/48] Update code --- .../src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/resources/application.properties b/services/data_plane_manager/src/main/resources/application.properties index 8584243dc..546d81260 100644 --- a/services/data_plane_manager/src/main/resources/application.properties +++ b/services/data_plane_manager/src/main/resources/application.properties @@ -42,7 +42,7 @@ group.topic.to.multicast.topic.map=multicast-topic1:group-topic1,group-topic3 mu #####Microservice url configuration###### microservices.zeta.management.url=http://10.213.43.90 microservices.gateway.service.url=http://localhost:9015 -microservices.netwconfigmanager.service.url=netwconfigmanager-service +microservices.netwconfigmanager.service.url=localhost #####ZetaGateway##### zetaGateway.node.mac=e0:97:96:02:45:53 From 722e1974a18bb42d917c6d9612c81b39b49004c0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 24 Nov 2021 15:59:34 -0800 Subject: [PATCH 48/48] Update code --- schema/proto3/common.proto | 2 +- .../dataplane/client/grpc/DataPlaneClientImplV2.java | 8 ++++---- .../java/com/futurewei/alcor/dataplane/config/Config.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/schema/proto3/common.proto b/schema/proto3/common.proto index 6ce48b96c..765fa781e 100644 --- a/schema/proto3/common.proto +++ b/schema/proto3/common.proto @@ -26,7 +26,7 @@ enum ResourceType { SUBNET = 1; PORT = 2; NEIGHBOR = 3; - SECURITYGROUP =4; + SECURITYGROUP = 4; DHCP = 5; ROUTER = 6; GATEWAY = 7; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java index ca1878804..70eede9a3 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImplV2.java @@ -56,7 +56,7 @@ public class DataPlaneClientImplV2 implements DataPlaneClient monitorHosts; @@ -98,8 +98,8 @@ public DataPlaneClientImplV2(Config globalConfig, ArrayList monitorHosts numberOfWarmupsPerChannel = 0; } - if (netwconfigmanagerHost == null || netwconfigmanagerHost.isEmpty()) { - netwconfigmanagerHost = globalConfig.netwconfigmanagerHost; + if (netwconfigmanagerGrpcServiceUrl == null || netwconfigmanagerGrpcServiceUrl.isEmpty()) { + netwconfigmanagerGrpcServiceUrl = globalConfig.netwconfigmanagerGrpcServiceUrl; } this.monitorHosts = monitorHosts; @@ -232,7 +232,7 @@ public void onCompleted() { } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, List replies) { - String hostIp = netwconfigmanagerHost; + String hostIp = netwconfigmanagerGrpcServiceUrl; long start = System.currentTimeMillis(); GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); long chan_established = System.currentTimeMillis(); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java index 2e26d31c1..b307338b9 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/config/Config.java @@ -59,7 +59,7 @@ public class Config { public ArrayList monitorHosts; @Value("${microservices.netwconfigmanager.service.url}") - public String netwconfigmanagerHost; + public String netwconfigmanagerGrpcServiceUrl; public static FileWriter TIME_STAMP_FILE; public static BufferedWriter TIME_STAMP_WRITER;