Search in sources :

Example 1 with RouterConfigurationBuilder

use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.

the class ConfigurationTest method shouldBuildProperRouterConfiguration.

@Test
public void shouldBuildProperRouterConfiguration() {
    // given
    RouterConfigurationBuilder multiTenantConfigurationBuilder = new RouterConfigurationBuilder();
    RouteSource s1 = new RouteSource() {
    };
    RouteDestination d1 = () -> null;
    // when
    multiTenantConfigurationBuilder.hotrod().tcpKeepAlive(true).receiveBufferSize(1).sendBufferSize(1).tcpNoDelay(false).port(1010).ip(InetAddress.getLoopbackAddress()).rest().port(1111).ip(InetAddress.getLoopbackAddress()).routing().add(new Route(s1, d1));
    RouterConfiguration routerConfiguration = multiTenantConfigurationBuilder.build();
    HotRodRouterConfiguration hotRodRouterConfiguration = routerConfiguration.hotRodRouter();
    RestRouterConfiguration restRouterConfiguration = routerConfiguration.restRouter();
    // then
    assertThat(hotRodRouterConfiguration.getPort()).isEqualTo(1010);
    assertThat(hotRodRouterConfiguration.getIp()).isEqualTo(InetAddress.getLoopbackAddress());
    assertThat(hotRodRouterConfiguration.tcpKeepAlive()).isTrue();
    assertThat(hotRodRouterConfiguration.tcpNoDelay()).isFalse();
    assertThat(hotRodRouterConfiguration.sendBufferSize()).isEqualTo(1);
    assertThat(hotRodRouterConfiguration.receiveBufferSize()).isEqualTo(1);
    assertThat(restRouterConfiguration.getPort()).isEqualTo(1111);
    assertThat(restRouterConfiguration.getIp()).isEqualTo(InetAddress.getLoopbackAddress());
    assertThat(routerConfiguration.routingTable().routesCount()).isEqualTo(1);
}
Also used : RouteSource(org.infinispan.server.router.routes.RouteSource) RouteDestination(org.infinispan.server.router.routes.RouteDestination) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Example 2 with RouterConfigurationBuilder

use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder 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 3 with RouterConfigurationBuilder

use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.

the class RestEndpointRouterTest method shouldRouteToProperRestServerBasedOnPath.

/**
 * In this scenario we create 2 REST servers, each one with different REST Path: <ul> <li>REST1 -
 * http://127.0.0.1:8080/rest/rest1</li> <li>REST2 - http://127.0.0.1:8080/rest/rest2</li> </ul>
 * <p>
 * The router should match requests based on path and redirect them to proper server.
 */
@Test
public void shouldRouteToProperRestServerBasedOnPath() {
    // given
    restServer1 = RestTestingUtil.createDefaultRestServer("rest1", "default");
    restServer2 = RestTestingUtil.createDefaultRestServer("rest2", "default");
    RestServerRouteDestination rest1Destination = new RestServerRouteDestination("rest1", restServer1);
    RestRouteSource rest1Source = new RestRouteSource("rest1");
    Route<RestRouteSource, RestServerRouteDestination> routeToRest1 = new Route<>(rest1Source, rest1Destination);
    RestServerRouteDestination rest2Destination = new RestServerRouteDestination("rest2", restServer2);
    RestRouteSource rest2Source = new RestRouteSource("rest2");
    Route<RestRouteSource, RestServerRouteDestination> routeToRest2 = new Route<>(rest2Source, rest2Destination);
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.rest().port(8080).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest1).add(routeToRest2);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    int port = router.getRouter(EndpointRouter.Protocol.REST).get().getPort();
    // when
    ServerConfigurationBuilder builder = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(port);
    restClient = RestClient.forConfiguration(builder.build());
    RestRawClient rawClient = restClient.raw();
    String path1 = "/rest/rest1/v2/caches/default/test";
    String path2 = "/rest/rest2/v2/caches/default/test";
    join(rawClient.putValue(path1, emptyMap(), "rest1", TEXT_PLAIN_TYPE));
    join(rawClient.putValue(path2, emptyMap(), "rest2", TEXT_PLAIN_TYPE));
    String valueReturnedFromRest1 = join(rawClient.get(path1)).getBody();
    String valueReturnedFromRest2 = join(rawClient.get(path2)).getBody();
    // then
    assertThat(valueReturnedFromRest1).isEqualTo("rest1");
    assertThat(valueReturnedFromRest2).isEqualTo("rest2");
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestRawClient(org.infinispan.client.rest.RestRawClient) RestRouteSource(org.infinispan.server.router.routes.rest.RestRouteSource) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) ServerConfigurationBuilder(org.infinispan.client.rest.configuration.ServerConfigurationBuilder) Test(org.junit.Test)

Example 4 with RouterConfigurationBuilder

use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.

the class SinglePortTest method shouldUpgradeThroughALPN.

@Test
public void shouldUpgradeThroughALPN() throws Exception {
    checkForOpenSSL();
    // given
    restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
    RestServerRouteDestination restDestination = new RestServerRouteDestination("rest", restServer);
    SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
    Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
    SslContextFactory sslContextFactory = new SslContextFactory();
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.singlePort().sslContext(sslContextFactory.keyStoreFileName(KEY_STORE_PATH).keyStorePassword(KEY_STORE_PASSWORD.toCharArray()).getContext()).port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    EndpointRouter singlePortRouter = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get();
    // when
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(singlePortRouter.getHost()).port(singlePortRouter.getPort()).protocol(Protocol.HTTP_20).security().ssl().trustStoreFileName(TRUST_STORE_PATH).trustStorePassword("secret".toCharArray()).hostnameVerifier((hostname, session) -> true);
    httpClient = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
    // then
    ResponseAssertion.assertThat(response).hasNoContent();
}
Also used : SslContextFactory(org.infinispan.commons.util.SslContextFactory) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestResponse(org.infinispan.client.rest.RestResponse) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Example 5 with RouterConfigurationBuilder

use of org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder in project infinispan by infinispan.

the class SinglePortTest method shouldUpgradeThroughHTTP11UpgradeHeaders.

@Test
public void shouldUpgradeThroughHTTP11UpgradeHeaders() {
    // given
    restServer = RestTestingUtil.createDefaultRestServer("rest", "default");
    RestServerRouteDestination restDestination = new RestServerRouteDestination("rest1", restServer);
    SinglePortRouteSource singlePortSource = new SinglePortRouteSource();
    Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination);
    RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder();
    routerConfigurationBuilder.singlePort().port(0).ip(InetAddress.getLoopbackAddress()).routing().add(routeToRest);
    router = new Router(routerConfigurationBuilder.build());
    router.start();
    int port = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get().getPort();
    // when
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host("localhost").port(port).protocol(Protocol.HTTP_20);
    httpClient = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = httpClient.cache("default").post("test", VALUE);
    // then
    ResponseAssertion.assertThat(response).hasNoContent();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) RestResponse(org.infinispan.client.rest.RestResponse) Router(org.infinispan.server.router.Router) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) RouterConfigurationBuilder(org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder) Route(org.infinispan.server.router.routes.Route) Test(org.junit.Test)

Aggregations

RouterConfigurationBuilder (org.infinispan.server.router.configuration.builder.RouterConfigurationBuilder)8 Router (org.infinispan.server.router.Router)7 EndpointRouter (org.infinispan.server.router.router.EndpointRouter)7 Route (org.infinispan.server.router.routes.Route)7 Test (org.junit.Test)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)5 RestServerRouteDestination (org.infinispan.server.router.routes.rest.RestServerRouteDestination)5 SinglePortRouteSource (org.infinispan.server.router.routes.singleport.SinglePortRouteSource)4 RestResponse (org.infinispan.client.rest.RestResponse)3 HotRodServerRouteDestination (org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination)3 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)2 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)2 SslContextFactory (org.infinispan.commons.util.SslContextFactory)2 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)2 HotRodServerConfigurationBuilder (org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder)2 InetAddress (java.net.InetAddress)1 RestRawClient (org.infinispan.client.rest.RestRawClient)1 ServerConfigurationBuilder (org.infinispan.client.rest.configuration.ServerConfigurationBuilder)1 UTF8StringMarshaller (org.infinispan.commons.marshall.UTF8StringMarshaller)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1