use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project YCSB by brianfrankcooper.
the class ElasticsearchRestClient method delete.
@Override
public Status delete(final String table, final String key) {
try {
final Response searchResponse = search(table, key);
final int statusCode = searchResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_NOT_FOUND) {
return Status.NOT_FOUND;
} else if (statusCode != HttpStatus.SC_OK) {
return Status.ERROR;
}
final Map<String, Object> map = map(searchResponse);
@SuppressWarnings("unchecked") final Map<String, Object> hits = (Map<String, Object>) map.get("hits");
final int total = (int) hits.get("total");
if (total == 0) {
return Status.NOT_FOUND;
}
@SuppressWarnings("unchecked") final Map<String, Object> hit = (Map<String, Object>) ((List<Object>) hits.get("hits")).get(0);
final Response deleteResponse = restClient.performRequest("DELETE", "/" + indexKey + "/" + table + "/" + hit.get("_id"));
if (deleteResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return Status.ERROR;
}
if (!isRefreshNeeded) {
synchronized (this) {
isRefreshNeeded = true;
}
}
return Status.OK;
} catch (final Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project spring-boot by spring-projects.
the class ElasticsearchRestHealthIndicatorTests method elasticsearchWithYellowStatusIsUp.
@Test
void elasticsearchWithYellowStatusIsUp() throws IOException {
BasicHttpEntity httpEntity = new BasicHttpEntity();
httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "yellow").getBytes()));
Response response = mock(Response.class);
StatusLine statusLine = mock(StatusLine.class);
given(statusLine.getStatusCode()).willReturn(200);
given(response.getStatusLine()).willReturn(statusLine);
given(response.getEntity()).willReturn(httpEntity);
given(this.restClient.performRequest(any(Request.class))).willReturn(response);
Health health = this.elasticsearchRestHealthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "yellow");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project spring-boot by spring-projects.
the class ElasticsearchRestHealthIndicatorTests method elasticsearchIsUp.
@Test
void elasticsearchIsUp() throws IOException {
BasicHttpEntity httpEntity = new BasicHttpEntity();
httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "green").getBytes()));
Response response = mock(Response.class);
StatusLine statusLine = mock(StatusLine.class);
given(statusLine.getStatusCode()).willReturn(200);
given(response.getStatusLine()).willReturn(statusLine);
given(response.getEntity()).willReturn(httpEntity);
given(this.restClient.performRequest(any(Request.class))).willReturn(response);
Health health = this.elasticsearchRestHealthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertHealthDetailsWithStatus(health.getDetails(), "green");
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project spring-boot by spring-projects.
the class ElasticsearchRestHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Response response = this.client.performRequest(new Request("GET", "/_cluster/health/"));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
builder.down();
builder.withDetail("statusCode", statusLine.getStatusCode());
builder.withDetail("reasonPhrase", statusLine.getReasonPhrase());
return;
}
try (InputStream inputStream = response.getEntity().getContent()) {
doHealthCheck(builder, StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Response in project hazelcast by hazelcast.
the class ElasticCatClient method shards.
/**
* Returns list of shards for given indexes
*
* Only STARTED shards are returned.
*
* @param indices indexes to return shards for (wildcard format accepted)
*/
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public List<Shard> shards(String... indices) {
Map<String, String> idToAddress = nodes().stream().collect(toMap(Node::getId, Node::getHttpAddress));
try {
Request r = new Request("GET", "/_cat/shards/" + String.join(",", indices));
r.addParameter("format", "json");
r.addParameter("h", "id,index,shard,prirep,docs,state,ip,node");
Response res = withRetry(() -> client.performRequest(r), retries);
try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
JsonArray array = Json.parse(reader).asArray();
List<Shard> shards = new ArrayList<>(array.size());
for (JsonValue value : array) {
Optional<Shard> shard = convertToShard(value, idToAddress);
shard.ifPresent(shards::add);
}
LOG.log(FINE, "Shards " + shards);
return shards;
}
} catch (IOException e) {
throw new JetException("Could not get ES shards", e);
}
}
Aggregations