use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project elasticsearch by elastic.
the class ESClientYamlSuiteTestCase method initAndResetContext.
@Before
public void initAndResetContext() throws IOException {
if (restTestExecutionContext == null) {
assert adminExecutionContext == null;
assert blacklistPathMatchers == null;
String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH);
ClientYamlSuiteRestSpec restSpec = null;
FileSystem fileSystem = getFileSystem();
// ... and you can't close() the default filesystem
try {
restSpec = ClientYamlSuiteRestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths);
} finally {
IOUtils.close(fileSystem);
}
validateSpec(restSpec);
List<HttpHost> hosts = getClusterHosts();
RestClient restClient = client();
Version infoVersion = readVersionsFromInfo(restClient, hosts.size());
Version esVersion;
try {
Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(restClient);
esVersion = versionVersionTuple.v1();
Version masterVersion = versionVersionTuple.v2();
logger.info("initializing yaml client, minimum es version: [{}] master version: [{}] hosts: {}", esVersion, masterVersion, hosts);
} catch (ResponseException ex) {
if (ex.getResponse().getStatusLine().getStatusCode() == 403) {
logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized");
esVersion = infoVersion;
logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts);
} else {
throw ex;
}
}
ClientYamlTestClient clientYamlTestClient = new ClientYamlTestClient(restSpec, restClient, hosts, esVersion);
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
blacklistPathMatchers = new ArrayList<>();
for (String entry : blacklist) {
blacklistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
}
}
assert restTestExecutionContext != null;
assert adminExecutionContext != null;
assert blacklistPathMatchers != null;
// admin context must be available for @After always, regardless of whether the test was blacklisted
adminExecutionContext.clear();
//skip test if it matches one of the blacklist globs
for (BlacklistedPathPatternMatcher blacklistedPathMatcher : blacklistPathMatchers) {
String testPath = testCandidate.getSuitePath() + "/" + testCandidate.getTestSection().getName();
assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.isSuffixMatch(testPath));
}
restTestExecutionContext.clear();
//skip test if the whole suite (yaml file) is disabled
assumeFalse(testCandidate.getSetupSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getSetupSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
//skip test if the whole suite (yaml file) is disabled
assumeFalse(testCandidate.getTeardownSection().getSkipSection().getSkipMessage(testCandidate.getSuitePath()), testCandidate.getTeardownSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
//skip test if test section is disabled
assumeFalse(testCandidate.getTestSection().getSkipSection().getSkipMessage(testCandidate.getTestPath()), testCandidate.getTestSection().getSkipSection().skip(restTestExecutionContext.esVersion()));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project components by Talend.
the class ElasticsearchBeamRuntimeTestIT method init.
@Before
public void init() throws IOException, ExecutionException, InterruptedException {
client = ElasticsearchTestUtils.createClient(ElasticsearchTestConstants.HOSTS.split(":")[0], ElasticsearchTestConstants.TRANSPORT_PORT, ElasticsearchTestConstants.CLUSTER_NAME);
datastoreProperties = new ElasticsearchDatastoreProperties("datastore");
datastoreProperties.init();
datastoreProperties.nodes.setValue(ElasticsearchTestConstants.HOSTS);
RestClient restClient = ElasticsearchConnection.createClient(datastoreProperties);
BasicHeader emptyHeader = new BasicHeader("", "");
Map<String, String> emptyParams = new HashMap<>();
ElasticsearchTestUtils.deleteIndex(INDEX_NAME, client);
Response checkExistsResponse = restClient.performRequest("HEAD", "/" + INDEX_NAME, emptyParams);
ElasticsearchResponse checkExists = new ElasticsearchResponse(checkExistsResponse);
if (!checkExists.isOk()) {
// create index for test, name is 'beam'
restClient.performRequest("PUT", "/" + INDEX_NAME, emptyHeader);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project kylo by Teradata.
the class ElasticSearchRestService method index.
@Override
public void index(@Nonnull String indexName, @Nonnull String typeName, @Nonnull String id, @Nonnull Map<String, Object> fields) {
try (RestClient restClient = buildRestClient()) {
JSONObject jsonContent = new JSONObject(fields);
HttpEntity httpEntity = new NStringEntity(jsonContent.toString(), ContentType.APPLICATION_JSON);
restClient.performRequest(PUT_METHOD, getIndexWriteEndPoint(indexName, typeName, id), Collections.emptyMap(), httpEntity);
log.debug("Wrote to index with name {}", indexName);
} catch (ResponseException responseException) {
log.warn("Index write encountered issues in Elasticsearch for index={" + indexName + "}, type={" + typeName + "}, id={" + id + "}", responseException);
} catch (ClientProtocolException clientProtocolException) {
log.debug("Http protocol error for write for index {" + indexName + "}", clientProtocolException);
} catch (IOException ioException) {
log.error("IO Error in rest client", ioException);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project kylo by Teradata.
the class ElasticSearchRestService method deleteAll.
@Override
public int deleteAll(@Nonnull String indexName, @Nonnull String typeName) {
try (RestClient restClient = buildRestClient()) {
if ((restClientConfig.getEsversion() != null) && (restClientConfig.getEsversion().equals(VERSION_TWO))) {
log.info("Elasticsearch v2");
Response response = restClient.performRequest(DELETE_METHOD, getAllDocumentsDeleteEndPointEsV2(indexName, typeName), new HashMap<>(), getAllDocumentsDeleteRequestBodyDslV2());
if (response != null) {
try {
String entityString = EntityUtils.toString(response.getEntity());
JSONObject entityStringJsonObject = new JSONObject(entityString);
JSONObject indicesJsonObject = entityStringJsonObject.getJSONObject("_indices");
JSONObject allJsonObject = indicesJsonObject.getJSONObject("_all");
return (Integer) allJsonObject.get("deleted");
} catch (JSONException e) {
log.warn("Unable to get number of documents deleted. [{}]", e);
}
} else {
log.warn("Unable to identify number of documents deleted since null response received");
}
} else {
log.info("Elasticsearch v5 or above");
Response response = restClient.performRequest(POST_METHOD, getAllDocumentsDeleteEndPoint(indexName, typeName), new HashMap<>(), getAllDocumentsDeleteRequestBodyDsl());
if (response != null) {
try {
String entityString = EntityUtils.toString(response.getEntity());
JSONObject entityStringJsonObject = new JSONObject(entityString);
return (Integer) entityStringJsonObject.get("deleted");
} catch (JSONException e) {
log.warn("Unable to get number of documents deleted. [{}]", e);
}
} else {
log.warn("Unable to identify number of documents deleted since null response received");
}
}
log.info("Deleted all-documents for index={}, type={}", indexName, typeName);
} catch (ResponseException responseException) {
log.error("Index all-documents deletion encountered issues in Elasticsearch for index={}, type={} [{}]", indexName, typeName, responseException);
} catch (ClientProtocolException clientProtocolException) {
log.error("Http protocol error for delete all-documents for index={}, type={} [{}]", indexName, typeName, clientProtocolException);
} catch (IOException ioException) {
log.error("IO Error in rest client [{}]", ioException);
}
return 0;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestClient in project spring-boot by spring-projects.
the class ElasticsearchRestClientAutoConfigurationTests method configureUriWithNoScheme.
@Test
void configureUriWithNoScheme() {
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=localhost:9876").run((context) -> {
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString)).containsExactly("http://localhost:9876");
});
}
Aggregations