use of org.elasticsearch.action.bulk.BulkResponse in project fabric8 by jboss-fuse.
the class AbstractElasticsearchStorage method run.
public void run() {
while (running) {
try {
ActionRequest req = queue.take();
// Send data
BulkRequest bulk = new BulkRequest();
int nb = 0;
while (req != null && (nb == 0 || nb < max)) {
bulk.add(req);
nb++;
req = queue.poll();
}
if (bulk.numberOfActions() > 0) {
BulkResponse rep = getNode().client().bulk(bulk).actionGet();
for (BulkItemResponse bir : rep.getItems()) {
if (bir.isFailed()) {
LOGGER.warn("Error executing request: {}", bir.getFailureMessage());
}
}
}
} catch (Exception e) {
if (running) {
LOGGER.warn("Error while sending requests", e);
}
}
}
}
use of org.elasticsearch.action.bulk.BulkResponse in project pentaho-kettle by pentaho.
the class ElasticSearchBulk method processBatch.
private boolean processBatch(boolean makeNew) throws KettleStepException {
ActionFuture<BulkResponse> actionFuture = currentRequest.execute();
boolean responseOk = false;
BulkResponse response = null;
try {
if (timeout != null && timeoutUnit != null) {
response = actionFuture.actionGet(timeout, timeoutUnit);
} else {
response = actionFuture.actionGet();
}
} catch (ElasticsearchException e) {
String msg = BaseMessages.getString(PKG, "ElasticSearchBulk.Error.BatchExecuteFail", e.getLocalizedMessage());
if (e instanceof ElasticsearchTimeoutException) {
msg = BaseMessages.getString(PKG, "ElasticSearchBulk.Error.Timeout");
}
logError(msg);
rejectAllRows(msg);
}
if (response != null) {
responseOk = handleResponse(response);
requestsBuffer.clear();
} else {
// have to assume all failed
numberOfErrors += currentRequest.numberOfActions();
setErrors(numberOfErrors);
}
if (makeNew) {
currentRequest = client.prepareBulk();
data.nextBufferRowIdx = 0;
data.inputRowBuffer = new Object[batchSize][];
} else {
currentRequest = null;
data.inputRowBuffer = null;
}
return responseOk;
}
use of org.elasticsearch.action.bulk.BulkResponse in project uavstack by uavorg.
the class SlowOperDataCollectHandler method handle.
@Override
public void handle(CollectDataFrame frame) {
if (this.log.isDebugEnable()) {
this.log.debug(this, frame.toJSONString());
}
BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
String appUUID = frame.getTarget();
// 从uuid中获取appid
String appid = appUUID.split("---")[1];
for (Line line : frame.getLines()) {
String content = line.getContent();
try {
// 提取epinfo
StringBuilder builder = new StringBuilder();
int headPoint = 0;
for (int i = 0; i < content.length(); i++) {
char item = content.charAt(i);
if (item == ';') {
headPoint++;
if (headPoint == 3) {
break;
}
} else {
if (headPoint > 1) {
builder.append(item);
}
}
}
String epinfo = builder.toString();
// 若epinfo为数字则说明为方法级
if (DataConvertHelper.toInt(epinfo, -1) != -1) {
epinfo = "method";
}
IActionEngine engine = this.getActionEngineMgr().getActionEngine("SlowOperActionEngine");
ActionContext ac = new ActionContext();
ac.putParam("content", content);
ac.putParam("appid", appid);
engine.execute(epinfo, ac);
SlowOperSpan span = (SlowOperSpan) ac.getParam("span");
pushSpanToBulkRequest(appUUID, frame.getAppgroup(), span, bulkRequest, (String) ac.getParam("protocolType"));
} catch (Exception e) {
// 防止有不合法的协议报文出现
this.log.err(this, "unsupported protocol,content is" + frame.toJSONString(), e);
}
}
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
log.err(this, "INSERT InvokeChain Data to ES FAIL: " + bulkResponse.buildFailureMessage());
}
}
use of org.elasticsearch.action.bulk.BulkResponse in project uavstack by uavorg.
the class ThreadAnalysisCollectDataHandler method insertThreadObjectToES.
/**
* TODO:线程分析数据的存储
*
* @param result
*/
private void insertThreadObjectToES(List<JavaThreadObject> result) {
if (this.log.isDebugEnable()) {
this.log.debug(this, "ThreadObjectToES is :" + JSONHelper.toString(result));
}
BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
for (JavaThreadObject item : result) {
pushDataToBulkRequest(item, bulkRequest);
}
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
log.err(this, "INSERT ThreadAnalysis Data to ES FAIL: " + bulkResponse.buildFailureMessage());
}
}
use of org.elasticsearch.action.bulk.BulkResponse in project ecs-dashboard by carone1.
the class ElasticBillingDAO method insert.
/**
* {@inheritDoc}
*/
@Override
public void insert(NamespaceBillingInfo billingData, Date collectionTime) {
// Generate JSON for namespace billing info
XContentBuilder namespaceBuilder = toJsonFormat(billingData, collectionTime);
elasticClient.prepareIndex(billingNamespaceIndexDayName, BILLING_NAMESPACE_INDEX_TYPE).setSource(namespaceBuilder).get();
if (billingData.getBucketBillingInfo() == null || billingData.getBucketBillingInfo().isEmpty()) {
// nothing to insert
return;
}
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for namespace billing info
for (BucketBillingInfo bucketBillingInfo : billingData.getBucketBillingInfo()) {
XContentBuilder bucketBuilder = toJsonFormat(bucketBillingInfo, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(billingBucketIndexDayName).setType(BILLING_BUCKET_INDEX_TYPE).setSource(bucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in Elasticsearch" + "index: " + billingNamespaceIndexDayName + " index type: " + BILLING_BUCKET_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failures occured while items in Elasticsearch " + "index: " + billingNamespaceIndexDayName + " index type: " + BILLING_BUCKET_INDEX_TYPE);
}
}
Aggregations