Exemplo n.º 1
0
 /**
  * Run method for this thread: if this thread is set to stop, then stop a VM and wait for it to
  * stop. If this thread is set to start then start a VM and wait for it to start. Any errors are
  * placed in the blackboard errStr.
  */
 public void run() {
   try {
     Log.getLogWriter().info("Started " + getName());
     try {
       if (stop) {
         ClientVmMgr.stop(
             "Test is synchronously stopping "
                 + targetVm
                 + " with "
                 + ClientVmMgr.toStopModeString(stopMode),
             stopMode,
             ClientVmMgr.ON_DEMAND,
             targetVm);
       }
       VMotionUtil.doVMotion(targetVm);
       if (start) {
         ClientVmMgr.start("Test is synchronously starting " + targetVm, targetVm);
       }
     } catch (hydra.ClientVmNotFoundException e) {
       Log.getLogWriter()
           .info("Caught in thread " + getName() + ":" + TestHelper.getStackTrace(e));
       StopStartBB.getBB().getSharedMap().put(StopStartBB.errKey, TestHelper.getStackTrace(e));
     }
   } catch (Throwable e) {
     Log.getLogWriter().info("Caught in thread " + getName() + ":" + TestHelper.getStackTrace(e));
     StopStartBB.getBB().getSharedMap().put(StopStartBB.errKey, TestHelper.getStackTrace(e));
   }
   Log.getLogWriter().info(getName() + " terminating");
 }
Exemplo n.º 2
0
 /**
  * Constructor to specify stop only or start only or both.
  *
  * @param aVmId The VmId of the VM to stop then restart.
  * @param howToStop The hydra.ClientVmMgr stopMode (unused if stop is false).
  * @parram doStop If true then this thread stops vms.
  * @parram doStart If true then this thread starts vms.
  */
 public StopStartVMs(ClientVmInfo aVmId, int howToStop, boolean doStop, boolean doStart) {
   if (!doStop && !doStart) {
     throw new TestException(
         "You must specify at least one of stop or start, stop is "
             + doStop
             + " and start is "
             + doStart);
   }
   targetVm = aVmId;
   stopMode = howToStop;
   stop = doStop;
   start = doStart;
   if (doStop) {
     setName(
         "<StopStartVMs-thread to "
             + getAction(stop, start)
             + " "
             + aVmId
             + " with "
             + ClientVmMgr.toStopModeString(stopMode)
             + ">");
   } else {
     setName("<StopStartVMs-thread to " + getAction(stop, start) + " " + aVmId + ">");
   }
 }
Exemplo n.º 3
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.º 4
0
 /**
  * Constructor to specify stop and start.
  *
  * @param aVmId The VmId of the VM to stop then restart.
  * @param howToStop The hydra.ClientVmMgr stopMode (unused if stop is false).
  */
 public StopStartVMs(ClientVmInfo aVmId, int howToStop) {
   targetVm = aVmId;
   stopMode = howToStop;
   stop = true;
   start = true;
   setName(
       "<StopStartVMs-thread to "
           + getAction(stop, start)
           + " "
           + aVmId
           + " with "
           + ClientVmMgr.toStopModeString(stopMode)
           + ">");
 }
Exemplo n.º 5
0
 /**
  * Return a List of all other vms except for one along with a parallel stop mode list, and also
  * return the one vm not in the list.
  *
  * @return [0] (List<ClientVmInfo>)A List of ClientVmInfo instances; this includes all vms except
  *     the current vm and except for one other vm. [1] (List<String>) A parallel List to [0]
  *     containing stop modes. [2] (ClientVMInfo) The ClientVmInfo instance of the one vm excluded
  *     from [0] (other than this vm) [3] (String) The stop mode for [2] [4] (List<ClientVmInfo>) A
  *     List of ClientVmInfo instances for all vms except this one. [5] (List<String>) A parallel
  *     List to [4] of stop modes.
  */
 public static Object[] getOtherVMsDivided(String[] excludedClientNames) {
   Vector<Integer> otherVmIDs = ClientVmMgr.getOtherClientVmids();
   List<ClientVmInfo> allOtherVMs = new ArrayList();
   List<String> stopModeList = new ArrayList();
   for (int i = 0; i < otherVmIDs.size(); i++) {
     ClientVmInfo info = new ClientVmInfo(otherVmIDs.get(i));
     ClientVmInfo infoFromBB =
         (ClientVmInfo) StopStartBB.getBB().getSharedMap().get(VmInfoKey + otherVmIDs.get(i));
     if (infoFromBB != null) {
       info = infoFromBB;
     }
     String clientName = info.getClientName();
     if (clientName == null) {
       allOtherVMs.add(info);
       stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes));
     } else {
       boolean inExcludedNames = false;
       for (String excludeName : excludedClientNames) {
         if (clientName.indexOf(excludeName) >= 0) inExcludedNames = true;
         break;
       }
       if (!inExcludedNames) {
         allOtherVMs.add(info);
         stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes));
       }
     }
   }
   List<ClientVmInfo> allOtherVMsExceptOne = allOtherVMs.subList(0, allOtherVMs.size() - 1);
   List<String> stopModesExceptOne = stopModeList.subList(0, stopModeList.size() - 1);
   ClientVmInfo remainingVM = allOtherVMs.get(allOtherVMs.size() - 1);
   String remainingStopMode = stopModeList.get(stopModeList.size() - 1);
   return new Object[] {
     allOtherVMsExceptOne,
     stopModesExceptOne,
     remainingVM,
     remainingStopMode,
     allOtherVMs,
     stopModeList
   };
 }
Exemplo n.º 6
0
 /**
  * Return a List of all other vms except for one along with a parallel stop mode list, and also
  * return the one vm not in the list.
  *
  * @return [0] (List<ClientVmInfo>)A List of ClientVmInfo instances; this includes all vms except
  *     the current vm and except for one other vm. [1] (List<String>) A parallel List to [0]
  *     containing stop modes. [2] (ClientVMInfo) The ClientVmInfo instance of the one vm excluded
  *     from [0] (other than this vm) [3] (String) The stop mode for [2] [4] (List<ClientVmInfo>) A
  *     List of ClientVmInfo instances for all vms except this one. [5] (List<String>) A parallel
  *     List to [4] of stop modes.
  */
 public static Object[] getOtherVMsDivided() {
   Vector<Integer> otherVmIDs = ClientVmMgr.getOtherClientVmids();
   List<ClientVmInfo> allOtherVMs = new ArrayList();
   List<String> stopModeList = new ArrayList();
   for (int i = 0; i < otherVmIDs.size(); i++) {
     ClientVmInfo info = new ClientVmInfo(otherVmIDs.get(i));
     allOtherVMs.add(info);
     stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes));
   }
   List<ClientVmInfo> allOtherVMsExceptOne = allOtherVMs.subList(0, allOtherVMs.size() - 1);
   List<String> stopModesExceptOne = stopModeList.subList(0, stopModeList.size() - 1);
   ClientVmInfo remainingVM = allOtherVMs.get(allOtherVMs.size() - 1);
   String remainingStopMode = stopModeList.get(stopModeList.size() - 1);
   return new Object[] {
     allOtherVMsExceptOne,
     stopModesExceptOne,
     remainingVM,
     remainingStopMode,
     allOtherVMs,
     stopModeList
   };
 }
Exemplo n.º 7
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);
  }