Example #1
0
 /** Returns a "smart" node client to a random node in the cluster */
 public synchronized Client smartClient() {
   NodeAndClient randomNodeAndClient = getRandomNodeAndClient();
   if (randomNodeAndClient != null) {
     return randomNodeAndClient.nodeClient();
   }
   Assert.fail("No smart client found");
   return null; // can't happen
 }
Example #2
0
 /**
  * Returns a node client to random node but not the master. This method will fail if no non-master
  * client is available.
  */
 public synchronized Client nonMasterClient() {
   ensureOpen();
   NodeAndClient randomNodeAndClient =
       getRandomNodeAndClient(Predicates.not(new MasterNodePredicate(getMasterName())));
   if (randomNodeAndClient != null) {
     return randomNodeAndClient.nodeClient(); // ensure node client non-master is requested
   }
   Assert.fail("No non-master client found");
   return null; // can't happen
 }
Example #3
0
 private void restartAllNodes(boolean rollingRestart, RestartCallback callback) throws Exception {
   ensureOpen();
   List<NodeAndClient> toRemove = new ArrayList<TestCluster.NodeAndClient>();
   try {
     for (NodeAndClient nodeAndClient : nodes.values()) {
       if (!callback.doRestart(nodeAndClient.name)) {
         logger.info("Closing node [{}] during restart", nodeAndClient.name);
         toRemove.add(nodeAndClient);
         nodeAndClient.close();
       }
     }
   } finally {
     for (NodeAndClient nodeAndClient : toRemove) {
       nodes.remove(nodeAndClient.name);
     }
   }
   logger.info("Restarting remaining nodes rollingRestart [{}]", rollingRestart);
   if (rollingRestart) {
     int numNodesRestarted = 0;
     for (NodeAndClient nodeAndClient : nodes.values()) {
       callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient());
       logger.info("Restarting node [{}] ", nodeAndClient.name);
       nodeAndClient.restart(callback);
     }
   } else {
     int numNodesRestarted = 0;
     for (NodeAndClient nodeAndClient : nodes.values()) {
       callback.doAfterNodes(numNodesRestarted++, nodeAndClient.nodeClient());
       logger.info("Stopping node [{}] ", nodeAndClient.name);
       nodeAndClient.node.close();
     }
     for (NodeAndClient nodeAndClient : nodes.values()) {
       logger.info("Starting node [{}] ", nodeAndClient.name);
       nodeAndClient.restart(callback);
     }
   }
 }