Search in sources :

Example 1 with ObjectUserDetails

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

the class ObjectBO method collectObjectVersionData.

public void collectObjectVersionData(Date collectionTime) {
    // collect S3 user Id and credentials
    List<ObjectUserDetails> objectUserDetailsList = billingBO.getObjectUserSecretKeys();
    // Collect bucket details
    Map<NamespaceBucketKey, ObjectBucket> objectBucketMap = new HashMap<>();
    billingBO.getObjectBucketData(objectBucketMap);
    Map<String, S3JerseyClient> s3ObjectClientMap = null;
    try {
        // create all required S3 jersey clients for very S3 users
        s3ObjectClientMap = createS3ObjectClients(objectUserDetailsList, this.ecsObjectHosts);
        // collect objects for all users
        for (ObjectUserDetails objectUserDetails : objectUserDetailsList) {
            if (objectUserDetails.getObjectUser().getUserId() == null || objectUserDetails.getSecretKeys().getSecretKey1() == null) {
                // in that case we just skip over that user
                continue;
            }
            String userId = objectUserDetails.getObjectUser().getUserId().toString();
            S3JerseyClient s3JerseyClient = s3ObjectClientMap.get(userId);
            String namespace = objectUserDetails.getObjectUser().getNamespace().toString();
            if (s3JerseyClient != null && namespace != null) {
                ObjectCollectionConfig collectionConfig = new ObjectCollectionConfig(s3JerseyClient, namespace, objectDAO, objectBucketMap, collectionTime, objectCount, threadPoolExecutor, futures, // no criteria required here
                null);
                NamespaceObjectVersionCollection namespaceObjectVersionCollection = new NamespaceObjectVersionCollection(collectionConfig);
                try {
                    // submit namespace collection to thread pool
                    futures.add(threadPoolExecutor.submit(namespaceObjectVersionCollection));
                } catch (RejectedExecutionException e) {
                    // Thread pool didn't accept bucket collection
                    // running in the current thread
                    logger.error("Thread pool didn't accept bucket collection - running in current thread");
                    try {
                        namespaceObjectVersionCollection.call();
                    } catch (Exception e1) {
                        logger.error("Error occured during namespace object version collection operation - message: " + e.getLocalizedMessage());
                    }
                }
            }
        }
    } finally {
        // ensure to clean up S3 jersey clients
        if (s3ObjectClientMap != null) {
            for (S3JerseyClient s3JerseyClient : s3ObjectClientMap.values()) {
                s3JerseyClient.destroy();
            }
        }
    }
}
Also used : ObjectBucket(com.emc.ecs.management.entity.ObjectBucket) HashMap(java.util.HashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) S3JerseyClient(com.emc.object.s3.jersey.S3JerseyClient) ObjectUserDetails(com.emc.ecs.management.entity.ObjectUserDetails)

Example 2 with ObjectUserDetails

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

the class ObjectBO method collectObjectData.

public void collectObjectData(Date collectionTime, String queryCriteria) {
    // collect S3 user Id and credentials
    List<ObjectUserDetails> objectUserDetailsList = billingBO.getObjectUserSecretKeys();
    // Collect bucket details
    Map<NamespaceBucketKey, ObjectBucket> objectBucketMap = new HashMap<>();
    billingBO.getObjectBucketData(objectBucketMap);
    Map<String, S3JerseyClient> s3ObjectClientMap = null;
    try {
        // create all required S3 jersey clients for very S3 users
        s3ObjectClientMap = createS3ObjectClients(objectUserDetailsList, this.ecsObjectHosts);
        // collect objects for all users
        for (ObjectUserDetails objectUserDetails : objectUserDetailsList) {
            if (objectUserDetails.getObjectUser().getUserId() == null || objectUserDetails.getSecretKeys().getSecretKey1() == null) {
                // in that case we just skip over that user
                continue;
            }
            String userId = objectUserDetails.getObjectUser().getUserId().toString();
            S3JerseyClient s3JerseyClient = s3ObjectClientMap.get(userId);
            String namespace = objectUserDetails.getObjectUser().getNamespace().toString();
            if (s3JerseyClient != null && namespace != null) {
                ObjectCollectionConfig collectionConfig = new ObjectCollectionConfig(s3JerseyClient, namespace, this.objectDAO, objectBucketMap, collectionTime, objectCount, threadPoolExecutor, futures, queryCriteria);
                NamespaceObjectCollection namespaceObjectCollection = new NamespaceObjectCollection(collectionConfig);
                try {
                    // submit namespace collection to thread pool
                    futures.add(threadPoolExecutor.submit(namespaceObjectCollection));
                } catch (RejectedExecutionException e) {
                    // Thread pool didn't accept bucket collection
                    // running in the current thread
                    logger.error("Thread pool didn't accept bucket collection - running in current thread");
                    try {
                        namespaceObjectCollection.call();
                    } catch (Exception e1) {
                        logger.error("Error occured during namespace object collection operation - message: " + e.getLocalizedMessage());
                    }
                }
            }
        }
    } finally {
        // ensure to clean up S3 jersey clients
        if (s3ObjectClientMap != null) {
            for (S3JerseyClient s3JerseyClient : s3ObjectClientMap.values()) {
                s3JerseyClient.destroy();
            }
        }
    }
}
Also used : ObjectBucket(com.emc.ecs.management.entity.ObjectBucket) HashMap(java.util.HashMap) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) S3JerseyClient(com.emc.object.s3.jersey.S3JerseyClient) ObjectUserDetails(com.emc.ecs.management.entity.ObjectUserDetails)

Example 3 with ObjectUserDetails

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

the class BillingBO method getObjectUserSecretKeys.

// ================================
// Public methods
// ================================
/**
 * Retrieve Object uid and secret keys
 * @return ObjectUserDetails
 */
public List<ObjectUserDetails> getObjectUserSecretKeys() {
    List<ObjectUserDetails> userDetails = new ArrayList<ObjectUserDetails>();
    // Collect all uids in order to collect secret keys after
    List<ObjectUser> objectUserList = new ArrayList<ObjectUser>();
    // first batch
    ObjectUsersRequest objectUsersRequest = new ObjectUsersRequest();
    ObjectUsers objectUsersResult = client.getObjectUsersUid(objectUsersRequest);
    if (objectUsersResult != null) {
        if (objectUsersResult.getBlobUser() != null) {
            objectUserList.addAll(objectUsersResult.getBlobUser());
        }
        objectUsersRequest.setMarker(objectUsersResult.getNextMarker());
        // Subsequent batches
        while (objectUsersResult.getNextMarker() != null) {
            objectUsersResult = client.getObjectUsersUid(objectUsersRequest);
            if (objectUsersResult != null) {
                objectUserList.addAll(objectUsersResult.getBlobUser());
                objectUsersRequest.setMarker(objectUsersResult.getNextMarker());
            } else {
                break;
            }
        }
    }
    // Collect secret keys
    for (ObjectUser objectUser : objectUserList) {
        ObjectUserSecretKeys objectUserSecretKeys = client.getObjectUserSecretKeys(objectUser.getUserId().toString(), objectUser.getNamespace().toString());
        if (objectUserSecretKeys != null) {
            userDetails.add(new ObjectUserDetails(objectUser, objectUserSecretKeys));
        }
    }
    return userDetails;
}
Also used : ObjectUsers(com.emc.ecs.management.entity.ObjectUsers) ObjectUserDetails(com.emc.ecs.management.entity.ObjectUserDetails) ObjectUser(com.emc.ecs.management.entity.ObjectUser) ObjectUsersRequest(com.emc.ecs.management.entity.ObjectUsersRequest) ArrayList(java.util.ArrayList) ObjectUserSecretKeys(com.emc.ecs.management.entity.ObjectUserSecretKeys)

Example 4 with ObjectUserDetails

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

the class ObjectBO method createS3ObjectClients.

private Map<String, S3JerseyClient> createS3ObjectClients(List<ObjectUserDetails> objectUserDetailsList, List<String> ecsObjectHosts) {
    Map<String, S3JerseyClient> s3JerseyClientList = new HashMap<String, S3JerseyClient>();
    // collect objects for all users
    for (ObjectUserDetails objectUserDetails : objectUserDetailsList) {
        if (objectUserDetails.getObjectUser().getUserId() == null || objectUserDetails.getSecretKeys().getSecretKey1() == null) {
            // in that case we just skip over that user
            continue;
        }
        // Create object client user
        Vdc vdc = new Vdc((String[]) this.ecsObjectHosts.toArray());
        S3Config s3config = new S3Config(Protocol.HTTP, vdc);
        // in all cases, you need to provide your credentials
        s3config.withIdentity(objectUserDetails.getObjectUser().getUserId().toString()).withSecretKey(objectUserDetails.getSecretKeys().getSecretKey1());
        s3config.setSmartClient(true);
        URLConnectionClientHandler urlHandler = new URLConnectionClientHandler();
        S3JerseyClient s3JerseyClient = new S3JerseyClient(s3config, urlHandler);
        s3JerseyClientList.put(objectUserDetails.getObjectUser().getUserId().toString(), s3JerseyClient);
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        logger.error(e.getLocalizedMessage());
    }
    return s3JerseyClientList;
}
Also used : S3Config(com.emc.object.s3.S3Config) S3JerseyClient(com.emc.object.s3.jersey.S3JerseyClient) ObjectUserDetails(com.emc.ecs.management.entity.ObjectUserDetails) Vdc(com.emc.rest.smart.ecs.Vdc) HashMap(java.util.HashMap) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler)

Aggregations

ObjectUserDetails (com.emc.ecs.management.entity.ObjectUserDetails)4 S3JerseyClient (com.emc.object.s3.jersey.S3JerseyClient)3 HashMap (java.util.HashMap)3 ObjectBucket (com.emc.ecs.management.entity.ObjectBucket)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ObjectUser (com.emc.ecs.management.entity.ObjectUser)1 ObjectUserSecretKeys (com.emc.ecs.management.entity.ObjectUserSecretKeys)1 ObjectUsers (com.emc.ecs.management.entity.ObjectUsers)1 ObjectUsersRequest (com.emc.ecs.management.entity.ObjectUsersRequest)1 S3Config (com.emc.object.s3.S3Config)1 Vdc (com.emc.rest.smart.ecs.Vdc)1 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)1 ArrayList (java.util.ArrayList)1