From 04cbb1e6d7368bbaeb351841edf6cc9c5352c68d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Jun 2021 12:06:50 -0700 Subject: [PATCH 01/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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/54] 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 4a62be18a363a2dd2f569d642db4cd025af3a4d4 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 27 May 2022 18:20:48 -0700 Subject: [PATCH 13/54] Add consistent hash --- .../java/com/futurewei/alcor/dataplane/entity/ArionWing.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java new file mode 100644 index 000000000..5316fb984 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java @@ -0,0 +1,2 @@ +package com.futurewei.alcor.dataplane.entity;public class ArionWing { +} From 7be13f86c450ae3ea7335f3df6701293f27db222 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 27 May 2022 18:21:07 -0700 Subject: [PATCH 14/54] Add consistent hash --- schema/proto3/gateway.proto | 10 +++ schema/proto3/goalstateprovisioner.proto | 19 +++++ services/data_plane_manager/pom.xml | 6 +- .../alcor/dataplane/entity/ArionWing.java | 73 ++++++++++++++++++- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/schema/proto3/gateway.proto b/schema/proto3/gateway.proto index 327d38e0b..e3c574a2e 100644 --- a/schema/proto3/gateway.proto +++ b/schema/proto3/gateway.proto @@ -29,6 +29,7 @@ enum GatewayType { TGW = 2; // Transit Gateway IGW = 3; // Internet Gateway NGW = 4; // NAT Gateway + ARION=5; } message GatewayConfiguration { @@ -50,8 +51,17 @@ message GatewayConfiguration { uint32 port_inband_operation = 1; } + message arion { + string vpc_id = 1; + uint32 vni = 2; + string subnet_id = 3; + // port for in-band (same NIC channel) operation + uint32 port_inband_operation = 4; + } + oneof extra_info { zeta zeta_info = 6; + arion arion_info = 7; } } diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index b2d27f0f4..5596d8fd8 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -36,6 +36,9 @@ service GoalStateProvisioner { rpc PushNetworkResourceStates (GoalState) returns (GoalStateOperationReply) { } + rpc PushGoalstates (RoutingRulesRequest) returns (GoalStateOperationReply) { + } + // similar to PushGoalStatesStream with streaming GoalStateV2 and streaming GoalStateOperationReply // this is for DPM->NCM, and NCM->ACA rpc PushGoalStatesStream (stream GoalStateV2) returns (stream GoalStateOperationReply) { @@ -51,6 +54,22 @@ service GoalStateProvisioner { } +message RoutingRulesRequest { + uint32 format_version = 1; + string request_id = 2; + + message RoutingRule { + OperationType operation_type = 1; + string ip = 2; + string hostip = 3; + string mac = 4; + uint32 tunnel_id = 5; + string hostmac = 6; + } + + repeated RoutingRule routingRules = 3; +} + message HostRequest { uint32 format_version = 1; diff --git a/services/data_plane_manager/pom.xml b/services/data_plane_manager/pom.xml index f55eb600a..eeb83948c 100644 --- a/services/data_plane_manager/pom.xml +++ b/services/data_plane_manager/pom.xml @@ -86,7 +86,11 @@ Copyright(c) 2020 Futurewei Cloud junit-jupiter test - + + com.github.ishugaliy + allgood-consistent-hash + 1.0.0 + org.springframework.boot spring-boot-starter-test diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java index 5316fb984..3ddb3d065 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java @@ -1,2 +1,73 @@ -package com.futurewei.alcor.dataplane.entity;public class ArionWing { +package com.futurewei.alcor.dataplane.entity; + +import org.ishugaliy.allgood.consistent.hash.annotation.Generated; +import org.ishugaliy.allgood.consistent.hash.node.Node; + +import java.util.Objects; +import java.util.StringJoiner; + +public class ArionWing implements Node { + private final String dc; + private final String ip; + private final String mac; + private final int port; + + public ArionWing(String ip, String mac, int port) { + this("", ip, mac, port); + } + + public ArionWing(String dc, String ip, String mac, int port) { + this.dc = dc != null ? dc : ""; + this.mac = mac; + this.ip = ip != null ? ip : ""; + this.port = port; + } + + public String getDc() { + return dc; + } + + public String getIp() { + return ip; + } + + public String getMac() {return mac; } + + public int getPort() { + return port; + } + + @Override + public String getKey() { + return String.format("%s:%s:%s", dc, ip, port); + } + + @Override + @Generated + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ArionWing)) return false; + ArionWing that = (ArionWing) o; + return port == that.port && + Objects.equals(dc, that.dc) && + Objects.equals(ip, that.ip) && + Objects.equals(mac, that.mac); + } + + @Override + @Generated + public int hashCode() { + return Objects.hash(dc, ip, mac, port); + } + + @Override + @Generated + public String toString() { + return new StringJoiner(", ", ArionWing.class.getSimpleName() + "[", "]") + .add("dc='" + dc + "'") + .add("ip='" + ip + "'") + .add("ip='" + mac + "'") + .add("port=" + port) + .toString(); + } } From 6b798e0da71990691da12782decacf5d903b930a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 31 May 2022 10:28:06 -0700 Subject: [PATCH 15/54] Update code --- schema/pom.xml | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/schema/pom.xml b/schema/pom.xml index 69932c164..72798716c 100644 --- a/schema/pom.xml +++ b/schema/pom.xml @@ -28,6 +28,11 @@ javax.annotation-api 1.3.2 + + net.devh + grpc-spring-boot-starter + 2.13.1.RELEASE + com.google.protobuf protobuf-java @@ -38,33 +43,11 @@ grpc-netty-shaded 1.23.0 - - io.grpc - grpc-protobuf - 1.23.0 - - - io.grpc - grpc-stub - 1.23.0 - - - io.grpc - protoc-gen-grpc-java - 1.23.0 - pom - com.googlecode.json-simple json-simple 1.1.1 - - io.grpc - grpc-testing - 1.23.0 - test - From fabd939ae78c3e409fbd60190ffc9abfe35c8561 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 31 May 2022 10:58:45 -0700 Subject: [PATCH 16/54] Revert "Update code" This reverts commit 6b798e0da71990691da12782decacf5d903b930a. --- schema/pom.xml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/schema/pom.xml b/schema/pom.xml index 72798716c..69932c164 100644 --- a/schema/pom.xml +++ b/schema/pom.xml @@ -28,11 +28,6 @@ javax.annotation-api 1.3.2 - - net.devh - grpc-spring-boot-starter - 2.13.1.RELEASE - com.google.protobuf protobuf-java @@ -43,11 +38,33 @@ grpc-netty-shaded 1.23.0 + + io.grpc + grpc-protobuf + 1.23.0 + + + io.grpc + grpc-stub + 1.23.0 + + + io.grpc + protoc-gen-grpc-java + 1.23.0 + pom + com.googlecode.json-simple json-simple 1.1.1 + + io.grpc + grpc-testing + 1.23.0 + test + From ac01902357a555425d55366e8557da87c2e9e998 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 31 May 2022 11:17:27 -0700 Subject: [PATCH 17/54] Update code --- lib/pom.xml | 22 +++------------------- schema/pom.xml | 32 +++++--------------------------- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/lib/pom.xml b/lib/pom.xml index fe404374a..166823f0f 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -79,25 +79,9 @@ Copyright(c) 2020 Futurewei Cloud 3.16.1 - io.grpc - grpc-netty-shaded - 1.23.0 - - - io.grpc - grpc-protobuf - 1.23.0 - - - io.grpc - grpc-stub - 1.23.0 - - - io.grpc - protoc-gen-grpc-java - 1.23.0 - pom + net.devh + grpc-spring-boot-starter + 2.13.1.RELEASE diff --git a/schema/pom.xml b/schema/pom.xml index 69932c164..d0e9d8f93 100644 --- a/schema/pom.xml +++ b/schema/pom.xml @@ -28,43 +28,21 @@ javax.annotation-api 1.3.2 + + net.devh + grpc-spring-boot-starter + 2.13.1.RELEASE + com.google.protobuf protobuf-java 3.16.1 - - io.grpc - grpc-netty-shaded - 1.23.0 - - - io.grpc - grpc-protobuf - 1.23.0 - - - io.grpc - grpc-stub - 1.23.0 - - - io.grpc - protoc-gen-grpc-java - 1.23.0 - pom - com.googlecode.json-simple json-simple 1.1.1 - - io.grpc - grpc-testing - 1.23.0 - test - From 053d5ab4bdabee5f2f7d287b31b42c19d57b9388 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 31 May 2022 14:02:07 -0700 Subject: [PATCH 18/54] Revert "Update code" This reverts commit ac01902357a555425d55366e8557da87c2e9e998. --- lib/pom.xml | 22 +++++++++++++++++++--- schema/pom.xml | 32 +++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/pom.xml b/lib/pom.xml index 166823f0f..fe404374a 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -79,9 +79,25 @@ Copyright(c) 2020 Futurewei Cloud 3.16.1 - net.devh - grpc-spring-boot-starter - 2.13.1.RELEASE + io.grpc + grpc-netty-shaded + 1.23.0 + + + io.grpc + grpc-protobuf + 1.23.0 + + + io.grpc + grpc-stub + 1.23.0 + + + io.grpc + protoc-gen-grpc-java + 1.23.0 + pom diff --git a/schema/pom.xml b/schema/pom.xml index d0e9d8f93..69932c164 100644 --- a/schema/pom.xml +++ b/schema/pom.xml @@ -28,21 +28,43 @@ javax.annotation-api 1.3.2 - - net.devh - grpc-spring-boot-starter - 2.13.1.RELEASE - com.google.protobuf protobuf-java 3.16.1 + + io.grpc + grpc-netty-shaded + 1.23.0 + + + io.grpc + grpc-protobuf + 1.23.0 + + + io.grpc + grpc-stub + 1.23.0 + + + io.grpc + protoc-gen-grpc-java + 1.23.0 + pom + com.googlecode.json-simple json-simple 1.1.1 + + io.grpc + grpc-testing + 1.23.0 + test + From ebbeefaffb1d0f610fab9b16336ff81396eb8979 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 31 May 2022 15:02:23 -0700 Subject: [PATCH 19/54] Update code --- lib/pom.xml | 8 ++++---- schema/pom.xml | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/pom.xml b/lib/pom.xml index fe404374a..206b6ce59 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -81,22 +81,22 @@ Copyright(c) 2020 Futurewei Cloud io.grpc grpc-netty-shaded - 1.23.0 + 1.42.2 io.grpc grpc-protobuf - 1.23.0 + 1.42.2 io.grpc grpc-stub - 1.23.0 + 1.42.2 io.grpc protoc-gen-grpc-java - 1.23.0 + 1.42.2 pom diff --git a/schema/pom.xml b/schema/pom.xml index 69932c164..698197372 100644 --- a/schema/pom.xml +++ b/schema/pom.xml @@ -36,22 +36,22 @@ io.grpc grpc-netty-shaded - 1.23.0 + 1.42.2 io.grpc grpc-protobuf - 1.23.0 + 1.42.2 io.grpc grpc-stub - 1.23.0 + 1.42.2 io.grpc protoc-gen-grpc-java - 1.23.0 + 1.42.2 pom @@ -62,7 +62,7 @@ io.grpc grpc-testing - 1.23.0 + 1.42.2 test From c1beae45f04cd534786fef699e7dfab6d5c21568 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Jun 2022 09:24:03 -0700 Subject: [PATCH 20/54] Update code --- schema/proto3/goalstateprovisioner.proto | 15 ++- schema/proto3/neighbor.proto | 1 + .../alcor/dataplane/cache/ArionWingCache.java | 83 +++++++++++++ .../client/grpc/DataPlaneClientImplV2.java | 32 ++++- .../controller/ArionGatewayController.java | 72 +++++++++++ .../alcor/dataplane/entity/ArionWing.java | 40 +++--- .../service/impl/ArionWingService.java | 116 ++++++++++++++++++ .../service/impl/DpmServiceImplV2.java | 10 ++ .../service/impl/NeighborService.java | 6 +- .../src/main/resources/application.properties | 4 + .../web/entity/gateway/ArionWingInfo.java | 34 +++++ 11 files changed, 383 insertions(+), 30 deletions(-) create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java create mode 100644 web/src/main/java/com/futurewei/alcor/web/entity/gateway/ArionWingInfo.java diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 5596d8fd8..1ffe7566c 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -22,6 +22,7 @@ option java_package = "com.futurewei.alcor.schema"; import "common.proto"; import "goalstate.proto"; +import "neighbor.proto"; service GoalStateProvisioner { @@ -36,7 +37,7 @@ service GoalStateProvisioner { rpc PushNetworkResourceStates (GoalState) returns (GoalStateOperationReply) { } - rpc PushGoalstates (RoutingRulesRequest) returns (GoalStateOperationReply) { + rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { } // similar to PushGoalStatesStream with streaming GoalStateV2 and streaming GoalStateOperationReply @@ -54,20 +55,28 @@ service GoalStateProvisioner { } +message NeighborRulesRequest { + uint32 format_version = 1; + string request_id = 2; + + repeated NeighborState neigborstates = 3; +} + message RoutingRulesRequest { uint32 format_version = 1; string request_id = 2; - message RoutingRule { + message NeighborRule { OperationType operation_type = 1; string ip = 2; string hostip = 3; string mac = 4; uint32 tunnel_id = 5; string hostmac = 6; + string arionwing_group = 7; } - repeated RoutingRule routingRules = 3; + repeated NeighborRule neighborRules = 3; } message HostRequest { diff --git a/schema/proto3/neighbor.proto b/schema/proto3/neighbor.proto index f72d8cf33..f10e6fb05 100644 --- a/schema/proto3/neighbor.proto +++ b/schema/proto3/neighbor.proto @@ -43,6 +43,7 @@ message NeighborConfiguration { NeighborType neighbor_type = 1; string subnet_id = 2; string ip_address = 3; + string arion_group = 4; } message AllowAddressPair { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java new file mode 100644 index 000000000..8853f3c22 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java @@ -0,0 +1,83 @@ +package com.futurewei.alcor.dataplane.cache; + +import com.futurewei.alcor.common.db.CacheException; +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.dataplane.entity.ArionWing; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + + +@Repository +@ComponentScan(value="com.futurewei.alcor.common.db") +public class ArionWingCache { + + private ICache arionWingCache; + private ICache arionWingGroupCache; + private CacheFactory cacheFactory; + + @Autowired + public ArionWingCache(CacheFactory cacheFactory) { + this.cacheFactory = cacheFactory; + arionWingCache = cacheFactory.getCache(ArionWing.class); + arionWingGroupCache = cacheFactory.getCache(Object.class); + } + + @DurationStatistics + public ArionWing getArionWing (String resourceId) throws CacheException { + return arionWingCache.get(resourceId); + } + + @DurationStatistics + public Collection getArionWings () throws CacheException { + return arionWingCache.getAll().values(); + } + + @DurationStatistics + public Map getAllSubnetPorts(Map queryParams) throws CacheException { + return arionWingCache.getAll(queryParams); + } + + @DurationStatistics + public Collection getArionWings (Set keys) throws CacheException { + return arionWingCache.getAll(keys).values(); + } + + @DurationStatistics + public void insertArionWing (ArionWing arionWing) throws CacheException { + arionWingCache.put(String.valueOf(arionWing.hashCode()), arionWing); + } + + @DurationStatistics + public void deleteArionWing (String resourceId) throws CacheException { + arionWingCache.remove(resourceId); + } + + @DurationStatistics + public Object getArionGroup (String resourceId) throws CacheException { + return arionWingGroupCache.get(resourceId); + } + + @DurationStatistics + public void insertArionGroup (String resourceId) throws CacheException { + System.out.println("Insert arion group: " + resourceId); + arionWingGroupCache.put(resourceId, resourceId); + } + + @DurationStatistics + public void deleteArionGroup (String resourceId) throws CacheException { + arionWingGroupCache.remove(resourceId); + } + + @DurationStatistics + public Map getAllArionGroup () throws CacheException { + return arionWingGroupCache.getAll(); + } + +} 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 c51796262..677684f5f 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 @@ -59,6 +59,15 @@ public class DataPlaneClientImplV2 implements DataPlaneClient monitorHosts; + @Value("${arionGateway.enabled:false}") + private boolean arionGatwayEnabled; + + @Value("${arionGateway.server:127.0.0.1}") + private String arionMasterServer; + + @Value("${arionGateway.port:9090}") + private int arionMasterPort; + @Value("${microservices.connectTimeout:300}") private String connectTimeout; @@ -73,6 +82,9 @@ public List sendGoalStates(List unicastGoalStates) t goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } doSendGoalState(goalStateBuilder.build(), finishLatch, results); + if (arionGatwayEnabled) { + doSendGoalStateToArionMaster(goalStateBuilder); + } if (!finishLatch.await(Integer.parseInt(connectTimeout), TimeUnit.SECONDS)) { LOG.warn("Send goal states can not finish within %s seconds", connectTimeout); @@ -149,8 +161,8 @@ public List sendGoalStates(List unicastGoalStates, M return null; } - private GrpcChannelStub createGrpcChannelStub(String hostIp) { - ManagedChannel channel = ManagedChannelBuilder.forAddress(hostIp, this.hostAgentPort) + private GrpcChannelStub createGrpcChannelStub(String hostIp, int port) { + ManagedChannel channel = ManagedChannelBuilder.forAddress(hostIp, port) .usePlaintext() .keepAliveWithoutCalls(true) .keepAliveTime(Long.MAX_VALUE, TimeUnit.SECONDS) @@ -160,7 +172,7 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp) { return new GrpcChannelStub(channel, asyncStub); } - private GrpcChannelStub getOrCreateGrpcChannel(String hostIp) { + private GrpcChannelStub getOrCreateGrpcChannel(String hostIp, Integer... port) { if (!this.hostIpGrpcChannelStubMap.containsKey(hostIp)) { this.hostIpGrpcChannelStubMap.put(hostIp, createGrpcChannelStubArrayList(hostIp)); LOG.info("[getOrCreateGrpcChannel] Created a channel and stub to host IP: " + hostIp); @@ -171,7 +183,7 @@ private GrpcChannelStub getOrCreateGrpcChannel(String hostIp) { ConnectivityState channelState = chan.getState(true); if (channelState != ConnectivityState.READY && channelState != ConnectivityState.CONNECTING && channelState != ConnectivityState.IDLE) { - GrpcChannelStub newChannelStub = createGrpcChannelStub(hostIp); + GrpcChannelStub newChannelStub = port == null ? createGrpcChannelStub(hostIp, this.hostAgentPort) : createGrpcChannelStub(hostIp, arionMasterPort); this.hostIpGrpcChannelStubMap.get(hostIp).set(usingChannelWithThisIndex, newChannelStub); LOG.info("[getOrCreateGrpcChannel] Replaced a channel and stub to host IP: " + hostIp); } @@ -179,11 +191,11 @@ private GrpcChannelStub getOrCreateGrpcChannel(String hostIp) { return this.hostIpGrpcChannelStubMap.get(hostIp).get(usingChannelWithThisIndex); } - private ArrayList createGrpcChannelStubArrayList(String hostIp) { + private ArrayList createGrpcChannelStubArrayList(String hostIp, String... port) { long start = System.currentTimeMillis(); ArrayList arr = new ArrayList<>(); for (int i = 0; i < numberOfGrpcChannelPerHost; i++) { - GrpcChannelStub channelStub = createGrpcChannelStub(hostIp); + GrpcChannelStub channelStub = port == null ? createGrpcChannelStub(hostIp, this.hostAgentPort) : createGrpcChannelStub(hostIp, arionMasterPort); // Using Linkerd load balance //warmUpChannelStub(channelStub, hostIp); arr.add(channelStub); @@ -232,6 +244,14 @@ public void onCompleted() { return; } + private String doSendGoalStateToArionMaster (Goalstate.GoalStateV2.Builder goalStateV2) { + GrpcChannelStub channelStub = getOrCreateGrpcChannel(arionMasterServer, arionMasterPort); + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; + var neighborStateRequestBuilder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); + neighborStateRequestBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); + return null; + } + private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, List replies) { String hostIp = netwconfigmanagerGrpcServiceUrl; long start = System.currentTimeMillis(); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java new file mode 100644 index 000000000..03d464a34 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java @@ -0,0 +1,72 @@ +/* +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.dataplane.controller; + +import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.ArionWing; +import com.futurewei.alcor.dataplane.service.impl.ArionWingService; +import com.futurewei.alcor.web.entity.gateway.ArionWingInfo; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@Slf4j +@RestController +@ComponentScan(value = "com.futurewei.alcor.common.stats") +public class ArionGatewayController { + + @Autowired + private ArionWingService arionWingService; + + @PostMapping({"/arionwing"}) + @ResponseStatus(HttpStatus.CREATED) + @DurationStatistics + public ArionWingInfo createGateway(@RequestBody ArionWingInfo arionWingInfo) throws Exception { + arionWingService.createArionWing(new ArionWing(arionWingInfo.getGroup(), arionWingInfo.getIp(), arionWingInfo.getMac(), arionWingInfo.getVni())); + return arionWingInfo; + } + + @PutMapping({"/arionwing/{resource_id}"}) + @DurationStatistics + public ArionWingInfo updateGateway(@PathVariable String resource_id, @RequestBody ArionWingInfo arionWingInfo) throws Exception { + + arionWingService.updateArionWing(new ArionWing(arionWingInfo.getGroup(), arionWingInfo.getIp(), arionWingInfo.getMac(), arionWingInfo.getVni())); + return arionWingInfo; + } + + @DeleteMapping({"/arionwing/{resource_id}"}) + @DurationStatistics + public void deleteGateway(@PathVariable String resource_id) throws Exception { + arionWingService.deleteArionWing(resource_id); + } + + + @PostMapping({"/ariongroup/{group_id}"}) + @ResponseStatus(HttpStatus.CREATED) + @DurationStatistics + public String createGatewayGroup(@PathVariable String group_id) throws Exception { + arionWingService.createArionWingGroup(group_id); + return group_id; + } + + @DeleteMapping({"/ariongroup/{group_id}"}) + @DurationStatistics + public void deleteGatewayGroup(@PathVariable String group_id) throws Exception { + arionWingService.deleteArionWingGroup(group_id); + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java index 3ddb3d065..0735eebd0 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java @@ -7,24 +7,24 @@ import java.util.StringJoiner; public class ArionWing implements Node { - private final String dc; - private final String ip; - private final String mac; - private final int port; + private String group; + private String ip; + private String mac; + private int port; + + public ArionWing() { - public ArionWing(String ip, String mac, int port) { - this("", ip, mac, port); } - public ArionWing(String dc, String ip, String mac, int port) { - this.dc = dc != null ? dc : ""; + public ArionWing(String group, String ip, String mac, int port) { + this.group = group != null ? group : ""; this.mac = mac; this.ip = ip != null ? ip : ""; this.port = port; } - public String getDc() { - return dc; + public String getGroup() { + return group; } public String getIp() { @@ -39,7 +39,7 @@ public int getPort() { @Override public String getKey() { - return String.format("%s:%s:%s", dc, ip, port); + return getGroup(); } @Override @@ -48,26 +48,26 @@ public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ArionWing)) return false; ArionWing that = (ArionWing) o; - return port == that.port && - Objects.equals(dc, that.dc) && - Objects.equals(ip, that.ip) && - Objects.equals(mac, that.mac); + return getPort() == that.getPort() && + Objects.equals(getGroup(), that.getGroup()) && + Objects.equals(getIp(), that.getIp()) && + Objects.equals(getMac(), that.getMac()); } @Override @Generated public int hashCode() { - return Objects.hash(dc, ip, mac, port); + return Objects.hash(getGroup(), getIp(), getMac(), getPort()); } @Override @Generated public String toString() { return new StringJoiner(", ", ArionWing.class.getSimpleName() + "[", "]") - .add("dc='" + dc + "'") - .add("ip='" + ip + "'") - .add("ip='" + mac + "'") - .add("port=" + port) + .add("dc='" + getGroup() + "'") + .add("ip='" + getIp() + "'") + .add("ip='" + getMac() + "'") + .add("port=" + getPort()) .toString(); } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java new file mode 100644 index 000000000..8e3b4b6fd --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java @@ -0,0 +1,116 @@ +package com.futurewei.alcor.dataplane.service.impl; + +import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.dataplane.cache.ArionWingCache; +import com.futurewei.alcor.dataplane.entity.ArionWing; +import com.futurewei.alcor.dataplane.entity.UnicastGoalState; +import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.schema.Gateway; +import com.futurewei.alcor.web.entity.dataplane.InternalSubnetEntity; +import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import org.ishugaliy.allgood.consistent.hash.ConsistentHash; +import org.ishugaliy.allgood.consistent.hash.HashRing; +import org.ishugaliy.allgood.consistent.hash.hasher.DefaultHasher; +import org.ishugaliy.allgood.consistent.hash.node.SimpleNode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + + +@Service +public class ArionWingService { + + @Autowired + private ArionWingCache arionWingCache; + + private ConsistentHash ring; + + public ArionWingService () { + ring = HashRing.newBuilder() + .name("file_cache_hash_ring") // set hash ring name + .hasher(DefaultHasher.METRO_HASH) // hash function to distribute partitions + .partitionRate(10) // number of partitions per node + .nodes(Arrays.asList()) // initial nodes set + .build(); + } + + public void buildArionGatewayState (NetworkConfiguration networkConfiguration, UnicastGoalStateV2 unicastGoalStateV2) throws CacheException { + for (InternalSubnetEntity internalSubnetEntity : networkConfiguration.getSubnets()) { + Gateway.GatewayState.Builder gatewayStateBuilder = Gateway.GatewayState.newBuilder(); + int vni = internalSubnetEntity.getTunnelId().intValue(); + String subnet = internalSubnetEntity.getCidr(); + String key = String.valueOf(vni) + "-" + subnet; + getArionWings(); + Optional group = ring.locate(key); + Map queryParams = new HashMap<>(); + Object[] value = new Object[1]; + value[0] = group.get().getKey(); + queryParams.put("group", value); + Collection arionWings = arionWingCache.getAllSubnetPorts(queryParams).values(); + for (ArionWing arionWing : arionWings) { + Gateway.GatewayConfiguration.destination.Builder builder = Gateway.GatewayConfiguration.destination.newBuilder(); + builder.setIpAddress(arionWing.getIp()); + builder.setMacAddress(arionWing.getMac()); + gatewayStateBuilder.getConfigurationBuilder().addDestinations(builder); + } + gatewayStateBuilder.getConfigurationBuilder().getArionInfoBuilder().setVni(vni); + gatewayStateBuilder.getConfigurationBuilder().getArionInfoBuilder().setSubnetId(subnet); + unicastGoalStateV2.getGoalStateBuilder().putGatewayStates(key, gatewayStateBuilder.build()); + } + } + + public String getArionGroup (int vni, String subnet) { + String key = String.valueOf(vni) + "-" + subnet; + Optional group = ring.locate(key); + return group.get().getKey(); + } + + + public void getArionWings () throws CacheException { + Set keys = new HashSet<>(); + if (!ring.getNodes().isEmpty()) { + keys = ring.getNodes().stream().map(item -> item.getKey()).collect(Collectors.toSet()); + } + Set keysInCache = arionWingCache.getAllArionGroup().keySet(); + if (!keys.equals(keysInCache)) { + keys.retainAll(keysInCache); + for (SimpleNode node : ring.getNodes()) { + if (!keys.contains(node.getKey())) { + ring.remove(node); + } + } + + keysInCache.removeAll(keys); + + + for (var key : keysInCache) { + System.out.println(key); + } + for (var key : keysInCache) { + ring.add(SimpleNode.of(key)); + } + } + } + + public void createArionWingGroup (String resourcdId) throws CacheException { + arionWingCache.insertArionGroup(resourcdId); + } + + public void deleteArionWingGroup (String resourcdId) throws CacheException { + arionWingCache.deleteArionGroup(resourcdId); + } + + public void createArionWing(ArionWing arionWing) throws CacheException { + arionWingCache.insertArionWing(arionWing); + } + + public void updateArionWing(ArionWing arionWing) throws CacheException { + arionWingCache.insertArionWing(arionWing); + } + + public void deleteArionWing (String resourceId) throws CacheException { + arionWingCache.deleteArionWing(resourceId); + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index 39cd3c7ca..98a6ca0e6 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -53,6 +53,9 @@ public class DpmServiceImplV2 implements DpmService { @Value("${zetaGateway.enabled:false}") private boolean zetaGatwayEnabled; + @Value("${arionGateway.enabled:false}") + private boolean arionGatwayEnabled; + @Autowired private ZetaGatewayClient zetaGatewayClient; @@ -104,6 +107,9 @@ public class DpmServiceImplV2 implements DpmService { @Autowired private PortHostInfoCache portHostInfoCache; + @Autowired + private ArionWingService arionWingService; + @Autowired private DpmServiceImplV2(Config globalConfig) { this.goalStateMessageVersion = globalConfig.goalStateMessageVersion; @@ -141,6 +147,10 @@ private UnicastGoalStateV2 buildUnicastGoalState(NetworkConfiguration networkCon neighborService.buildNeighborStatesL3(networkConfig, unicastGoalState, multicastGoalState); } + if (arionGatwayEnabled) { + arionWingService.buildArionGatewayState(networkConfig, unicastGoalState); + } + unicastGoalState.setGoalState(unicastGoalState.getGoalStateBuilder().build()); unicastGoalState.setGoalStateBuilder(null); multicastGoalState.setGoalState(multicastGoalState.getGoalStateBuilder().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 c80116a01..3fcf15767 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 @@ -16,7 +16,6 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.dataplane.service.impl; import com.futurewei.alcor.common.db.CacheException; -import com.futurewei.alcor.common.db.CacheFactory; import com.futurewei.alcor.dataplane.cache.NeighborCache; import com.futurewei.alcor.dataplane.cache.PortHostInfoCache; import com.futurewei.alcor.dataplane.cache.SubnetPortsCacheV2; @@ -60,6 +59,9 @@ public class NeighborService extends ResourceService { @Autowired private RouterService routerService; + @Autowired + private ArionWingService arionWingService; + private static String NEIGHBOR_STATE_L2_PREFIX = "L2/"; private static String NEIGHBOR_STATE_L3_PREFIX = "L3/"; @@ -106,6 +108,8 @@ public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type fixedIpBuilder.setSubnetId(portHostInfo.getSubnetId()); fixedIpBuilder.setIpAddress(portHostInfo.getPortIp()); fixedIpBuilder.setNeighborType(neighborType); + var subnetEntity = subnetPortsCache.getSubnetPorts(portHostInfo.getSubnetId()); + fixedIpBuilder.setArionGroup(arionWingService.getArionGroup(subnetEntity.getTunnelId().intValue(), subnetEntity.getCidr())); neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); //TODO:setAllowAddressPairs //neighborConfigBuilder.setAllowAddressPairs(); diff --git a/services/data_plane_manager/src/main/resources/application.properties b/services/data_plane_manager/src/main/resources/application.properties index 5c00a8c19..287df8bb7 100644 --- a/services/data_plane_manager/src/main/resources/application.properties +++ b/services/data_plane_manager/src/main/resources/application.properties @@ -60,6 +60,10 @@ zetaGateway.enabled=false zetaGateway.check.timeout=30 zetaGateway.check.interval=2 +arionGateway.enabled = true +arionMaster.server = 127.0.0.1 +arionMaster.port = 9090 + #####Spring health##### management.health.redis.enabled=false diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/gateway/ArionWingInfo.java b/web/src/main/java/com/futurewei/alcor/web/entity/gateway/ArionWingInfo.java new file mode 100644 index 000000000..f5ef740f8 --- /dev/null +++ b/web/src/main/java/com/futurewei/alcor/web/entity/gateway/ArionWingInfo.java @@ -0,0 +1,34 @@ +/* +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.web.entity.gateway; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class ArionWingInfo { + private String group; + private String ip; + private String mac; + private int vni; + + public ArionWingInfo(String group, String ip, String mac, int vni) { + this.group = group; + this.ip = ip; + this.mac = mac; + this.vni = vni; + } +} From ce0ad7ad43b558ef5c6dabbfca8e97e648e00915 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Jun 2022 09:50:35 -0700 Subject: [PATCH 21/54] Update code --- schema/proto3/neighbor.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/schema/proto3/neighbor.proto b/schema/proto3/neighbor.proto index f10e6fb05..028dbd384 100644 --- a/schema/proto3/neighbor.proto +++ b/schema/proto3/neighbor.proto @@ -53,6 +53,7 @@ message NeighborConfiguration { repeated FixedIp fixed_ips = 9; repeated AllowAddressPair allow_address_pairs = 10; + uint32 tunnel_id = 11; } message NeighborState { From f51898600d7e59bbea1210c73e19868634057c55 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Jun 2022 09:52:02 -0700 Subject: [PATCH 22/54] Update code --- schema/proto3/goalstateprovisioner.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 1ffe7566c..9b0625616 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -64,6 +64,7 @@ message NeighborRulesRequest { message RoutingRulesRequest { uint32 format_version = 1; + string request_id = 2; message NeighborRule { From 3fba144d2ebc853a73bf001c6469766578fbcfbc Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Jun 2022 09:58:00 -0700 Subject: [PATCH 23/54] Update code --- schema/proto3/neighbor.proto | 2 +- .../futurewei/alcor/dataplane/service/impl/NeighborService.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/schema/proto3/neighbor.proto b/schema/proto3/neighbor.proto index 028dbd384..f388c08ed 100644 --- a/schema/proto3/neighbor.proto +++ b/schema/proto3/neighbor.proto @@ -44,6 +44,7 @@ message NeighborConfiguration { string subnet_id = 2; string ip_address = 3; string arion_group = 4; + uint32 tunnel_id = 5; } message AllowAddressPair { @@ -53,7 +54,6 @@ message NeighborConfiguration { repeated FixedIp fixed_ips = 9; repeated AllowAddressPair allow_address_pairs = 10; - uint32 tunnel_id = 11; } message NeighborState { 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 3fcf15767..cb5115656 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 @@ -110,6 +110,7 @@ public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type fixedIpBuilder.setNeighborType(neighborType); var subnetEntity = subnetPortsCache.getSubnetPorts(portHostInfo.getSubnetId()); fixedIpBuilder.setArionGroup(arionWingService.getArionGroup(subnetEntity.getTunnelId().intValue(), subnetEntity.getCidr())); + fixedIpBuilder.setTunnelId(subnetEntity.getTunnelId().intValue()); neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); //TODO:setAllowAddressPairs //neighborConfigBuilder.setAllowAddressPairs(); From aa43fc6b710948471c607d9083db53674441222a Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 8 Jun 2022 10:15:39 -0700 Subject: [PATCH 24/54] Update code --- schema/proto3/neighbor.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/schema/proto3/neighbor.proto b/schema/proto3/neighbor.proto index f388c08ed..d60c6b691 100644 --- a/schema/proto3/neighbor.proto +++ b/schema/proto3/neighbor.proto @@ -45,6 +45,7 @@ message NeighborConfiguration { string ip_address = 3; string arion_group = 4; uint32 tunnel_id = 5; + string mac_address = 6; } message AllowAddressPair { From da6ed64d2e911e56b3b5384c43c1a3a33ac03de5 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 13 Jun 2022 09:33:21 -0700 Subject: [PATCH 25/54] Update code --- .../client/grpc/DataPlaneClientImplV2.java | 39 +++++++++++++------ .../service/impl/ArionWingService.java | 6 --- 2 files changed, 28 insertions(+), 17 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 677684f5f..6cadc998c 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 @@ -81,10 +81,10 @@ public List sendGoalStates(List unicastGoalStates) t for (UnicastGoalStateV2 unicastGoalState : unicastGoalStates) { goalStateBuilder = getGoalState(goalStateBuilder, unicastGoalState); } - doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (arionGatwayEnabled) { doSendGoalStateToArionMaster(goalStateBuilder); } + doSendGoalState(goalStateBuilder.build(), finishLatch, results); if (!finishLatch.await(Integer.parseInt(connectTimeout), TimeUnit.SECONDS)) { LOG.warn("Send goal states can not finish within %s seconds", connectTimeout); @@ -172,30 +172,31 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp, int port) { return new GrpcChannelStub(channel, asyncStub); } - private GrpcChannelStub getOrCreateGrpcChannel(String hostIp, Integer... port) { - if (!this.hostIpGrpcChannelStubMap.containsKey(hostIp)) { - this.hostIpGrpcChannelStubMap.put(hostIp, createGrpcChannelStubArrayList(hostIp)); + private GrpcChannelStub getOrCreateGrpcChannel(String hostIp, Integer port) { + if (!this.hostIpGrpcChannelStubMap.containsKey(hostIp + port)) { + + this.hostIpGrpcChannelStubMap.put(hostIp + port, createGrpcChannelStubArrayList(hostIp, port)); LOG.info("[getOrCreateGrpcChannel] Created a channel and stub to host IP: " + hostIp); } int usingChannelWithThisIndex = ThreadLocalRandom.current().nextInt(0, numberOfGrpcChannelPerHost); - ManagedChannel chan = this.hostIpGrpcChannelStubMap.get(hostIp).get(usingChannelWithThisIndex).channel; + ManagedChannel chan = this.hostIpGrpcChannelStubMap.get(hostIp + port).get(usingChannelWithThisIndex).channel; //checks the channel status, reconnects if the channel is IDLE ConnectivityState channelState = chan.getState(true); if (channelState != ConnectivityState.READY && channelState != ConnectivityState.CONNECTING && channelState != ConnectivityState.IDLE) { - GrpcChannelStub newChannelStub = port == null ? createGrpcChannelStub(hostIp, this.hostAgentPort) : createGrpcChannelStub(hostIp, arionMasterPort); - this.hostIpGrpcChannelStubMap.get(hostIp).set(usingChannelWithThisIndex, newChannelStub); + GrpcChannelStub newChannelStub = createGrpcChannelStub(hostIp, port); + this.hostIpGrpcChannelStubMap.get(hostIp + port).set(usingChannelWithThisIndex, newChannelStub); LOG.info("[getOrCreateGrpcChannel] Replaced a channel and stub to host IP: " + hostIp); } LOG.info("[getOrCreateGrpcChannel] Using channel and stub index " + usingChannelWithThisIndex + " to host IP: " + hostIp); - return this.hostIpGrpcChannelStubMap.get(hostIp).get(usingChannelWithThisIndex); + return this.hostIpGrpcChannelStubMap.get(hostIp + port).get(usingChannelWithThisIndex); } - private ArrayList createGrpcChannelStubArrayList(String hostIp, String... port) { + private ArrayList createGrpcChannelStubArrayList(String hostIp, int port) { long start = System.currentTimeMillis(); ArrayList arr = new ArrayList<>(); for (int i = 0; i < numberOfGrpcChannelPerHost; i++) { - GrpcChannelStub channelStub = port == null ? createGrpcChannelStub(hostIp, this.hostAgentPort) : createGrpcChannelStub(hostIp, arionMasterPort); + GrpcChannelStub channelStub = createGrpcChannelStub(hostIp, port); // Using Linkerd load balance //warmUpChannelStub(channelStub, hostIp); arr.add(channelStub); @@ -249,13 +250,29 @@ private String doSendGoalStateToArionMaster (Goalstate.GoalStateV2.Builder goalS GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; var neighborStateRequestBuilder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); neighborStateRequestBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); + asyncStub.pushGoalstates(neighborStateRequestBuilder.build(), new StreamObserver() { + @Override + public void onNext(Goalstateprovisioner.GoalStateOperationReply goalStateOperationReply) { + LOG.info("Get response: " + goalStateOperationReply.toString()); + } + + @Override + public void onError(Throwable throwable) { + LOG.info(throwable.getMessage()); + } + + @Override + public void onCompleted() { + + } + }); return null; } private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch finishLatch, List replies) { String hostIp = netwconfigmanagerGrpcServiceUrl; long start = System.currentTimeMillis(); - GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp); + GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp, hostAgentPort); long chan_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established channel, elapsed Time in milli seconds: " + (chan_established - start)); GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java index 8e3b4b6fd..b483c70ab 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java @@ -81,13 +81,7 @@ public void getArionWings () throws CacheException { ring.remove(node); } } - keysInCache.removeAll(keys); - - - for (var key : keysInCache) { - System.out.println(key); - } for (var key : keysInCache) { ring.add(SimpleNode.of(key)); } From 5741f07b393077d58fa35ec632cb61104f8fe21f Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 11:13:03 -0700 Subject: [PATCH 26/54] Add arion watch service for arion wing --- schema/proto3/goalstateprovisioner.proto | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 9b0625616..40bbe115d 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -53,6 +53,9 @@ service GoalStateProvisioner { rpc RequestGoalStates (HostRequest) returns (HostRequestReply) { } + + rpc RequestNeighborState (ArionWingRequest) returns (NeighborRulesRequest) { + } } message NeighborRulesRequest { @@ -80,6 +83,11 @@ message RoutingRulesRequest { repeated NeighborRule neighborRules = 3; } +message ArionWingRequest { + string vni = 1; + string ip = 2; +} + message HostRequest { uint32 format_version = 1; From ad57f7b1d064f6e37923bfd02d66993238879bd0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 12:38:19 -0700 Subject: [PATCH 27/54] Update code --- schema/proto3/goalstateprovisioner.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 40bbe115d..a140e5a6e 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -54,7 +54,7 @@ service GoalStateProvisioner { } - rpc RequestNeighborState (ArionWingRequest) returns (NeighborRulesRequest) { + rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborRulesRequest) { } } From bea71bb44aea7d3fa9325aa07be61bebb9ef2722 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 15:20:57 -0700 Subject: [PATCH 28/54] Update code --- schema/proto3/goalstateprovisioner.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index a140e5a6e..a0b988f79 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -52,8 +52,9 @@ service GoalStateProvisioner { // this is for ACA->NCM rpc RequestGoalStates (HostRequest) returns (HostRequestReply) { } +} - +service Watch { rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborRulesRequest) { } } From df7f8e784e3d61bfd98879f4c84da7b04adf4c66 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 15:34:40 -0700 Subject: [PATCH 29/54] Update code --- schema/proto3/goalstateprovisioner.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index a0b988f79..1da8c4c6e 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -55,11 +55,11 @@ service GoalStateProvisioner { } service Watch { - rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborRulesRequest) { + rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborRules) { } } -message NeighborRulesRequest { +message NeighborRules { uint32 format_version = 1; string request_id = 2; From 5936c4b7d8a21dcf6cc9f6c8540da198071f9560 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 15:42:16 -0700 Subject: [PATCH 30/54] Update code --- schema/proto3/goalstateprovisioner.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 1da8c4c6e..7b98c35f6 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -55,11 +55,11 @@ service GoalStateProvisioner { } service Watch { - rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborRules) { + rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborState) { } } -message NeighborRules { +message NeighborRulesRequest { uint32 format_version = 1; string request_id = 2; From 45cb7e20db607f38f0fa13fbccdeb7a49d09e2e0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 15:50:26 -0700 Subject: [PATCH 31/54] Update code --- schema/proto3/goalstateprovisioner.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 7b98c35f6..0d6fad71a 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -55,7 +55,7 @@ service GoalStateProvisioner { } service Watch { - rpc RequestNeighborState (stream ArionWingRequest) returns (stream NeighborState) { + rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { } } From 24896a8ea90469dba59dc2261a10a190a7513c3b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 16:02:37 -0700 Subject: [PATCH 32/54] Update code --- schema/proto3/arionmaster.proto | 33 ++++++++++++++++++++++++ schema/proto3/goalstateprovisioner.proto | 8 ------ 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 schema/proto3/arionmaster.proto diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto new file mode 100644 index 000000000..66494c4e0 --- /dev/null +++ b/schema/proto3/arionmaster.proto @@ -0,0 +1,33 @@ +/* +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. +*/ + +syntax = "proto3"; + +package alcor.schema; + +option java_package = "com.futurewei.alcor.schema"; + +import "neighbor.proto"; + +service Watch { + rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { + } +} + +message ArionWingRequest { + string vni = 1; + string ip = 2; +} \ No newline at end of file diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 0d6fad71a..f56f5d26d 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -54,10 +54,6 @@ service GoalStateProvisioner { } } -service Watch { - rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { - } -} message NeighborRulesRequest { uint32 format_version = 1; @@ -84,10 +80,6 @@ message RoutingRulesRequest { repeated NeighborRule neighborRules = 3; } -message ArionWingRequest { - string vni = 1; - string ip = 2; -} message HostRequest { uint32 format_version = 1; From 243c799f64bfebe71cca8c26d87a0705bb294c54 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 16:19:22 -0700 Subject: [PATCH 33/54] Update code --- schema/proto3/arionmaster.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 66494c4e0..04874566d 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -22,8 +22,8 @@ option java_package = "com.futurewei.alcor.schema"; import "neighbor.proto"; -service Watch { - rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { +service WatchNetworkConfig { + rpc WatchNeighborRule (stream ArionWingRequest) returns (stream NeighborState) { } } From 5ba0d9a467e97bdbd1fbb6845922d1b9c1866b93 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 16 Jun 2022 16:23:54 -0700 Subject: [PATCH 34/54] Update code --- schema/proto3/arionmaster.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 04874566d..66494c4e0 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -22,8 +22,8 @@ option java_package = "com.futurewei.alcor.schema"; import "neighbor.proto"; -service WatchNetworkConfig { - rpc WatchNeighborRule (stream ArionWingRequest) returns (stream NeighborState) { +service Watch { + rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { } } From 79832ef044abcbd83b81d52ada0e4dde96830f7b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 17 Jun 2022 11:18:03 -0700 Subject: [PATCH 35/54] Update code --- schema/proto3/arionmaster.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 66494c4e0..5435d63da 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -30,4 +30,5 @@ service Watch { message ArionWingRequest { string vni = 1; string ip = 2; + string group = 3; } \ No newline at end of file From b067987c0ac9eb98258da80bf940ae79f4c024cd Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 17 Jun 2022 12:05:33 -0700 Subject: [PATCH 36/54] Update code --- schema/proto3/arionmaster.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 5435d63da..c68a014bd 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -30,5 +30,6 @@ service Watch { message ArionWingRequest { string vni = 1; string ip = 2; - string group = 3; + uint64 rev = 3; + string group = 4; } \ No newline at end of file From e4793c5cde2bfd82b9c1dbb1b7713482ae1955e5 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 17 Jun 2022 16:07:35 -0700 Subject: [PATCH 37/54] Update code --- schema/proto3/arionmaster.proto | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index c68a014bd..be3beaaa3 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -20,10 +20,10 @@ package alcor.schema; option java_package = "com.futurewei.alcor.schema"; -import "neighbor.proto"; +import "common.proto"; service Watch { - rpc Watch (stream ArionWingRequest) returns (stream NeighborState) { + rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { } } @@ -32,4 +32,14 @@ message ArionWingRequest { string ip = 2; uint64 rev = 3; string group = 4; +} + +message NeighborRule { + OperationType operation_type = 1; + string ip = 2; + string hostip = 3; + string mac = 4; + uint32 tunnel_id = 5; + string hostmac = 6; + string arionwing_group = 7; } \ No newline at end of file From 7122cc89e97d352d3720fe176b8a2bb94356cdb0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 17 Jun 2022 16:11:39 -0700 Subject: [PATCH 38/54] Update code --- schema/proto3/arionmaster.proto | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index be3beaaa3..0e827cbb6 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -22,11 +22,14 @@ option java_package = "com.futurewei.alcor.schema"; import "common.proto"; + service Watch { rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { } } + + message ArionWingRequest { string vni = 1; string ip = 2; @@ -34,12 +37,16 @@ message ArionWingRequest { string group = 4; } + + message NeighborRule { OperationType operation_type = 1; + string ip = 2; string hostip = 3; string mac = 4; uint32 tunnel_id = 5; string hostmac = 6; string arionwing_group = 7; + uint64 version = 8; } \ No newline at end of file From ba723d59478bc76ad393723400948ca89ce66a1b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 22 Jun 2022 09:50:06 -0700 Subject: [PATCH 39/54] Update code --- .../alcor/dataplane/cache/ArionWingCache.java | 25 +++++++++++++++---- .../alcor/dataplane/entity/ArionGroup.java | 17 +++++++++++++ .../service/impl/ArionWingService.java | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java index 8853f3c22..599474eee 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java @@ -1,9 +1,25 @@ +/* +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.dataplane.cache; import com.futurewei.alcor.common.db.CacheException; 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.dataplane.entity.ArionGroup; import com.futurewei.alcor.dataplane.entity.ArionWing; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; @@ -13,20 +29,19 @@ import java.util.Map; import java.util.Set; - @Repository @ComponentScan(value="com.futurewei.alcor.common.db") public class ArionWingCache { private ICache arionWingCache; - private ICache arionWingGroupCache; + private ICache arionWingGroupCache; private CacheFactory cacheFactory; @Autowired public ArionWingCache(CacheFactory cacheFactory) { this.cacheFactory = cacheFactory; arionWingCache = cacheFactory.getCache(ArionWing.class); - arionWingGroupCache = cacheFactory.getCache(Object.class); + arionWingGroupCache = cacheFactory.getCache(ArionGroup.class); } @DurationStatistics @@ -67,7 +82,7 @@ public Object getArionGroup (String resourceId) throws CacheException { @DurationStatistics public void insertArionGroup (String resourceId) throws CacheException { System.out.println("Insert arion group: " + resourceId); - arionWingGroupCache.put(resourceId, resourceId); + arionWingGroupCache.put(resourceId, new ArionGroup(resourceId)); } @DurationStatistics @@ -76,7 +91,7 @@ public void deleteArionGroup (String resourceId) throws CacheException { } @DurationStatistics - public Map getAllArionGroup () throws CacheException { + public Map getAllArionGroup () throws CacheException { return arionWingGroupCache.getAll(); } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java new file mode 100644 index 000000000..f7a6b8694 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java @@ -0,0 +1,17 @@ +package com.futurewei.alcor.dataplane.entity; + +public class ArionGroup { + String groupName; + + public ArionGroup(String groupName) { + this.groupName = groupName; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java index b483c70ab..a0c44f9b7 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/ArionWingService.java @@ -73,7 +73,7 @@ public void getArionWings () throws CacheException { if (!ring.getNodes().isEmpty()) { keys = ring.getNodes().stream().map(item -> item.getKey()).collect(Collectors.toSet()); } - Set keysInCache = arionWingCache.getAllArionGroup().keySet(); + Set keysInCache = arionWingCache.getAllArionGroup().values().stream().map(item -> item.getGroupName()).collect(Collectors.toSet()); if (!keys.equals(keysInCache)) { keys.retainAll(keysInCache); for (SimpleNode node : ring.getNodes()) { From 3d233c9110a34944a9497c6519431e416d4e4b74 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 23 Jun 2022 12:29:29 -0700 Subject: [PATCH 40/54] Update code --- schema/proto3/arionmaster.proto | 30 +++++++++++++++++++++++- schema/proto3/goalstateprovisioner.proto | 12 ---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 0e827cbb6..471e974ab 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -21,11 +21,22 @@ package alcor.schema; option java_package = "com.futurewei.alcor.schema"; import "common.proto"; - +import "goalstateprovisioner.proto"; +import "neighbor.proto"; service Watch { + rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { } + + rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { + } + + rpc RequestGoalstates (HostRequest) returns (NeighborRulesResponse) { + } + + rpc RequestGoalstateStream (stream HostRequest) returns (stream NeighborRulesResponse) { + } } @@ -49,4 +60,21 @@ message NeighborRule { string hostmac = 6; string arionwing_group = 7; uint64 version = 8; +} + +message NeighborRulesRequest { + uint32 format_version = 1; + string request_id = 2; + + repeated NeighborState neigborstates = 3; +} + +message NeighborRulesResponse { + uint32 format_version = 1; + + message NeighborRuleReply { + string request_id = 1; + NeighborRule neighborrule = 2; + } + repeated NeighborRuleReply neighborrules = 2; } \ No newline at end of file diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index f56f5d26d..644a7f3ca 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -22,7 +22,6 @@ option java_package = "com.futurewei.alcor.schema"; import "common.proto"; import "goalstate.proto"; -import "neighbor.proto"; service GoalStateProvisioner { @@ -37,9 +36,6 @@ service GoalStateProvisioner { rpc PushNetworkResourceStates (GoalState) returns (GoalStateOperationReply) { } - rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { - } - // similar to PushGoalStatesStream with streaming GoalStateV2 and streaming GoalStateOperationReply // this is for DPM->NCM, and NCM->ACA rpc PushGoalStatesStream (stream GoalStateV2) returns (stream GoalStateOperationReply) { @@ -54,14 +50,6 @@ service GoalStateProvisioner { } } - -message NeighborRulesRequest { - uint32 format_version = 1; - string request_id = 2; - - repeated NeighborState neigborstates = 3; -} - message RoutingRulesRequest { uint32 format_version = 1; From f2213d5e39a59900e3616eee3001f9d5e9739b9d Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 23 Jun 2022 15:58:52 -0700 Subject: [PATCH 41/54] Update code --- schema/proto3/arionmaster.proto | 9 ++++++--- .../client/grpc/DataPlaneClientImplV2.java | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto index 471e974ab..137fef61b 100644 --- a/schema/proto3/arionmaster.proto +++ b/schema/proto3/arionmaster.proto @@ -24,10 +24,9 @@ import "common.proto"; import "goalstateprovisioner.proto"; import "neighbor.proto"; -service Watch { - rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { - } + +service ArionMasterService { rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { } @@ -39,7 +38,11 @@ service Watch { } } +service Watch { + rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { + } +} message ArionWingRequest { string vni = 1; 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 6cadc998c..0b3aff078 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 @@ -21,10 +21,12 @@ 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.dataplane.service.impl.ArionWingService; import com.futurewei.alcor.schema.*; import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import io.grpc.stub.AbstractStub; import io.grpc.stub.StreamObserver; import io.netty.util.concurrent.DefaultThreadFactory; import org.slf4j.Logger; @@ -167,6 +169,10 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp, int port) { .keepAliveWithoutCalls(true) .keepAliveTime(Long.MAX_VALUE, TimeUnit.SECONDS) .build(); + if (port == arionMasterPort) { + ArionMasterServiceGrpc.ArionMasterServiceStub arionMasterServiceStub = ArionMasterServiceGrpc.newStub(channel); + return new GrpcChannelStub(channel, arionMasterServiceStub); + } GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = GoalStateProvisionerGrpc.newStub(channel); return new GrpcChannelStub(channel, asyncStub); @@ -208,7 +214,7 @@ private ArrayList createGrpcChannelStubArrayList(String hostIp, // try to warmup a gRPC channel and its stub, by sending an empty GoalState`. void warmUpChannelStub(GrpcChannelStub channelStub, String hostIp) { - GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = (GoalStateProvisionerGrpc.GoalStateProvisionerStub)channelStub.stub; StreamObserver responseObserver = new StreamObserver<>() { @Override @@ -247,8 +253,8 @@ public void onCompleted() { private String doSendGoalStateToArionMaster (Goalstate.GoalStateV2.Builder goalStateV2) { GrpcChannelStub channelStub = getOrCreateGrpcChannel(arionMasterServer, arionMasterPort); - GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; - var neighborStateRequestBuilder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); + ArionMasterServiceGrpc.ArionMasterServiceStub asyncStub = (ArionMasterServiceGrpc.ArionMasterServiceStub)channelStub.stub; + var neighborStateRequestBuilder = Arionmaster.NeighborRulesRequest.newBuilder(); neighborStateRequestBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); asyncStub.pushGoalstates(neighborStateRequestBuilder.build(), new StreamObserver() { @Override @@ -275,7 +281,7 @@ private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp, hostAgentPort); long chan_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established channel, elapsed Time in milli seconds: " + (chan_established - start)); - GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = (GoalStateProvisionerGrpc.GoalStateProvisionerStub)channelStub.stub; long stub_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established stub, elapsed Time after channel established in milli seconds: " + (stub_established - chan_established)); @@ -325,9 +331,9 @@ public void onCompleted() { private class GrpcChannelStub { public ManagedChannel channel; - public GoalStateProvisionerGrpc.GoalStateProvisionerStub stub; + public AbstractStub stub; - public GrpcChannelStub(ManagedChannel channel, GoalStateProvisionerGrpc.GoalStateProvisionerStub stub) { + public GrpcChannelStub(ManagedChannel channel, AbstractStub stub) { this.channel = channel; this.stub = stub; } From b2f22d8801f86e1e21bff52fa94d09adb5840f71 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 1 Jul 2022 17:11:24 -0700 Subject: [PATCH 42/54] Update code --- schema/proto3/arionmaster.proto | 83 ------------------------ schema/proto3/gateway.proto | 2 +- schema/proto3/goalstateprovisioner.proto | 11 ++++ 3 files changed, 12 insertions(+), 84 deletions(-) delete mode 100644 schema/proto3/arionmaster.proto diff --git a/schema/proto3/arionmaster.proto b/schema/proto3/arionmaster.proto deleted file mode 100644 index 137fef61b..000000000 --- a/schema/proto3/arionmaster.proto +++ /dev/null @@ -1,83 +0,0 @@ -/* -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. -*/ - -syntax = "proto3"; - -package alcor.schema; - -option java_package = "com.futurewei.alcor.schema"; - -import "common.proto"; -import "goalstateprovisioner.proto"; -import "neighbor.proto"; - - - -service ArionMasterService { - - rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { - } - - rpc RequestGoalstates (HostRequest) returns (NeighborRulesResponse) { - } - - rpc RequestGoalstateStream (stream HostRequest) returns (stream NeighborRulesResponse) { - } -} - -service Watch { - - rpc Watch (stream ArionWingRequest) returns (stream NeighborRule) { - } -} - -message ArionWingRequest { - string vni = 1; - string ip = 2; - uint64 rev = 3; - string group = 4; -} - - - -message NeighborRule { - OperationType operation_type = 1; - - string ip = 2; - string hostip = 3; - string mac = 4; - uint32 tunnel_id = 5; - string hostmac = 6; - string arionwing_group = 7; - uint64 version = 8; -} - -message NeighborRulesRequest { - uint32 format_version = 1; - string request_id = 2; - - repeated NeighborState neigborstates = 3; -} - -message NeighborRulesResponse { - uint32 format_version = 1; - - message NeighborRuleReply { - string request_id = 1; - NeighborRule neighborrule = 2; - } - repeated NeighborRuleReply neighborrules = 2; -} \ No newline at end of file diff --git a/schema/proto3/gateway.proto b/schema/proto3/gateway.proto index e3c574a2e..2614ae168 100644 --- a/schema/proto3/gateway.proto +++ b/schema/proto3/gateway.proto @@ -29,7 +29,7 @@ enum GatewayType { TGW = 2; // Transit Gateway IGW = 3; // Internet Gateway NGW = 4; // NAT Gateway - ARION=5; + ARION = 5; } message GatewayConfiguration { diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 644a7f3ca..4654c41c4 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -22,6 +22,7 @@ option java_package = "com.futurewei.alcor.schema"; import "common.proto"; import "goalstate.proto"; +import "neighbor.proto"; service GoalStateProvisioner { @@ -48,6 +49,9 @@ service GoalStateProvisioner { // this is for ACA->NCM rpc RequestGoalStates (HostRequest) returns (HostRequestReply) { } + + rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { + } } message RoutingRulesRequest { @@ -101,6 +105,13 @@ message HostRequestReply { uint32 total_operation_time = 3; } +message NeighborRulesRequest { + uint32 format_version = 1; + string request_id = 2; + + repeated NeighborState neigborstates = 3; +} + message GoalStateOperationReply { uint32 format_version = 1; From 92ad98a3436925877ca43bb9d8a5ffb54acb03cb Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 1 Jul 2022 17:22:21 -0700 Subject: [PATCH 43/54] Update code --- schema/proto3/goalstateprovisioner.proto | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 4654c41c4..4bb16c36c 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -54,25 +54,6 @@ service GoalStateProvisioner { } } -message RoutingRulesRequest { - uint32 format_version = 1; - - string request_id = 2; - - message NeighborRule { - OperationType operation_type = 1; - string ip = 2; - string hostip = 3; - string mac = 4; - uint32 tunnel_id = 5; - string hostmac = 6; - string arionwing_group = 7; - } - - repeated NeighborRule neighborRules = 3; -} - - message HostRequest { uint32 format_version = 1; From 85f8dcea5a4e811a733b9454d251c57c3bfe3e47 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Fri, 1 Jul 2022 17:32:48 -0700 Subject: [PATCH 44/54] Update code --- .../client/grpc/DataPlaneClientImplV2.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 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 0b3aff078..2db8628ea 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 @@ -21,12 +21,10 @@ 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.dataplane.service.impl.ArionWingService; import com.futurewei.alcor.schema.*; import io.grpc.ConnectivityState; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.grpc.stub.AbstractStub; import io.grpc.stub.StreamObserver; import io.netty.util.concurrent.DefaultThreadFactory; import org.slf4j.Logger; @@ -169,10 +167,6 @@ private GrpcChannelStub createGrpcChannelStub(String hostIp, int port) { .keepAliveWithoutCalls(true) .keepAliveTime(Long.MAX_VALUE, TimeUnit.SECONDS) .build(); - if (port == arionMasterPort) { - ArionMasterServiceGrpc.ArionMasterServiceStub arionMasterServiceStub = ArionMasterServiceGrpc.newStub(channel); - return new GrpcChannelStub(channel, arionMasterServiceStub); - } GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = GoalStateProvisionerGrpc.newStub(channel); return new GrpcChannelStub(channel, asyncStub); @@ -214,7 +208,7 @@ private ArrayList createGrpcChannelStubArrayList(String hostIp, // try to warmup a gRPC channel and its stub, by sending an empty GoalState`. void warmUpChannelStub(GrpcChannelStub channelStub, String hostIp) { - GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = (GoalStateProvisionerGrpc.GoalStateProvisionerStub)channelStub.stub; + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; StreamObserver responseObserver = new StreamObserver<>() { @Override @@ -253,8 +247,8 @@ public void onCompleted() { private String doSendGoalStateToArionMaster (Goalstate.GoalStateV2.Builder goalStateV2) { GrpcChannelStub channelStub = getOrCreateGrpcChannel(arionMasterServer, arionMasterPort); - ArionMasterServiceGrpc.ArionMasterServiceStub asyncStub = (ArionMasterServiceGrpc.ArionMasterServiceStub)channelStub.stub; - var neighborStateRequestBuilder = Arionmaster.NeighborRulesRequest.newBuilder(); + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; + var neighborStateRequestBuilder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); neighborStateRequestBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); asyncStub.pushGoalstates(neighborStateRequestBuilder.build(), new StreamObserver() { @Override @@ -281,7 +275,7 @@ private String doSendGoalState(Goalstate.GoalStateV2 goalStateV2, CountDownLatch GrpcChannelStub channelStub = getOrCreateGrpcChannel(hostIp, hostAgentPort); long chan_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established channel, elapsed Time in milli seconds: " + (chan_established - start)); - GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = (GoalStateProvisionerGrpc.GoalStateProvisionerStub)channelStub.stub; + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; long stub_established = System.currentTimeMillis(); LOG.info("[doSendGoalState] Established stub, elapsed Time after channel established in milli seconds: " + (stub_established - chan_established)); @@ -331,9 +325,9 @@ public void onCompleted() { private class GrpcChannelStub { public ManagedChannel channel; - public AbstractStub stub; + public GoalStateProvisionerGrpc.GoalStateProvisionerStub stub; - public GrpcChannelStub(ManagedChannel channel, AbstractStub stub) { + public GrpcChannelStub(ManagedChannel channel, GoalStateProvisionerGrpc.GoalStateProvisionerStub stub) { this.channel = channel; this.stub = stub; } @@ -414,10 +408,10 @@ private Goalstate.GoalStateV2.Builder getGoalState(Goalstate.GoalStateV2.Builder 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); + 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()); } From f09eb24c33d07eb49e0289dea51f4ed5aa65fa7b Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 5 Jul 2022 14:44:40 -0700 Subject: [PATCH 45/54] Update code --- kubernetes/services/dpm_manager.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kubernetes/services/dpm_manager.yaml b/kubernetes/services/dpm_manager.yaml index 62778111d..07291cbb7 100644 --- a/kubernetes/services/dpm_manager.yaml +++ b/kubernetes/services/dpm_manager.yaml @@ -61,6 +61,11 @@ data: host.ip.to.group.topic.map=group-topic1:192.168.131.131,10.10.10.11 group-topic2:192.168.131.131,11.11.11.12 group.topic.to.multicast.topic.map=multicast-topic1:group-topic1,group-topic3 multicast-topic2:group-topic2,group-topic4 + + arionGateway.enabled = false + arionMaster.server = 127.0.0.1 + arionMaster.port = 9090 + 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 From ada7d09cbbda133fa862f167149a0f34a9da89e0 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 5 Jul 2022 15:12:45 -0700 Subject: [PATCH 46/54] Update code --- .../dataplane/service/impl/NeighborService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 cb5115656..785027d34 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 @@ -35,6 +35,7 @@ free of charge, to any person obtaining a copy of this software and associated d import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.*; @@ -62,6 +63,9 @@ public class NeighborService extends ResourceService { @Autowired private ArionWingService arionWingService; + @Value("${arionGateway.enabled:false}") + private boolean arionGatwayEnabled; + private static String NEIGHBOR_STATE_L2_PREFIX = "L2/"; private static String NEIGHBOR_STATE_L3_PREFIX = "L3/"; @@ -108,9 +112,11 @@ public Neighbor.NeighborState buildNeighborState(NeighborEntry.NeighborType type fixedIpBuilder.setSubnetId(portHostInfo.getSubnetId()); fixedIpBuilder.setIpAddress(portHostInfo.getPortIp()); fixedIpBuilder.setNeighborType(neighborType); - var subnetEntity = subnetPortsCache.getSubnetPorts(portHostInfo.getSubnetId()); - fixedIpBuilder.setArionGroup(arionWingService.getArionGroup(subnetEntity.getTunnelId().intValue(), subnetEntity.getCidr())); - fixedIpBuilder.setTunnelId(subnetEntity.getTunnelId().intValue()); + if (arionGatwayEnabled) { + var subnetEntity = subnetPortsCache.getSubnetPorts(portHostInfo.getSubnetId()); + fixedIpBuilder.setArionGroup(arionWingService.getArionGroup(subnetEntity.getTunnelId().intValue(), subnetEntity.getCidr())); + fixedIpBuilder.setTunnelId(subnetEntity.getTunnelId().intValue()); + } neighborConfigBuilder.addFixedIps(fixedIpBuilder.build()); //TODO:setAllowAddressPairs //neighborConfigBuilder.setAllowAddressPairs(); From 0d784fad244a6ad9344f308bf4278f0e95a04469 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 7 Jul 2022 11:32:55 -0700 Subject: [PATCH 47/54] Update code --- .../alcor/dataplane/cache/ArionWingCache.java | 3 +++ .../controller/ArionGatewayController.java | 6 ++++++ .../alcor/dataplane/entity/ArionGroup.java | 15 +++++++++++++++ .../alcor/dataplane/entity/ArionWing.java | 15 +++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java index 599474eee..e13cc623b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java @@ -33,7 +33,10 @@ free of charge, to any person obtaining a copy of this software and associated d @ComponentScan(value="com.futurewei.alcor.common.db") public class ArionWingCache { + // arionWingCache store Arion wing meta data. key is Arion Wing hash code and value is Arion wing meta data. private ICache arionWingCache; + + // arionWingGroupCache store Arion group meta data. key is Arion wing group name, value is Arion wing meta data. private ICache arionWingGroupCache; private CacheFactory cacheFactory; diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java index 03d464a34..19e4a1d3f 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/ArionGatewayController.java @@ -25,6 +25,12 @@ free of charge, to any person obtaining a copy of this software and associated d import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; + +/* +This controller provide api for Arion master input group and Arion wing information. +It used for Arion wing Consistent Hash. Could be deprecated once Arion Master could be made self-contained + */ + @Slf4j @RestController @ComponentScan(value = "com.futurewei.alcor.common.stats") diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java index f7a6b8694..3971c6d45 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionGroup.java @@ -1,3 +1,18 @@ +/* +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.dataplane.entity; public class ArionGroup { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java index 0735eebd0..02d4ef880 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/entity/ArionWing.java @@ -1,3 +1,18 @@ +/* +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.dataplane.entity; import org.ishugaliy.allgood.consistent.hash.annotation.Generated; From 378b5570da9f2dee8e7ed13b8308f51ff94d4953 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Thu, 7 Jul 2022 14:01:58 -0700 Subject: [PATCH 48/54] Update code --- .../com/futurewei/alcor/dataplane/cache/ArionWingCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java index e13cc623b..e39cc156d 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/ArionWingCache.java @@ -36,7 +36,7 @@ public class ArionWingCache { // arionWingCache store Arion wing meta data. key is Arion Wing hash code and value is Arion wing meta data. private ICache arionWingCache; - // arionWingGroupCache store Arion group meta data. key is Arion wing group name, value is Arion wing meta data. + // arionWingGroupCache store Arion group meta data. key is Arion wing group name, value is Arion group meta data. private ICache arionWingGroupCache; private CacheFactory cacheFactory; From 8fe5f62d880bf5c83ae7d83de59f382bfa3ce973 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Tue, 29 Nov 2022 11:37:06 -0800 Subject: [PATCH 49/54] Add security group --- .../PortBindingSecurityGroupRepository.java | 82 +++++++++++++++++ .../cache/SecurityGroupRepository.java | 88 +++++++++++++++++++ .../controller/SecurityGroupController.java | 76 ++++++++++++++++ .../service/SecurityGroupService.java | 26 ++++++ .../service/impl/SecurityGroupService.java | 14 +++ .../impl/SecurityGroupServiceImpl.java | 72 +++++++++++++++ .../implement/SecurityGroupServiceImpl.java | 2 +- 7 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortBindingSecurityGroupRepository.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java create mode 100644 services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortBindingSecurityGroupRepository.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortBindingSecurityGroupRepository.java new file mode 100644 index 000000000..341b01059 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/PortBindingSecurityGroupRepository.java @@ -0,0 +1,82 @@ +/* +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.dataplane.cache; + +import com.futurewei.alcor.common.db.CacheException; +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.web.entity.securitygroup.PortBindingSecurityGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; +import javax.annotation.PostConstruct; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Repository +@ComponentScan(value="com.futurewei.alcor.common.db") +public class PortBindingSecurityGroupRepository { + private static final Logger LOG = LoggerFactory.getLogger(PortBindingSecurityGroupRepository.class); + + private ICache bindingCache; + + @Autowired + public PortBindingSecurityGroupRepository(CacheFactory cacheFactory) { + bindingCache = cacheFactory.getCache(PortBindingSecurityGroup.class); + } + + @PostConstruct + private void init() { + LOG.info("PortBindingSecurityGroupRepository init done"); + } + + @DurationStatistics + public Collection getPortBindingSecurityGroupBySecurityGroupId(String securityGroupId) throws CacheException { + Map filterParams = new HashMap<>(); + filterParams.put("securityGroupId", new String[] {securityGroupId}); + + Map portBindingSecurityGroupMap = bindingCache.getAll(filterParams); + return portBindingSecurityGroupMap.values(); + } + + @DurationStatistics + public Collection getPortBindingSecurityGroupByPortId(String portId) throws CacheException { + Map filterParams = new HashMap<>(); + filterParams.put("portId", new String[] {portId}); + + Map portBindingSecurityGroupMap = bindingCache.getAll(filterParams); + return portBindingSecurityGroupMap.values(); + } + + @DurationStatistics + public synchronized void addPortBindingSecurityGroup(List portBindingSecurityGroups) throws Exception { + Map portBindingSecurityGroupMap = portBindingSecurityGroups + .stream() + .collect(Collectors.toMap(PortBindingSecurityGroup::getId, Function.identity())); + bindingCache.putAll(portBindingSecurityGroupMap); + } + + @DurationStatistics + public synchronized void deleteSecurityGroupBinding(List portBindingSecurityGroups) throws Exception { + for (PortBindingSecurityGroup portBindingSecurityGroup: portBindingSecurityGroups) { + bindingCache.remove(portBindingSecurityGroup.getId()); + } + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java new file mode 100644 index 000000000..5a1ae962f --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java @@ -0,0 +1,88 @@ +/* +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.dataplane.cache; + +import com.futurewei.alcor.common.db.CacheException; +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.web.entity.securitygroup.SecurityGroupRule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; +import javax.annotation.PostConstruct; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Repository +public class SecurityGroupRepository { + private static final Logger LOG = LoggerFactory.getLogger(SecurityGroupRepository.class); + + private ICache securityGroupRuleCache; + + @Autowired + public SecurityGroupRepository(CacheFactory cacheFactory) { + securityGroupRuleCache = cacheFactory.getCache(SecurityGroupRule.class); + } + + @PostConstruct + private void init() { + LOG.info("SecurityGroupRepository init done"); + } + + @DurationStatistics + public synchronized void addSecurityGroupRules(List securityGroupRules) throws Exception { + var securityGroupRuleMap = securityGroupRules.stream().collect(Collectors.toMap(SecurityGroupRule::getId, Function.identity())); + securityGroupRuleCache.putAll(securityGroupRuleMap); + } + + @DurationStatistics + public synchronized void deleteSecurityGroupRules(List securityGroupIds) throws Exception { + securityGroupIds.forEach(securityGroupId -> { + try { + securityGroupRuleCache.remove(securityGroupId); + } catch (CacheException e) { + e.printStackTrace(); + } + }); + } + + @DurationStatistics + public SecurityGroupRule getSecurityGroupRule(String securityGroupRuleId) throws CacheException { + return securityGroupRuleCache.get(securityGroupRuleId); + } + + @DurationStatistics + public List getSecurityGroupRules(List securityGroupRuleIds) throws CacheException { + List securityGroupRules = new ArrayList<>(); + for (String securityGroupId : securityGroupRuleIds) { + SecurityGroupRule securityGroupRule = securityGroupRuleCache.get(securityGroupId); + securityGroupRules.add(securityGroupRule); + } + return securityGroupRules; + } + + @DurationStatistics + public Collection getSecurityGroupRules(String scurityGroupId) throws CacheException { + Map queryParams = new HashMap<>(); + Object[] value = new Object[1]; + value[0] = scurityGroupId; + queryParams.put("securityGroupId", value); + return securityGroupRuleCache.getAll(queryParams).values(); + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java new file mode 100644 index 000000000..d93ac443c --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java @@ -0,0 +1,76 @@ +/* +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.dataplane.controller; + +import com.futurewei.alcor.common.exception.ParameterNullOrEmptyException; +import com.futurewei.alcor.common.stats.DurationStatistics; +import com.futurewei.alcor.dataplane.entity.ArionWing; +import com.futurewei.alcor.dataplane.service.SecurityGroupService; +import com.futurewei.alcor.dataplane.service.impl.ArionWingService; +import com.futurewei.alcor.web.entity.gateway.ArionWingInfo; +import com.futurewei.alcor.web.entity.route.RouteTable; +import com.futurewei.alcor.web.entity.route.RouteTableWebJson; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + + +@Slf4j +@RestController +@ComponentScan(value = "com.futurewei.alcor.common.stats") +public class SecurityGroupController { + + @Autowired + private SecurityGroupService securityGroupService; + + @PostMapping({"/securitygrouprules"}) + @ResponseStatus(HttpStatus.CREATED) + @DurationStatistics + public String createSecurityGroupRules(@RequestBody List securityGroupRuleList) throws Exception { + securityGroupService.updateSecurityGroupRules(securityGroupRuleList); + return "Success created"; + } + + @PutMapping({"/securitygrouprules"}) + @DurationStatistics + public String updateSecurityGroupRules(@PathVariable List securityGroupRuleList) throws Exception { + securityGroupService.updateSecurityGroupRules(securityGroupRuleList); + return "Success updated"; + } + + @DeleteMapping({"/securitygrouprules/{resource_id}"}) + @DurationStatistics + public void deleteSecurityGroupRule(@PathVariable String resource_id) throws Exception { + securityGroupService.deleteSecurityGroupRules(new ArrayList<>(){{add(resource_id);}}); + } + + @RequestMapping( + method = GET, + value = {"/securitygrouprules/{security_group_id}"}) + @DurationStatistics + public Collection getSecurityGroupRules(@PathVariable String security_group_id) throws Exception { + return securityGroupService.getSecurityGroupRules(security_group_id); + } +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java new file mode 100644 index 000000000..5fc1d3dc3 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java @@ -0,0 +1,26 @@ +package com.futurewei.alcor.dataplane.service; + +import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroup; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; + +import java.util.Collection; +import java.util.List; + +public interface SecurityGroupService { + void updateSecurityGroupRules(List securityGroupRuleList) throws Exception; + + void deleteSecurityGroupRules(List securityGroupIds) throws Exception; + + List getSecurityGroupRules(List securityGroupRuleIds) throws CacheException; + + Collection getSecurityGroupRules(String securityGroupId) throws CacheException; + + void addPortBindingSecurityGroup(List portBindingSecurityGroups) throws Exception; + + void deletePortBindingSecurityGroup (List portBindingSecurityGroups) throws Exception; + + Collection getPortBindingSecurityGroupBySecurityGroupId(String securityGroupId) throws CacheException; + + Collection getPortBindingSecurityGroupByPortId(String portId); +} diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupService.java index 61483757f..1ef361e2c 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupService.java @@ -15,6 +15,7 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.dataplane.service.impl; +import com.futurewei.alcor.dataplane.cache.PortBindingSecurityGroupRepository; import com.futurewei.alcor.dataplane.entity.UnicastGoalState; import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; import com.futurewei.alcor.dataplane.exception.*; @@ -25,8 +26,10 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.schema.Port; import com.futurewei.alcor.schema.SecurityGroup.SecurityGroupConfiguration.Direction; import com.futurewei.alcor.web.entity.dataplane.v2.NetworkConfiguration; +import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroup; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroup; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -38,6 +41,11 @@ free of charge, to any person obtaining a copy of this software and associated d @Service public class SecurityGroupService extends ResourceService { + + + @Autowired + private PortBindingSecurityGroupRepository portBindingSecurityGroupRepository; + private SecurityGroup getSecurityGroup(NetworkConfiguration networkConfig, String securityGroupId) throws Exception { SecurityGroup result = null; for (SecurityGroup securityGroup: networkConfig.getSecurityGroups()) { @@ -183,6 +191,12 @@ public void buildSecurityGroupStates(NetworkConfiguration networkConfig, Unicast .map(Port.PortConfiguration.SecurityGroupId::getId) .collect(Collectors.toList())); } + var portBindingSecurityGroupList = securityGroupIdList.stream().map(securityGroupId -> { + PortBindingSecurityGroup portBindingSecurityGroup = new PortBindingSecurityGroup(portState.getConfiguration().getId(), securityGroupId.getId()); + portBindingSecurityGroup.setId(portState.getConfiguration().getId() + securityGroupId.getId()); + return portBindingSecurityGroup; + }).collect(Collectors.toList()); + portBindingSecurityGroupRepository.addPortBindingSecurityGroup(portBindingSecurityGroupList); } for (String securityGroupId: securityGroupIds) { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java new file mode 100644 index 000000000..51268b3b5 --- /dev/null +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java @@ -0,0 +1,72 @@ +package com.futurewei.alcor.dataplane.service.impl; + +import com.futurewei.alcor.common.db.CacheException; +import com.futurewei.alcor.dataplane.cache.PortBindingSecurityGroupRepository; +import com.futurewei.alcor.dataplane.cache.SecurityGroupRepository; +import com.futurewei.alcor.dataplane.service.SecurityGroupService; +import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroup; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +public class SecurityGroupServiceImpl implements SecurityGroupService { + private static final Logger LOG = LoggerFactory.getLogger(DpmServiceImpl.class); + + + @Autowired + private PortBindingSecurityGroupRepository portBindingSecurityGroupRepository; + + + @Autowired + private SecurityGroupRepository securityGroupRepository; + + + @Override + public void updateSecurityGroupRules(List securityGroupRuleList) throws Exception { + securityGroupRepository.addSecurityGroupRules(securityGroupRuleList); + } + + @Override + public void deleteSecurityGroupRules(List securityGroupIds) throws Exception { + securityGroupRepository.deleteSecurityGroupRules(securityGroupIds); + } + + @Override + public List getSecurityGroupRules(List securityGroupRuleIds) throws CacheException { + return securityGroupRepository.getSecurityGroupRules(securityGroupRuleIds); + } + + @Override + public Collection getSecurityGroupRules(String securityGroupId) throws CacheException { + return securityGroupRepository.getSecurityGroupRules(securityGroupId); + } + + @Override + public void addPortBindingSecurityGroup(List portBindingSecurityGroups) throws Exception { + portBindingSecurityGroupRepository.addPortBindingSecurityGroup(portBindingSecurityGroups); + } + + @Override + public void deletePortBindingSecurityGroup(List portBindingSecurityGroups) throws Exception { + portBindingSecurityGroupRepository.deleteSecurityGroupBinding(portBindingSecurityGroups); + } + + @Override + public Collection getPortBindingSecurityGroupBySecurityGroupId(String securityGroupId) throws CacheException { + return portBindingSecurityGroupRepository.getPortBindingSecurityGroupBySecurityGroupId(securityGroupId); + } + + @Override + public Collection getPortBindingSecurityGroupByPortId(String portId) { + return null; + } +} diff --git a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java index 1d527a93b..bb9b807b9 100644 --- a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java +++ b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java @@ -96,7 +96,7 @@ public SecurityGroupJson createSecurityGroup(SecurityGroupJson securityGroupJson if (isDefaultSecurityGroup(securityGroup) && defaultSecurityGroup != null) { throw new DefaultSecurityGroupExists(); } - + System.out.println("test: " + securityGroupJson.getSecurityGroup().getSecurityGroupRules().toString()); if (!isDefaultSecurityGroup(securityGroup)) { //Default security group not exists, create it if (defaultSecurityGroup == null) { From c90578210d4d3ff357a4a2b41189fca123ad92bb Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 30 Nov 2022 17:43:28 -0800 Subject: [PATCH 50/54] Update code --- .../alcor/portmanager/processor/DataPlaneProcessor.java | 3 +++ .../service/implement/SecurityGroupServiceImpl.java | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java index 21b69198d..03be4f4d6 100644 --- a/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java +++ b/services/port_manager/src/main/java/com/futurewei/alcor/portmanager/processor/DataPlaneProcessor.java @@ -16,6 +16,7 @@ free of charge, to any person obtaining a copy of this software and associated d package com.futurewei.alcor.portmanager.processor; import com.futurewei.alcor.common.enumClass.StatusEnum; +import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.common.utils.CommonUtil; import com.futurewei.alcor.common.utils.SpringContextUtil; import com.futurewei.alcor.portmanager.exception.GetNodeInfoException; @@ -34,6 +35,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.route.InternalRouterInfo; import com.futurewei.alcor.web.entity.subnet.SubnetEntity; import com.futurewei.alcor.web.entity.vpc.VpcEntity; +import lombok.Data; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -307,6 +309,7 @@ private void createNetworkConfig(PortContext context, NetworkConfiguration netwo } } + @DurationStatistics private void updateNetworkConfig(PortContext context, NetworkConfiguration networkConfig) throws Exception { PortService portService = SpringContextUtil.getBean(PortService.class); if (networkConfig != null) { diff --git a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java index bb9b807b9..91c681504 100644 --- a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java +++ b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java @@ -60,7 +60,7 @@ private void createDefaultSecurityGroupRules(SecurityGroup securityGroup, Securi securityGroupRules.add(securityGroupRule); } - securityGroup.setSecurityGroupRules(securityGroupRules); + securityGroup.getSecurityGroupRules().addAll(securityGroupRules); } private void createDefaultSecurityGroup(String tenantId, String projectId, String description) throws Exception { @@ -96,7 +96,6 @@ public SecurityGroupJson createSecurityGroup(SecurityGroupJson securityGroupJson if (isDefaultSecurityGroup(securityGroup) && defaultSecurityGroup != null) { throw new DefaultSecurityGroupExists(); } - System.out.println("test: " + securityGroupJson.getSecurityGroup().getSecurityGroupRules().toString()); if (!isDefaultSecurityGroup(securityGroup)) { //Default security group not exists, create it if (defaultSecurityGroup == null) { From b5a537074e46d310ab5f810012cf263d2323ccb8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Wed, 11 Jan 2023 15:13:08 -0800 Subject: [PATCH 51/54] Update code --- schema/proto3/goalstateprovisioner.proto | 10 +- .../cache/SecurityGroupRepository.java | 12 +- .../dataplane/client/DataPlaneClient.java | 2 + .../client/grpc/DataPlaneClientImpl.java | 6 + .../client/grpc/DataPlaneClientImplV2.java | 36 ++++- .../controller/SecurityGroupController.java | 21 ++- .../service/SecurityGroupService.java | 8 +- .../service/impl/DpmServiceImplV2.java | 7 + .../impl/SecurityGroupServiceImpl.java | 132 +++++++++++++++++- services/security_group_manager/pom.xml | 5 + .../SecurityGroupRuleServiceImpl.java | 71 +++++++++- .../implement/SecurityGroupServiceImpl.java | 41 +++++- .../src/main/resources/application.properties | 1 + .../securitygroup/SecurityGroupRuleJson.java | 6 +- 14 files changed, 330 insertions(+), 28 deletions(-) diff --git a/schema/proto3/goalstateprovisioner.proto b/schema/proto3/goalstateprovisioner.proto index 4bb16c36c..751736b3f 100644 --- a/schema/proto3/goalstateprovisioner.proto +++ b/schema/proto3/goalstateprovisioner.proto @@ -23,6 +23,8 @@ option java_package = "com.futurewei.alcor.schema"; import "common.proto"; import "goalstate.proto"; import "neighbor.proto"; +import "securitygroup.proto"; +import "port.proto"; service GoalStateProvisioner { @@ -50,7 +52,10 @@ service GoalStateProvisioner { rpc RequestGoalStates (HostRequest) returns (HostRequestReply) { } - rpc PushGoalstates (NeighborRulesRequest) returns (GoalStateOperationReply) { + rpc PushGoalstates (ArionGoalStateRequest) returns (GoalStateOperationReply) { + } + + rpc PushSecurityGroupGoalState (SecurityGroupState) returns (GoalStateOperationReply) { } } @@ -86,11 +91,12 @@ message HostRequestReply { uint32 total_operation_time = 3; } -message NeighborRulesRequest { +message ArionGoalStateRequest { uint32 format_version = 1; string request_id = 2; repeated NeighborState neigborstates = 3; + repeated PortState portstates = 4; } message GoalStateOperationReply { diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java index 5a1ae962f..d33075036 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/cache/SecurityGroupRepository.java @@ -20,6 +20,8 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.common.db.ICache; import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleBulkJson; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleJson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -46,9 +48,13 @@ private void init() { } @DurationStatistics - public synchronized void addSecurityGroupRules(List securityGroupRules) throws Exception { - var securityGroupRuleMap = securityGroupRules.stream().collect(Collectors.toMap(SecurityGroupRule::getId, Function.identity())); - securityGroupRuleCache.putAll(securityGroupRuleMap); + public synchronized void addSecurityGroupRule(SecurityGroupRuleJson securityGroupRuleJson) throws Exception { + securityGroupRuleCache.put(securityGroupRuleJson.getSecurityGroupRule().getId(), securityGroupRuleJson.getSecurityGroupRule()); + } + @DurationStatistics + public synchronized void addSecurityGroupRules(SecurityGroupRuleBulkJson securityGroupRuleBulkJson) throws Exception { + var securityGroupRules = securityGroupRuleBulkJson.getSecurityGroupRules().stream().collect(Collectors.toMap(SecurityGroupRule::getId, Function.identity())); + securityGroupRuleCache.putAll(securityGroupRules); } @DurationStatistics diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/DataPlaneClient.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/DataPlaneClient.java index 6e81e70d3..dff1be25b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/DataPlaneClient.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/DataPlaneClient.java @@ -21,6 +21,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; import com.futurewei.alcor.schema.Goalstate.GoalState; import com.futurewei.alcor.schema.Goalstateprovisioner.GoalStateOperationReply.GoalStateOperationStatus; +import com.futurewei.alcor.schema.SecurityGroup; import org.springframework.stereotype.Component; import java.util.List; @@ -31,4 +32,5 @@ public interface DataPlaneClient { List sendGoalStates(List unicastGoalStates) throws Exception; List sendGoalStates(List unicastGoalStates, T multicastGoalState) throws Exception; + List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception; } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImpl.java index 5312b1723..0d65c257f 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/grpc/DataPlaneClientImpl.java @@ -23,6 +23,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.schema.Goalstate; import com.futurewei.alcor.schema.Goalstateprovisioner.GoalStateOperationReply.GoalStateOperationStatus; import com.futurewei.alcor.schema.Goalstateprovisioner.GoalStateOperationReply; +import com.futurewei.alcor.schema.SecurityGroup; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; import io.grpc.stub.StreamObserver; @@ -89,6 +90,11 @@ public List sendGoalStates( return null; } + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } + private List doSendGoalStates(List unicastGoalStates) { List> futures = new ArrayList<>(unicastGoalStates.size()); 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 f285d03b6..59ea62fcb 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 @@ -164,6 +164,12 @@ public List sendGoalStates(List unicastGoalStates, M return null; } + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + doSendGoalStateToArionMaster(securityGroupState); + return new ArrayList<>(); + } + private GrpcChannelStub createGrpcChannelStub(String hostIp, int port) { ManagedChannel channel = ManagedChannelBuilder.forAddress(hostIp, port) .usePlaintext() @@ -251,9 +257,33 @@ public void onCompleted() { private String doSendGoalStateToArionMaster (Goalstate.GoalStateV2.Builder goalStateV2) { GrpcChannelStub channelStub = getOrCreateGrpcChannel(arionMasterServer, arionMasterPort); GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; - var neighborStateRequestBuilder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); - neighborStateRequestBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); - asyncStub.pushGoalstates(neighborStateRequestBuilder.build(), new StreamObserver() { + var arionGoalStateBuilder = Goalstateprovisioner.ArionGoalStateRequest.newBuilder(); + arionGoalStateBuilder.addAllNeigborstates(goalStateV2.getNeighborStatesMap().values()); + arionGoalStateBuilder.addAllPortstates(goalStateV2.getPortStatesMap().values()); + + asyncStub.pushGoalstates(arionGoalStateBuilder.build(), new StreamObserver() { + @Override + public void onNext(Goalstateprovisioner.GoalStateOperationReply goalStateOperationReply) { + LOG.info("Get response: " + goalStateOperationReply.toString()); + } + + @Override + public void onError(Throwable throwable) { + LOG.info(throwable.getMessage()); + } + + @Override + public void onCompleted() { + + } + }); + return null; + } + + private String doSendGoalStateToArionMaster (SecurityGroup.SecurityGroupState securityGroupState) { + GrpcChannelStub channelStub = getOrCreateGrpcChannel(arionMasterServer, arionMasterPort); + GoalStateProvisionerGrpc.GoalStateProvisionerStub asyncStub = channelStub.stub; + asyncStub.pushSecurityGroupGoalState(securityGroupState, new StreamObserver() { @Override public void onNext(Goalstateprovisioner.GoalStateOperationReply goalStateOperationReply) { LOG.info("Get response: " + goalStateOperationReply.toString()); diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java index d93ac443c..df3669675 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/controller/SecurityGroupController.java @@ -24,12 +24,15 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.route.RouteTable; import com.futurewei.alcor.web.entity.route.RouteTableWebJson; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleBulkJson; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleJson; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import javax.ws.rs.QueryParam; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -48,21 +51,29 @@ public class SecurityGroupController { @PostMapping({"/securitygrouprules"}) @ResponseStatus(HttpStatus.CREATED) @DurationStatistics - public String createSecurityGroupRules(@RequestBody List securityGroupRuleList) throws Exception { - securityGroupService.updateSecurityGroupRules(securityGroupRuleList); + public String createSecurityGroupRule(@RequestBody SecurityGroupRuleJson securityGroupRuleJson) throws Exception { + securityGroupService.updateSecurityGroupRule(securityGroupRuleJson); + return "Success created"; + } + + @PostMapping({"/securitygrouprules/bulk"}) + @ResponseStatus(HttpStatus.CREATED) + @DurationStatistics + public String createSecurityGroupRules(@RequestBody SecurityGroupRuleBulkJson securityGroupRuleBulkJson) throws Exception { + securityGroupService.updateSecurityGroupRules(securityGroupRuleBulkJson); return "Success created"; } @PutMapping({"/securitygrouprules"}) @DurationStatistics - public String updateSecurityGroupRules(@PathVariable List securityGroupRuleList) throws Exception { - securityGroupService.updateSecurityGroupRules(securityGroupRuleList); + public String updateSecurityGroupRules(@PathVariable SecurityGroupRuleJson securityGroupRuleJson) throws Exception { + securityGroupService.updateSecurityGroupRule(securityGroupRuleJson); return "Success updated"; } @DeleteMapping({"/securitygrouprules/{resource_id}"}) @DurationStatistics - public void deleteSecurityGroupRule(@PathVariable String resource_id) throws Exception { + public void deleteSecurityGroupRule(@RequestParam String resource_id) throws Exception { securityGroupService.deleteSecurityGroupRules(new ArrayList<>(){{add(resource_id);}}); } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java index 5fc1d3dc3..7610b3f5b 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/SecurityGroupService.java @@ -3,12 +3,16 @@ import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroup; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleBulkJson; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleJson; import java.util.Collection; import java.util.List; public interface SecurityGroupService { - void updateSecurityGroupRules(List securityGroupRuleList) throws Exception; + void updateSecurityGroupRule(SecurityGroupRuleJson securityGroupRuleJson) throws Exception; + + void updateSecurityGroupRules(SecurityGroupRuleBulkJson securityGroupRuleBulkJson) throws Exception; void deleteSecurityGroupRules(List securityGroupIds) throws Exception; @@ -22,5 +26,5 @@ public interface SecurityGroupService { Collection getPortBindingSecurityGroupBySecurityGroupId(String securityGroupId) throws CacheException; - Collection getPortBindingSecurityGroupByPortId(String portId); + Collection getPortBindingSecurityGroupByPortId(String portId) throws CacheException; } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java index c46a42098..2e0b2a8a2 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/DpmServiceImplV2.java @@ -30,6 +30,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.web.entity.port.PortHostInfo; import com.futurewei.alcor.web.entity.route.InternalRouterInfo; import com.futurewei.alcor.web.entity.route.InternalSubnetRoutingTable; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleJson; import com.futurewei.alcor.web.entity.subnet.InternalSubnetPorts; import com.futurewei.alcor.web.restclient.DataPlaneManagerRestClient; import org.slf4j.Logger; @@ -293,6 +294,12 @@ private List processSecurityGroupConfiguration(NetworkConfiguration netw return new ArrayList<>(); } + private List processSecurityGroupConfiguration(SecurityGroupRuleJson securityGroupRuleJson) throws Exception { + + return new ArrayList<>(); + } + + /** * This method get the subnet routing configuration from the NetworkConfiguration, * then find the host information of all the virtual machines under the subnet from diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java index 51268b3b5..ce66f07e6 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/service/impl/SecurityGroupServiceImpl.java @@ -3,14 +3,26 @@ import com.futurewei.alcor.common.db.CacheException; import com.futurewei.alcor.dataplane.cache.PortBindingSecurityGroupRepository; import com.futurewei.alcor.dataplane.cache.SecurityGroupRepository; +import com.futurewei.alcor.dataplane.client.DataPlaneClient; +import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; +import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.dataplane.exception.SecurityGroupDirectionInvalid; +import com.futurewei.alcor.dataplane.exception.SecurityGroupEtherTypeInvalid; +import com.futurewei.alcor.dataplane.exception.SecurityGroupProtocolInvalid; import com.futurewei.alcor.dataplane.service.SecurityGroupService; +import com.futurewei.alcor.schema.Common; +import com.futurewei.alcor.schema.SecurityGroup; import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroup; import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRule; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleBulkJson; +import com.futurewei.alcor.web.entity.securitygroup.SecurityGroupRuleJson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -19,20 +31,126 @@ @Service public class SecurityGroupServiceImpl implements SecurityGroupService { - private static final Logger LOG = LoggerFactory.getLogger(DpmServiceImpl.class); - + private static final Logger LOG = LoggerFactory.getLogger(SecurityGroupServiceImpl.class); @Autowired private PortBindingSecurityGroupRepository portBindingSecurityGroupRepository; - @Autowired private SecurityGroupRepository securityGroupRepository; + @Autowired + private DataPlaneClient grpcDataPlaneClient; + + + private SecurityGroup.SecurityGroupConfiguration.Direction transformDirection(String direction) throws Exception { + if (StringUtils.isEmpty(direction)) { + throw new SecurityGroupDirectionInvalid(); + } + + switch (direction) { + case "ingress": + return SecurityGroup.SecurityGroupConfiguration.Direction.INGRESS; + case "egress": + return SecurityGroup.SecurityGroupConfiguration.Direction.EGRESS; + } + + throw new SecurityGroupDirectionInvalid(); + } + + private Common.EtherType transformEtherType(String etherType) throws Exception { + if (StringUtils.isEmpty(etherType)) { + return Common.EtherType.IPV4; + } + + switch (etherType) { + case "IPv4": + return Common.EtherType.IPV4; + case "IPv6": + return Common.EtherType.IPV6; + } + + throw new SecurityGroupEtherTypeInvalid(); + } + + private Common.Protocol transformProtocol(String protocol) throws Exception { + if (StringUtils.isEmpty(protocol)) { + throw new SecurityGroupProtocolInvalid(); + } + + switch (protocol) { + case "tcp": + return Common.Protocol.TCP; + case "udp": + return Common.Protocol.UDP; + case "icmp": + return Common.Protocol.ICMP; + case "http": + return Common.Protocol.HTTP; + } + + throw new SecurityGroupProtocolInvalid(); + } + + public SecurityGroup.SecurityGroupConfiguration.SecurityGroupRule buildSecurityGroupGoalState(SecurityGroupRule securityGroupRule) throws Exception { + SecurityGroup.SecurityGroupConfiguration.SecurityGroupRule.Builder securityGroupRuleBuilder = SecurityGroup.SecurityGroupConfiguration.SecurityGroupRule.newBuilder(); + + securityGroupRuleBuilder.setSecurityGroupId(securityGroupRule.getId()); + securityGroupRuleBuilder.setOperationType(Common.OperationType.CREATE); + securityGroupRuleBuilder.setId(securityGroupRule.getId()); + securityGroupRuleBuilder.setDirection(transformDirection(securityGroupRule.getDirection())); + securityGroupRuleBuilder.setEthertype(transformEtherType(securityGroupRule.getEtherType())); + + if (securityGroupRule.getProtocol() != null) { + securityGroupRuleBuilder.setProtocol(transformProtocol(securityGroupRule.getProtocol())); + } + + if (securityGroupRule.getPortRangeMin() != null) { + securityGroupRuleBuilder.setPortRangeMin(securityGroupRule.getPortRangeMin()); + } + + if (securityGroupRule.getPortRangeMax() != null) { + securityGroupRuleBuilder.setPortRangeMax(securityGroupRule.getPortRangeMax()); + } + + if (securityGroupRule.getRemoteIpPrefix() != null) { + securityGroupRuleBuilder.setRemoteIpPrefix(securityGroupRule.getRemoteIpPrefix()); + } + + if (securityGroupRule.getRemoteGroupId() != null) { + securityGroupRuleBuilder.setRemoteGroupId(securityGroupRule.getRemoteGroupId()); + } + return securityGroupRuleBuilder.build(); + } + + + @Override + public void updateSecurityGroupRule(SecurityGroupRuleJson securityGroupRuleJson) throws Exception { + SecurityGroup.SecurityGroupState.Builder securityGroupStateBuilder = SecurityGroup.SecurityGroupState.newBuilder(); + SecurityGroup.SecurityGroupConfiguration.Builder securityGroupConfigurationBuilder = SecurityGroup.SecurityGroupConfiguration.newBuilder(); + List securityGroupRules = new ArrayList<>(); + securityGroupRules.add(buildSecurityGroupGoalState(securityGroupRuleJson.getSecurityGroupRule())); + securityGroupConfigurationBuilder.addAllSecurityGroupRules(securityGroupRules); + securityGroupStateBuilder.setConfiguration(securityGroupConfigurationBuilder); + + grpcDataPlaneClient.sendGoalStates(securityGroupStateBuilder.build()); + securityGroupRepository.addSecurityGroupRule(securityGroupRuleJson); + + } @Override - public void updateSecurityGroupRules(List securityGroupRuleList) throws Exception { - securityGroupRepository.addSecurityGroupRules(securityGroupRuleList); + public void updateSecurityGroupRules(SecurityGroupRuleBulkJson securityGroupRuleBulkJson) throws Exception { + SecurityGroup.SecurityGroupState.Builder securityGroupStateBuilder = SecurityGroup.SecurityGroupState.newBuilder(); + SecurityGroup.SecurityGroupConfiguration.Builder securityGroupConfigurationBuilder = SecurityGroup.SecurityGroupConfiguration.newBuilder(); + List securityGroupRules = new ArrayList<>(); + for (var securityGroupRule : securityGroupRuleBulkJson.getSecurityGroupRules()) { + securityGroupRules.add(buildSecurityGroupGoalState(securityGroupRule)); + } + securityGroupConfigurationBuilder.addAllSecurityGroupRules(securityGroupRules); + securityGroupStateBuilder.setConfiguration(securityGroupConfigurationBuilder); + + grpcDataPlaneClient.sendGoalStates(securityGroupStateBuilder.build()); + securityGroupRepository.addSecurityGroupRules(securityGroupRuleBulkJson); } @Override @@ -66,7 +184,7 @@ public Collection getPortBindingSecurityGroupBySecurit } @Override - public Collection getPortBindingSecurityGroupByPortId(String portId) { - return null; + public Collection getPortBindingSecurityGroupByPortId(String portId) throws CacheException { + return portBindingSecurityGroupRepository.getPortBindingSecurityGroupByPortId(portId); } } diff --git a/services/security_group_manager/pom.xml b/services/security_group_manager/pom.xml index 6ad41ec06..5ff914b08 100644 --- a/services/security_group_manager/pom.xml +++ b/services/security_group_manager/pom.xml @@ -107,6 +107,11 @@ Copyright(c) 2020 Futurewei Cloud 0.1.0-SNAPSHOT compile + + org.asynchttpclient + async-http-client + 2.12.3 + diff --git a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupRuleServiceImpl.java b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupRuleServiceImpl.java index b35508991..e553ced54 100644 --- a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupRuleServiceImpl.java +++ b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupRuleServiceImpl.java @@ -15,6 +15,7 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.securitygroup.service.implement; +import com.fasterxml.jackson.databind.ObjectMapper; import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.securitygroup.exception.RemoteSecurityGroupNotFound; import com.futurewei.alcor.securitygroup.exception.SecurityGroupNotFound; @@ -22,15 +23,19 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.securitygroup.repo.SecurityGroupRepository; import com.futurewei.alcor.securitygroup.service.SecurityGroupRuleService; import com.futurewei.alcor.web.entity.securitygroup.*; +import org.asynchttpclient.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.Executors; @Service public class SecurityGroupRuleServiceImpl implements SecurityGroupRuleService { @@ -39,6 +44,14 @@ public class SecurityGroupRuleServiceImpl implements SecurityGroupRuleService { @Autowired SecurityGroupRepository securityGroupRepository; + @Autowired + ObjectMapper objectMapper; + + @Value("${microservices.dataplane.service.url:#{\"\"}}") + private String dataplaneManagerUrl; + + + @Override @DurationStatistics public SecurityGroupRuleJson createSecurityGroupRule(SecurityGroupRuleJson securityGroupRuleJson) throws Exception { @@ -61,8 +74,24 @@ public SecurityGroupRuleJson createSecurityGroupRule(SecurityGroupRuleJson secur securityGroupRule.setId(UUID.randomUUID().toString()); } - securityGroupRepository.addSecurityGroupRule(securityGroup, securityGroupRule); + AsyncHttpClient client = Dsl.asyncHttpClient(); + var request = Dsl.post(dataplaneManagerUrl).setBody(objectMapper.writeValueAsString(securityGroupRuleJson)).setHeader("Content-Type", "application/json"); + + ListenableFuture listenableFuture = client + .executeRequest(request); + listenableFuture.addListener(() -> { + Response response = null; + try { + response = listenableFuture.get(); + if (response.getStatusCode() == HttpServletResponse.SC_CREATED) { + securityGroupRepository.addSecurityGroupRule(securityGroup, securityGroupRule); + } + + } catch (Exception e) { + e.printStackTrace(); + } + }, Executors.newCachedThreadPool()); LOG.info("Create security group rule success, securityGroupRuleJson: {}", securityGroupRuleJson); return securityGroupRuleJson; @@ -86,7 +115,24 @@ public SecurityGroupRuleBulkJson createSecurityGroupRuleBulk(SecurityGroupRuleBu } } - securityGroupRepository.addSecurityGroupRuleBulk(securityGroupRules); + AsyncHttpClient client = Dsl.asyncHttpClient(); + + var request = Dsl.post(dataplaneManagerUrl).setBody(objectMapper.writeValueAsString(securityGroupRuleBulkJson)).setHeader("Content-Type", "application/json"); + + ListenableFuture listenableFuture = client + .executeRequest(request); + listenableFuture.addListener(() -> { + Response response = null; + try { + response = listenableFuture.get(); + if (response.getStatusCode() == HttpServletResponse.SC_CREATED) { + securityGroupRepository.addSecurityGroupRuleBulk(securityGroupRules); + } + + } catch (Exception e) { + e.printStackTrace(); + } + }, Executors.newCachedThreadPool()); LOG.info("Create security group rule bulk success, securityGroupRuleBulkJson: {}", securityGroupRuleBulkJson); @@ -107,7 +153,26 @@ public void deleteSecurityGroupRule(String securityGroupRuleId) throws Exception throw new SecurityGroupRuleNotFound(); } - securityGroupRepository.deleteSecurityGroupRule(securityGroupRule); + AsyncHttpClient client = Dsl.asyncHttpClient(); + Param param = new Param("resource_id", securityGroupRuleId); + List params = new ArrayList<>(); + params.add(param); + var request = Dsl.delete(dataplaneManagerUrl).setQueryParams(params).setHeader("Content-Type", "application/json"); + + ListenableFuture listenableFuture = client + .executeRequest(request); + listenableFuture.addListener(() -> { + Response response = null; + try { + response = listenableFuture.get(); + if (response.getStatusCode() == HttpServletResponse.SC_CREATED) { + securityGroupRepository.deleteSecurityGroupRule(securityGroupRule); + } + + } catch (Exception e) { + e.printStackTrace(); + } + }, Executors.newCachedThreadPool()); LOG.info("Delete security group rule success, securityGroupRuleId: {}", securityGroupRuleId); } diff --git a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java index 91c681504..f7c944b15 100644 --- a/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java +++ b/services/security_group_manager/src/main/java/com/futurewei/alcor/securitygroup/service/implement/SecurityGroupServiceImpl.java @@ -15,6 +15,8 @@ free of charge, to any person obtaining a copy of this software and associated d */ package com.futurewei.alcor.securitygroup.service.implement; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.futurewei.alcor.common.stats.DurationStatistics; import com.futurewei.alcor.securitygroup.exception.*; import com.futurewei.alcor.securitygroup.repo.PortBindingSecurityGroupRepository; @@ -23,12 +25,19 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.securitygroup.utils.TimeUtil; import com.futurewei.alcor.web.entity.securitygroup.PortBindingSecurityGroupsJson; import com.futurewei.alcor.web.entity.securitygroup.*; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Dsl; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; import java.util.*; +import java.util.concurrent.Executors; @Service public class SecurityGroupServiceImpl implements SecurityGroupService { @@ -40,11 +49,17 @@ public class SecurityGroupServiceImpl implements SecurityGroupService { @Autowired private PortBindingSecurityGroupRepository portBindingSecurityGroupRepository; + @Autowired + ObjectMapper objectMapper; + + @Value("${microservices.dataplane.service.url:#{\"\"}}") + private String dataplaneManagerUrl; + private boolean isDefaultSecurityGroup(SecurityGroup securityGroup) { return "default".equals(securityGroup.getName()); } - private void createDefaultSecurityGroupRules(SecurityGroup securityGroup, SecurityGroupRule.Direction direction) { + private void createDefaultSecurityGroupRules(SecurityGroup securityGroup, SecurityGroupRule.Direction direction) throws JsonProcessingException { List securityGroupRules = new ArrayList<>(); List etherTypes = Arrays.asList(SecurityGroupRule.EtherType.IPV4, SecurityGroupRule.EtherType.IPV6); @@ -60,7 +75,28 @@ private void createDefaultSecurityGroupRules(SecurityGroup securityGroup, Securi securityGroupRules.add(securityGroupRule); } - securityGroup.getSecurityGroupRules().addAll(securityGroupRules); + SecurityGroupRuleBulkJson securityGroupRuleJson = new SecurityGroupRuleBulkJson(securityGroupRules); + + AsyncHttpClient client = Dsl.asyncHttpClient(); + + var request = Dsl.post(dataplaneManagerUrl).setBody(objectMapper.writeValueAsString(securityGroupRuleJson)).setHeader("Content-Type", "application/json"); + + ListenableFuture listenableFuture = client + .executeRequest(request); + listenableFuture.addListener(() -> { + Response response = null; + try { + response = listenableFuture.get(); + if (response.getStatusCode() == HttpServletResponse.SC_CREATED) { + securityGroup.getSecurityGroupRules().addAll(securityGroupRules); + } + + } catch (Exception e) { + e.printStackTrace(); + } + }, Executors.newCachedThreadPool()); + + } private void createDefaultSecurityGroup(String tenantId, String projectId, String description) throws Exception { @@ -70,6 +106,7 @@ private void createDefaultSecurityGroup(String tenantId, String projectId, Strin defaultSecurityGroup.setProjectId(projectId); defaultSecurityGroup.setDescription(description); defaultSecurityGroup.setName("default"); + defaultSecurityGroup.setSecurityGroupRules(new ArrayList<>()); //Create default security group rules createDefaultSecurityGroupRules(defaultSecurityGroup, SecurityGroupRule.Direction.INGRESS); diff --git a/services/security_group_manager/src/main/resources/application.properties b/services/security_group_manager/src/main/resources/application.properties index 8f393b36a..5dc22ec9d 100644 --- a/services/security_group_manager/src/main/resources/application.properties +++ b/services/security_group_manager/src/main/resources/application.properties @@ -34,6 +34,7 @@ ignite.thin.client.enable=true #####Spring health##### management.health.redis.enabled=false +microservices.dataplane.service.url=http://localhost:9010/securitygrouprules #####Rbac##### rbac.policy.type=Enforced diff --git a/web/src/main/java/com/futurewei/alcor/web/entity/securitygroup/SecurityGroupRuleJson.java b/web/src/main/java/com/futurewei/alcor/web/entity/securitygroup/SecurityGroupRuleJson.java index 793a1a9dc..ab217b988 100644 --- a/web/src/main/java/com/futurewei/alcor/web/entity/securitygroup/SecurityGroupRuleJson.java +++ b/web/src/main/java/com/futurewei/alcor/web/entity/securitygroup/SecurityGroupRuleJson.java @@ -17,7 +17,11 @@ free of charge, to any person obtaining a copy of this software and associated d import com.fasterxml.jackson.annotation.JsonProperty; -public class SecurityGroupRuleJson { +import java.io.Serializable; + +public class SecurityGroupRuleJson implements Serializable { + private static final long serialVersionUID = 1234567L; + @JsonProperty("security_group_rule") private SecurityGroupRule securityGroupRule; From 35dec66876c700049e61cfae0cf6035cc6084d74 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 30 Jan 2023 10:12:36 -0800 Subject: [PATCH 52/54] Update code --- .../alcor/securitygroup/controller/SecurityGroupTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/security_group_manager/src/test/java/com/futurewei/alcor/securitygroup/controller/SecurityGroupTest.java b/services/security_group_manager/src/test/java/com/futurewei/alcor/securitygroup/controller/SecurityGroupTest.java index 5245e65b2..7cdaf67ce 100644 --- a/services/security_group_manager/src/test/java/com/futurewei/alcor/securitygroup/controller/SecurityGroupTest.java +++ b/services/security_group_manager/src/test/java/com/futurewei/alcor/securitygroup/controller/SecurityGroupTest.java @@ -76,6 +76,8 @@ public void Test02_createSecurityGroupTest() throws Exception { securityGroup.setProjectId(UnitTestConfig.projectId); securityGroup.setTenantId(UnitTestConfig.tenantId); securityGroup.setDescription(UnitTestConfig.securityGroupDescription); + List securityGroupRules = new ArrayList<>(); + securityGroup.setSecurityGroupRules(securityGroupRules); SecurityGroupJson securityGroupJson = new SecurityGroupJson(securityGroup); @@ -97,6 +99,8 @@ public void Test03_createSecurityGroupBulkTest() throws Exception { securityGroup1.setProjectId(UnitTestConfig.projectId); securityGroup1.setTenantId(UnitTestConfig.tenantId); securityGroup1.setDescription(UnitTestConfig.securityGroupDescription); + List securityGroupRules = new ArrayList<>(); + securityGroup1.setSecurityGroupRules(securityGroupRules); SecurityGroup securityGroup2 = new SecurityGroup(); securityGroup2.setId(UnitTestConfig.securityGroupId2); @@ -104,6 +108,7 @@ public void Test03_createSecurityGroupBulkTest() throws Exception { securityGroup2.setProjectId(UnitTestConfig.projectId); securityGroup2.setTenantId(UnitTestConfig.tenantId); securityGroup2.setDescription(UnitTestConfig.securityGroupDescription2); + securityGroup2.setSecurityGroupRules(securityGroupRules); List securityGroups = new ArrayList<>(); securityGroups.add(securityGroup1); From 238ceeeaecede4c9312f1652edb656931be55a56 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 30 Jan 2023 10:34:16 -0800 Subject: [PATCH 53/54] Update code --- .../alcor/dataplane/client/kafka/DataPlaneClientImpl.java | 6 ++++++ .../alcor/dataplane/client/kafka/DataPlaneClientImplV2.java | 6 ++++++ .../client/pulsar/group_node_mode/DataPlaneClientImpl.java | 6 ++++++ .../pulsar/group_node_mode/DataPlaneClientImplV2.java | 6 ++++++ .../client/pulsar/vpc_mode/DataPlaneClientImpl.java | 6 ++++++ .../client/pulsar/vpc_mode/DataPlaneClientImplV2.java | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImpl.java index dd49a0646..358f099a2 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImpl.java @@ -22,6 +22,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; import com.futurewei.alcor.schema.Goalstate; import com.futurewei.alcor.schema.Goalstateprovisioner; +import com.futurewei.alcor.schema.SecurityGroup; import java.util.List; import java.util.Map; @@ -37,4 +38,9 @@ public List sendGoalStates(List unicastGoalStates) thr public List sendGoalStates(List unicastGoalStates, MulticastGoalState multicastGoalState) throws Exception { return null; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImplV2.java index 33cb09267..bcc959eb5 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/kafka/DataPlaneClientImplV2.java @@ -21,6 +21,7 @@ import com.futurewei.alcor.dataplane.client.DataPlaneClient; import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.schema.SecurityGroup; import java.util.List; @@ -34,4 +35,9 @@ public List sendGoalStates(List unicastGoalStates) t public List sendGoalStates(List unicastGoalStates, MulticastGoalStateV2 multicastGoalState) throws Exception { return null; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImpl.java index fa762a124..f65579c26 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImpl.java @@ -21,6 +21,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.dataplane.entity.UnicastGoalState; import com.futurewei.alcor.dataplane.exception.GroupTopicNotFound; import com.futurewei.alcor.dataplane.exception.MulticastTopicNotFound; +import com.futurewei.alcor.schema.SecurityGroup; import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.dataplane.UnicastGoalStateByte; import org.apache.pulsar.client.api.Producer; @@ -152,4 +153,9 @@ public List sendGoalStates(List unicastGoalStates, Mul return failedHosts; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImplV2.java index 946788659..700eab0c8 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/group_node_mode/DataPlaneClientImplV2.java @@ -20,6 +20,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.dataplane.entity.*; import com.futurewei.alcor.dataplane.exception.GroupTopicNotFound; import com.futurewei.alcor.dataplane.exception.MulticastTopicNotFound; +import com.futurewei.alcor.schema.SecurityGroup; import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.dataplane.UnicastGoalStateByte; import org.apache.pulsar.client.api.Producer; @@ -159,4 +160,9 @@ public List sendGoalStates(List unicastGoalStates, M return failedHosts; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImpl.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImpl.java index 99c493d92..b577076da 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImpl.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImpl.java @@ -19,6 +19,7 @@ free of charge, to any person obtaining a copy of this software and associated d import com.futurewei.alcor.dataplane.client.DataPlaneClient; import com.futurewei.alcor.dataplane.entity.MulticastGoalState; import com.futurewei.alcor.dataplane.entity.UnicastGoalState; +import com.futurewei.alcor.schema.SecurityGroup; import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.dataplane.UnicastGoalStateByte; import com.futurewei.alcor.web.entity.topic.VpcTopicInfo; @@ -129,4 +130,9 @@ public List sendGoalStates(List unicastGoalStates, Mul return failedHosts; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } \ No newline at end of file diff --git a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImplV2.java b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImplV2.java index a287f3e33..a3f7fbe4a 100644 --- a/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImplV2.java +++ b/services/data_plane_manager/src/main/java/com/futurewei/alcor/dataplane/client/pulsar/vpc_mode/DataPlaneClientImplV2.java @@ -21,6 +21,7 @@ import com.futurewei.alcor.dataplane.client.DataPlaneClient; import com.futurewei.alcor.dataplane.entity.MulticastGoalStateV2; import com.futurewei.alcor.dataplane.entity.UnicastGoalStateV2; +import com.futurewei.alcor.schema.SecurityGroup; import com.futurewei.alcor.schema.Subscribeinfoprovisioner.NodeSubscribeInfo; import com.futurewei.alcor.web.entity.dataplane.MulticastGoalStateByte; import com.futurewei.alcor.web.entity.topic.VpcTopicInfo; @@ -137,4 +138,9 @@ public List sendGoalStates(List unicastGoalStates, M return failedHosts; } + + @Override + public List sendGoalStates(SecurityGroup.SecurityGroupState securityGroupState) throws Exception { + return null; + } } From 0be7cb2dd54bfdd384cec601f902c3e9ffc7d6a8 Mon Sep 17 00:00:00 2001 From: Dahai Liu Date: Mon, 30 Jan 2023 10:56:50 -0800 Subject: [PATCH 54/54] Update code --- .../futurewei/alcor/pseudo_controller/ncm_test/ncm_test.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/pseudo_controller/src/main/java/com/futurewei/alcor/pseudo_controller/ncm_test/ncm_test.java b/services/pseudo_controller/src/main/java/com/futurewei/alcor/pseudo_controller/ncm_test/ncm_test.java index fe5f23902..935db6d8a 100644 --- a/services/pseudo_controller/src/main/java/com/futurewei/alcor/pseudo_controller/ncm_test/ncm_test.java +++ b/services/pseudo_controller/src/main/java/com/futurewei/alcor/pseudo_controller/ncm_test/ncm_test.java @@ -242,7 +242,7 @@ public void run_test_against_ncm() { ); // a new Goalstate and its builder for Arion master; should have only neigbhor states. - Goalstateprovisioner.NeighborRulesRequest.Builder arion_neighbor_rule_request_builder = Goalstateprovisioner.NeighborRulesRequest.newBuilder(); + Goalstateprovisioner.ArionGoalStateRequest.Builder arion_neighbor_rule_request_builder = Goalstateprovisioner.ArionGoalStateRequest.newBuilder(); arion_neighbor_rule_request_builder.setFormatVersion(1); arion_neighbor_rule_request_builder.setRequestId("arion_routing_rule-" + (System.currentTimeMillis() / 1000L)); @@ -458,7 +458,7 @@ public void run_test_against_ncm() { } // build the GroutingRuleRequest, to be sent to Arion Master - Goalstateprovisioner.NeighborRulesRequest arion_neighbor_state_request = arion_neighbor_rule_request_builder.build(); + Goalstateprovisioner.ArionGoalStateRequest arion_neighbor_state_request = arion_neighbor_rule_request_builder.build(); compute_node_ips.forEach(ip -> {