本文整理汇总了Java中org.elasticsearch.action.ActionResponse类的典型用法代码示例。如果您正苦于以下问题:Java ActionResponse类的具体用法?Java ActionResponse怎么用?Java ActionResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActionResponse类属于org.elasticsearch.action包,在下文中一共展示了ActionResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(Task task, String action,
Request request, ActionListener<Response> listener, ActionFilterChain<Request, Response> chain) {
if (false == action.equals(SearchAction.NAME)) {
chain.proceed(task, action, request, listener);
return;
}
if (context.getHeader(EXAMPLE_HEADER) != null) {
throw new IllegalArgumentException("Hurray! Sent the header!");
}
String auth = context.getHeader(AUTHORIZATION_HEADER);
if (auth == null) {
ElasticsearchSecurityException e = new ElasticsearchSecurityException("Authentication required",
RestStatus.UNAUTHORIZED);
e.addHeader("WWW-Authenticate", "Basic realm=auth-realm");
throw e;
}
if (false == REQUIRED_AUTH.equals(auth)) {
throw new ElasticsearchSecurityException("Bad Authorization", RestStatus.FORBIDDEN);
}
chain.proceed(task, action, request, listener);
}
示例2: checkIfIndexExists
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private void checkIfIndexExists(final ActionListener<ActionResponse> listener) {
client.admin().indices().prepareExists(IndexingProxyPlugin.INDEX_NAME).execute(wrap(response -> {
if (response.isExists()) {
if (logger.isDebugEnabled()) {
logger.debug(IndexingProxyPlugin.INDEX_NAME + " exists.");
}
listener.onResponse(response);
} else {
createIndex(listener);
}
}, e -> {
if (e instanceof IndexNotFoundException) {
createIndex(listener);
} else {
listener.onFailure(e);
}
}));
}
示例3: createIndex
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private void createIndex(final ActionListener<ActionResponse> listener) {
try (final Reader in = new InputStreamReader(IndexingProxyService.class.getClassLoader().getResourceAsStream(FILE_MAPPING_JSON),
StandardCharsets.UTF_8)) {
final String source = Streams.copyToString(in);
final XContentBuilder settingsBuilder = XContentFactory.jsonBuilder()//
.startObject()//
.startObject("index")//
.field("number_of_shards", numberOfShards)//
.field("number_of_replicas", numberOfReplicas)//
.endObject()//
.endObject();
client.admin().indices().prepareCreate(IndexingProxyPlugin.INDEX_NAME).setSettings(settingsBuilder)
.addMapping(IndexingProxyPlugin.TYPE_NAME, source, XContentFactory.xContentType(source))
.execute(wrap(response -> waitForIndex(listener), listener::onFailure));
} catch (final IOException e) {
listener.onFailure(e);
}
}
示例4: renew
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
public <Response extends ActionResponse> void renew(final ActionListener<Response> listener) {
client.prepareGet(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, FILE_ID).setRefresh(true).execute(wrap(res -> {
if (res.isExists()) {
final Map<String, Object> source = res.getSourceAsMap();
final String nodeName = (String) source.get(IndexingProxyPlugin.NODE_NAME);
if (nodeName().equals(nodeName)) {
renewOnLocal(listener);
} else {
renewOnRemote(nodeName, listener);
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("No file_id. Skipped renew action.");
}
listener.onResponse(null);
}
}, listener::onFailure));
}
示例5: writeOnLocal
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
public <Request extends ActionRequest, Response extends ActionResponse> void writeOnLocal(final Request request,
final ActionListener<Response> listener) {
final ActionListener<Response> next = wrap(res -> {
final short classType = RequestUtils.getClassType(request);
if (classType > 0) {
synchronized (this) {
streamOutput.writeShort(classType);
request.writeTo(streamOutput);
if (flushPerDoc) {
streamOutput.flush();
}
}
} else {
throw new ElasticsearchException("Unknown request: " + request);
}
listener.onResponse(res);
}, listener::onFailure);
if (streamOutput == null || streamOutput.getByteCount() > dataFileSize) {
createStreamOutput(next);
} else {
next.onResponse(null);
}
}
示例6: apply
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void apply(final Task task, final String action,
final Request request, final ActionListener<Response> listener, final ActionFilterChain<Request, Response> chain) {
if (logger.isDebugEnabled()) {
logger.debug("node: " + nodeName() + ", action: " + action + ", request: " + request);
}
final Supplier<Response> executor = getExecutor(task, action, request);
if (executor != null) {
indexingProxyService.write(request, ActionListener.wrap(res -> {
listener.onResponse(executor.get());
}, listener::onFailure));
} else if (indexingProxyService.isRenewAction(action)) {
indexingProxyService.renew(ActionListener.wrap(res -> {
chain.proceed(task, action, request, listener);
}, listener::onFailure));
} else {
chain.proceed(task, action, request, listener);
}
}
示例7: proceed
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
@Override @SuppressWarnings("unchecked")
public void proceed(String action, ActionResponse response, ActionListener listener) {
int i = index.decrementAndGet();
try {
if (i >= 0) {
filters[i].apply(action, response, listener, this);
} else if (i == -1) {
listener.onResponse(response);
} else {
listener.onFailure(new IllegalStateException("proceed was called too many times"));
}
} catch (Throwable t) {
logger.trace("Error during transport action execution.", t);
listener.onFailure(t);
}
}
示例8: auth
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
@Override
public <Response extends ActionResponse> boolean auth(Task task, String action, ActionRequest request, ActionListener<Response> listener,
boolean isJavaClient) {
if (!restUsing && !isJavaClient) {
return true;
}
if (!clienttUsing && isJavaClient) {
return true;
}
if (isJavaClient) {
return dealClientAuth(request);
} else {
return dealRestAuth(task, action, request, listener);
}
}
示例9: dealRestAuth
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private <Response extends ActionResponse> boolean dealRestAuth(Task task, String action, ActionRequest request, ActionListener<Response> listener) {
if (request.remoteAddress() != null) {
String addr = request.remoteAddress().getAddress();
Permissions permission = ipListRest.get(addr);
if (permission != null) {
if (permission.allowed == true) {
return true;
} else {
return false;
}
}
} else {
log(10, "dealRestAuth: remoteAddress is null!");
return true;
}
AuthInfo info = SimpleAutherUtil.getAuthInfo(task, action, request, listener);
if (info.key == null) {
return false;
}
return valKey(null, info.user, info.key);
}
示例10: getIndex
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private String getIndex(ActionResponse response) {
String index = "";
if (response instanceof IndexResponse) {
index = ((IndexResponse) response).getIndex();
} else if (response instanceof GetResponse) {
index = ((GetResponse) response).getIndex();
} else if (response instanceof DeleteResponse) {
index = ((DeleteResponse) response).getIndex();
}
if (isKibanaUserIndex(index)) {
index = kibanaIndex;
}
return index;
}
示例11: bind
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
protected <T extends ActionResponse> AsyncFuture<T> bind(
final ListenableActionFuture<T> actionFuture
) {
final ResolvableFuture<T> future = async.future();
actionFuture.addListener(new ActionListener<T>() {
@Override
public void onResponse(T result) {
future.resolve(result);
}
@Override
public void onFailure(Exception e) {
future.fail(e);
}
});
return future;
}
示例12: checkIfIndexExists
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private void checkIfIndexExists(final ActionListener<ActionResponse> listener) {
client.admin().indices().prepareExists(index).execute(wrap(response -> {
if (response.isExists()) {
if (logger.isDebugEnabled()) {
logger.debug(index + " exists.");
}
listener.onResponse(response);
} else {
createIndex(listener);
}
}, e -> {
if (e instanceof IndexNotFoundException) {
createIndex(listener);
} else {
listener.onFailure(e);
}
}));
}
示例13: createIndex
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private void createIndex(final ActionListener<ActionResponse> listener) {
try (final Reader in = new InputStreamReader(ConfigSyncService.class.getClassLoader().getResourceAsStream(FILE_MAPPING_JSON),
StandardCharsets.UTF_8)) {
final String source = Streams.copyToString(in);
final XContentBuilder settingsBuilder = XContentFactory.jsonBuilder()//
.startObject()//
.startObject("index")//
.field("number_of_replicas", 0)//
.endObject()//
.endObject();
client.admin().indices().prepareCreate(index).setSettings(settingsBuilder)
.addMapping(type, source, XContentType.JSON)
.execute(wrap(response -> waitForIndex(listener), listener::onFailure));
} catch (final IOException e) {
listener.onFailure(e);
}
}
示例14: apply
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
@Override
public void apply(final String action, final ActionResponse response,
@SuppressWarnings("rawtypes") final ActionListener listener,
final ActionFilterChain chain) {
if (!CreateSnapshotAction.NAME.equals(action) || !clusterService.state().nodes().localNodeMaster()) {
chain.proceed(action, response, listener);
} else {
final CreateSnapshotResponse createSnapshotResponse = (CreateSnapshotResponse) response;
final SnapshotInfo snapshotInfo = createSnapshotResponse
.getSnapshotInfo();
dictionarySnapshotService.createDictionarySnapshot(
((ActionListenerWrapper<?>) listener).getSnapshotId(),
snapshotInfo, new ActionListener<Void>() {
@Override
public void onResponse(final Void resp) {
chain.proceed(action, response, listener);
}
@Override
public void onFailure(final Throwable e) {
listener.onFailure(e);
}
});
}
}
示例15: executeBlocking
import org.elasticsearch.action.ActionResponse; //导入依赖的package包/类
private void executeBlocking(final ActionRequest action) {
try {
if (action instanceof PutMappingRequest) {
getDataContext().getElasticSearchClient().createMapping((PutMappingRequest) action);
} else {
final ActionResponse result = getDataContext().getElasticSearchClient().execute(action);
if (result instanceof BulkResponse && ((BulkResponse) result).hasFailures()) {
BulkItemResponse[] failedItems = ((BulkResponse) result).getItems();
for (int i = 0; i < failedItems.length; i++) {
if (failedItems[i].isFailed()) {
final BulkItemResponse failedItem = failedItems[i];
logger.error("Bulk failed with item no. {} of {}: id={} op={} status={} error={}", i + 1,
failedItems.length, failedItem.getId(), failedItem.getOpType(), failedItem.status(),
failedItem.getFailureMessage());
}
}
}
}
} catch (IOException e) {
logger.warn("Could not execute command {} ", action, e);
throw new MetaModelException("Could not execute " + action, e);
}
}