Search in sources :

Example 1 with SniNettyRouteSource

use of org.infinispan.server.router.routes.hotrod.SniNettyRouteSource in project infinispan by infinispan.

the class ProtocolServerEndpointRouterTest method shouldRouteToProperHotRodServerBasedOnSniHostName.

/**
 * In this scenario we create 2 HotRod servers, each one with different credentials and SNI name. We also create a
 * new client for each server. The clients use proper TrustStores as well as SNI names.
 * <p>
 * The router should match properly SNI based routes and connect clients to proper server instances.
 */
@Test
public void shouldRouteToProperHotRodServerBasedOnSniHostName() {
    // given
    hotrodServer1 = HotRodTestingUtil.startHotRodServerWithoutTransport("default");
    hotrodServer2 = HotRodTestingUtil.startHotRodServerWithoutTransport("default");
    HotRodServerRouteDestination hotrod1Destination = new HotRodServerRouteDestination("HotRod1", hotrodServer1);
    SniNettyRouteSource hotrod1Source = new SniNettyRouteSource("hotrod1", KEYSTORE_LOCATION_FOR_HOTROD_1, "secret".toCharArray());
    Route<SniNettyRouteSource, HotRodServerRouteDestination> routeToHotrod1 = new Route<>(hotrod1Source, hotrod1Destination);
    HotRodServerRouteDestination hotrod2Destination = new HotRodServerRouteDestination("HotRod2", hotrodServer2);
    SniNettyRouteSource hotrod2Source = new SniNettyRouteSource("hotrod2", KEYSTORE_LOCATION_FOR_HOTROD_2, "secret".toCharArray());
    Route<SniNettyRouteSource, HotRodServerRouteDestination> routeToHotrod2 = new Route<>(hotrod2Source, hotrod2Destination);
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.hotrod().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToHotrod1).add(routeToHotrod2);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    InetAddress routerIp = router.getRouter(EndpointRouter.Protocol.HOT_ROD).get().getIp();
    int routerPort = router.getRouter(EndpointRouter.Protocol.HOT_ROD).get().getPort();
    // when
    hotrod1Client = HotRodClientTestingUtil.createWithSni(routerIp, routerPort, "hotrod1", TRUSTSTORE_LOCATION_FOR_HOTROD_1, "secret".toCharArray());
    hotrod2Client = HotRodClientTestingUtil.createWithSni(routerIp, routerPort, "hotrod2", TRUSTSTORE_LOCATION_FOR_HOTROD_2, "secret".toCharArray());
    hotrod1Client.getCache("default").put("test", "hotrod1");
    hotrod2Client.getCache("default").put("test", "hotrod2");
    // then
    Cache<String, String> hotrod1Cache = hotrodServer1.getCacheManager().getCache("default");
    Cache<String, String> hotrod2Cache = hotrodServer2.getCacheManager().getCache("default");
    assertThat(hotrod1Cache.size()).isEqualTo(1);
    assertThat(hotrod2Cache.size()).isEqualTo(1);
    assertThat(hotrod1Cache.get("test")).isEqualTo("hotrod1");
    assertThat(hotrod2Cache.get("test")).isEqualTo("hotrod2");
}
Also used : SniNettyRouteSource(org.infinispan.server.router.routes.hotrod.SniNettyRouteSource) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) InetAddress(java.net.InetAddress) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Example 2 with SniNettyRouteSource

use of org.infinispan.server.router.routes.hotrod.SniNettyRouteSource in project infinispan by infinispan.

the class TwoServersWithSslSni method initRoutes.

@Override
public Optional<Set<Route<? extends RouteSource, ? extends RouteDestination>>> initRoutes(List<HotRodServer> servers) {
    Set<Route<? extends RouteSource, ? extends RouteDestination>> routes = new HashSet<>();
    HotRodServerRouteDestination hotrod1Destination = new HotRodServerRouteDestination("hotrod1", servers.get(0));
    SniNettyRouteSource hotrod1Source = new SniNettyRouteSource("hotrod1", KEYSTORE_LOCATION_FOR_HOTROD_1, KEYSTORE_PASSWORD);
    routes.add(new Route<>(hotrod1Source, hotrod1Destination));
    HotRodServerRouteDestination hotrod2Destination = new HotRodServerRouteDestination("hotrod2", servers.get(1));
    SniNettyRouteSource hotrod2Source = new SniNettyRouteSource("hotrod2", KEYSTORE_LOCATION_FOR_HOTROD_2, KEYSTORE_PASSWORD);
    routes.add(new Route<>(hotrod2Source, hotrod2Destination));
    return Optional.of(routes);
}
Also used : SniNettyRouteSource(org.infinispan.server.router.routes.hotrod.SniNettyRouteSource) RouteSource(org.infinispan.server.router.routes.RouteSource) SniNettyRouteSource(org.infinispan.server.router.routes.hotrod.SniNettyRouteSource) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) RouteDestination(org.infinispan.server.router.routes.RouteDestination) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) Route(org.infinispan.server.router.routes.Route) HashSet(java.util.HashSet)

Aggregations

Route (org.infinispan.server.router.routes.Route)2 HotRodServerRouteDestination (org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination)2 SniNettyRouteSource (org.infinispan.server.router.routes.hotrod.SniNettyRouteSource)2 InetAddress (java.net.InetAddress)1 HashSet (java.util.HashSet)1 Router (org.infinispan.server.router.Router)1 RouterConfigurationBuilder (org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder)1 EndpointRouter (org.infinispan.server.router.router.EndpointRouter)1 RouteDestination (org.infinispan.server.router.routes.RouteDestination)1 RouteSource (org.infinispan.server.router.routes.RouteSource)1 Test (org.junit.Test)1