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);
  }
Exemple #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;
  }
Exemple #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"));

  }