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