use of org.codelibs.elasticsearch.idxproxy.action.CreateRequest in project elasticsearch-indexing-proxy by codelibs.
the class IndexingProxyService method renewOnRemote.
private <Request extends ActionRequest, Response extends ActionResponse> void renewOnRemote(final String nodeName, final long version, final ActionListener<Response> listener, final int tryCount) {
final List<DiscoveryNode> nodeList = new ArrayList<>();
clusterService.state().nodes().getNodes().valuesIt().forEachRemaining(node -> {
if (writerNodes.isEmpty() || writerNodes.contains(node.getName())) {
nodeList.add(node);
}
});
int pos = -1;
for (int i = 0; i < nodeList.size(); i++) {
if (nodeList.get(i).getName().equals(nodeName)) {
pos = i;
break;
}
}
if (pos == -1) {
if (tryCount >= writerRetryCount) {
listener.onFailure(new ElasticsearchException("Writer nodes are not found for renew."));
} else {
if (logger.isDebugEnabled()) {
logger.debug("No available write node.");
}
updateWriterNode(version, nodeList, (res, ex) -> renew(listener, tryCount + 1));
}
return;
}
final int nodeIdx = pos;
transportService.sendRequest(nodeList.get(nodeIdx), IndexingProxyPlugin.ACTION_IDXPROXY_CREATE, new CreateRequest(), new TransportResponseHandler<CreateResponse>() {
@Override
public CreateResponse newInstance() {
return new CreateResponse();
}
@Override
public void handleResponse(final CreateResponse response) {
if (response.isAcknowledged()) {
if (logger.isDebugEnabled()) {
logger.debug("Update file_id in " + nodeName);
}
listener.onResponse(null);
} else {
throw new ElasticsearchException("Failed to update file_id in " + nodeName);
}
}
@Override
public void handleException(final TransportException e) {
listener.onFailure(e);
}
@Override
public String executor() {
return ThreadPool.Names.GENERIC;
}
});
}
Aggregations