Search in sources :

Example 1 with ListVersionsResult

use of com.emc.object.s3.bean.ListVersionsResult 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)

Example 2 with ListVersionsResult

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

the class ListObjectsVersionsCollection method collectObjectVersions.

// =============================
// Public methods
// =============================
public void collectObjectVersions() {
    // Verify if versioning is enabled on bucket
    if (!getBucketVersioningConfiguration().equals(VersioningConfiguration.Status.Enabled)) {
        logger.info("No object version collected from namespace: " + collectionConfig.getNamespace() + " bucket: " + objectBucket.getName() + " because versioning is disabled on bucket");
        return;
    }
    // prepare request object
    ListVersionsRequest listVersionsRequest = new ListVersionsRequest(objectBucket.getName());
    listVersionsRequest.setMaxKeys(maxObjectPerRequest);
    listVersionsRequest.setNamespace(collectionConfig.getNamespace());
    long startTime = System.currentTimeMillis();
    try {
        // collect objects
        ListVersionsResult listVersionsResult = collectionConfig.getS3JerseyClient().listVersions(listVersionsRequest);
        long stopTime = System.currentTimeMillis();
        Double elapsedTime = Double.valueOf(stopTime - startTime) / 1000;
        if (listVersionsResult != null) {
            Long collected = (long) listVersionsResult.getVersions().size();
            this.collectionConfig.getObjectCount().getAndAdd(collected);
            logger.info("Took: " + elapsedTime + " seconds to collect " + collected + " objects from namespace: " + collectionConfig.getNamespace() + " bucket: " + objectBucket.getName());
            // add collected entries into datastore
            if (collectionConfig.getObjectDAO() != null) {
                collectionConfig.getObjectDAO().insert(listVersionsResult, collectionConfig.getNamespace(), objectBucket.getName(), collectionConfig.getCollectionTime());
            }
            // process extra pages of objects
            while (listVersionsResult.isTruncated()) {
                listVersionsRequest.setVersionIdMarker(listVersionsResult.getNextVersionIdMarker());
                startTime = System.currentTimeMillis();
                listVersionsResult = collectionConfig.getS3JerseyClient().listVersions(listVersionsRequest);
                stopTime = System.currentTimeMillis();
                elapsedTime = Double.valueOf(stopTime - startTime) / 1000;
                collected = (long) listVersionsResult.getVersions().size();
                collectionConfig.getObjectCount().getAndAdd(collected);
                logger.info("Took: " + elapsedTime + " seconds to collect " + collected + " objects versions from namespace: " + collectionConfig.getNamespace() + " bucket: " + objectBucket.getName());
                // add collected entries into datastore
                if (collectionConfig.getObjectDAO() != null) {
                    collectionConfig.getObjectDAO().insert(listVersionsResult, collectionConfig.getNamespace(), objectBucket.getName(), collectionConfig.getCollectionTime());
                }
            }
        }
    } catch (Exception ex) {
        logger.error("Error occur while listing object versions from namespace: " + collectionConfig.getNamespace() + " Bucket: " + objectBucket.getName() + " " + ex.getLocalizedMessage());
        throw new RuntimeException(ex.getLocalizedMessage());
    }
}
Also used : ListVersionsResult(com.emc.object.s3.bean.ListVersionsResult) ListVersionsRequest(com.emc.object.s3.request.ListVersionsRequest)

Aggregations

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