Search in sources :

Example 16 with ClusterMapConfig

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

the class TestUtils method getDummyConfig.

/**
 * For use when the the actual values in {@link ClusterMapConfig} are unimportant.
 * @return a {@link ClusterMapConfig} with some default values.
 */
static ClusterMapConfig getDummyConfig() {
    Properties props = new Properties();
    props.setProperty("clustermap.host.name", "localhost");
    props.setProperty("clustermap.cluster.name", "cluster");
    props.setProperty("clustermap.datacenter.name", "");
    props.setProperty("clustermap.resolve.hostnames", "false");
    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 17 with ClusterMapConfig

use of com.github.ambry.config.ClusterMapConfig 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 18 with ClusterMapConfig

use of com.github.ambry.config.ClusterMapConfig 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 19 with ClusterMapConfig

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

the class AccountStatsMySqlStoreIntegrationTest method createAccountStatsMySqlStore.

private AccountStatsMySqlStore createAccountStatsMySqlStore(String clusterName, String hostname, int port) throws Exception {
    Path localBackupFilePath = createTemporaryFile();
    Properties configProps = Utils.loadPropsFromResource("accountstats_mysql.properties");
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_CLUSTER_NAME, clusterName);
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_HOST_NAME, hostname);
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_DATACENTER_NAME, "dc1");
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_PORT, String.valueOf(port));
    configProps.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, ".github.com");
    configProps.setProperty(AccountStatsMySqlConfig.UPDATE_BATCH_SIZE, String.valueOf(batchSize));
    configProps.setProperty(AccountStatsMySqlConfig.POOL_SIZE, String.valueOf(5));
    configProps.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, localBackupFilePath.toString());
    VerifiableProperties verifiableProperties = new VerifiableProperties(configProps);
    return (AccountStatsMySqlStore) new AccountStatsMySqlStoreFactory(verifiableProperties, new ClusterMapConfig(verifiableProperties), new MetricRegistry()).getAccountStatsStore();
}
Also used : Path(java.nio.file.Path) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig)

Example 20 with ClusterMapConfig

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

the class PartitionClassReportsDaoTest method createAccountStatsMySqlStore.

private static AccountStatsMySqlStore createAccountStatsMySqlStore(String clusterName, String hostname, int port, int batchSize) throws Exception {
    Path tempDir = Files.createTempDirectory("PartitionClassReportsDaoTest");
    Properties configProps = Utils.loadPropsFromResource("accountstats_mysql.properties");
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_CLUSTER_NAME, clusterName);
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_HOST_NAME, hostname);
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_DATACENTER_NAME, "dc1");
    configProps.setProperty(ClusterMapConfig.CLUSTERMAP_PORT, String.valueOf(port));
    configProps.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, ".github.com");
    configProps.setProperty(AccountStatsMySqlConfig.UPDATE_BATCH_SIZE, String.valueOf(batchSize));
    configProps.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, tempDir.toString());
    VerifiableProperties verifiableProperties = new VerifiableProperties(configProps);
    return (AccountStatsMySqlStore) new AccountStatsMySqlStoreFactory(verifiableProperties, new ClusterMapConfig(verifiableProperties), new MetricRegistry()).getAccountStatsStore();
}
Also used : Path(java.nio.file.Path) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig)

Aggregations

ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)100 VerifiableProperties (com.github.ambry.config.VerifiableProperties)81 Test (org.junit.Test)56 Properties (java.util.Properties)52 MetricRegistry (com.codahale.metrics.MetricRegistry)47 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)26 HashSet (java.util.HashSet)25 JSONObject (org.json.JSONObject)25 File (java.io.File)24 ClusterMap (com.github.ambry.clustermap.ClusterMap)23 HashMap (java.util.HashMap)21 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)19 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)18 DataNodeId (com.github.ambry.clustermap.DataNodeId)18 StoreConfig (com.github.ambry.config.StoreConfig)18 ReplicaId (com.github.ambry.clustermap.ReplicaId)16 List (java.util.List)16 Map (java.util.Map)16 CountDownLatch (java.util.concurrent.CountDownLatch)16