Search in sources :

Example 61 with VerifiableProperties

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

the class StaticClusterManagerTest method clusterMapInterface.

@Test
public void clusterMapInterface() {
    // Exercise entire clusterMap interface
    TestHardwareLayout testHardwareLayout = new TestHardwareLayout("Alpha");
    TestPartitionLayout testPartitionLayout = new TestPartitionLayout(testHardwareLayout, null);
    // add 3 partitions with read_only state.
    testPartitionLayout.partitionState = PartitionState.READ_ONLY;
    testPartitionLayout.addNewPartitions(3, DEFAULT_PARTITION_CLASS, testPartitionLayout.partitionState, null);
    testPartitionLayout.partitionState = PartitionState.READ_WRITE;
    Datacenter localDatacenter = testHardwareLayout.getRandomDatacenter();
    Properties props = new Properties();
    props.setProperty("clustermap.host.name", "localhost");
    props.setProperty("clustermap.cluster.name", "cluster");
    props.setProperty("clustermap.datacenter.name", localDatacenter.getName());
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    ClusterMap clusterMapManager = (new StaticClusterAgentsFactory(clusterMapConfig, testPartitionLayout.getPartitionLayout())).getClusterMap();
    for (String metricName : clusterMapManager.getMetricRegistry().getNames()) {
        System.out.println(metricName);
    }
    assertEquals("Incorrect local datacenter ID", localDatacenter.getId(), clusterMapManager.getLocalDatacenterId());
    List<? extends PartitionId> writablePartitionIds = clusterMapManager.getWritablePartitionIds(null);
    List<? extends PartitionId> partitionIds = clusterMapManager.getAllPartitionIds(null);
    assertEquals(writablePartitionIds.size(), testPartitionLayout.getPartitionCount() - 3);
    assertEquals(partitionIds.size(), testPartitionLayout.getPartitionCount());
    for (PartitionId partitionId : partitionIds) {
        if (partitionId.getPartitionState().equals(PartitionState.READ_WRITE)) {
            assertTrue("Partition not found in writable set ", writablePartitionIds.contains(partitionId));
        } else {
            assertFalse("READ_ONLY Partition found in writable set ", writablePartitionIds.contains(partitionId));
        }
    }
    for (int i = 0; i < partitionIds.size(); i++) {
        PartitionId partitionId = partitionIds.get(i);
        assertEquals(partitionId.getReplicaIds().size(), testPartitionLayout.getTotalReplicaCount());
        DataInputStream partitionStream = new DataInputStream(new ByteBufferInputStream(ByteBuffer.wrap(partitionId.getBytes())));
        try {
            PartitionId fetchedPartitionId = clusterMapManager.getPartitionIdFromStream(partitionStream);
            assertEquals(partitionId, fetchedPartitionId);
        } catch (IOException e) {
            assertEquals(true, false);
        }
    }
    for (Datacenter datacenter : testHardwareLayout.getHardwareLayout().getDatacenters()) {
        for (DataNode dataNode : datacenter.getDataNodes()) {
            DataNodeId dataNodeId = clusterMapManager.getDataNodeId(dataNode.getHostname(), dataNode.getPort());
            assertEquals(dataNodeId, dataNode);
            for (ReplicaId replicaId : clusterMapManager.getReplicaIds(dataNodeId)) {
                assertEquals(dataNodeId, replicaId.getDataNodeId());
            }
        }
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) IOException(java.io.IOException) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DataInputStream(java.io.DataInputStream) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 62 with VerifiableProperties

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

the class HelixHealthReportAggregationTaskTest method makeClusterMapConfig.

private ClusterMapConfig makeClusterMapConfig() {
    Properties props = new Properties();
    props.setProperty("clustermap.host.name", INSTANCE_NAME);
    props.setProperty("clustermap.cluster.name", CLUSTER_NAME);
    props.setProperty("clustermap.datacenter.name", "DC1");
    return new ClusterMapConfig(new VerifiableProperties(props));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig)

Example 63 with VerifiableProperties

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

the class AmbrySecurityServiceTest method postProcessQuotaManagerTest.

/**
 * {@link AmbrySecurityService#postProcessRequest(RestRequest, Callback)})} should throw RestServiceException if rate
 * is more than expected. RestServiceErrorCode.TooManyRequests is expected in this case.
 */
@Test
public void postProcessQuotaManagerTest() throws Exception {
    HostLevelThrottler quotaManager = Mockito.mock(HostLevelThrottler.class);
    AmbrySecurityService ambrySecurityService = new AmbrySecurityService(new FrontendConfig(new VerifiableProperties(new Properties())), new FrontendMetrics(new MetricRegistry()), URL_SIGNING_SERVICE_FACTORY.getUrlSigningService(), quotaManager, QUOTA_MANAGER);
    // Everything should be good.
    Mockito.when(quotaManager.shouldThrottle(any())).thenReturn(false);
    for (int i = 0; i < 100; i++) {
        for (RestMethod restMethod : RestMethod.values()) {
            RestRequest restRequest = createRestRequest(restMethod, "/", null);
            ambrySecurityService.postProcessRequest(restRequest).get();
        }
    }
    // Requests should be denied.
    Mockito.when(quotaManager.shouldThrottle(any())).thenReturn(true);
    for (RestMethod restMethod : RestMethod.values()) {
        RestRequest restRequest = createRestRequest(restMethod, "/", null);
        try {
            ambrySecurityService.postProcessRequest(restRequest).get();
            Assert.fail("Should have failed.");
        } catch (Exception e) {
            Assert.assertEquals("Exception should be TooManyRequests", RestServiceErrorCode.TooManyRequests, ((RestServiceException) e.getCause()).getErrorCode());
        }
    }
}
Also used : RestServiceException(com.github.ambry.rest.RestServiceException) FrontendConfig(com.github.ambry.config.FrontendConfig) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) VerifiableProperties(com.github.ambry.config.VerifiableProperties) HostLevelThrottler(com.github.ambry.commons.HostLevelThrottler) MetricRegistry(com.codahale.metrics.MetricRegistry) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) RestServiceException(com.github.ambry.rest.RestServiceException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RestMethod(com.github.ambry.rest.RestMethod) Test(org.junit.Test)

Example 64 with VerifiableProperties

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

the class FrontendIntegrationTest method buildFrontendVProps.

/**
 * Builds properties required to start a {@link RestServer} as an Ambry frontend server.
 * @param trustStoreFile the trust store file to add certificates to for SSL testing.
 * @param enableUndelete enable undelete in frontend when it's true.
 * @param plaintextServerPort server port number to support plaintext protocol
 * @param sslServerPort server port number to support ssl protocol
 * @return a {@link Properties} with the parameters for an Ambry frontend server.
 */
private static VerifiableProperties buildFrontendVProps(File trustStoreFile, boolean enableUndelete, int plaintextServerPort, int sslServerPort) throws IOException, GeneralSecurityException {
    Properties properties = new Properties();
    properties.put("rest.server.rest.request.service.factory", "com.github.ambry.frontend.FrontendRestRequestServiceFactory");
    properties.put("rest.server.router.factory", "com.github.ambry.router.InMemoryRouterFactory");
    properties.put("rest.server.account.service.factory", "com.github.ambry.account.InMemAccountServiceFactory");
    properties.put("netty.server.port", Integer.toString(plaintextServerPort));
    properties.put("netty.server.ssl.port", Integer.toString(sslServerPort));
    properties.put("netty.server.enable.ssl", "true");
    properties.put(NettyConfig.SSL_FACTORY_KEY, NettySslFactory.class.getName());
    // to test that backpressure does not impede correct operation.
    properties.put("netty.server.request.buffer.watermark", "1");
    // to test that multipart requests over a certain size fail
    properties.put("netty.multipart.post.max.size.bytes", Long.toString(MAX_MULTIPART_POST_SIZE_BYTES));
    CommonTestUtils.populateRequiredRouterProps(properties);
    TestSSLUtils.addSSLProperties(properties, "", SSLFactory.Mode.SERVER, trustStoreFile, "frontend");
    // add key for singleKeyManagementService
    properties.put("kms.default.container.key", TestUtils.getRandomKey(32));
    properties.setProperty("clustermap.cluster.name", CLUSTER_NAME);
    properties.setProperty("clustermap.datacenter.name", DATA_CENTER_NAME);
    properties.setProperty("clustermap.host.name", HOST_NAME);
    properties.setProperty(FrontendConfig.ENABLE_UNDELETE, Boolean.toString(enableUndelete));
    return new VerifiableProperties(properties);
}
Also used : NettySslFactory(com.github.ambry.commons.NettySslFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 65 with VerifiableProperties

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

the class CommonUtilsTest method createHelixPropertyStoreTest.

/**
 * Tests for {@link CommonUtils#createHelixPropertyStore(String, HelixPropertyStoreConfig, List)}.
 */
@Test
public void createHelixPropertyStoreTest() throws IOException {
    Properties storeProps = new Properties();
    storeProps.setProperty("helix.property.store.root.path", "/Ambry-Test/" + ClusterMapUtils.PROPERTYSTORE_STR);
    HelixPropertyStoreConfig propertyStoreConfig = new HelixPropertyStoreConfig(new VerifiableProperties(storeProps));
    String tempDirPath = getTempDir("clusterMapUtils-");
    ZkInfo zkInfo = new ZkInfo(tempDirPath, "DC1", (byte) 0, 2200, true);
    try {
        CommonUtils.createHelixPropertyStore(null, propertyStoreConfig, Collections.emptyList());
        fail("create HelixPropertyStore with invalid arguments should fail");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        CommonUtils.createHelixPropertyStore("", propertyStoreConfig, Collections.emptyList());
        fail("create HelixPropertyStore with invalid arguments should fail");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        CommonUtils.createHelixPropertyStore("localhost:" + zkInfo.getPort(), (HelixPropertyStoreConfig) null, Collections.emptyList());
        fail("create HelixPropertyStore with invalid arguments should fail");
    } catch (IllegalArgumentException e) {
    // expected
    }
    HelixPropertyStore<ZNRecord> propertyStore = CommonUtils.createHelixPropertyStore("localhost:" + zkInfo.getPort(), propertyStoreConfig, Collections.singletonList(propertyStoreConfig.rootPath));
    assertNotNull(propertyStore);
    // Ensure the HelixPropertyStore works correctly
    List<String> list = Arrays.asList("first", "second", "third");
    String path = propertyStoreConfig.rootPath + ClusterMapUtils.PARTITION_OVERRIDE_ZNODE_PATH;
    ZNRecord znRecord = new ZNRecord(ClusterMapUtils.PARTITION_OVERRIDE_STR);
    znRecord.setListField("AmbryList", list);
    if (!propertyStore.set(path, znRecord, AccessOption.PERSISTENT)) {
        fail("Failed to set HelixPropertyStore");
    }
    // Verify path exists
    assertTrue("The record path doesn't exist", propertyStore.exists(path, AccessOption.PERSISTENT));
    // Verify record
    ZNRecord result = propertyStore.get(path, null, AccessOption.PERSISTENT);
    assertEquals("Mismatch in list content", new HashSet<>(list), new HashSet<>(result.getListField("AmbryList")));
    zkInfo.shutdown();
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) Test(org.junit.Test)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)335 Properties (java.util.Properties)219 Test (org.junit.Test)192 MetricRegistry (com.codahale.metrics.MetricRegistry)131 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)80 ArrayList (java.util.ArrayList)62 BlobProperties (com.github.ambry.messageformat.BlobProperties)61 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)52 StoreConfig (com.github.ambry.config.StoreConfig)51 IOException (java.io.IOException)47 File (java.io.File)39 RouterConfig (com.github.ambry.config.RouterConfig)37 ClusterMap (com.github.ambry.clustermap.ClusterMap)36 JSONObject (org.json.JSONObject)34 HashMap (java.util.HashMap)33 BlobId (com.github.ambry.commons.BlobId)31 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)31 CountDownLatch (java.util.concurrent.CountDownLatch)31 Map (java.util.Map)28 InMemAccountService (com.github.ambry.account.InMemAccountService)26