Package org.apache.hama.bsp.sync

Examples of org.apache.hama.bsp.sync.ZKSyncBSPMasterClient


   * Initialize the global synchronization client.
   *
   * @param conf Hama configuration.
   */
  private void initZK(HamaConfiguration conf) {
    this.syncClient = new ZKSyncBSPMasterClient();
    this.syncClient.init(conf);
  }
View Full Code Here


      String bspRoot = "/bsp";

      ZooKeeperSyncClientImpl peerClient = (ZooKeeperSyncClientImpl) SyncServiceFactory
          .getPeerSyncClient(configuration);

      ZKSyncBSPMasterClient masterClient = (ZKSyncBSPMasterClient) SyncServiceFactory
          .getMasterSyncClient(configuration);

      masterClient.init(configuration);

      Thread.sleep(100);

      Log.info("Created master and client sync clients");

      assertTrue(masterClient.hasKey(bspRoot));

      Log.info("BSP root exists");

      BSPJobID jobID = new BSPJobID("test1", 1);
      masterClient.registerJob(jobID.toString());
      TaskID taskId1 = new TaskID(jobID, 1);
      TaskID taskId2 = new TaskID(jobID, 2);

      TaskAttemptID task1 = new TaskAttemptID(taskId1, 1);
      TaskAttemptID task2 = new TaskAttemptID(taskId2, 1);

      int zkPort = BSPNetUtils.getFreePort(21815);
      configuration.setInt(Constants.PEER_PORT, zkPort);
      peerClient.init(configuration, jobID, task1);

      peerClient.registerTask(jobID, "hamanode1", 5000L, task1);
      peerClient.registerTask(jobID, "hamanode2", 5000L, task2);

      peerClient.storeInformation(
          peerClient.constructKey(jobID, "info", "level2"), new IntWritable(5),
          true, null);

      String[] names = peerClient.getAllPeerNames(task1);

      Log.info("Found child count = " + names.length);

      assertEquals(2, names.length);

      Log.info("Passed the child count test");

      masterClient.addKey(masterClient.constructKey(jobID, "peer", "1"),
          true, null);
      masterClient.addKey(masterClient.constructKey(jobID, "peer", "2"),
          true, null);

      String[] peerChild = masterClient.getChildKeySet(
          masterClient.constructKey(jobID, "peer"), null);
      Log.info("Found child count = " + peerChild.length);

      assertEquals(2, peerChild.length);

      Log.info(" Peer name " + peerChild[0]);
      Log.info(" Peer name " + peerChild[1]);

      Log.info("Passed the child key set test");

      masterClient.deregisterJob(jobID.toString());
      Log.info(masterClient.constructKey(jobID));

      Thread.sleep(200);

      assertEquals(false, masterClient.hasKey(masterClient.constructKey(jobID)));

      Log.info("Passed the key presence test");

      boolean result = masterClient
          .getInformation(masterClient.constructKey(jobID, "info", "level3"),
              new IntWritable());

      assertEquals(false, result);
     
      Writable[] writableArr = new Writable[2];
      writableArr[0] = new LongWritable(3L);
      writableArr[1] = new LongWritable(5L);
      ArrayWritable arrWritable = new ArrayWritable(LongWritable.class);
      arrWritable.set(writableArr);
      masterClient.storeInformation(
          masterClient.constructKey(jobID, "info", "level3"),
          arrWritable, true, null);
     
      ArrayWritable valueHolder = new ArrayWritable(LongWritable.class);
     
      boolean getResult = masterClient.getInformation(
          masterClient.constructKey(jobID, "info", "level3"), valueHolder);
     
      assertTrue(getResult);
     
      assertEquals(arrWritable.get()[0], valueHolder.get()[0]);
      assertEquals(arrWritable.get()[1], valueHolder.get()[1]);
View Full Code Here

  /**
   * Initialize the global synchronization client.
   * @param conf Hama configuration.
   */
  private void initZK(HamaConfiguration conf) {
    this.syncClient = new ZKSyncBSPMasterClient();
    this.syncClient.init(conf);
  }
View Full Code Here

   * Initialize the global synchronization client.
   *
   * @param conf Hama configuration.
   */
  private void initZK(HamaConfiguration conf) {
    this.syncClient = new ZKSyncBSPMasterClient();
    this.syncClient.init(conf);
  }
View Full Code Here

      String bspRoot = "/bsp";

      ZooKeeperSyncClientImpl peerClient = (ZooKeeperSyncClientImpl) SyncServiceFactory
          .getPeerSyncClient(configuration);

      ZKSyncBSPMasterClient masterClient = (ZKSyncBSPMasterClient) SyncServiceFactory
          .getMasterSyncClient(configuration);

      masterClient.init(configuration);

      Thread.sleep(100);

      Log.info("Created master and client sync clients");

      assertTrue(masterClient.hasKey(bspRoot));

      Log.info("BSP root exists");

      BSPJobID jobID = new BSPJobID("test1", 1);
      masterClient.registerJob(jobID.toString());
      TaskID taskId1 = new TaskID(jobID, 1);
      TaskID taskId2 = new TaskID(jobID, 2);

      TaskAttemptID task1 = new TaskAttemptID(taskId1, 1);
      TaskAttemptID task2 = new TaskAttemptID(taskId2, 1);

      int zkPort = BSPNetUtils.getFreePort(21815);
      configuration.setInt(Constants.PEER_PORT, zkPort);
      peerClient.init(configuration, jobID, task1);

      peerClient.registerTask(jobID, "hamanode1", 5000L, task1);
      peerClient.registerTask(jobID, "hamanode2", 5000L, task2);

      peerClient.storeInformation(
          peerClient.constructKey(jobID, "info", "level2"), new IntWritable(5),
          true, null);

      String[] names = peerClient.getAllPeerNames(task1);

      Log.info("Found child count = " + names.length);

      assertEquals(2, names.length);

      Log.info("Passed the child count test");

      masterClient.addKey(masterClient.constructKey(jobID, "peer", "1"), true,
          null);
      masterClient.addKey(masterClient.constructKey(jobID, "peer", "2"), true,
          null);

      String[] peerChild = masterClient.getChildKeySet(
          masterClient.constructKey(jobID, "peer"), null);
      Log.info("Found child count = " + peerChild.length);

      assertEquals(2, peerChild.length);

      Log.info(" Peer name " + peerChild[0]);
      Log.info(" Peer name " + peerChild[1]);

      Log.info("Passed the child key set test");

      masterClient.deregisterJob(jobID.toString());
      Log.info(masterClient.constructKey(jobID));

      Thread.sleep(200);

      assertEquals(false, masterClient.hasKey(masterClient.constructKey(jobID)));

      Log.info("Passed the key presence test");

      boolean result = masterClient
          .getInformation(masterClient.constructKey(jobID, "info", "level3"),
              new IntWritable());

      assertEquals(false, result);

      Writable[] writableArr = new Writable[2];
      writableArr[0] = new LongWritable(3L);
      writableArr[1] = new LongWritable(5L);
      ArrayWritable arrWritable = new ArrayWritable(LongWritable.class);
      arrWritable.set(writableArr);
      masterClient.storeInformation(
          masterClient.constructKey(jobID, "info", "level3"), arrWritable,
          true, null);

      ArrayWritable valueHolder = new ArrayWritable(LongWritable.class);

      boolean getResult = masterClient.getInformation(
          masterClient.constructKey(jobID, "info", "level3"), valueHolder);

      assertTrue(getResult);

      assertEquals(arrWritable.get()[0], valueHolder.get()[0]);
      assertEquals(arrWritable.get()[1], valueHolder.get()[1]);
View Full Code Here

   * Initialize the global synchronization client.
   *
   * @param conf Hama configuration.
   */
  private void initZK(HamaConfiguration conf) {
    this.syncClient = new ZKSyncBSPMasterClient();
    this.syncClient.init(conf);
  }
View Full Code Here

      String bspRoot = "/bsp";

      ZooKeeperSyncClientImpl peerClient = (ZooKeeperSyncClientImpl) SyncServiceFactory
          .getPeerSyncClient(configuration);

      ZKSyncBSPMasterClient masterClient = (ZKSyncBSPMasterClient) SyncServiceFactory
          .getMasterSyncClient(configuration);

      masterClient.init(configuration);

      Thread.sleep(100);

      Log.info("Created master and client sync clients");

      assertTrue(masterClient.hasKey(bspRoot));

      Log.info("BSP root exists");

      BSPJobID jobID = new BSPJobID("test1", 1);
      masterClient.registerJob(jobID.toString());
      TaskID taskId1 = new TaskID(jobID, 1);
      TaskID taskId2 = new TaskID(jobID, 2);

      TaskAttemptID task1 = new TaskAttemptID(taskId1, 1);
      TaskAttemptID task2 = new TaskAttemptID(taskId2, 1);

      int zkPort = BSPNetUtils.getFreePort(21815);
      configuration.setInt(Constants.PEER_PORT, zkPort);
      peerClient.init(configuration, jobID, task1);

      peerClient.registerTask(jobID, "hamanode1", 5000L, task1);
      peerClient.registerTask(jobID, "hamanode2", 5000L, task2);

      peerClient.storeInformation(
          peerClient.constructKey(jobID, "info", "level2"), new IntWritable(5),
          true, null);

      String[] names = peerClient.getAllPeerNames(task1.getJobID());

      Log.info("Found child count = " + names.length);

      assertEquals(2, names.length);

      Log.info("Passed the child count test");

      masterClient.addKey(masterClient.constructKey(jobID, "peer", "1"), true,
          null);
      masterClient.addKey(masterClient.constructKey(jobID, "peer", "2"), true,
          null);

      String[] peerChild = masterClient.getChildKeySet(
          masterClient.constructKey(jobID, "peer"), null);
      Log.info("Found child count = " + peerChild.length);

      assertEquals(2, peerChild.length);

      Log.info(" Peer name " + peerChild[0]);
      Log.info(" Peer name " + peerChild[1]);

      Log.info("Passed the child key set test");

      masterClient.deregisterJob(jobID.toString());
      Log.info(masterClient.constructKey(jobID));

      Thread.sleep(200);

      assertEquals(false, masterClient.hasKey(masterClient.constructKey(jobID)));

      Log.info("Passed the key presence test");

      boolean result = masterClient
          .getInformation(masterClient.constructKey(jobID, "info", "level3"),
              new IntWritable());

      assertEquals(false, result);

      Writable[] writableArr = new Writable[2];
      writableArr[0] = new LongWritable(3L);
      writableArr[1] = new LongWritable(5L);
      ArrayWritable arrWritable = new ArrayWritable(LongWritable.class);
      arrWritable.set(writableArr);
      masterClient.storeInformation(
          masterClient.constructKey(jobID, "info", "level3"), arrWritable,
          true, null);

      ArrayWritable valueHolder = new ArrayWritable(LongWritable.class);

      boolean getResult = masterClient.getInformation(
          masterClient.constructKey(jobID, "info", "level3"), valueHolder);

      assertTrue(getResult);

      assertEquals(arrWritable.get()[0], valueHolder.get()[0]);
      assertEquals(arrWritable.get()[1], valueHolder.get()[1]);
View Full Code Here

TOP

Related Classes of org.apache.hama.bsp.sync.ZKSyncBSPMasterClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.