Java Code Examples for org.apache.solr.client.solrj.response.QueryResponse#getStatus()

The following examples show how to use org.apache.solr.client.solrj.response.QueryResponse#getStatus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSolrHealthIndicator.java    From ambari-logsearch with Apache License 2.0 9 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
  Status status = Status.DOWN;
  String errorDetails = null;
  if (getSolrTemplate() != null && getSolrTemplate().getSolrClient() != null) {
    try {
      SolrClient solrClient = getSolrTemplate().getSolrClient();
      SolrQuery q = new SolrQuery("*:*");
      q.setRows(0);
      QueryResponse response = solrClient.query(q);
      if (response.getStatus() == 0) {
        status = Status.UP;
        if (response.getResults() != null) {
          builder.withDetail("numDocs", response.getResults().getNumFound());
        }
      }
    } catch (Exception e) {
      errorDetails = e.getMessage();
    }
  }
  builder.status(status);
  if (errorDetails != null) {
    builder.withDetail("error", errorDetails);
  }
}
 
Example 2
Source File: CaseController.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@GetMapping("/healthcheck")
public String healthcheck() throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.Q, "*:*");
    params.set(CommonParams.OMIT_HEADER, true);

    HttpSolrClient client = getClient();
    try {
        QueryResponse response = client.query(collection, params);
        if (response.getStatus() == 0) {
            return "Success";
        }
        throw new Exception(response.toString());
    } catch (Exception e) {
        throw e;
    }
}
 
Example 3
Source File: SolrResponsesComparator.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Validates that solr instance is running and that query was processed.
 * @param response
 */
public void validateResponse(QueryResponse response)
{
    switch (response.getStatus())
    {
        case 500:
            throw new RuntimeException("Solr instance internal server error 500");

        default:
            break;
    }
}
 
Example 4
Source File: LBSolrClient.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void checkAZombieServer(ServerWrapper zombieServer) {
  try {
    QueryRequest queryRequest = new QueryRequest(solrQuery);
    queryRequest.setBasePath(zombieServer.baseUrl);
    QueryResponse resp = queryRequest.process(getClient(zombieServer.getBaseUrl()));
    if (resp.getStatus() == 0) {
      // server has come back up.
      // make sure to remove from zombies before adding to alive to avoid a race condition
      // where another thread could mark it down, move it back to zombie, and then we delete
      // from zombie and lose it forever.
      ServerWrapper wrapper = zombieServers.remove(zombieServer.getBaseUrl());
      if (wrapper != null) {
        wrapper.failedPings = 0;
        if (wrapper.standard) {
          addToAlive(wrapper);
        }
      } else {
        // something else already moved the server from zombie to alive
      }
    }
  } catch (Exception e) {
    //Expected. The server is still down.
    zombieServer.failedPings++;

    // If the server doesn't belong in the standard set belonging to this load balancer
    // then simply drop it after a certain number of failed pings.
    if (!zombieServer.standard && zombieServer.failedPings >= NONSTANDARD_PING_LIMIT) {
      zombieServers.remove(zombieServer.getBaseUrl());
    }
  }
}
 
Example 5
Source File: ServiceSolrClient.java    From ranger with Apache License 2.0 5 votes vote down vote up
public List<String> getFieldList(String collection,
		List<String> ignoreFieldList) throws Exception {
	// TODO: Best is to get the collections based on the collection value
	// which could contain wild cards
	String queryStr = "";
	if (collection != null && !collection.isEmpty()) {
		queryStr += "/" + collection;
	}
	queryStr += "/schema/fields";
	SolrQuery query = new SolrQuery();
	query.setRequestHandler(queryStr);
	QueryRequest req = new QueryRequest(query);
	String decPassword = getDecryptedPassword();
	if (username != null && decPassword != null) {
	    req.setBasicAuthCredentials(username, decPassword);
	}
	QueryResponse response = req.process(solrClient);

	List<String> fieldList = new ArrayList<String>();
	if (response != null && response.getStatus() == 0) {
		@SuppressWarnings("unchecked")
		List<SimpleOrderedMap<String>> fields = (ArrayList<SimpleOrderedMap<String>>) response
				.getResponse().get("fields");
		for (SimpleOrderedMap<String> fmap : fields) {
			String fieldName = fmap.get("name");
			if (ignoreFieldList == null
					|| !ignoreFieldList.contains(fieldName)) {
				fieldList.add(fieldName);
			}
		}
	} else {
		LOG.error("Error getting fields for collection=" + collection
				+ ", response=" + response);
	}
	return fieldList;
}