Search in sources :

Example 26 with AdminClient

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();
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) StoreDefinition(voldemort.store.StoreDefinition) ArrayList(java.util.ArrayList) SerializerDefinition(voldemort.serialization.SerializerDefinition) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 27 with AdminClient

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();
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) VoldemortException(voldemort.VoldemortException) VoldemortApplicationException(voldemort.VoldemortApplicationException) IOException(java.io.IOException) InvalidMetadataException(voldemort.store.InvalidMetadataException) StoreDefinition(voldemort.store.StoreDefinition) AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) SerializerDefinition(voldemort.serialization.SerializerDefinition) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 28 with AdminClient

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();
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) StoreDefinition(voldemort.store.StoreDefinition) ArrayList(java.util.ArrayList) SerializerDefinition(voldemort.serialization.SerializerDefinition) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 29 with AdminClient

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());
}
Also used : HashMap(java.util.HashMap) StoreDefinition(voldemort.store.StoreDefinition) ArrayList(java.util.ArrayList) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 30 with AdminClient

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);
}
Also used : AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) Node(voldemort.cluster.Node) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Properties(java.util.Properties) AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient) Before(org.junit.Before)

Aggregations

AdminClient (voldemort.client.protocol.admin.AdminClient)80 Test (org.junit.Test)35 Cluster (voldemort.cluster.Cluster)26 Node (voldemort.cluster.Node)26 Properties (java.util.Properties)19 StoreDefinition (voldemort.store.StoreDefinition)19 ArrayList (java.util.ArrayList)18 AdminClientConfig (voldemort.client.protocol.admin.AdminClientConfig)18 VoldemortException (voldemort.VoldemortException)17 IOException (java.io.IOException)14 Before (org.junit.Before)14 ByteArray (voldemort.utils.ByteArray)14 HashMap (java.util.HashMap)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)13 File (java.io.File)11 VoldemortServer (voldemort.server.VoldemortServer)11 ClientConfig (voldemort.client.ClientConfig)10 VectorClock (voldemort.versioning.VectorClock)10 Versioned (voldemort.versioning.Versioned)9 ClusterMapper (voldemort.xml.ClusterMapper)9