Search in sources :

Example 1 with CompositeNetworkClientFactory

use of com.github.ambry.network.CompositeNetworkClientFactory in project ambry by linkedin.

the class CloudRouterFactory method getRouter.

/**
 * Construct and return a {@link NonBlockingRouter} that works with cloud storage.
 * @return a {@link NonBlockingRouter}
 */
@Override
public Router getRouter() throws InstantiationException {
    try {
        MetricRegistry registry = clusterMap.getMetricRegistry();
        CloudConfig cloudConfig = new CloudConfig(verifiableProperties);
        CloudDestinationFactory cloudDestinationFactory = Utils.getObj(cloudConfig.cloudDestinationFactoryClass, verifiableProperties, registry, clusterMap);
        CloudDestination cloudDestination = cloudDestinationFactory.getCloudDestination();
        RequestHandlerPool requestHandlerPool = getRequestHandlerPool(verifiableProperties, clusterMap, cloudDestination, cloudConfig);
        CompositeNetworkClientFactory networkClientFactory = getCompositeNetworkClientFactory(requestHandlerPool);
        NonBlockingRouter router = new NonBlockingRouter(routerConfig, routerMetrics, networkClientFactory, notificationSystem, clusterMap, kms, cryptoService, cryptoJobHandler, accountService, time, defaultPartitionClass);
        // Make sure requestHandlerPool is shut down properly
        router.addResourceToClose(requestHandlerPool);
        router.addResourceToClose(cloudDestination);
        logger.info("Instantiated NonBlockingRouter");
        return router;
    } catch (Exception e) {
        logger.error("Error instantiating NonBlocking Router", e);
        throw new InstantiationException("Error instantiating NonBlocking Router: " + e.toString());
    }
}
Also used : CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) CloudDestination(com.github.ambry.cloud.CloudDestination) CloudConfig(com.github.ambry.config.CloudConfig) RequestHandlerPool(com.github.ambry.protocol.RequestHandlerPool) CloudDestinationFactory(com.github.ambry.cloud.CloudDestinationFactory)

Example 2 with CompositeNetworkClientFactory

use of com.github.ambry.network.CompositeNetworkClientFactory in project ambry by linkedin.

the class CloudRouterFactory method getCompositeNetworkClientFactory.

/**
 * @param requestHandlerPool the pool to connect to {@link LocalNetworkClientFactory}.
 * @return a {@link CompositeNetworkClientFactory} that can be used to talk to cloud managed services or ambry server
 *         nodes.
 */
private CompositeNetworkClientFactory getCompositeNetworkClientFactory(RequestHandlerPool requestHandlerPool) {
    NetworkClientFactory cloudNetworkClientFactory = new LocalNetworkClientFactory((LocalRequestResponseChannel) requestHandlerPool.getChannel(), networkConfig, networkMetrics, time);
    NetworkClientFactory diskNetworkClientFactory = null;
    if (routerConfig.routerEnableHttp2NetworkClient) {
        diskNetworkClientFactory = new Http2NetworkClientFactory(http2ClientMetrics, http2ClientConfig, sslFactory, time);
    } else {
        diskNetworkClientFactory = new SocketNetworkClientFactory(networkMetrics, networkConfig, sslFactory, routerConfig.routerScalingUnitMaxConnectionsPerPortPlainText, routerConfig.routerScalingUnitMaxConnectionsPerPortSsl, routerConfig.routerConnectionCheckoutTimeoutMs, time);
    }
    Map<ReplicaType, NetworkClientFactory> childFactories = new EnumMap<>(ReplicaType.class);
    childFactories.put(ReplicaType.CLOUD_BACKED, cloudNetworkClientFactory);
    childFactories.put(ReplicaType.DISK_BACKED, diskNetworkClientFactory);
    return new CompositeNetworkClientFactory(childFactories);
}
Also used : LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) SocketNetworkClientFactory(com.github.ambry.network.SocketNetworkClientFactory) ReplicaType(com.github.ambry.clustermap.ReplicaType) Http2NetworkClientFactory(com.github.ambry.network.http2.Http2NetworkClientFactory) LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) SocketNetworkClientFactory(com.github.ambry.network.SocketNetworkClientFactory) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) Http2NetworkClientFactory(com.github.ambry.network.http2.Http2NetworkClientFactory) EnumMap(java.util.EnumMap)

Example 3 with CompositeNetworkClientFactory

use of com.github.ambry.network.CompositeNetworkClientFactory in project ambry by linkedin.

the class CloudRouterTest method setRouter.

/**
 * Initialize and set the router with the given {@link Properties} and {@link MockServerLayout}
 * @param props the {@link Properties}
 * @param notificationSystem the {@link NotificationSystem} to use.
 */
@Override
protected void setRouter(Properties props, MockServerLayout mockServerLayout, NotificationSystem notificationSystem) throws Exception {
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    RouterConfig routerConfig = new RouterConfig(verifiableProperties);
    routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
    CloudConfig cloudConfig = new CloudConfig(verifiableProperties);
    CloudDestinationFactory cloudDestinationFactory = Utils.getObj(cloudConfig.cloudDestinationFactoryClass, verifiableProperties, mockClusterMap.getMetricRegistry(), mockClusterMap);
    CloudDestination cloudDestination = cloudDestinationFactory.getCloudDestination();
    AccountService accountService = new InMemAccountService(false, true);
    CloudRouterFactory cloudRouterFactory = new CloudRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService);
    RequestHandlerPool requestHandlerPool = cloudRouterFactory.getRequestHandlerPool(verifiableProperties, mockClusterMap, cloudDestination, cloudConfig);
    Map<ReplicaType, NetworkClientFactory> childFactories = new EnumMap<>(ReplicaType.class);
    childFactories.put(ReplicaType.CLOUD_BACKED, new LocalNetworkClientFactory((LocalRequestResponseChannel) requestHandlerPool.getChannel(), new NetworkConfig(verifiableProperties), new NetworkMetrics(routerMetrics.getMetricRegistry()), mockTime));
    childFactories.put(ReplicaType.DISK_BACKED, new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, mockServerLayout, mockTime));
    NetworkClientFactory networkClientFactory = new CompositeNetworkClientFactory(childFactories);
    router = new NonBlockingRouter(routerConfig, routerMetrics, networkClientFactory, notificationSystem, mockClusterMap, kms, cryptoService, cryptoJobHandler, accountService, mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
    router.addResourceToClose(requestHandlerPool);
}
Also used : LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) LocalRequestResponseChannel(com.github.ambry.network.LocalRequestResponseChannel) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) NetworkMetrics(com.github.ambry.network.NetworkMetrics) CloudDestination(com.github.ambry.cloud.CloudDestination) CloudConfig(com.github.ambry.config.CloudConfig) NetworkConfig(com.github.ambry.config.NetworkConfig) CloudDestinationFactory(com.github.ambry.cloud.CloudDestinationFactory) LatchBasedInMemoryCloudDestinationFactory(com.github.ambry.cloud.LatchBasedInMemoryCloudDestinationFactory) RouterConfig(com.github.ambry.config.RouterConfig) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) InMemAccountService(com.github.ambry.account.InMemAccountService) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ReplicaType(com.github.ambry.clustermap.ReplicaType) RequestHandlerPool(com.github.ambry.protocol.RequestHandlerPool) AccountService(com.github.ambry.account.AccountService) InMemAccountService(com.github.ambry.account.InMemAccountService) EnumMap(java.util.EnumMap)

Aggregations

CompositeNetworkClientFactory (com.github.ambry.network.CompositeNetworkClientFactory)3 CloudDestination (com.github.ambry.cloud.CloudDestination)2 CloudDestinationFactory (com.github.ambry.cloud.CloudDestinationFactory)2 ReplicaType (com.github.ambry.clustermap.ReplicaType)2 CloudConfig (com.github.ambry.config.CloudConfig)2 LocalNetworkClientFactory (com.github.ambry.network.LocalNetworkClientFactory)2 NetworkClientFactory (com.github.ambry.network.NetworkClientFactory)2 RequestHandlerPool (com.github.ambry.protocol.RequestHandlerPool)2 EnumMap (java.util.EnumMap)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AccountService (com.github.ambry.account.AccountService)1 InMemAccountService (com.github.ambry.account.InMemAccountService)1 LatchBasedInMemoryCloudDestinationFactory (com.github.ambry.cloud.LatchBasedInMemoryCloudDestinationFactory)1 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)1 NetworkConfig (com.github.ambry.config.NetworkConfig)1 RouterConfig (com.github.ambry.config.RouterConfig)1 VerifiableProperties (com.github.ambry.config.VerifiableProperties)1 LocalRequestResponseChannel (com.github.ambry.network.LocalRequestResponseChannel)1 NetworkMetrics (com.github.ambry.network.NetworkMetrics)1 SocketNetworkClientFactory (com.github.ambry.network.SocketNetworkClientFactory)1