Exemplo n.º 1
0
  /**
   * Asynchronously start the given vms and return a List of threads that spawned the start. This
   * allows the caller to carry out operations concurrent with the start activity, then wait for the
   * start to complete using {@link #joinStopStartThreads(List,List)}.
   *
   * @param targetVmList A list of hydra.ClientVmInfos to start.
   * @return threadList The threads created to start the VMs.
   */
  public static List startAsync(List targetVmList) {
    Log.getLogWriter().info("In stopStartVMs, vms to start: " + targetVmList);

    // start all vms in targetVms list
    List threadList = new ArrayList();
    for (int i = 0; i < targetVmList.size(); i++) {
      ClientVmInfo targetVm = (ClientVmInfo) (targetVmList.get(i));
      Thread aThread = new StopStartVMs(targetVm, 0, false, true);
      aThread = new HydraSubthread(aThread);
      threadList.add(aThread);
      aThread.start();
    }
    return threadList;
  }
Exemplo n.º 2
0
  /**
   * Concurrently stops a List of Vms, then restart them. Does not wait for the restart to complete
   * before returning. This allows the caller to carry out operations concurrent with the stop and
   * start activity, then wait for the restart to complete using {@link
   * #joinStopStartThreads(List,List)}.
   *
   * <p>Side effects: For any VM which is performing a NICE_KILL because of this call, it is marked
   * as such in the StopStartBB (blackboard). The blackboard will contain a key prefixed with
   * util.StopStartVMs.NiceKillInProgress and appended to with its VmId. The value of this key is
   * the true.
   *
   * <p>This blackboard entry is for the convenience of the caller, and it is up to the caller to
   * look for it or not. When a VM undergoes a NICE_KILL, the VM closes the cache and disconnects
   * from the distributed system. Any threads in that VM doing work can get exceptions during the
   * close and/or disconnect step. This blackboard entry is useful for those threads to allow
   * exceptions when they know an exception is possible.
   *
   * @param targetVmList A list of hydra.ClientVmInfos to stop then restart.
   * @param stopModeList A parallel list of stop modes (Strings).
   * @return threadList The threads created to stop the VMs.
   */
  public static List stopStartAsync(List targetVmList, List stopModeList) {
    if (targetVmList.size() != stopModeList.size()) {
      throw new TestException(
          "Expected targetVmList "
              + targetVmList
              + " and stopModeList "
              + stopModeList
              + " to be parallel lists of the same size, but they have different sizes");
    }
    Log.getLogWriter()
        .info(
            "In stopStartVMs, vms to stop: "
                + targetVmList
                + ", corresponding stop modes: "
                + stopModeList);

    // mark in the blackboard any vms that will undergo a NICE_KILL
    for (int i = 0; i < stopModeList.size(); i++) {
      String stopMode = (String) (stopModeList.get(i));
      if (ClientVmMgr.toStopMode(stopMode) == ClientVmMgr.NICE_KILL) {
        // write nice kills to the blackboard so the killed vm may, if it chooses, handle any
        // exceptions that are underway.
        StopStartBB.getBB()
            .getSharedMap()
            .put(
                NiceKillInProgress + ((ClientVmInfo) targetVmList.get(i)).getVmid(),
                new Boolean(true));
      }
    }

    // stop all vms in targetVms list
    List threadList = new ArrayList();
    for (int i = 0; i < targetVmList.size(); i++) {
      ClientVmInfo targetVm = (ClientVmInfo) (targetVmList.get(i));
      int stopMode = ClientVmMgr.toStopMode((String) (stopModeList.get(i)));
      Thread aThread = new StopStartVMs(targetVm, stopMode);
      aThread = new HydraSubthread(aThread);
      threadList.add(aThread);
      aThread.start();
    }
    return threadList;
  }
Exemplo n.º 3
0
  /**
   * Concurrently stop and/or start a List of Vms. Wait for the operations to complete before
   * returning.
   *
   * <p>Side effects: For any VM which is performing a NICE_KILL because of this call, it is marked
   * as such in the StopStartBB (blackboard). The blackboard will contain a key prefixed with
   * util.StopStartVMs.NiceKillInProgress and appended to with its VmId. The value of this key is
   * the true.
   *
   * <p>This blackboard entry is for the convenience of the caller, and it is up to the caller to
   * look for it or not. When a VM undergoes a NICE_KILL, the VM closes the cache and disconnects
   * from the distributed system. Any threads in that VM doing work can get exceptions during the
   * close and/or disconnect step. This blackboard entry is useful for those threads to allow
   * exceptions when they know an exception is possible.
   *
   * @param targetVmList A list of hydra.ClientVmInfos to stop and/or start.
   * @param stopModeList A parallel list of stop modes (Strings), if doStop is true.
   * @param doStop True if we want to stop the targetVmList, false if not.
   * @param doStart True if we want to start the targetVmList, false if not.
   */
  private static void stopStartVMs(
      List targetVmList, List stopModeList, boolean doStop, boolean doStart) {
    Log.getLogWriter()
        .info(
            "In stopStartVMs, vms to "
                + getAction(doStop, doStart)
                + ": "
                + targetVmList
                + ", corresponding stop modes: "
                + stopModeList);
    if (doStop) {

      // mark in the blackboard any vms that will undergo a NICE_KILL
      for (int i = 0; i < stopModeList.size(); i++) {
        String stopMode = (String) (stopModeList.get(i));
        if (ClientVmMgr.toStopMode(stopMode) == ClientVmMgr.NICE_KILL) {
          // write nice kills to the blackboard so the killed vm may, if it chooses, handle any
          // exceptions that are underway.
          StopStartBB.getBB()
              .getSharedMap()
              .put(
                  NiceKillInProgress + ((ClientVmInfo) targetVmList.get(i)).getVmid(),
                  new Boolean(true));
        }
      }
    }

    // process the vms in targetVms list
    List threadList = new ArrayList();
    for (int i = 0; i < targetVmList.size(); i++) {
      ClientVmInfo targetVm = (ClientVmInfo) (targetVmList.get(i));
      int stopMode = 0;
      if (doStop) {
        stopMode = ClientVmMgr.toStopMode((String) (stopModeList.get(i)));
      }
      StringBuffer aStr = new StringBuffer();
      Thread aThread = new StopStartVMs(targetVm, stopMode, doStop, doStart);
      aThread = new HydraSubthread(aThread);
      threadList.add(aThread);
      aThread.start();
    }

    // wait for all threads to complete their actions
    for (int i = 0; i < threadList.size(); i++) {
      Thread aThread = (Thread) (threadList.get(i));
      try {
        aThread.join();
      } catch (InterruptedException e) {
        throw new TestException(TestHelper.getStackTrace(e));
      }
    }
    String err = (String) (StopStartBB.getBB().getSharedMap().get(StopStartBB.errKey));
    if (err != null) {
      throw new TestException(err);
    }

    // reset the blackboard entries
    if (doStop) {
      for (int i = 0; i < targetVmList.size(); i++) {
        ClientVmInfo targetVm = (ClientVmInfo) (targetVmList.get(i));
        StopStartBB.getBB()
            .getSharedMap()
            .put(StopStartVMs.NiceKillInProgress + targetVm.getVmid(), new Boolean(false));
      }
    }
    Log.getLogWriter()
        .info("In stopStartVMs, done with " + getAction(doStop, doStart) + ": " + targetVmList);
  }
Exemplo n.º 4
0
 /**
  * Convenience method for obtaining the key created for the opList serial tests may put this key
  * on the BB for other threads to use for opList access
  */
 public static String getOpListKey() {
   return OpListKey + Thread.currentThread().getName();
 }
Exemplo n.º 5
0
 /** Convenience method for reading the list of operations for the current client thread. */
 public static OpList getOpList() {
   Object key = OpListKey + Thread.currentThread().getName();
   OpList opList = (OpList) (AsyncMsgBB.getBB().getSharedMap().get(key));
   Log.getLogWriter().info("AsyncBB read from shared map key " + key + ", value " + opList);
   return opList;
 }
Exemplo n.º 6
0
 /** Convenience method for writing a list of operations for the current client thread. */
 public static void putOpList(OpList opList) {
   Object key = OpListKey + Thread.currentThread().getName();
   AsyncMsgBB.getBB().getSharedMap().put(key, opList);
   Log.getLogWriter().info("AsyncBB put into shared map key " + key + ", value " + opList);
 }
Exemplo n.º 7
0
 /**
  * Return the expected commit success/failure for the current thread.
  *
  * @returns true if the current thread should succeed in its commit, false otherwise.
  */
 public static boolean getCommitStatus() {
   Object key = TxBB.CommitStatusKey + Thread.currentThread().getName();
   Object result = TxBB.getBB().getSharedMap().get(key);
   if (result instanceof Boolean) return ((Boolean) result).booleanValue();
   else throw new TestException("Unknown value " + result + " for TxBB sharedMap key " + key);
 }
Exemplo n.º 8
0
 /**
  * Write to the blackboard the expected commit success/failure for the current thread.
  *
  * @param expectCommitStatus True if we expect the current thread to successfully commit, false
  *     otherwise.
  */
 public static void recordCommitStatus(boolean expectCommitStatus) {
   Object key = TxBB.CommitStatusKey + Thread.currentThread().getName();
   TxBB.getBB().getSharedMap().put(key, new Boolean(expectCommitStatus));
   Log.getLogWriter().info("Written to TxBB: " + key + ", " + expectCommitStatus);
 }