@Override
  public Node findNode(URL node) throws RestApiException {
    Node ret = null;
    Collection<String> aliases = aliasLookup.getForAlias(node.getHost());
    List<Node> nodes = getNodes();
    for (Node n : nodes) {

      boolean hostMatches = false;
      // Not the same host

      for (String alias : aliases) {
        if (n.getRestUrl().getHost().equals(alias)) {
          hostMatches = true;
          break;
        }
      }

      if (!hostMatches) {
        continue;
      }

      if (node.getPort() != -1) {
        if (n.getRestUrl().getPort() == node.getPort()) {
          return n;
        }
      } else {
        if (ret != null) {
          throw new IllegalArgumentException(
                  "Found more than one node with the same hostname. Need port");
        }
        ret = n;
      }
    }

    if (ret == null) {
      throw new RestApiException("Couldn't find node " + node);
    }

    return ret;
  }