public static void main(String[] args) throws Exception {

    OptionParser parser = new OptionParser();
    parser
        .accepts("client-zone-id", "client zone id for zone routing")
        .withRequiredArg()
        .describedAs("zone-id")
        .ofType(Integer.class);
    OptionSet options = parser.parse(args);

    List<String> nonOptions = options.nonOptionArguments();
    if (nonOptions.size() < 2 || nonOptions.size() > 3) {
      System.err.println(
          "Usage: java VoldemortClientShell store_name bootstrap_url [command_file] [options]");
      parser.printHelpOn(System.err);
      System.exit(-1);
    }

    String storeName = nonOptions.get(0);
    String bootstrapUrl = nonOptions.get(1);

    String commandsFileName = "";
    BufferedReader fileReader = null;
    BufferedReader inputReader = null;
    try {
      if (nonOptions.size() == 3) {
        commandsFileName = nonOptions.get(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)
            .setRequestFormatType(RequestFormatType.VOLDEMORT_V3);

    if (options.has("client-zone-id")) {
      clientConfig.setClientZoneId((Integer) options.valueOf("client-zone-id"));
    }

    StoreClientFactory factory = new SocketStoreClientFactory(clientConfig);

    try {
      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);
    if (fileReader != null) {
      processCommands(factory, fileReader, true);
      fileReader.close();
    }
    processCommands(factory, inputReader, false);
  }
示例#2
0
  public static void main(String[] args) {

    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory =
        new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));

    // create a client that executes operations on a single store
    StoreClient store = factory.getStoreClient("kevoree");

    store.put("pompier1", "capteurs");

    Versioned<String> data = store.get("pompier1");

    System.out.println(data.getValue() + " " + data.getVersion());
    store.delete("pompier1", data.getVersion());
  }
  public long multiWrite(int count, String keyRoot) {

    StoreClient<String, Doc> client = _factory.getStoreClient("test");

    long start = System.currentTimeMillis();

    for (int i = 0; i < count; i++) {
      Doc d = new Doc("name", "geir");
      d.add("x", 1);

      Versioned<Doc> v = new Versioned<Doc>(d);

      client.put(keyRoot + i, v);
    }

    long end = System.currentTimeMillis();

    return end - start;
  }
  public void simple() {

    StoreClient<String, Doc> client = _factory.getStoreClient("test");

    Versioned<Doc> v = client.get("key");

    if (v == null) {
      Doc d = new Doc("name", "geir");
      d.add("x", 1);

      v = new Versioned<Doc>(d);
    }

    // update the value
    client.put("key", v);

    v = client.get("key");

    System.out.println("value : " + v.getValue());
    System.out.println("clock : " + v.getVersion());
  }
  public long multiRead(int count, String keyRoot) {

    StoreClient<String, Doc> client = _factory.getStoreClient("test");

    long start = System.currentTimeMillis();

    int found = 0;

    for (int i = 0; i < count; i++) {
      Versioned<Doc> v = client.get(keyRoot + i);

      if (v != null) {
        found++;
      }
    }

    long end = System.currentTimeMillis();

    System.out.println("Found : " + found);

    return end - start;
  }
示例#6
0
  public static void main(String[] args) {

    /*              */
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory =
        new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));

    String bootstrapUrl2 = "tcp://localhost:6667";
    StoreClientFactory factory2 =
        new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl2));

    String bootstrapUrl3 = "tcp://localhost:6668";
    StoreClientFactory factory3 =
        new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl3));

    // create a client that executes operations on a single store
    StoreClient client = factory.getStoreClient("kevoree");
    StoreClient client2 = factory2.getStoreClient("kevoree");
    StoreClient client3 = factory3.getStoreClient("kevoree");

    /*
    AdminClientConfig config =  new AdminClientConfig();


    AdminClient t2 = new AdminClient(bootstrapUrl,config);
    Cluster current = t2.getAdminClientCluster();
    System.out.println("Number of node "+current.getNodes().size());


    Node newNode = new Node(11,"localhost",8081,6666,9000, new ArrayList<Integer>());
    List<Node> nodes = Lists.newArrayList();



    Cluster newCluster = new Cluster(current.getName(),nodes,Lists.newArrayList(current.getZones()));



    Cluster generatedCluster = RebalanceUtils.getClusterWithNewNodes(current, newCluster);




    RebalanceClientConfig config2 = new RebalanceClientConfig();
    config2.setMaxParallelRebalancing(1);
    config2.setDeleteAfterRebalancingEnabled(false);
    config2.setEnableShowPlan(false);
    config2.setMaxTriesRebalancing(100);
    config2.setRebalancingClientTimeoutSeconds(500);
    config2.setPrimaryPartitionBatchSize(1000);
    config2.setStealerBasedRebalancing(false);


    RebalanceController   rebalanceController = new RebalanceController(bootstrapUrl, config2);

    rebalanceController.rebalance(generatedCluster);
    rebalanceController.stop();

    AdminClient t3 = new AdminClient(bootstrapUrl,config);
    Cluster current3 = t2.getAdminClientCluster();
    System.out.println("Number of node "+current3.getNodes().size());

       */

    client2.put("pompier1", "jed2");

    List<Node> t = client2.getResponsibleNodes("id2");

    System.out.println(t);

    factory.close();

    factory2.close();

    factory3.close();

    // System.out.println(client.get("some_key"));

  }
 private static void processCommands(
     StoreClientFactory factory, BufferedReader reader, boolean printCommands) throws IOException {
   for (String line = reader.readLine(); line != null; line = reader.readLine()) {
     if (line.trim().equals("")) continue;
     if (printCommands) System.out.println(line);
     try {
       if (line.toLowerCase().startsWith("put")) {
         JsonReader jsonReader = new JsonReader(new StringReader(line.substring("put".length())));
         Object key = tightenNumericTypes(jsonReader.read());
         Object value = tightenNumericTypes(jsonReader.read());
         if (jsonReader.hasMore()) client.put(key, value, tightenNumericTypes(jsonReader.read()));
         else client.put(key, value);
       } else if (line.toLowerCase().startsWith("getall")) {
         JsonReader jsonReader =
             new JsonReader(new StringReader(line.substring("getall".length())));
         List<Object> keys = new ArrayList<Object>();
         try {
           while (true) keys.add(jsonReader.read());
         } catch (EndOfFileException e) {
           // this is okay, just means we are done reading
         }
         Map<Object, Versioned<Object>> vals = client.getAll(keys);
         if (vals.size() > 0) {
           for (Map.Entry<Object, Versioned<Object>> entry : vals.entrySet()) {
             System.out.print(entry.getKey());
             System.out.print(" => ");
             printVersioned(entry.getValue());
           }
         } else {
           System.out.println("null");
         }
       } else if (line.toLowerCase().startsWith("get")) {
         JsonReader jsonReader = new JsonReader(new StringReader(line.substring("get".length())));
         Object key = tightenNumericTypes(jsonReader.read());
         if (jsonReader.hasMore())
           printVersioned(client.get(key, tightenNumericTypes(jsonReader.read())));
         else printVersioned(client.get(key));
       } else if (line.toLowerCase().startsWith("delete")) {
         JsonReader jsonReader =
             new JsonReader(new StringReader(line.substring("delete".length())));
         client.delete(tightenNumericTypes(jsonReader.read()));
       } else if (line.startsWith("preflist")) {
         JsonReader jsonReader =
             new JsonReader(new StringReader(line.substring("preflist".length())));
         Object key = tightenNumericTypes(jsonReader.read());
         printNodeList(client.getResponsibleNodes(key), factory.getFailureDetector());
       } else if (line.startsWith("help")) {
         System.out.println("Commands:");
         System.out.println("put key value -- Associate the given value with the key.");
         System.out.println("get key -- Retrieve the value associated with the key.");
         System.out.println("getall key -- Retrieve the value(s) associated with the key.");
         System.out.println("delete key -- Remove all values associated with the key.");
         System.out.println("preflist key -- Get node preference list for given key.");
         System.out.println("help -- Print this message.");
         System.out.println("exit -- Exit from this shell.");
         System.out.println();
       } else if (line.startsWith("quit") || line.startsWith("exit")) {
         System.out.println("k k thx bye.");
         System.exit(0);
       } else {
         System.err.println("Invalid command.");
       }
     } catch (EndOfFileException e) {
       System.err.println("Expected additional token.");
     } catch (SerializationException e) {
       System.err.print("Error serializing values: ");
       e.printStackTrace();
     } catch (VoldemortException e) {
       System.err.println("Exception thrown during operation.");
       e.printStackTrace(System.err);
     } catch (ArrayIndexOutOfBoundsException e) {
       System.err.println("Invalid command.");
     } catch (Exception e) {
       System.err.println("Unexpected error:");
       e.printStackTrace(System.err);
     }
     System.out.print(PROMPT);
   }
 }