Search in sources :

Example 1 with DeleteMarker

use of com.emc.object.s3.bean.DeleteMarker in project ecs-dashboard by carone1.

the class ElasticS3ObjectDAO method insert.

/**
 * {@inheritDoc}
 */
@Override
public void insert(ListVersionsResult listVersionsResult, String namespace, String bucketName, Date collectionTime) {
    if (listVersionsResult == null || listVersionsResult.getVersions() == null || listVersionsResult.getVersions().isEmpty()) {
        // nothing to insert
        return;
    }
    BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
    // Generate JSON for object version info
    for (AbstractVersion abstractVersion : listVersionsResult.getVersions()) {
        if (abstractVersion instanceof Version) {
            XContentBuilder s3ObjectVersionBuilder = toJsonFormat((Version) abstractVersion, namespace, bucketName, collectionTime);
            IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(s3ObjectVersionIndexDayName).setType(S3_OBJECT_VERSION_INDEX_TYPE).setSource(s3ObjectVersionBuilder);
            requestBuilder.add(request);
        } else if (abstractVersion instanceof DeleteMarker) {
            XContentBuilder s3ObjectVersionBuilder = toJsonFormat((DeleteMarker) abstractVersion, namespace, bucketName, collectionTime);
            IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(s3ObjectVersionIndexDayName).setType(S3_OBJECT_VERSION_INDEX_TYPE).setSource(s3ObjectVersionBuilder);
            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: " + s3ObjectVersionIndexDayName + " index type: " + S3_OBJECT_VERSION_INDEX_TYPE);
    if (bulkResponse.hasFailures()) {
        LOGGER.error("Failure(s) occured while items in Elasticsearch " + "index: " + s3ObjectVersionIndexDayName + " index type: " + S3_OBJECT_VERSION_INDEX_TYPE);
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) DeleteMarker(com.emc.object.s3.bean.DeleteMarker) Version(com.emc.object.s3.bean.Version) AbstractVersion(com.emc.object.s3.bean.AbstractVersion) AbstractVersion(com.emc.object.s3.bean.AbstractVersion) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

AbstractVersion (com.emc.object.s3.bean.AbstractVersion)1 DeleteMarker (com.emc.object.s3.bean.DeleteMarker)1 Version (com.emc.object.s3.bean.Version)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