use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.
the class AdminServiceBasicTest method testUpdateMultipleStores.
@Test
public void testUpdateMultipleStores() {
doClientOperation();
AdminClient client = getAdminClient();
List<StoreDefinition> originalStoreDefinitions = client.metadataMgmtOps.getRemoteStoreDefList(0).getValue();
StoreDefinition oldTestReplicationStore = getStoreDefinitionFromList(originalStoreDefinitions, "test-replication-memory");
StoreDefinition oldTestRecoveryStore = getStoreDefinitionFromList(originalStoreDefinitions, "test-recovery-data");
StoreDefinition oldTestBasicStore = getStoreDefinitionFromList(originalStoreDefinitions, "test-basic-replication-memory");
// Create store definitions for existing stores with different 'safe' changes
List<StoreDefinition> storesToBeUpdatedList = new ArrayList<StoreDefinition>();
StoreDefinition definition1 = new StoreDefinitionBuilder().setName("test-replication-memory").setType(InMemoryStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition(oldTestReplicationStore.getKeySerializer().getName())).setValueSerializer(oldTestReplicationStore.getValueSerializer()).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(1).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).setOwners(Collections.singletonList("alice")).build();
StoreDefinition definition2 = new StoreDefinitionBuilder().setName("test-recovery-data").setType(InMemoryStorageConfiguration.TYPE_NAME).setKeySerializer(oldTestRecoveryStore.getKeySerializer()).setValueSerializer(oldTestRecoveryStore.getValueSerializer()).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(2).setRequiredWrites(1).build();
StoreDefinition definition3 = new StoreDefinitionBuilder().setName("test-basic-replication-memory").setType(InMemoryStorageConfiguration.TYPE_NAME).setKeySerializer(oldTestBasicStore.getKeySerializer()).setValueSerializer(oldTestBasicStore.getValueSerializer()).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(2).setRequiredReads(1).setPreferredWrites(2).setRequiredWrites(2).build();
storesToBeUpdatedList.add(definition1);
storesToBeUpdatedList.add(definition2);
storesToBeUpdatedList.add(definition3);
updateAndResetStoreDefinitions(storesToBeUpdatedList);
doClientOperation();
}
use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.
the class AdminServiceBasicTest method testDeleteStore.
@Test
public void testDeleteStore() throws Exception {
AdminClient adminClient = getAdminClient();
doClientOperation();
StoreDefinition definition = new StoreDefinitionBuilder().setName("deleteTest").setType(InMemoryStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(1).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
adminClient.storeMgmtOps.addStore(definition);
// now test the store
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setCacheStoreClients(false).setBootstrapUrls(cluster.getNodeById(0).getSocketUrl().toString()));
StoreClient<Object, Object> client = factory.getStoreClient("deleteTest");
int numStores = adminClient.metadataMgmtOps.getRemoteStoreDefList(0).getValue().size();
// delete the store
assertEquals(adminClient.metadataMgmtOps.getRemoteStoreDefList(0).getValue().contains(definition), true);
adminClient.storeMgmtOps.deleteStore("deleteTest");
assertEquals(adminClient.metadataMgmtOps.getRemoteStoreDefList(0).getValue().size(), numStores - 1);
assertEquals(adminClient.metadataMgmtOps.getRemoteStoreDefList(0).getValue().contains(definition), false);
// will attempt to bootstrap)
try {
client = factory.getStoreClient("deleteTest");
client.put("abc", "123");
String s = (String) client.get("abc").getValue();
assertEquals(s, "123");
fail("Should have received bootstrap failure exception");
} catch (Exception e) {
if (!(e instanceof BootstrapFailureException))
throw e;
}
doClientOperation();
// try adding the store again
adminClient.storeMgmtOps.addStore(definition);
client = factory.getStoreClient("deleteTest");
client.put("abc", "123");
String s = (String) client.get("abc").getValue();
assertEquals(s, "123");
doClientOperation();
}
use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.
the class AdminServiceBasicTest method testUpdateSerializerFails.
@Test(expected = VoldemortException.class)
public void testUpdateSerializerFails() {
doClientOperation();
AdminClient client = getAdminClient();
List<StoreDefinition> originalStoreDefinitions = client.metadataMgmtOps.getRemoteStoreDefList(0).getValue();
StoreDefinition oldStore = getStoreDefinitionFromList(originalStoreDefinitions, "test-replication-memory");
// Create a store definition for an existing store with a different
// replication factor
List<StoreDefinition> storesToBeUpdatedList = new ArrayList<StoreDefinition>();
String storeName = "test-replication-memory";
StoreDefinition definitionNew = new StoreDefinitionBuilder().setName(storeName).setType(InMemoryStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("changing-the-serializer")).setValueSerializer(oldStore.getValueSerializer()).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
storesToBeUpdatedList.add(definitionNew);
updateAndResetStoreDefinitions(storesToBeUpdatedList);
doClientOperation();
}
use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.
the class AdminServiceBasicTest method updateAndResetStoreDefinitions.
/**
* Function to update the given stores and then reset the stores.xml back to
* its original state. This is used for confirming that the updates only
* affect the specified stores in the server. Rest of the stores remain
* untouched.
*
* @param storesToBeUpdatedList specifies list of stores to be updated
*/
private void updateAndResetStoreDefinitions(List<StoreDefinition> storesToBeUpdatedList) {
// Track the names of the stores to be updated
Set<String> storesNamesToBeUpdated = getStoreNames(storesToBeUpdatedList);
// Keep track of the original store definitions for the specific stores
// about to be updated
List<StoreDefinition> originalStoreDefinitionsList = new ArrayList<StoreDefinition>();
for (StoreDefinition def : this.storeDefs) {
if (storesNamesToBeUpdated.contains(def.getName())) {
originalStoreDefinitionsList.add(def);
}
}
// Update the definitions on all the nodes
AdminClient adminClient = getAdminClient();
adminClient.metadataMgmtOps.updateRemoteStoreDefList(storesToBeUpdatedList);
// Retrieve stores list and check that other definitions are unchanged
String allStoresDefStr = bootstrapMetadata(MetadataStore.STORES_KEY);
StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
List<StoreDefinition> storeDefList = mapper.readStoreList(new StringReader(allStoresDefStr));
assertEquals(storeDefList.size(), this.storeDefs.size());
// Insert original stores in the map
Map<String, StoreDefinition> storeNameToDefMap = new HashMap<String, StoreDefinition>();
for (StoreDefinition def : this.storeDefs) {
storeNameToDefMap.put(def.getName(), def);
}
// definition should be different. Everything else should be as is
for (StoreDefinition def : storeDefList) {
if (!storesNamesToBeUpdated.contains(def.getName())) {
assertEquals(def, storeNameToDefMap.get(def.getName()));
}
}
// Reset the store definition back to original
adminClient.metadataMgmtOps.updateRemoteStoreDefList(originalStoreDefinitionsList, this.cluster.getNodeIds());
}
use of voldemort.client.protocol.admin.AdminClient in project voldemort by voldemort.
the class AdminServiceBasicTest method setUp.
@Before
public void setUp() throws IOException {
int numServers = 2;
servers = new VoldemortServer[numServers];
int[][] partitionMap = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
Properties serverProperties = new Properties();
serverProperties.setProperty("client.max.connections.per.node", "20");
serverProperties.setProperty("enforce.retention.policy.on.read", Boolean.toString(onlineRetention));
serverProperties.setProperty(VoldemortConfig.DEFAULT_STORAGE_SPACE_QUOTA_IN_KB, Long.toString(defaultStoreQuota));
cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, partitionMap, socketStoreFactory, useNio, null, storesXmlfile, serverProperties);
storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXmlfile));
Properties adminProperties = new Properties();
adminProperties.setProperty("max_connections", "20");
adminClient = new AdminClient(cluster, new AdminClientConfig(adminProperties));
Node node = cluster.getNodeById(0);
String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
storeClient = storeClientFactory.getStoreClient(STORE_NAME);
}
Aggregations