Search in sources :

Example 1 with StoreClientFactory

use of voldemort.client.StoreClientFactory in project voldemort by voldemort.

the class VoldemortAvroClientShell method main.

public static void main(String[] args) throws IOException {
    if (args.length < 2 || args.length > 3) {
        System.err.println("Usage: java VoldemortAvroClient store_name bootstrap_url [command_file]");
        System.exit(-1);
    }
    String storeName = args[0];
    String bootstrapUrl = args[1];
    String commandsFileName = "";
    BufferedReader fileReader = null;
    BufferedReader inputReader = null;
    try {
        if (args.length == 3) {
            commandsFileName = args[2];
            fileReader = new BufferedReader(new FileReader(commandsFileName));
        }
        inputReader = new BufferedReader(new InputStreamReader(System.in));
    } catch (IOException e) {
        Utils.croak("Failure to open input stream: " + e.getMessage());
    }
    ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(bootstrapUrl).setEnableLazy(false).setRequestFormatType(RequestFormatType.VOLDEMORT_V3);
    StoreClientFactory factory = null;
    DefaultStoreClient<Object, Object> client = null;
    try {
        try {
            factory = new SocketStoreClientFactory(clientConfig);
            client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
        } catch (Exception e) {
            Utils.croak("Could not connect to server: " + e.getMessage());
        }
        System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
        System.out.print(PROMPT);
        Pair<Schema, Schema> keyValueSchemaPair = getLatestKeyValueSchema(bootstrapUrl, storeName);
        Schema latestKeySchema = keyValueSchemaPair.getFirst();
        if (latestKeySchema == null) {
            Utils.croak("Could not parse latest key schema for store name " + storeName);
        }
        Schema latestValueSchema = keyValueSchemaPair.getSecond();
        if (latestValueSchema == null) {
            Utils.croak("Could not parse latest value schema for store name " + storeName);
        }
        if (fileReader != null) {
            processCommands(client, fileReader, latestKeySchema, latestValueSchema, true);
        } else {
            processCommands(client, inputReader, latestKeySchema, latestValueSchema, false);
        }
    } finally {
        if (factory != null)
            factory.close();
        if (fileReader != null)
            fileReader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Schema(org.apache.avro.Schema) IOException(java.io.IOException) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ClientConfig(voldemort.client.ClientConfig)

Example 2 with StoreClientFactory

use of voldemort.client.StoreClientFactory in project voldemort by voldemort.

the class ClientExample method avroStoreExample.

public static void avroStoreExample() {
    System.out.println("==============Avro store example=================");
    // In production environment, the StoreClient instantiation should be done using factory pattern
    // through a Framework such as Spring
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    StoreClient<GenericRecord, GenericRecord> client = factory.getStoreClient("avro-example");
    // creating initial k-v pair
    System.out.println("Creating initial Key and Value");
    String keySchemaJson = "{ \"name\": \"key\", \"type\": \"record\", \"fields\": [{ \"name\": \"user_id\", \"type\": \"int\" }] }";
    Schema keySchema = Schema.parse(keySchemaJson);
    GenericRecord key = new GenericData.Record(keySchema);
    key.put("user_id", 123);
    String valueSchemaJson = "{\n" + "      \"name\": \"value\",\n" + "      \"type\": \"record\",\n" + "      \"fields\": [{ \n" + "        \"name\": \"user_id\",\n" + "        \"type\": \"int\"\n" + "      }, {\n" + "        \"name\": \"gender\",\n" + "        \"type\": \"string\"\n" + "      }, {\n" + "        \"name\": \"age\",\n" + "        \"type\": \"int\",\n" + "        \"optional\": true\n" + "      }]\n" + "    }";
    Schema valueSchema = Schema.parse(valueSchemaJson);
    GenericRecord value = new GenericData.Record(valueSchema);
    value.put("user_id", 123);
    value.put("gender", "male");
    value.put("age", 23);
    // put initial value
    System.out.println("Putting Initial value");
    client.put(key, value);
    // get the value
    System.out.println("Getting the value");
    Versioned<GenericRecord> versioned = client.get(key);
    System.out.println("Initial Versioned Object: " + String.valueOf(versioned));
    System.out.println("           Initial Value: " + String.valueOf(versioned.getValue()));
    // modify the value
    System.out.println("Modifying the value");
    GenericRecord modifiedRecord = versioned.getValue();
    modifiedRecord.put("gender", "female");
    modifiedRecord.put("age", 55);
    versioned.setObject(modifiedRecord);
    // update the value
    System.out.println("Putting the new value");
    client.put(key, versioned);
    // get again and print
    System.out.println("Getting the new value");
    versioned = client.get(key);
    System.out.println("    New Versioned Object: " + String.valueOf(versioned));
    System.out.println("               New Value: " + String.valueOf(versioned.getValue()));
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) ClientConfig(voldemort.client.ClientConfig) GenericRecord(org.apache.avro.generic.GenericRecord) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 3 with StoreClientFactory

use of voldemort.client.StoreClientFactory in project voldemort by voldemort.

the class ChainedInconsistencyResolverTest method setUp.

@Before
public void setUp() throws IOException {
    boolean useNio = false;
    int numServers = 2;
    VoldemortServer[] servers = new VoldemortServer[numServers];
    Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, null, socketStoreFactory, useNio, null, STORES_XML, new Properties());
    // Initialize versioned puts for basic test
    v1 = getVersioned(0, 1, 1, 1, 1, 1);
    v2 = getVersioned(0, 0, 1, 1, 1, 1);
    // Initialize versioned puts for > 1 conflicts
    conflict1 = getVersioned(0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
    conflict2 = getVersioned(0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
    conflict3 = getVersioned(0, 0, 0, 1, 1, 1, 1, 1, 1, 1);
    conflict4 = getVersioned(0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
    conflict5 = getVersioned(0, 0, 0, 0, 0, 1, 1, 1, 1, 1);
    conflict6 = getVersioned(0, 0, 0, 0, 0, 0, 1, 1, 1, 1);
    Node node = cluster.getNodes().iterator().next();
    String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
    StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    defaultStoreClient = storeClientFactory.getStoreClient("test");
    socketStore = ServerTestUtils.getSocketStore(socketStoreFactory, "test", node.getSocketPort(), RequestFormatType.VOLDEMORT_V1);
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) Before(org.junit.Before)

Example 4 with StoreClientFactory

use of voldemort.client.StoreClientFactory in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    //        // start embedded
    //        VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
    //        VoldemortServer server = new VoldemortServer(config);
    //        server.start();
    // bootstrap
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    // create a client that executes operations on a single store
    client = factory.getStoreClient("test");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) PostConstruct(javax.annotation.PostConstruct)

Example 5 with StoreClientFactory

use of voldemort.client.StoreClientFactory in project voldemort by voldemort.

the class ZoneShrinkageCLITest method testZoneShrinkageCLI.

@Test
public void testZoneShrinkageCLI() throws Exception {
    cluster = ClusterTestUtils.getZZZCluster();
    oldStores = ClusterTestUtils.getZZZStoreDefsInMemory();
    setup();
    String[] argv = ("--url " + bsURL + " --drop-zoneid 0 --real-run").split(" ");
    ZoneShrinkageCLI.main(argv);
    AdminClient adminClient = new AdminClient(bsURL);
    assertEquals(2, adminClient.getAdminClientCluster().getZoneIds().size());
    String bootstrapUrl = adminClient.getAdminClientCluster().getNodes().iterator().next().getSocketUrl().toString();
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    StoreClient<String, String> client = factory.getStoreClient(oldStores.get(0).getName());
    client.put("k1", "v1");
    assertEquals("v1", client.get("k1").getValue());
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) AdminClient(voldemort.client.protocol.admin.AdminClient) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) Test(org.junit.Test)

Aggregations

ClientConfig (voldemort.client.ClientConfig)9 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)9 StoreClientFactory (voldemort.client.StoreClientFactory)9 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Schema (org.apache.avro.Schema)2 Before (org.junit.Before)2 Cluster (voldemort.cluster.Cluster)2 Node (voldemort.cluster.Node)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 PostConstruct (javax.annotation.PostConstruct)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 Test (org.junit.Test)1 AdminClient (voldemort.client.protocol.admin.AdminClient)1 VoldemortServer (voldemort.server.VoldemortServer)1