Search in sources :

Example 1 with BucketBillingInfo

use of com.emc.ecs.management.entity.BucketBillingInfo 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);
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) BucketBillingInfo(com.emc.ecs.management.entity.BucketBillingInfo) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with BucketBillingInfo

use of com.emc.ecs.management.entity.BucketBillingInfo in project ecs-dashboard by carone1.

the class BillingBO method collectBillingData.

/**
 * Collects Billing metadata for all namespace defined on a cluster
 * @param collectionTime - Collection Time
 */
public void collectBillingData(Date collectionTime) {
    // Collect the object bucket data first in order to use some of
    // the fields from object bucket
    Map<NamespaceBucketKey, ObjectBucket> objectBuckets = new HashMap<NamespaceBucketKey, ObjectBucket>();
    Map<String, Set<ObjectBucket>> objectBucketsPerNamespace = new HashMap<String, Set<ObjectBucket>>();
    // Collect bucket data and write to datastore
    // secondly returns classified data per namespace
    // and also per namespace+bucketname
    collectObjectBucketData(objectBucketsPerNamespace, objectBuckets, collectionTime, billingDAO);
    // Start collecting billing data from ECS systems
    List<Namespace> namespaceList = getNamespaces();
    // At this point we should have all namespaces in the ECS system
    long objCounter = 0;
    for (Namespace namespace : namespaceList) {
        // ===============================================
        // Initial billing request for current namespace
        // ===============================================
        NamespaceRequest namespaceRequest = new NamespaceRequest();
        namespaceRequest.setName(namespace.getName());
        if (objectBucketsPerNamespace.get(namespace.getName()) != null && !objectBucketsPerNamespace.get(namespace.getName()).isEmpty()) {
            // There are buckets in that namespace
            // indicate to client to include bucket data
            namespaceRequest.setIncludeBuckets(true);
        }
        NamespaceBillingInfo namespaceBillingResponse = client.getNamespaceBillingInfo(namespaceRequest);
        if (namespaceBillingResponse == null) {
            continue;
        }
        // add object bucket attributes
        for (BucketBillingInfo bucketBillingInfo : namespaceBillingResponse.getBucketBillingInfo()) {
            NamespaceBucketKey namespaceBucketKey = new NamespaceBucketKey(namespace.getName(), bucketBillingInfo.getName());
            ObjectBucket objectBucket = objectBuckets.get(namespaceBucketKey);
            if (objectBucket != null) {
                // set api type
                bucketBillingInfo.setApiType(objectBucket.getApiType());
                // set namespace
                bucketBillingInfo.setNamespace(namespace.getName());
            } else {
                // set api type
                bucketBillingInfo.setApiType("unknown");
                // set namespace
                bucketBillingInfo.setNamespace(namespace.getName());
            }
            objCounter++;
        }
        // Push collected info into datastore
        if (this.billingDAO != null) {
            // insert something
            billingDAO.insert(namespaceBillingResponse, collectionTime);
        }
        // collect n subsequent pages
        while (namespaceRequest.getNextMarker() != null) {
            namespaceBillingResponse = client.getNamespaceBillingInfo(namespaceRequest);
            if (namespaceBillingResponse != null) {
                namespaceRequest.setNextMarker(namespaceBillingResponse.getNextMarker());
                // add object bucket attributes
                for (BucketBillingInfo bucketBillingInfo : namespaceBillingResponse.getBucketBillingInfo()) {
                    ObjectBucket objectBucket = objectBuckets.get(bucketBillingInfo.getName());
                    if (objectBucket != null) {
                        // set api type
                        bucketBillingInfo.setApiType(objectBucket.getApiType());
                        // set namespace
                        bucketBillingInfo.setNamespace(namespace.getName());
                    }
                    objCounter++;
                }
                // Push collected info into datastore
                if (this.billingDAO != null) {
                    // insert something
                    billingDAO.insert(namespaceBillingResponse, collectionTime);
                }
            } else {
                namespaceRequest.setNextMarker(null);
            }
        }
    }
    // peg global counter
    this.objectCount.getAndAdd(objCounter);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ObjectBucket(com.emc.ecs.management.entity.ObjectBucket) HashMap(java.util.HashMap) BucketBillingInfo(com.emc.ecs.management.entity.BucketBillingInfo) NamespaceRequest(com.emc.ecs.management.entity.NamespaceRequest) ListNamespaceRequest(com.emc.ecs.management.entity.ListNamespaceRequest) Namespace(com.emc.ecs.management.entity.Namespace) NamespaceBillingInfo(com.emc.ecs.management.entity.NamespaceBillingInfo)

Aggregations

BucketBillingInfo (com.emc.ecs.management.entity.BucketBillingInfo)2 ListNamespaceRequest (com.emc.ecs.management.entity.ListNamespaceRequest)1 Namespace (com.emc.ecs.management.entity.Namespace)1 NamespaceBillingInfo (com.emc.ecs.management.entity.NamespaceBillingInfo)1 NamespaceRequest (com.emc.ecs.management.entity.NamespaceRequest)1 ObjectBucket (com.emc.ecs.management.entity.ObjectBucket)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)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