Search in sources :

Example 1 with NamespaceBillingInfo

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

Example 2 with NamespaceBillingInfo

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());
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) NamespaceBillingInfo(com.emc.ecs.management.entity.NamespaceBillingInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with NamespaceBillingInfo

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;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) NamespaceBillingInfo(com.emc.ecs.management.entity.NamespaceBillingInfo)

Aggregations

NamespaceBillingInfo (com.emc.ecs.management.entity.NamespaceBillingInfo)3 BucketBillingInfo (com.emc.ecs.management.entity.BucketBillingInfo)1 ListNamespaceRequest (com.emc.ecs.management.entity.ListNamespaceRequest)1 Namespace (com.emc.ecs.management.entity.Namespace)1 NamespaceRequest (com.emc.ecs.management.entity.NamespaceRequest)1 ObjectBucket (com.emc.ecs.management.entity.ObjectBucket)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 WebResource (com.sun.jersey.api.client.WebResource)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1