Search in sources :

Example 31 with StoreDefinitionBuilder

use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.

the class AdminToolTestUtils method storeDefToBuilder.

// This function should only be used in test code path
public static StoreDefinitionBuilder storeDefToBuilder(StoreDefinition sd) {
    StoreDefinitionBuilder sb = new StoreDefinitionBuilder();
    sb.setName(sd.getName()).setDescription(sd.getDescription()).setType(sd.getType()).setRoutingPolicy(sd.getRoutingPolicy()).setRoutingStrategyType(sd.getRoutingStrategyType()).setKeySerializer(sd.getKeySerializer()).setValueSerializer(sd.getKeySerializer()).setReplicationFactor(sd.getReplicationFactor()).setZoneReplicationFactor(sd.getZoneReplicationFactor()).setRequiredReads(sd.getRequiredReads()).setRequiredWrites(sd.getRequiredWrites()).setZoneCountReads(sd.getZoneCountReads()).setZoneCountWrites(sd.getZoneCountWrites());
    return sb;
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder)

Example 32 with StoreDefinitionBuilder

use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.

the class MetaOperationsTest method testMetaSet.

@Test
public void testMetaSet() throws Exception {
    // check if all old metadata are the same
    Set<Object> storesValues = Sets.newHashSet();
    for (Node node : adminClient.getAdminClientCluster().getNodes()) {
        Versioned<String> versioned = adminClient.metadataMgmtOps.getRemoteMetadata(node.getId(), MetadataStore.STORES_KEY);
        assertTrue(versioned != null && versioned.getValue() != null);
        storesValues.add(new StoreDefinitionsMapper().readStoreList(new StringReader(versioned.getValue())));
    }
    assertTrue(storesValues.size() == 1);
    // create new metadata object
    final String newStoreXMLFilePrefix = "updated.stores";
    final String newStoreXMLFileSuffix = "xml";
    List<StoreDefinition> newStoresToUpload = new ArrayList<StoreDefinition>();
    for (StoreDefinition storeDef : stores) {
        StoreDefinitionBuilder sb = AdminToolTestUtils.storeDefToBuilder(storeDef);
        sb.setRoutingPolicy(sb.getRoutingPolicy().equals(RoutingTier.CLIENT) ? RoutingTier.SERVER : RoutingTier.CLIENT);
        sb.setPreferredReads(sb.getPreferredReads() == null ? sb.getRequiredReads() : null);
        newStoresToUpload.add(sb.build());
    }
    // create file of new metadata
    File newStoresXMLFolder = TestUtils.createTempDir();
    File newStoreXMLFile = File.createTempFile(newStoreXMLFilePrefix, newStoreXMLFileSuffix, newStoresXMLFolder);
    FileWriter fwriter = new FileWriter(newStoreXMLFile);
    fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStoresToUpload));
    fwriter.close();
    // set new metadata from file
    AdminCommand.executeCommand(new String[] { "meta", "set", MetadataStore.STORES_KEY + "=" + newStoreXMLFile.getAbsolutePath(), "-u", bsURL, "--confirm" });
    // fetch new metadata from node
    List<StoreDefinition> newStoresToVerify = adminClient.metadataMgmtOps.getRemoteStoreDefList(adminClient.getAdminClientCluster().getNodes().iterator().next().getId()).getValue();
    System.out.println("Uploades stores" + new StoreDefinitionsMapper().writeStoreList(newStoresToUpload));
    System.out.println("Retrieved stores" + new StoreDefinitionsMapper().writeStoreList(newStoresToVerify));
    // check if new metadata is the same as the source
    assertTrue("Old store should not equal to new stores", !newStoresToVerify.equals(stores));
    assertTrue("Uploaded stores and retrieved stores are different", newStoresToVerify.equals(newStoresToUpload));
    // check if all new metadata are the same
    storesValues.clear();
    for (Node node : adminClient.getAdminClientCluster().getNodes()) {
        Versioned<String> versioned = adminClient.metadataMgmtOps.getRemoteMetadata(node.getId(), MetadataStore.STORES_KEY);
        assertTrue(versioned != null && versioned.getValue() != null);
        storesValues.add(new StoreDefinitionsMapper().readStoreList(new StringReader(versioned.getValue())));
    }
    System.out.println(storesValues.size());
    assertTrue(storesValues.size() == 1);
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Node(voldemort.cluster.Node) FileWriter(java.io.FileWriter) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ArrayList(java.util.ArrayList) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) File(java.io.File) Test(org.junit.Test)

Example 33 with StoreDefinitionBuilder

use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.

the class SetMetadataTest method storeDefToBuilder.

// This function is not a full implementation and should only used
// in this test suite
private StoreDefinitionBuilder storeDefToBuilder(StoreDefinition sd) {
    StoreDefinitionBuilder sb = new StoreDefinitionBuilder();
    sb.setName(sd.getName()).setDescription(sd.getDescription()).setType(sd.getType()).setRoutingPolicy(sd.getRoutingPolicy()).setRoutingStrategyType(sd.getRoutingStrategyType()).setKeySerializer(sd.getKeySerializer()).setValueSerializer(sd.getKeySerializer()).setReplicationFactor(sd.getReplicationFactor()).setZoneReplicationFactor(sd.getZoneReplicationFactor()).setRequiredReads(sd.getRequiredReads()).setRequiredWrites(sd.getRequiredWrites()).setZoneCountReads(sd.getZoneCountReads()).setZoneCountWrites(sd.getZoneCountWrites());
    return sb;
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder)

Example 34 with StoreDefinitionBuilder

use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.

the class SetMetadataTest method testSetMetadataStoreXmlVerifyVersionUpdate.

@Test
public void testSetMetadataStoreXmlVerifyVersionUpdate() throws Exception {
    // setup new stores xml
    final String newStoreXMLFilePrefix = "updated.stores";
    final String newStoreXMLFileSuffix = "xml";
    List<StoreDefinition> newStores = new ArrayList<StoreDefinition>();
    for (StoreDefinition storeDef : ClusterTestUtils.getZZZStoreDefsInMemory()) {
        StoreDefinitionBuilder sb = storeDefToBuilder(storeDef);
        Map<Integer, Integer> zrf = sb.getZoneReplicationFactor();
        Integer zone0RepFactor = zrf.get(0);
        zrf.remove(0);
        sb.setReplicationFactor(sb.getReplicationFactor() - zone0RepFactor);
        newStores.add(sb.build());
    }
    File newStoresXMLFolder = TestUtils.createTempDir();
    File newStoreXMLFile = File.createTempFile(newStoreXMLFilePrefix, newStoreXMLFileSuffix, newStoresXMLFolder);
    FileWriter fwriter = new FileWriter(newStoreXMLFile);
    fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStores));
    fwriter.close();
    // check version
    String sysStoreName = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name();
    ByteArray metadataKey = new ByteArray(ByteUtils.getBytes(SystemStoreConstants.VERSIONS_METADATA_KEY, "utf-8"));
    for (VoldemortServer vs : vservers.values()) {
        List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
        String versionInfo = new String(result.get(0).getValue());
        System.out.format("[INITIAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
        Properties props = new Properties();
        props.load(new ByteArrayInputStream(versionInfo.getBytes()));
        for (StoreDefinition sd : oldStores) {
            if (!props.getProperty(sd.getName()).equals("0")) {
                Assert.fail("Initial version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to be 0 but not");
            }
        }
        if (!props.getProperty("cluster.xml").equals("0")) {
            Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
        }
    }
    // update the stores xml
    VoldemortAdminTool.main(new String[] { "--auto", "--set-metadata", MetadataStore.STORES_KEY, "--set-metadata-value", newStoreXMLFile.getAbsolutePath(), "--url", bsURL });
    // properly
    try {
        Thread.sleep(10000);
    } catch (Exception e) {
    }
    // check version
    for (VoldemortServer vs : vservers.values()) {
        List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
        String versionInfo = new String(result.get(0).getValue());
        System.out.format("[FINAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
        Properties props = new Properties();
        props.load(new ByteArrayInputStream(versionInfo.getBytes()));
        for (StoreDefinition sd : oldStores) {
            if (!(Long.parseLong(props.getProperty(sd.getName())) > 0)) {
                Assert.fail("Final version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
            }
        }
        if (!(Long.parseLong(props.getProperty("stores.xml")) > 0)) {
            Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
        }
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Versioned(voldemort.versioning.Versioned) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) File(java.io.File) Test(org.junit.Test)

Example 35 with StoreDefinitionBuilder

use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.

the class StoreOperationsTest method testStoreAddAndDelete.

@Test
public void testStoreAddAndDelete() throws Exception {
    // create new stores_key object
    final String newStoreXMLFilePrefix = "updated.stores";
    final String newStoreXMLFileSuffix = "xml";
    List<StoreDefinition> newStores = new ArrayList<StoreDefinition>();
    List<String> newStoreNames = Lists.newArrayList();
    for (StoreDefinition storeDef : stores) {
        StoreDefinitionBuilder sb = AdminToolTestUtils.storeDefToBuilder(storeDef);
        sb.setName(sb.getName() + "_new");
        newStores.add(sb.build());
        newStoreNames.add(sb.getName());
    }
    // create stores.xml
    File newStoresXMLFolder = TestUtils.createTempDir();
    File newStoreXMLFile = File.createTempFile(newStoreXMLFilePrefix, newStoreXMLFileSuffix, newStoresXMLFolder);
    FileWriter fwriter = new FileWriter(newStoreXMLFile);
    fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStores));
    fwriter.close();
    // execute store-add command
    AdminCommand.executeCommand(new String[] { "store", "add", "-f", newStoreXMLFile.getAbsolutePath(), "-u", bsURL });
    // check if stores have been added
    Integer nodeId = adminClient.getAdminClientCluster().getNodes().iterator().next().getId();
    List<StoreDefinition> newStoresToVerify = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId).getValue();
    for (StoreDefinition newStore : newStores) {
        assertTrue(newStoresToVerify.contains(newStore));
    }
    // execute store-delete command
    AdminCommand.executeCommand(new String[] { "store", "delete", "-s", Joiner.on(",").join(newStoreNames), "-u", bsURL, "--confirm" });
    // check if stores have been deleted
    newStoresToVerify = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId).getValue();
    for (StoreDefinition newStore : newStores) {
        assertTrue(!newStoresToVerify.contains(newStore));
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) StoreDefinition(voldemort.store.StoreDefinition) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) File(java.io.File) Test(org.junit.Test)

Aggregations

StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)57 SerializerDefinition (voldemort.serialization.SerializerDefinition)46 StoreDefinition (voldemort.store.StoreDefinition)42 HashMap (java.util.HashMap)28 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)23 File (java.io.File)17 ByteArray (voldemort.utils.ByteArray)16 Cluster (voldemort.cluster.Cluster)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)12 LinkedList (java.util.LinkedList)10 List (java.util.List)9 VoldemortException (voldemort.VoldemortException)9 Node (voldemort.cluster.Node)8 IOException (java.io.IOException)7 Before (org.junit.Before)6 VoldemortTestConstants.getNineNodeCluster (voldemort.VoldemortTestConstants.getNineNodeCluster)6 AdminClient (voldemort.client.protocol.admin.AdminClient)6 Store (voldemort.store.Store)6 FileWriter (java.io.FileWriter)5