本文整理汇总了Java中io.searchbox.action.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于io.searchbox.action包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAction
import io.searchbox.action.Action; //导入依赖的package包/类
/**
* execute action
* @param action action
* @return JestResult
*/
@Retryable(maxAttempts = 3, value = RestClientException.class, backoff = @Backoff(delay = 5000, multiplier = 2))
public JestResult executeAction(Action action)
{
JestResult searchResult = null;
try
{
searchResult =
jestClientFactory.getJestClient().execute(action);
}
catch (final IOException ioException)
{
LOGGER.error("Failed to execute JEST client action.", ioException);
//throw a runtime exception so that the client needs not catch
throw new RestClientException(ioException.getMessage()); //NOPMD
}
return searchResult;
}
示例2: _exec
import io.searchbox.action.Action; //导入依赖的package包/类
private <T extends JestResult> T _exec(Action<T> action) throws Exception {
T result = client.execute(action);
if (result != null && result.isSucceeded() && result.getErrorMessage() == null) {
return result;
}
if (result != null && result.getErrorMessage() != null) {
throw new Exception(result.getErrorMessage());
}
return null;
}
示例3: execute
import io.searchbox.action.Action; //导入依赖的package包/类
private <T extends JestResult> T execute(Action<T> action, boolean acceptNotFound) {
try {
// Execute action
T result = client.execute(action);
// Check result and map error
errorMapper.mapError(action, result, acceptNotFound);
return result;
} catch (IOException e) {
throw new ElasticsearchException("failed to execute action", e);
}
}
示例4: mapError
import io.searchbox.action.Action; //导入依赖的package包/类
@Override
public void mapError(Action action, JestResult result, boolean acceptNotFound) {
if (!result.isSucceeded()) {
String errorMessage = String.format("Cannot execute jest action , response code : %s , error : %s , message : %s", result.getResponseCode(), result.getErrorMessage(), getMessage(result));
if (acceptNotFound && isSuccessfulResponse(result.getResponseCode())) {
logger.debug(errorMessage);
} else {
logger.error(errorMessage);
throw new JestElasticsearchException(errorMessage, result);
}
}
}
示例5: elasticsearchIsUp
import io.searchbox.action.Action; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void elasticsearchIsUp() throws IOException {
given(this.jestClient.execute(any(Action.class)))
.willReturn(createJestResult(4, 0));
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ElasticsearchJestHealthIndicatorTests.java
示例6: elasticsearchIsDown
import io.searchbox.action.Action; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void elasticsearchIsDown() throws IOException {
given(this.jestClient.execute(any(Action.class))).willThrow(
new CouldNotConnectException("http://localhost:9200", new IOException()));
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:ElasticsearchJestHealthIndicatorTests.java
示例7: elasticsearchIsOutOfService
import io.searchbox.action.Action; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void elasticsearchIsOutOfService() throws IOException {
given(this.jestClient.execute(any(Action.class)))
.willReturn(createJestResult(4, 1));
Health health = this.healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:ElasticsearchJestHealthIndicatorTests.java
示例8: indexExists
import io.searchbox.action.Action; //导入依赖的package包/类
private boolean indexExists(String index) {
Action action = new IndicesExists.Builder(index).build();
try {
JestResult result = client.execute(action);
return result.isSucceeded();
} catch (IOException e) {
throw new ConnectException(e);
}
}
示例9: execute
import io.searchbox.action.Action; //导入依赖的package包/类
public <T extends JestResult> T execute(Action<T> action) {
try {
logger.debug("executing action: {}, payload: {}", action, action.getData(gson));
T result = client.execute(action);
if (!result.isSucceeded())
logger.error(result.getErrorMessage());
return result;
} catch (IOException e) {
logger.error("failed executing action: {}, error: {}, payload: {}", action, e, action.getData(gson));
return null;
}
}
示例10: executeE
import io.searchbox.action.Action; //导入依赖的package包/类
public Tuple<JestResult, HttpResponse> executeE(final Action clientRequest) throws IOException {
final String elasticSearchRestUrl = getRequestURL(getNextServer(), clientRequest.getURI());
final HttpUriRequest request = constructHttpMethod(clientRequest.getRestMethodName(), elasticSearchRestUrl,
clientRequest.getData(gson));
log.debug("reqeust method and restUrl - " + clientRequest.getRestMethodName() + " " + elasticSearchRestUrl);
// add headers added to action
if (!clientRequest.getHeaders().isEmpty()) {
for (final Iterator<Entry> it = clientRequest.getHeaders().entrySet().iterator(); it.hasNext();) {
final Entry header = it.next();
request.addHeader((String) header.getKey(), header.getValue().toString());
}
}
final HttpResponse response = httpClient.execute(request);
// If head method returns no content, it is added according to response code thanks to https://github.com/hlassiege
if (request.getMethod().equalsIgnoreCase("HEAD")) {
if (response.getEntity() == null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
response.setEntity(new StringEntity("{\"ok\" : true, \"found\" : true}"));
} else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
response.setEntity(new StringEntity("{\"ok\" : false, \"found\" : false}"));
}
}
}
return new Tuple(deserializeResponse(response, clientRequest), response);
}
示例11: execute
import io.searchbox.action.Action; //导入依赖的package包/类
@Override
public <T extends JestResult> T execute(final Action<T> clientRequest) throws IOException {
final String elasticSearchRestUrl = getRequestURL(getNextServer(), clientRequest.getURI());
final HttpUriRequest request = constructHttpMethod(clientRequest.getRestMethodName(), elasticSearchRestUrl,
clientRequest.getData(gson));
log.debug("reqeust method and restUrl - " + clientRequest.getRestMethodName() + " " + elasticSearchRestUrl);
// add headers added to action
if (!clientRequest.getHeaders().isEmpty()) {
for (final Entry<String, Object> header : clientRequest.getHeaders().entrySet()) {
request.addHeader(header.getKey(), header.getValue().toString());
}
}
final HttpResponse response = httpClient.execute(request);
// If head method returns no content, it is added according to response code thanks to https://github.com/hlassiege
if (request.getMethod().equalsIgnoreCase("HEAD")) {
if (response.getEntity() == null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
response.setEntity(new StringEntity("{\"ok\" : true, \"found\" : true}"));
} else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
response.setEntity(new StringEntity("{\"ok\" : false, \"found\" : false}"));
}
}
}
return deserializeResponse(response, clientRequest);
}
示例12: isIndexExists
import io.searchbox.action.Action; //导入依赖的package包/类
@Override
public final boolean isIndexExists(String indexName)
{
Action action = new IndicesExists.Builder(indexName).build();
JestResult result = jestClientHelper.executeAction(action);
return result.isSucceeded();
}
示例13: deleteIndex
import io.searchbox.action.Action; //导入依赖的package包/类
/**
* The delete index function will take as an argument the index name and will delete the index.
*/
@Override
public final void deleteIndex(String indexName)
{
Action action = new DeleteIndex.Builder(indexName).build();
LOGGER.info("Deleting Elasticsearch index, indexName={}.", indexName);
JestResult result = jestClientHelper.executeAction(action);
LOGGER.info("Deleting Elasticsearch index, indexName={}. result successful is {} ", indexName, result.isSucceeded());
}
示例14: deleteDocumentById
import io.searchbox.action.Action; //导入依赖的package包/类
/**
* The delete document by id function will delete a document in the index by the document id.
*/
@Override
public final void deleteDocumentById(String indexName, String documentType, String id)
{
LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={}.", indexName, documentType, id);
Action action = new Delete.Builder(id).index(indexName).type(documentType).build();
JestResult result = jestClientHelper.executeAction(action);
LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={} is successfully {}. ", indexName, documentType, id,
result.isSucceeded());
}
示例15: getIndexStats
import io.searchbox.action.Action; //导入依赖的package包/类
@Override
public DocsStats getIndexStats(String indexName)
{
Action getStats = new Stats.Builder().addIndex(indexName).build();
JestResult jestResult = jestClientHelper.executeAction(getStats);
Assert.isTrue(jestResult.isSucceeded(), jestResult.getErrorMessage());
JsonObject statsJson = jestResult.getJsonObject().getAsJsonObject("indices").getAsJsonObject(indexName).getAsJsonObject("primaries");
JsonObject docsJson = statsJson.getAsJsonObject("docs");
return new DocsStats(docsJson.get("count").getAsLong(), docsJson.get("deleted").getAsLong());
}