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;
}
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);
}
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;
}
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");
}
}
}
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));
}
}
Aggregations