Search in sources :

Example 1 with ObjectBuckets

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

the class BillingBO method collectObjectBucketData.

/**
 * Collects Bucket metadata for all namespace defined on a cluster
 * @param objectBucketMap - Object Bucket Map
 * @param collectionTime - Collection Time
 * @param billDAO - Billing DAO Object
 */
private void collectObjectBucketData(Map<String, Set<ObjectBucket>> objectPerNamespaceMap, Map<NamespaceBucketKey, ObjectBucket> objectBucketMap, Date collectionTime, BillingDAO billDAO) {
    // Start collecting billing data from ECS systems
    List<Namespace> namespaceList = getNamespaces();
    // At this point we should have all the namespace supported by the ECS system
    long objCounter = 0;
    for (Namespace namespace : namespaceList) {
        // ===============================================
        // Initial billing request for current namespace
        // ===============================================
        NamespaceRequest namespaceRequest = new NamespaceRequest();
        namespaceRequest.setName(namespace.getName());
        ObjectBuckets objectBucketsResponse = client.getNamespaceBucketInfo(namespaceRequest);
        if (objectBucketsResponse == null) {
            continue;
        }
        logger.info("Collect Billing Data for namespace: " + namespace.getName());
        objCounter += (objectBucketsResponse.getObjectBucket() != null) ? objectBucketsResponse.getObjectBucket().size() : 0;
        // Push collected info into datastore
        if (billDAO != null) {
            // insert something
            billDAO.insert(objectBucketsResponse, collectionTime);
        }
        // Add to return map per namespace and bucket key
        if (objectBucketsResponse.getObjectBucket() != null && objectBucketMap != null) {
            for (ObjectBucket objectBucket : objectBucketsResponse.getObjectBucket()) {
                NamespaceBucketKey key = new NamespaceBucketKey(namespace.getName(), objectBucket.getName());
                objectBucketMap.put(key, objectBucket);
            }
        }
        // Add to return map per namespace key
        if (objectBucketsResponse.getObjectBucket() != null && objectPerNamespaceMap != null) {
            Set<ObjectBucket> objectSet = objectPerNamespaceMap.get(namespace.getName());
            if (objectSet == null) {
                // there isn;t already a set present for that namespace
                // create one
                objectSet = new HashSet<ObjectBucket>();
                // add reference of set to map
                objectPerNamespaceMap.put(namespace.getName(), objectSet);
            }
            for (ObjectBucket objectBucket : objectBucketsResponse.getObjectBucket()) {
                // add all object to set
                objectSet.add(objectBucket);
            }
        }
        // collect n subsequent pages
        while (namespaceRequest.getNextMarker() != null) {
            objectBucketsResponse = client.getNamespaceBucketInfo(namespaceRequest);
            if (objectBucketsResponse != null) {
                objCounter += (objectBucketsResponse.getObjectBucket() != null) ? objectBucketsResponse.getObjectBucket().size() : 0;
                namespaceRequest.setNextMarker(objectBucketsResponse.getNextMarker());
                // Push collected info into datastore
                if (billDAO != null) {
                    // insert something
                    billDAO.insert(objectBucketsResponse, collectionTime);
                }
                // Add to return map
                if (objectBucketsResponse.getObjectBucket() != null && objectBucketMap != null) {
                    for (ObjectBucket objectBucket : objectBucketsResponse.getObjectBucket()) {
                        NamespaceBucketKey key = new NamespaceBucketKey(namespace.getName(), objectBucket.getName());
                        objectBucketMap.put(key, objectBucket);
                    }
                }
                // Add to return map per namespace key
                if (objectBucketsResponse.getObjectBucket() != null && objectPerNamespaceMap != null) {
                    Set<ObjectBucket> objectSet = objectPerNamespaceMap.get(namespace.getName());
                    if (objectSet == null) {
                        // there isn;t already a set present for that namespace
                        // create one
                        objectSet = new HashSet<ObjectBucket>();
                        // add reference of set to map
                        objectPerNamespaceMap.put(namespace.getName(), objectSet);
                    }
                    for (ObjectBucket objectBucket : objectBucketsResponse.getObjectBucket()) {
                        // add all object to set
                        objectSet.add(objectBucket);
                    }
                }
            } else {
                // stop the loop
                namespaceRequest.setNextMarker(null);
            }
        }
    }
    // peg global counter
    this.objectCount.getAndAdd(objCounter);
}
Also used : ObjectBucket(com.emc.ecs.management.entity.ObjectBucket) ObjectBuckets(com.emc.ecs.management.entity.ObjectBuckets) NamespaceRequest(com.emc.ecs.management.entity.NamespaceRequest) ListNamespaceRequest(com.emc.ecs.management.entity.ListNamespaceRequest) Namespace(com.emc.ecs.management.entity.Namespace)

Example 2 with ObjectBuckets

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

the class FileBillingDAO method insert.

/**
 * {@inheritDoc}
 */
@Override
public void insert(ObjectBuckets bucketResponse, Date collectionTime) {
    JAXBContext jaxbContext;
    try {
        jaxbContext = JAXBContext.newInstance(ObjectBuckets.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        OutputStream byteOut = new ByteArrayOutputStream();
        jaxbMarshaller.marshal(bucketResponse, 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) ObjectBuckets(com.emc.ecs.management.entity.ObjectBuckets) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with ObjectBuckets

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

the class ManagementClient method getNamespaceBucketInfo.

/**
 * Returns billing bucket specific info
 * @param namespaceRequest - namespace request
 * @return ObjectBucketsResponse
 */
public ObjectBuckets getNamespaceBucketInfo(NamespaceRequest namespaceRequest) {
    String authToken = getAuthToken();
    WebResource mgmtResource = this.mgmtClient.resource(uri);
    StringBuilder restStr = new StringBuilder();
    restStr.append(REST_OBJECT_BUCKET);
    // get billing namespace Billing ressource
    WebResource getNamespaceBucketInfoResource = mgmtResource.path(restStr.toString()).queryParam(REST_NAMESPACE_PARAMETER, namespaceRequest.getName());
    // add marker
    if (namespaceRequest.getNextMarker() != null) {
        getNamespaceBucketInfoResource = getNamespaceBucketInfoResource.queryParam(REST_MARKER_PARAMETER, namespaceRequest.getNextMarker());
    }
    ObjectBuckets namespaceBucketInfoResponse = getNamespaceBucketInfoResource.header(X_SDS_AUTH_TOKEN, authToken).get(ObjectBuckets.class);
    return namespaceBucketInfoResponse;
}
Also used : ObjectBuckets(com.emc.ecs.management.entity.ObjectBuckets) WebResource(com.sun.jersey.api.client.WebResource)

Aggregations

ObjectBuckets (com.emc.ecs.management.entity.ObjectBuckets)3 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 WebResource (com.sun.jersey.api.client.WebResource)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1