Response errorResponse = e.getResponse(); if (errorResponse.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_REQUEST) { JsonNode root = objectMapper.readTree(EntityUtils.toString(errorResponse.getEntity()));
@Override public void deleteIndex(String index) throws IOException { try { Response response = lowLevelClient.performRequest("DELETE", "/" + index); logger.trace("delete index response: {}", asMap(response)); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.trace("index does not exist. Ignoring error..."); return; } throw e; } }
/** * Check if an index exists * @param index index name * @return true if the index exists, false otherwise * @throws IOException In case of error */ public boolean isExistingIndex(String index) throws IOException { logger.debug("is existing index [{}]", index); try { Response restResponse = lowLevelClient.performRequest("GET", "/" + index); logger.trace("get index metadata response: {}", asMap(restResponse)); return true; } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug("index [{}] does not exist", index); return false; } throw e; } }
/** * Check if a pipeline exists * @param pipelineName pipeline name * @return true if the pipeline exists, false otherwise * @throws IOException In case of error */ public boolean isExistingPipeline(String pipelineName) throws IOException { logger.debug("is existing pipeline [{}]", pipelineName); try { Response restResponse = lowLevelClient.performRequest("GET", "/_ingest/pipeline/" + pipelineName); logger.trace("get pipeline metadata response: {}", asMap(restResponse)); return true; } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug("pipeline [{}] does not exist", pipelineName); return false; } throw e; } }
/** * Create an index * @param index index name * @param ignoreErrors don't fail if the index already exists * @param indexSettings index settings if any * @throws IOException In case of error */ public void createIndex(String index, boolean ignoreErrors, String indexSettings) throws IOException { logger.debug("create index [{}]", index); logger.trace("index settings: [{}]", indexSettings); try { Response response = lowLevelClient.performRequest("PUT", "/" + index, Collections.emptyMap(), createEntity(indexSettings)); logger.trace("create index response: {}", asMap(response)); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 400 && (e.getMessage().contains("index_already_exists_exception") || // ES 5.x e.getMessage().contains("IndexAlreadyExistsException") )) { // ES 1.x and 2.x if (!ignoreErrors) { throw new RuntimeException("index already exists"); } logger.trace("index already exists. Ignoring error..."); return; } throw e; } }
public ClientYamlTestResponseException(ResponseException responseException) throws IOException { super(responseException); this.responseException = responseException; this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse()); }
protected HttpEntity handleNotFoundAsResponse(ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { return e.getResponse().getEntity(); } else { return null; } }
/** * Wrap a {@linkplain ResponseException} with another one with the current * stack trace. This is used during synchronous calls so that the caller * ends up in the stack trace of the exception thrown. */ ResponseException(ResponseException e) throws IOException { super(e.getMessage(), e); this.response = e.getResponse(); }
@Override public void onFailure(Exception exception) { if ( exception instanceof ResponseException ) { requestLog.debug( "ES client issued a ResponseException - not necessarily a problem", exception ); /* * The client tries to guess what's an error and what's not, but it's too naive. * A 404 on DELETE is not always important to us, for instance. * Thus we ignore the exception and do our own checks afterwards. */ completableFuture.complete( ( (ResponseException) exception ).getResponse() ); } else { completableFuture.completeExceptionally( exception ); } } }
@Override public void onFailure(Exception exception) { if ( exception instanceof ResponseException ) { requestLog.debug( "ES client issued a ResponseException - not necessarily a problem", exception ); /* * The client tries to guess what's an error and what's not, but it's too naive. * A 404 on DELETE is not always important to us, for instance. * Thus we ignore the exception and do our own checks afterwards. */ completableFuture.complete( ( (ResponseException) exception ).getResponse() ); } else { completableFuture.completeExceptionally( exception ); } } }
@Override public void onFailure(Exception exception) { if ( exception instanceof ResponseException ) { requestLog.debug( "ES client issued a ResponseException - not necessarily a problem", exception ); /* * The client tries to guess what's an error and what's not, but it's too naive. * A 404 on DELETE is not always important to us, for instance. * Thus we ignore the exception and do our own checks afterwards. */ completableFuture.complete( ( (ResponseException) exception ).getResponse() ); } else { completableFuture.completeExceptionally( exception ); } } }
@Override public void onFailure(Exception exception) { if ( exception instanceof ResponseException ) { requestLog.debug( "ES client issued a ResponseException - not necessarily a problem", exception ); /* * The client tries to guess what's an error and what's not, but it's too naive. * A 404 on DELETE is not always important to us, for instance. * Thus we ignore the exception and do our own checks afterwards. */ completableFuture.complete( ( (ResponseException) exception ).getResponse() ); } else { completableFuture.completeExceptionally( exception ); } } }
private void deleteMessageInIndex(final String id, final String index) { final String endpoint = "/" + index + "/log/" + id; try { restClient.performRequest("DELETE", endpoint); } catch (ResponseException e) { // sometimes we might try to delete something that was already deleted by something else; // in which case there is no error if (e.getResponse().getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { return; } log.error("Error deleting message with id {} for index {}", id, index, e); } catch (IOException e) { log.error("Error deleting message with id {} for index {}", id, index, e); } }
@Override public void deleteIndex(String index) throws IOException { try { Response response = lowLevelClient.performRequest("DELETE", "/" + index); logger.trace("delete index response: {}", asMap(response)); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.trace("index does not exist. Ignoring error..."); return; } throw e; } }
private void handleResponseException(ResponseException e) throws DataException { if (e.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug(e.getMessage()); } else { throw new DataException(e); } } }
@Override public List<MetricValue> getMetricValues(String metricName, int from, int size, long tmst) throws IOException { HttpEntity entity = getHttpEntityForSearch(metricName, from, size, tmst); try { Response response = client.performRequest("GET", urlGet, Collections.emptyMap(), entity); return getMetricValuesFromResponse(response); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == 404) { return Collections.emptyList(); } throw e; } }
private void logFailure(Exception e) { if (e instanceof ResponseException) { ResponseException re = (ResponseException) e; if (remoteVersion.before(Version.fromId(2000099)) && re.getResponse().getStatusLine().getStatusCode() == 404) { logger.debug((Supplier<?>) () -> new ParameterizedMessage( "Failed to clear scroll [{}] from pre-2.0 Elasticsearch. This is normal if the request terminated " + "normally as the scroll has already been cleared automatically.", scrollId), e); return; } } logger.warn((Supplier<?>) () -> new ParameterizedMessage("Failed to clear scroll [{}]", scrollId), e); } });
protected JSONObject extractErrorJSON(ResponseException e) { try { JSONObject response = JSON.parseObject(EntityUtils.toString(e.getResponse().getEntity())); return response.getJSONObject(PARAM_ERROR); } catch (IOException ex) { Exceptions.handle(Elastic.LOG, ex); throw Exceptions.handle() .to(Elastic.LOG) .error(e) .withSystemErrorMessage("Elasticsearch (%s) reported an error which cannot be unpacked: %s", e.getResponse().getHost()) .handle(); } }
@Override public void onFailure(Exception exception) { if (exception instanceof ResponseException) { ResponseException responseException = (ResponseException) exception; Response response = responseException.getResponse(); if (RestStatus.NOT_FOUND.getStatus() == response.getStatusLine().getStatusCode()) { actionListener.onResponse(Optional.empty()); } else { actionListener.onFailure(parseResponseException(responseException)); } } else { actionListener.onFailure(exception); } } };
private void wipeCluster() throws IOException { if (preserveIndicesUponCompletion() == false) { // wipe indices try { adminClient().performRequest("DELETE", "*"); } catch (ResponseException e) { // 404 here just means we had no indexes if (e.getResponse().getStatusLine().getStatusCode() != 404) { throw e; } } } // wipe index templates if (preserveTemplatesUponCompletion() == false) { adminClient().performRequest("DELETE", "_template/*"); } wipeSnapshots(); wipeClusterSettings(); }