Search in sources :

Example 21 with RouterConfig

use of com.github.ambry.config.RouterConfig in project ambry by linkedin.

the class ServerTestUtil method getSSLFactoryIfRequired.

/**
 * Create an {@link SSLFactory} if there are SSL enabled datacenters in the properties
 * @param verifiableProperties the {@link VerifiableProperties} to use.
 * @return an {@link SSLFactory}, or {@code null}, if no {@link SSLFactory} is required.
 * @throws Exception
 */
static SSLFactory getSSLFactoryIfRequired(VerifiableProperties verifiableProperties) throws Exception {
    if (new RouterConfig(verifiableProperties).routerEnableHttp2NetworkClient) {
        return new NettySslHttp2Factory(new SSLConfig(verifiableProperties));
    }
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
    boolean requiresSSL = clusterMapConfig.clusterMapSslEnabledDatacenters.length() > 0;
    return requiresSSL ? SSLFactory.getNewInstance(new SSLConfig(verifiableProperties)) : null;
}
Also used : SSLConfig(com.github.ambry.config.SSLConfig) NettySslHttp2Factory(com.github.ambry.commons.NettySslHttp2Factory) RouterConfig(com.github.ambry.config.RouterConfig) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig)

Example 22 with RouterConfig

use of com.github.ambry.config.RouterConfig in project ambry by linkedin.

the class UndeleteOperationTrackerTest method getOperationTracker.

/**
 * Returns {@link UndeleteOperationTracker}.
 * @param parallelism the number of parallel requests that can be in flight.
 * @return {@link UndeleteOperationTracker}.
 */
private UndeleteOperationTracker getOperationTracker(int parallelism) {
    Properties props = new Properties();
    props.setProperty(RouterConfig.ROUTER_HOSTNAME, "localhost");
    props.setProperty(RouterConfig.ROUTER_DATACENTER_NAME, localDcName);
    props.setProperty(RouterConfig.ROUTER_OPERATION_TRACKER_TERMINATE_ON_NOT_FOUND_ENABLED, "true");
    props.setProperty(RouterConfig.ROUTER_GET_ELIGIBLE_REPLICAS_BY_STATE_ENABLED, Boolean.toString(replicasStateEnabled));
    props.setProperty(RouterConfig.ROUTER_UNDELETE_REQUEST_PARALLELISM, Integer.toString(parallelism));
    RouterConfig routerConfig = new RouterConfig(new VerifiableProperties(props));
    NonBlockingRouterMetrics routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
    return new UndeleteOperationTracker(routerConfig, mockPartition, originatingDcName, routerMetrics);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig)

Example 23 with RouterConfig

use of com.github.ambry.config.RouterConfig in project ambry by linkedin.

the class NonBlockingRouterTest method setRouter.

/**
 * Initialize and set the router with the given {@link Properties} and {@link MockServerLayout}
 * @param props the {@link Properties}
 * @param mockServerLayout the {@link MockServerLayout}
 */
private void setRouter(Properties props, MockServerLayout mockServerLayout) throws IOException {
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    routerMetrics = new NonBlockingRouterMetrics(mockClusterMap);
    router = new NonBlockingRouter(new RouterConfig(verifiableProperties), routerMetrics, new MockNetworkClientFactory(verifiableProperties, null, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, mockServerLayout, mockTime), new LoggingNotificationSystem(), mockClusterMap, kms, cryptoService, cryptoJobHandler, mockTime);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) RouterConfig(com.github.ambry.config.RouterConfig)

Example 24 with RouterConfig

use of com.github.ambry.config.RouterConfig in project ambry by linkedin.

the class NonBlockingRouterTest method testCompositeBlobDataChunksDelete.

/**
 * Test that if a composite blob is deleted, the data chunks are eventually deleted. Also check the service IDs used
 * for delete operations.
 */
@Test
public void testCompositeBlobDataChunksDelete() throws Exception {
    // Ensure there are 4 chunks.
    maxPutChunkSize = PUT_CONTENT_SIZE / 4;
    Properties props = getNonBlockingRouterProperties("DC1");
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    RouterConfig routerConfig = new RouterConfig(verifiableProperties);
    MockClusterMap mockClusterMap = new MockClusterMap();
    MockTime mockTime = new MockTime();
    MockServerLayout mockServerLayout = new MockServerLayout(mockClusterMap);
    // metadata blob + data chunks.
    final AtomicReference<CountDownLatch> deletesDoneLatch = new AtomicReference<>();
    final Map<String, String> blobsThatAreDeleted = new HashMap<>();
    LoggingNotificationSystem deleteTrackingNotificationSystem = new LoggingNotificationSystem() {

        @Override
        public void onBlobDeleted(String blobId, String serviceId) {
            blobsThatAreDeleted.put(blobId, serviceId);
            deletesDoneLatch.get().countDown();
        }
    };
    router = new NonBlockingRouter(routerConfig, new NonBlockingRouterMetrics(mockClusterMap), new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, mockServerLayout, mockTime), deleteTrackingNotificationSystem, mockClusterMap, kms, cryptoService, cryptoJobHandler, mockTime);
    setOperationParams();
    String blobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel).get();
    String deleteServiceId = "delete-service";
    Set<String> blobsToBeDeleted = getBlobsInServers(mockServerLayout);
    int getRequestCount = mockServerLayout.getCount(RequestOrResponseType.GetRequest);
    // The third iteration is to test the case where the blob has expired.
    for (int i = 0; i < 3; i++) {
        if (i == 2) {
            // Create a clean cluster and put another blob that immediate expires.
            setOperationParams();
            putBlobProperties = new BlobProperties(-1, "serviceId", "memberId", "contentType", false, 0, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), false);
            blobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel).get();
            Set<String> allBlobsInServer = getBlobsInServers(mockServerLayout);
            allBlobsInServer.removeAll(blobsToBeDeleted);
            blobsToBeDeleted = allBlobsInServer;
        }
        blobsThatAreDeleted.clear();
        deletesDoneLatch.set(new CountDownLatch(5));
        router.deleteBlob(blobId, deleteServiceId, null).get();
        Assert.assertTrue("Deletes should not take longer than " + AWAIT_TIMEOUT_MS, deletesDoneLatch.get().await(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
        Assert.assertTrue("All blobs in server are deleted", blobsThatAreDeleted.keySet().containsAll(blobsToBeDeleted));
        Assert.assertTrue("Only blobs in server are deleted", blobsToBeDeleted.containsAll(blobsThatAreDeleted.keySet()));
        for (Map.Entry<String, String> blobIdAndServiceId : blobsThatAreDeleted.entrySet()) {
            String expectedServiceId = blobIdAndServiceId.getKey().equals(blobId) ? deleteServiceId : BackgroundDeleteRequest.SERVICE_ID_PREFIX + deleteServiceId;
            Assert.assertEquals("Unexpected service ID for deleted blob", expectedServiceId, blobIdAndServiceId.getValue());
        }
        // For 1 chunk deletion attempt, 1 background operation for Get is initiated which results in 2 Get Requests at
        // the servers.
        getRequestCount += 2;
        Assert.assertEquals("Only one attempt of chunk deletion should have been done", getRequestCount, mockServerLayout.getCount(RequestOrResponseType.GetRequest));
    }
    deletesDoneLatch.set(new CountDownLatch(5));
    router.deleteBlob(blobId, null, null).get();
    Assert.assertTrue("Deletes should not take longer than " + AWAIT_TIMEOUT_MS, deletesDoneLatch.get().await(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
    router.close();
    assertClosed();
    Assert.assertEquals("All operations should have completed", 0, router.getOperationsCount());
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) CountDownLatch(java.util.concurrent.CountDownLatch) RouterConfig(com.github.ambry.config.RouterConfig) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) BlobProperties(com.github.ambry.messageformat.BlobProperties) HashMap(java.util.HashMap) Map(java.util.Map) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) MockTime(com.github.ambry.utils.MockTime) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 25 with RouterConfig

use of com.github.ambry.config.RouterConfig in project ambry by linkedin.

the class ConnectionTrackerTest method initialize.

@Before
public void initialize() {
    Properties props = new Properties();
    props.setProperty("router.hostname", "localhost");
    props.setProperty("router.datacenter.name", "DC1");
    props.setProperty("router.scaling.unit.max.connections.per.port.plain.text", "3");
    props.setProperty("router.scaling.unit.max.connections.per.port.ssl", "2");
    verifiableProperties = new VerifiableProperties((props));
    routerConfig = new RouterConfig(verifiableProperties);
    networkConfig = new NetworkConfig(verifiableProperties);
    time = new MockTime();
    plainTextPort = new Port(100, PortType.PLAINTEXT);
    sslPort = new Port(200, PortType.SSL);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) NetworkConfig(com.github.ambry.config.NetworkConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig) MockTime(com.github.ambry.utils.MockTime) Before(org.junit.Before)

Aggregations

RouterConfig (com.github.ambry.config.RouterConfig)43 VerifiableProperties (com.github.ambry.config.VerifiableProperties)39 Properties (java.util.Properties)29 Test (org.junit.Test)28 BlobProperties (com.github.ambry.messageformat.BlobProperties)21 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)18 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)15 MockTime (com.github.ambry.utils.MockTime)12 ArrayList (java.util.ArrayList)12 InMemAccountService (com.github.ambry.account.InMemAccountService)10 PutManagerTest (com.github.ambry.router.PutManagerTest)10 ServerErrorCode (com.github.ambry.server.ServerErrorCode)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)7 BlobId (com.github.ambry.commons.BlobId)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ReplicaId (com.github.ambry.clustermap.ReplicaId)5 ResponseHandler (com.github.ambry.commons.ResponseHandler)5