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);
}
}
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);
}
Aggregations