@Override
  public Status isAgentAlive(Host agent) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("checking if agent (" + agent.getId() + ") is alive");
    }

    if (agent.getPodId() == null) {
      return null;
    }

    List<Long> otherHosts = findHostByPod(agent.getPodId(), agent.getId());

    for (Long hostId : otherHosts) {

      if (s_logger.isDebugEnabled()) {
        s_logger.debug(
            "sending ping from ("
                + hostId
                + ") to agent's host ip address ("
                + agent.getPrivateIpAddress()
                + ")");
      }
      Status hostState = testIpAddress(hostId, agent.getPrivateIpAddress());
      if (hostState == null) {
        continue;
      }
      if (hostState == Status.Up) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug(
              "ping from ("
                  + hostId
                  + ") to agent's host ip address ("
                  + agent.getPrivateIpAddress()
                  + ") successful, returning that agent is disconnected");
        }
        return Status
            .Disconnected; // the computing host ip is ping-able, but the computing agent is down,
        // report that the agent is disconnected
      } else if (hostState == Status.Down) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("returning host state: " + hostState);
        }
        return hostState;
      }
    }

    // could not reach agent, could not reach agent's host, unclear what the problem is but it'll
    // require more investigation...
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(
          "could not reach agent, could not reach agent's host, returning that we don't have enough information");
    }
    return null;
  }
Ejemplo n.º 2
0
  @Override
  public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.KVM
        && host.getHypervisorType() != HypervisorType.LXC) {
      s_logger.warn("Don't know how to fence non kvm hosts " + host.getHypervisorType());
      return null;
    }

    List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);

    int i = 0;
    for (HostVO h : hosts) {
      if (h.getHypervisorType() == HypervisorType.KVM
          || h.getHypervisorType() == HypervisorType.LXC) {
        if (h.getStatus() != Status.Up) {
          continue;
        }

        i++;

        if (h.getId() == host.getId()) {
          continue;
        }
        FenceAnswer answer;
        try {
          answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
        } catch (AgentUnavailableException e) {
          s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
          continue;
        } catch (OperationTimedoutException e) {
          s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
          continue;
        }
        if (answer != null && answer.getResult()) {
          return true;
        }
      }
    }

    _alertMgr.sendAlert(
        AlertManager.AlertType.ALERT_TYPE_HOST,
        host.getDataCenterId(),
        host.getPodId(),
        "Unable to fence off host: " + host.getId(),
        "Fencing off host "
            + host.getId()
            + " did not succeed after asking "
            + i
            + " hosts. "
            + "Check Agent logs for more information.");

    s_logger.error("Unable to fence off " + vm.toString() + " on " + host.toString());

    return false;
  }
    public boolean shouldAvoid(Host host) {
      if (_dcIds != null && _dcIds.contains(host.getDataCenterId())) {
        return true;
      }

      if (_podIds != null && _podIds.contains(host.getPodId())) {
        return true;
      }

      if (_clusterIds != null && _clusterIds.contains(host.getClusterId())) {
        return true;
      }

      if (_hostIds != null && _hostIds.contains(host.getId())) {
        return true;
      }

      return false;
    }