@Test public void testApplyVpnUsers() { vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr; final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class); final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class); networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology); networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology); networkTopologyContext.init(); final Vpc vpc = Mockito.mock(Vpc.class); final Zone zone = Mockito.mock(Zone.class); final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class); final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class); final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class); final VpnUser vpnUser1 = Mockito.mock(VpnUser.class); final VpnUser vpnUser2 = Mockito.mock(VpnUser.class); final List<VpnUser> users = new ArrayList<>(); users.add(vpnUser1); users.add(vpnUser2); final List<DomainRouterVO> routers = new ArrayList<>(); routers.add(domainRouterVO1); routers.add(domainRouterVO2); final Long vpcId = new Long(1l); final Long zoneId = new Long(1l); when(remoteAccessVpn.getVpcId()).thenReturn(vpcId); when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers); when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc); when(vpc.getZoneId()).thenReturn(zoneId); when(zoneRepository.findById(zoneId)).thenReturn(Optional.of(zone)); when(networkTopologyContext.retrieveNetworkTopology(zone)).thenReturn(advancedNetworkTopology); try { when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[]{"user1", "user2"}); when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[]{"user3", "user4"}); } catch (final ResourceUnavailableException e) { fail(e.getMessage()); } try { final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users); assertNotNull(results); assertEquals(results[0], "user1"); assertEquals(results[1], "user2"); assertEquals(results[2], "user3"); assertEquals(results[3], "user4"); } catch (final ResourceUnavailableException e) { fail(e.getMessage()); } verify(remoteAccessVpn, times(1)).getVpcId(); verify(vpc, times(1)).getZoneId(); verify(zoneRepository, times(1)).findById(zoneId); verify(networkTopologyContext, times(1)).retrieveNetworkTopology(zone); }
@Override public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException { final Long vpcId = vpn.getVpcId(); if (vpcId == null) { return null; } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId); if (routers == null) { s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId); return null; } final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone); String[] result; final List<String> combinedResults = new ArrayList<>(); for (final DomainRouterVO domainRouterVO : routers) { result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO); combinedResults.addAll(Arrays.asList(result)); } result = new String[combinedResults.size()]; final Object[] resultCast = combinedResults.toArray(); System.arraycopy(resultCast, 0, result, 0, resultCast.length); return result; }
VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider { @Override public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException { final Long vpcId = vpn.getVpcId(); if (vpcId == null) { return null; } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId); if (routers == null) { s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId); return null; } final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone); String[] result; final List<String> combinedResults = new ArrayList<>(); for (final DomainRouterVO domainRouterVO : routers) { result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO); combinedResults.addAll(Arrays.asList(result)); } result = new String[combinedResults.size()]; final Object[] resultCast = combinedResults.toArray(); System.arraycopy(resultCast, 0, result, 0, resultCast.length); return result; } }
VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider { @Override public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException { final Long vpcId = vpn.getVpcId(); if (vpcId == null) { return null; } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId); if (routers == null) { s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId); return null; } final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone); String[] result; final List<String> combinedResults = new ArrayList<>(); for (final DomainRouterVO domainRouterVO : routers) { result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO); combinedResults.addAll(Arrays.asList(result)); } result = new String[combinedResults.size()]; final Object[] resultCast = combinedResults.toArray(); System.arraycopy(resultCast, 0, result, 0, resultCast.length); return result; }  }
VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider { @Override public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException { final Long vpcId = vpn.getVpcId(); if (vpcId == null) { return null; } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId); if (routers == null) { s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId); return null; } final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone); String[] result; final List<String> combinedResults = new ArrayList<>(); for (final DomainRouterVO domainRouterVO : routers) { result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO); combinedResults.addAll(Arrays.asList(result)); } result = new String[combinedResults.size()]; final Object[] resultCast = combinedResults.toArray(); System.arraycopy(resultCast, 0, result, 0, resultCast.length); return result; }  @Override boolean implementVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context); @Override boolean shutdownVpc(final Vpc vpc, final ReservationContext context); @Override boolean createPrivateGateway(final PrivateGateway gateway); @Override boolean deletePrivateGateway(final PrivateGateway gateway); @Override boolean applyStaticRoutes(final Vpc vpc, final List<StaticRouteProfile> routes); @Override boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List<? extends NetworkACLItem> rules); @Override boolean applyACLItemsToPublicIp(final IpAddress publicIp, final List<? extends NetworkACLItem> rules); @Override boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules); @Override Map<Service, Map<Capability, String>> getCapabilities(); @Override boolean startSite2SiteVpn(final Site2SiteVpnConnection conn); @Override boolean refreshSite2SiteVpn(final Site2SiteVpnConnection conn); @Override Provider getProvider(); @Override boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn); @Override boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup); @Override boolean destroy(final Network config, final ReservationContext context); @Override String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users); @Override boolean startVpn(final RemoteAccessVpn vpn); @Override boolean stopVpn(final RemoteAccessVpn vpn); @Override boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services); }
VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider { @Override public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException { final Long vpcId = vpn.getVpcId(); if (vpcId == null) { return null; } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId); if (routers == null) { s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId); return null; } final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone); String[] result; final List<String> combinedResults = new ArrayList<>(); for (final DomainRouterVO domainRouterVO : routers) { result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO); combinedResults.addAll(Arrays.asList(result)); } result = new String[combinedResults.size()]; final Object[] resultCast = combinedResults.toArray(); System.arraycopy(resultCast, 0, result, 0, resultCast.length); return result; }  @Override boolean implementVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context); @Override boolean shutdownVpc(final Vpc vpc, final ReservationContext context); @Override boolean createPrivateGateway(final PrivateGateway gateway); @Override boolean deletePrivateGateway(final PrivateGateway gateway); @Override boolean applyStaticRoutes(final Vpc vpc, final List<StaticRouteProfile> routes); @Override boolean applyACLItemsToPrivateGw(final PrivateGateway gateway, final List<? extends NetworkACLItem> rules); @Override boolean applyACLItemsToPublicIp(final IpAddress publicIp, final List<? extends NetworkACLItem> rules); @Override boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules); @Override Map<Service, Map<Capability, String>> getCapabilities(); @Override boolean startSite2SiteVpn(final Site2SiteVpnConnection conn); @Override boolean refreshSite2SiteVpn(final Site2SiteVpnConnection conn); @Override Provider getProvider(); @Override boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn); @Override boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context); @Override boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context); @Override boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup); @Override boolean destroy(final Network config, final ReservationContext context); @Override String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users); @Override boolean startVpn(final RemoteAccessVpn vpn); @Override boolean stopVpn(final RemoteAccessVpn vpn); @Override boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services);  }