private QueryResponse doQuery(Resource.Type type, Request request, Predicate predicate, boolean checkEmptyResponse)
      throws UnsupportedPropertyException,
      SystemException,
      NoSuchResourceException,
      NoSuchParentResourceException {

    if (LOG.isDebugEnabled()) {
      LOG.debug("Executing resource query: {} where {}", request, predicate);
    }

    QueryResponse queryResponse = clusterController.getResources(type, request, predicate);

    if (checkEmptyResponse && queryResponse.getResources().isEmpty()) {

      // If this is not a collection request then we must throw
      // NoSuchResourceException (404 response) for an empty query result
      if(!isCollectionResource()) {
        throw new NoSuchResourceException(
            "The requested resource doesn't exist: " + type + " not found where " + predicate + ".");
      }
    }
    return queryResponse;
  }
Query the cluster controller for the resources.

@param type                the resource type
@param request             the request information
@param predicate           the predicate
@param checkEmptyResponse  true if an empty query response can trigger a NoSuchResourceException

@return the result of the cluster controller query

@throws NoSuchResourceException if a specific resource was asked for and not found and checkEmptyResponse == true
ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java