Search in sources :

Example 36 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class HttpStoreTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Cluster cluster = ServerTestUtils.getLocalCluster(1);
    Node node = cluster.getNodes().iterator().next();
    context = ServerTestUtils.getJettyServer(new ClusterMapper().writeCluster(cluster), VoldemortTestConstants.getSimpleStoreDefinitionsXml(), "users", RequestFormatType.VOLDEMORT_V1, node.getHttpPort());
    server = context.getServer();
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), 5000, TimeUnit.MILLISECONDS);
    httpClient = new DefaultHttpClient(connectionManager);
    httpStore = ServerTestUtils.getHttpStore("users", RequestFormatType.VOLDEMORT_V1, node.getHttpPort(), httpClient);
}
Also used : ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 37 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class TestDistribution method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2)
        Utils.croak("USAGE: java TestDistribution cluster.xml replication_factor max_id");
    long start = System.currentTimeMillis();
    File file = new File(args[0]);
    int repFactor = Integer.parseInt(args[1]);
    int maxVal = Integer.parseInt(args[2]);
    ClusterMapper mapper = new ClusterMapper();
    Cluster cluster = mapper.readCluster(file);
    RoutingStrategy strategy = new ConsistentRoutingStrategy(cluster, repFactor);
    JsonTypeSerializer serializer = new JsonTypeSerializer(JsonTypeDefinition.INT32);
    Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
    for (int i = 0; i < maxVal; i++) {
        for (Node node : strategy.routeRequest(serializer.toBytes(i))) {
            int newCount = 1;
            if (counts.get(node.getId()) != null) {
                newCount = counts.get(node.getId()) + 1;
            }
            counts.put(node.getId(), newCount);
        }
    }
    int sum = 0;
    int totalCounts = 0;
    for (int countVal : counts.values()) {
        sum += countVal;
        totalCounts++;
    }
    int avg = sum / totalCounts;
    NumberFormat percent = NumberFormat.getPercentInstance();
    percent.setMaximumFractionDigits(2);
    System.out.println("Node\tKeys\tPercent\tVariation");
    for (int nodeId : counts.keySet()) {
        System.out.println(nodeId + "\t" + counts.get(nodeId) + "\t" + percent.format(counts.get(nodeId) / (double) sum) + "\t" + percent.format((counts.get(nodeId) - avg) / (double) counts.get(nodeId)));
    }
    double msPerHash = (System.currentTimeMillis() - start) / ((double) repFactor * maxVal);
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(10);
    System.out.println(nf.format(msPerHash) + " ms per hash");
}
Also used : JsonTypeSerializer(voldemort.serialization.json.JsonTypeSerializer) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) RoutingStrategy(voldemort.routing.RoutingStrategy) ConsistentRoutingStrategy(voldemort.routing.ConsistentRoutingStrategy) ConsistentRoutingStrategy(voldemort.routing.ConsistentRoutingStrategy) File(java.io.File) NumberFormat(java.text.NumberFormat)

Example 38 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class ServerTestUtils method createServerConfigWithDefs.

public static VoldemortConfig createServerConfigWithDefs(boolean useNio, int nodeId, String baseDir, Cluster cluster, List<StoreDefinition> stores, Properties properties) throws IOException {
    File clusterXml = new File(TestUtils.createTempDir(), "cluster.xml");
    File storesXml = new File(TestUtils.createTempDir(), "stores.xml");
    ClusterMapper clusterMapper = new ClusterMapper();
    StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();
    FileWriter writer = new FileWriter(clusterXml);
    writer.write(clusterMapper.writeCluster(cluster));
    writer.close();
    writer = new FileWriter(storesXml);
    writer.write(storeDefMapper.writeStoreList(stores));
    writer.close();
    return createServerConfig(useNio, nodeId, baseDir, clusterXml.getAbsolutePath(), storesXml.getAbsolutePath(), properties);
}
Also used : FileWriter(java.io.FileWriter) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File)

Example 39 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class ServerJVMTestUtils method createAndInitializeVoldemortHome.

public static String createAndInitializeVoldemortHome(boolean useNio, int node, String storesXmlfile, Cluster cluster) throws IOException {
    VoldemortConfig config = ServerTestUtils.createServerConfig(useNio, node, TestUtils.createTempDir().getAbsolutePath(), null, storesXmlfile, new Properties());
    // Initialize voldemort config dir with all required files.
    // cluster.xml
    File clusterXml = new File(config.getMetadataDirectory() + File.separator + "cluster.xml");
    FileUtils.writeStringToFile(clusterXml, new ClusterMapper().writeCluster(cluster));
    // stores.xml
    File storesXml = new File(config.getMetadataDirectory() + File.separator + "stores.xml");
    FileUtils.copyFile(new File(storesXmlfile), storesXml);
    // server.properties
    File serverProperties = new File(config.getMetadataDirectory() + File.separator + "server.properties");
    FileUtils.writeLines(serverProperties, Arrays.asList("node.id=" + node, "bdb.cache.size=" + 1024 * 1024, "enable.metadata.checking=" + false, "enable.network.classloader=" + false));
    return config.getVoldemortHome();
}
Also used : ClusterMapper(voldemort.xml.ClusterMapper) Properties(java.util.Properties) File(java.io.File) VoldemortConfig(voldemort.server.VoldemortConfig)

Example 40 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class AdminServiceBasicTest method testIsClusterModified.

@Test
public void testIsClusterModified() {
    AdminClient client = getAdminClient();
    assertFalse("Newly Created admin client has valid cluster", client.isClusterModified());
    String clusterXml = new ClusterMapper().writeCluster(cluster);
    client.metadataMgmtOps.updateRemoteMetadata(cluster.getNodeIds(), MetadataStore.CLUSTER_KEY, clusterXml);
    assertTrue("After cluster update", client.isClusterModified());
}
Also used : ClusterMapper(voldemort.xml.ClusterMapper) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Aggregations

ClusterMapper (voldemort.xml.ClusterMapper)41 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)26 Cluster (voldemort.cluster.Cluster)23 File (java.io.File)18 StoreDefinition (voldemort.store.StoreDefinition)18 StringReader (java.io.StringReader)13 OptionSet (joptsimple.OptionSet)10 Node (voldemort.cluster.Node)10 AdminClient (voldemort.client.protocol.admin.AdminClient)9 VoldemortException (voldemort.VoldemortException)8 Test (org.junit.Test)6 ByteArray (voldemort.utils.ByteArray)6 Versioned (voldemort.versioning.Versioned)6 OptionParser (joptsimple.OptionParser)5 IOException (java.io.IOException)4 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)4 FileNotFoundException (java.io.FileNotFoundException)3 ClientConfig (voldemort.client.ClientConfig)3 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)3 BufferedReader (java.io.BufferedReader)2