Search in sources :

Example 1 with ServerMetrics

use of com.github.ambry.commons.ServerMetrics in project ambry by linkedin.

the class CloudRouterFactory method getRequestHandlerPool.

/**
 * Utility method to build  a {@link RequestHandlerPool}.
 * @param verifiableProperties the properties to use.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the constructed {@link RequestHandlerPool}.
 * @throws Exception if the construction fails.
 */
public RequestHandlerPool getRequestHandlerPool(VerifiableProperties verifiableProperties, ClusterMap clusterMap, CloudDestination cloudDestination, CloudConfig cloudConfig) throws Exception {
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
    MetricRegistry registry = clusterMap.getMetricRegistry();
    DataNodeId nodeId = new CloudDataNode(cloudConfig, clusterMapConfig);
    VcrMetrics vcrMetrics = new VcrMetrics(registry);
    StoreManager cloudStorageManager = new CloudStorageManager(verifiableProperties, vcrMetrics, cloudDestination, clusterMap);
    LocalRequestResponseChannel channel = new LocalRequestResponseChannel();
    ServerMetrics serverMetrics = new ServerMetrics(registry, AmbryRequests.class);
    StoreKeyFactory storeKeyFactory = new BlobIdFactory(clusterMap);
    StoreKeyConverterFactory storeKeyConverterFactory = Utils.getObj(routerConfig.routerStoreKeyConverterFactory, verifiableProperties, registry);
    // A null notification system is passed into AmbryRequests so that replication events are not emitted from a
    // frontend.
    AmbryRequests requests = new AmbryRequests(cloudStorageManager, channel, clusterMap, nodeId, registry, serverMetrics, null, null, null, storeKeyFactory, storeKeyConverterFactory);
    return new RequestHandlerPool(routerConfig.routerRequestHandlerNumOfThreads, channel, requests);
}
Also used : CloudStorageManager(com.github.ambry.cloud.CloudStorageManager) LocalRequestResponseChannel(com.github.ambry.network.LocalRequestResponseChannel) VcrMetrics(com.github.ambry.cloud.VcrMetrics) MetricRegistry(com.codahale.metrics.MetricRegistry) AmbryRequests(com.github.ambry.protocol.AmbryRequests) CloudDataNode(com.github.ambry.clustermap.CloudDataNode) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) StoreManager(com.github.ambry.server.StoreManager) BlobIdFactory(com.github.ambry.commons.BlobIdFactory) StoreKeyFactory(com.github.ambry.store.StoreKeyFactory) StoreKeyConverterFactory(com.github.ambry.store.StoreKeyConverterFactory) RequestHandlerPool(com.github.ambry.protocol.RequestHandlerPool) ServerMetrics(com.github.ambry.commons.ServerMetrics) DataNodeId(com.github.ambry.clustermap.DataNodeId)

Example 2 with ServerMetrics

use of com.github.ambry.commons.ServerMetrics in project ambry by linkedin.

the class MockServerSecurityService method securityCheckerTest.

/**
 * Test the code flow where {@link ServerSecurityHandler} waits for the SSL handshake complete event and
 * apply security policy from channelActive method.
 * @throws Exception
 */
@Test
public void securityCheckerTest() throws Exception {
    // secuirty validation success case, channel should not be closed.
    ServerMetrics metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    EmbeddedChannel channel = createChannelSsl(metrics);
    SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
    Promise<Channel> promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should not be closed", channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1, metrics.serverValidateConnectionSuccess.getCount());
    // security validation failure case (throw exception), channel should be closed.
    MockServerSecurityService mockServerSecurityService = (MockServerSecurityService) serverSecurityService;
    mockServerSecurityService.setThrowException(true);
    metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    channel = createChannelSsl(metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should be closed", !channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1, metrics.serverValidateConnectionFailure.getCount());
    // security validation failure case (service closed), channel should be closed.
    serverSecurityService.close();
    metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    channel = createChannelSsl(metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should be closed", !channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1, metrics.serverValidateConnectionFailure.getCount());
}
Also used : Promise(io.netty.util.concurrent.Promise) MetricRegistry(com.codahale.metrics.MetricRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ServerMetrics(com.github.ambry.commons.ServerMetrics) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 3 with ServerMetrics

use of com.github.ambry.commons.ServerMetrics in project ambry by linkedin.

the class AmbryServerRequestsTest method undeleteEnableDisableTest.

/**
 * Tests for server config to enable and disable UNDELETE
 */
@Test
public void undeleteEnableDisableTest() throws Exception {
    Assume.assumeTrue(MessageFormatRecord.getCurrentMessageHeaderVersion() >= MessageFormatRecord.Message_Header_Version_V3);
    Properties properties = createProperties(validateRequestOnStoreState, false);
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    ServerConfig serverConfig = new ServerConfig(verifiableProperties);
    ServerMetrics serverMetrics = new ServerMetrics(clusterMap.getMetricRegistry(), AmbryRequests.class, AmbryServer.class);
    AmbryServerRequests other = new AmbryServerRequests(storageManager, requestResponseChannel, clusterMap, dataNodeId, clusterMap.getMetricRegistry(), serverMetrics, findTokenHelper, null, replicationManager, null, serverConfig, storeKeyConverterFactory, statsManager, null);
    AmbryServerRequests temp = ambryRequests;
    ambryRequests = other;
    try {
        MockPartitionId id = (MockPartitionId) clusterMap.getWritablePartitionIds(DEFAULT_PARTITION_CLASS).get(0);
        int correlationId = TestUtils.RANDOM.nextInt();
        String clientId = TestUtils.getRandomString(10);
        BlobId blobId = new BlobId(CommonTestUtils.getCurrentBlobIdVersion(), BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), id, false, BlobId.BlobDataType.DATACHUNK);
        long opTimeMs = SystemTime.getInstance().milliseconds();
        doUndelete(correlationId++, clientId, blobId, opTimeMs, ServerErrorCode.Temporarily_Disabled);
    } finally {
        ambryRequests = temp;
    }
}
Also used : ServerConfig(com.github.ambry.config.ServerConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) ServerMetrics(com.github.ambry.commons.ServerMetrics) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test) MessageInfoTest(com.github.ambry.store.MessageInfoTest) MessageFormatInputStreamTest(com.github.ambry.messageformat.MessageFormatInputStreamTest)

Example 4 with ServerMetrics

use of com.github.ambry.commons.ServerMetrics in project ambry by linkedin.

the class VcrServer method startup.

/**
 * Start the VCR Server.
 * @throws InstantiationException if an error was encountered during startup.
 */
public void startup() throws InstantiationException {
    try {
        logger.info("starting");
        ServerConfig serverConfig = new ServerConfig(properties);
        ServerSecurityServiceFactory serverSecurityServiceFactory = Utils.getObj(serverConfig.serverSecurityServiceFactory, properties, serverMetrics, registry);
        serverSecurityService = serverSecurityServiceFactory.getServerSecurityService();
        clusterMap = clusterAgentsFactory.getClusterMap();
        logger.info("Initialized clusterMap");
        registry = clusterMap.getMetricRegistry();
        serverMetrics = new ServerMetrics(registry, VcrServer.class, VcrServer.class);
        logger.info("Setting up JMX.");
        long startTime = SystemTime.getInstance().milliseconds();
        registry = clusterMap.getMetricRegistry();
        reporter = reporterFactory != null ? reporterFactory.apply(registry) : JmxReporter.forRegistry(registry).build();
        reporter.start();
        logger.info("creating configs");
        NetworkConfig networkConfig = new NetworkConfig(properties);
        StoreConfig storeConfig = new StoreConfig(properties);
        ReplicationConfig replicationConfig = new ReplicationConfig(properties);
        CloudConfig cloudConfig = new CloudConfig(properties);
        ConnectionPoolConfig connectionPoolConfig = new ConnectionPoolConfig(properties);
        ClusterMapConfig clusterMapConfig = new ClusterMapConfig(properties);
        SSLConfig sslConfig = new SSLConfig(properties);
        // verify the configs
        properties.verify();
        // initialize cloud destination
        if (cloudDestinationFactory == null) {
            cloudDestinationFactory = Utils.getObj(cloudConfig.cloudDestinationFactoryClass, properties, registry, clusterMap);
        }
        cloudDestination = cloudDestinationFactory.getCloudDestination();
        // TODO Make sure that config.updaterPollingIntervalMs value is large (~one day) for VCR.
        AccountServiceFactory accountServiceFactory = Utils.getObj(serverConfig.serverAccountServiceFactory, properties, registry);
        AccountService accountService = accountServiceFactory.getAccountService();
        vcrClusterParticipant = ((VcrClusterAgentsFactory) Utils.getObj(cloudConfig.vcrClusterAgentsFactoryClass, cloudConfig, clusterMapConfig, clusterMap, accountService, storeConfig, cloudDestination, registry)).getVcrClusterParticipant();
        scheduler = Utils.newScheduler(serverConfig.serverSchedulerNumOfthreads, false);
        StoreKeyFactory storeKeyFactory = Utils.getObj(storeConfig.storeKeyFactory, clusterMap);
        SSLFactory sslFactory = new NettySslHttp2Factory(sslConfig);
        if (clusterMapConfig.clusterMapEnableHttp2Replication) {
            connectionPool = new Http2BlockingChannelPool(sslFactory, new Http2ClientConfig(properties), new Http2ClientMetrics(registry));
            logger.info("Using http2 for VCR replication.");
        } else {
            connectionPool = new BlockingChannelConnectionPool(connectionPoolConfig, sslConfig, clusterMapConfig, registry);
            logger.info("Using blocking channel for VCR replication.");
        }
        connectionPool.start();
        StoreKeyConverterFactory storeKeyConverterFactory = Utils.getObj(serverConfig.serverStoreKeyConverterFactory, properties, registry);
        VcrMetrics vcrMetrics = new VcrMetrics(registry);
        CloudStorageManager cloudStorageManager = new CloudStorageManager(properties, vcrMetrics, cloudDestination, clusterMap);
        vcrReplicationManager = new VcrReplicationManager(cloudConfig, replicationConfig, clusterMapConfig, storeConfig, cloudStorageManager, storeKeyFactory, clusterMap, vcrClusterParticipant, cloudDestination, scheduler, connectionPool, vcrMetrics, notificationSystem, storeKeyConverterFactory, serverConfig.serverMessageTransformer);
        vcrReplicationManager.start();
        DataNodeId currentNode = vcrClusterParticipant.getCurrentDataNodeId();
        ArrayList<Port> ports = new ArrayList<Port>();
        ports.add(new Port(networkConfig.port, PortType.PLAINTEXT));
        if (currentNode.hasSSLPort()) {
            ports.add(new Port(cloudConfig.vcrSslPort, PortType.SSL));
        }
        networkServer = new SocketServer(networkConfig, sslConfig, registry, ports);
        // todo fix enableDataPrefetch
        ServerMetrics serverMetrics = new ServerMetrics(registry, VcrRequests.class, VcrServer.class);
        VcrRequests requests = new VcrRequests(cloudStorageManager, networkServer.getRequestResponseChannel(), clusterMap, currentNode, registry, serverMetrics, new FindTokenHelper(storeKeyFactory, replicationConfig), notificationSystem, vcrReplicationManager, storeKeyFactory, storeKeyConverterFactory);
        requestHandlerPool = new RequestHandlerPool(serverConfig.serverRequestHandlerNumOfThreads, networkServer.getRequestResponseChannel(), requests);
        networkServer.start();
        // Start netty http2 server
        if (currentNode.hasHttp2Port()) {
            logger.info("Http2 port {} is enabled. Starting HTTP/2 service.", currentNode.getHttp2Port());
            NettyConfig nettyConfig = new NettyConfig(properties);
            NettyMetrics nettyMetrics = new NettyMetrics(registry);
            Http2ServerMetrics http2ServerMetrics = new Http2ServerMetrics(registry);
            Http2ClientConfig http2ClientConfig = new Http2ClientConfig(properties);
            NettyServerRequestResponseChannel requestResponseChannel = new NettyServerRequestResponseChannel(networkConfig.queuedMaxRequests, http2ServerMetrics);
            VcrRequests vcrRequestsForHttp2 = new VcrRequests(cloudStorageManager, requestResponseChannel, clusterMap, currentNode, registry, serverMetrics, new FindTokenHelper(storeKeyFactory, replicationConfig), notificationSystem, vcrReplicationManager, storeKeyFactory, storeKeyConverterFactory);
            requestHandlerPoolForHttp2 = new RequestHandlerPool(serverConfig.serverRequestHandlerNumOfThreads, requestResponseChannel, vcrRequestsForHttp2);
            NioServerFactory nioServerFactory = new StorageServerNettyFactory(currentNode.getHttp2Port(), requestResponseChannel, sslFactory, nettyConfig, http2ClientConfig, serverMetrics, nettyMetrics, http2ServerMetrics, serverSecurityService);
            nettyHttp2Server = nioServerFactory.getNioServer();
            nettyHttp2Server.start();
        }
        long processingTime = SystemTime.getInstance().milliseconds() - startTime;
        logger.info("VCR startup time in Ms {}", processingTime);
    } catch (Exception e) {
        logger.error("Error during VCR startup", e);
        throw new InstantiationException("failure during VCR startup " + e);
    }
}
Also used : ConnectionPoolConfig(com.github.ambry.config.ConnectionPoolConfig) SSLFactory(com.github.ambry.commons.SSLFactory) Http2ClientMetrics(com.github.ambry.network.http2.Http2ClientMetrics) Port(com.github.ambry.network.Port) CloudConfig(com.github.ambry.config.CloudConfig) ArrayList(java.util.ArrayList) StorageServerNettyFactory(com.github.ambry.rest.StorageServerNettyFactory) NettySslHttp2Factory(com.github.ambry.commons.NettySslHttp2Factory) NettyConfig(com.github.ambry.config.NettyConfig) ServerConfig(com.github.ambry.config.ServerConfig) StoreKeyFactory(com.github.ambry.store.StoreKeyFactory) StoreKeyConverterFactory(com.github.ambry.store.StoreKeyConverterFactory) ServerMetrics(com.github.ambry.commons.ServerMetrics) Http2ServerMetrics(com.github.ambry.network.http2.Http2ServerMetrics) SSLConfig(com.github.ambry.config.SSLConfig) ReplicationConfig(com.github.ambry.config.ReplicationConfig) Http2BlockingChannelPool(com.github.ambry.network.http2.Http2BlockingChannelPool) SocketServer(com.github.ambry.network.SocketServer) NettyMetrics(com.github.ambry.rest.NettyMetrics) FindTokenHelper(com.github.ambry.replication.FindTokenHelper) NettyServerRequestResponseChannel(com.github.ambry.network.NettyServerRequestResponseChannel) NetworkConfig(com.github.ambry.config.NetworkConfig) Http2ClientConfig(com.github.ambry.config.Http2ClientConfig) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) BlockingChannelConnectionPool(com.github.ambry.network.BlockingChannelConnectionPool) IOException(java.io.IOException) ServerSecurityServiceFactory(com.github.ambry.rest.ServerSecurityServiceFactory) Http2ServerMetrics(com.github.ambry.network.http2.Http2ServerMetrics) NioServerFactory(com.github.ambry.rest.NioServerFactory) RequestHandlerPool(com.github.ambry.protocol.RequestHandlerPool) StoreConfig(com.github.ambry.config.StoreConfig) AccountService(com.github.ambry.account.AccountService) DataNodeId(com.github.ambry.clustermap.DataNodeId) AccountServiceFactory(com.github.ambry.account.AccountServiceFactory)

Aggregations

ServerMetrics (com.github.ambry.commons.ServerMetrics)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 DataNodeId (com.github.ambry.clustermap.DataNodeId)2 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)2 ServerConfig (com.github.ambry.config.ServerConfig)2 RequestHandlerPool (com.github.ambry.protocol.RequestHandlerPool)2 StoreKeyConverterFactory (com.github.ambry.store.StoreKeyConverterFactory)2 StoreKeyFactory (com.github.ambry.store.StoreKeyFactory)2 Test (org.junit.Test)2 AccountService (com.github.ambry.account.AccountService)1 AccountServiceFactory (com.github.ambry.account.AccountServiceFactory)1 CloudStorageManager (com.github.ambry.cloud.CloudStorageManager)1 VcrMetrics (com.github.ambry.cloud.VcrMetrics)1 CloudDataNode (com.github.ambry.clustermap.CloudDataNode)1 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 BlobId (com.github.ambry.commons.BlobId)1 BlobIdFactory (com.github.ambry.commons.BlobIdFactory)1 NettySslHttp2Factory (com.github.ambry.commons.NettySslHttp2Factory)1 SSLFactory (com.github.ambry.commons.SSLFactory)1 CloudConfig (com.github.ambry.config.CloudConfig)1