Search in sources :

Example 1 with VdcDetail

use of Vdc.VdcDetail in project ecs-dashboard by carone1.

the class ElasticVdcDetailDAO method insert.

@Override
public void insert(VdcDetails vdcDetails, Date collectionTime) {
    if (vdcDetails == null || vdcDetails.getVdcDetails() == null || vdcDetails.getVdcDetails().isEmpty()) {
        return;
    }
    BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
    // Generate JSON for object buckets info
    for (VdcDetail vdcDetail : vdcDetails.getVdcDetails()) {
        XContentBuilder objectBucketBuilder = toJsonFormat(vdcDetail, collectionTime);
        IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(vdcIndexDayName).setType(VDC_INDEX_TYPE).setSource(objectBucketBuilder);
        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: " + vdcIndexDayName + " index type: " + VDC_INDEX_TYPE);
    if (bulkResponse.hasFailures()) {
        LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + vdcIndexDayName + " index type: " + VDC_INDEX_TYPE);
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) VdcDetail(Vdc.VdcDetail) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

VdcDetail (Vdc.VdcDetail)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1