use of com.emc.ecs.management.entity.NamespaceBillingInfo 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);
}
use of com.emc.ecs.management.entity.NamespaceBillingInfo in project ecs-dashboard by carone1.
the class FileBillingDAO method insert.
/**
* {@inheritDoc}
*/
@Override
public void insert(NamespaceBillingInfo billingData, Date collectionTime) {
JAXBContext jaxbContext;
try {
jaxbContext = JAXBContext.newInstance(NamespaceBillingInfo.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
OutputStream byteOut = new ByteArrayOutputStream();
jaxbMarshaller.marshal(billingData, byteOut);
String bytesOutStr = byteOut.toString();
System.out.println(bytesOutStr);
if (this.destinationPath != null) {
// could write the formatted output to a file too
}
} catch (JAXBException e) {
throw new RuntimeException(e.getLocalizedMessage());
}
}
use of com.emc.ecs.management.entity.NamespaceBillingInfo in project ecs-dashboard by carone1.
the class ManagementClient method getNamespaceBillingInfo.
/**
* Returns Billing Namespace info
* @param namespaceRequest - namespace request
* @return NamespaceBillingInfoResponse
*/
public NamespaceBillingInfo getNamespaceBillingInfo(NamespaceRequest namespaceRequest) {
String authToken = getAuthToken();
NamespaceBillingInfo namespaceBillingResponse = null;
WebResource mgmtResource = this.mgmtClient.resource(uri);
// Call using ?include_bucket_detail=true parameter
StringBuilder restStr = new StringBuilder();
restStr.append(REST_BILLING_NAMESPACES_FIRST).append(namespaceRequest.getName()).append(REST_BILLING_NAMESPACES_SECOND);
System.out.println("getNamespaceBillingInfo rest request: " + restStr.toString());
WebResource getNamespaceBillingResource;
// get billing namespace Billing ressource
if (namespaceRequest.getIncludeBuckets()) {
// include bucket data
getNamespaceBillingResource = mgmtResource.path(restStr.toString()).queryParam(REST_BILLING_NAMESAPCES_BUCKET_INCLUDED, "true");
} else {
// just namespace data without bucket details
getNamespaceBillingResource = mgmtResource.path(restStr.toString());
}
// add marker
if (namespaceRequest.getNextMarker() != null) {
getNamespaceBillingResource = getNamespaceBillingResource.queryParam(REST_MARKER_PARAMETER, namespaceRequest.getNextMarker());
}
try {
namespaceBillingResponse = getNamespaceBillingResource.header(X_SDS_AUTH_TOKEN, authToken).get(NamespaceBillingInfo.class);
} catch (UniformInterfaceException ex) {
// The workaround is to make the same call but without the parameter
if (ex.getResponse().getStatusInfo().getStatusCode() == Response.Status.BAD_REQUEST.getStatusCode()) {
System.out.println("getNamespaceBillingResource: " + restStr.toString());
// get billing namespace Billing ressource
getNamespaceBillingResource = mgmtResource.path(restStr.toString());
if (namespaceRequest.getNextMarker() != null) {
getNamespaceBillingResource = getNamespaceBillingResource.queryParam(REST_MARKER_PARAMETER, namespaceRequest.getNextMarker());
}
namespaceBillingResponse = getNamespaceBillingResource.header(X_SDS_AUTH_TOKEN, authToken).get(NamespaceBillingInfo.class);
}
}
return namespaceBillingResponse;
}
Aggregations