Search in sources :

Example 1 with Metadata

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

the class ElasticBillingDAO method toJsonFormat.

private static XContentBuilder toJsonFormat(ObjectBucket objectBucket, Date collectionTime, XContentBuilder builder) {
    try {
        if (builder == null) {
            builder = XContentFactory.jsonBuilder();
        }
        // initial portion
        builder = builder.startObject().field(ObjectBucket.CREATED_TAG, objectBucket.getCreated()).field(ObjectBucket.SOFT_QUOTA_TAG, objectBucket.getSoftQuota()).field(ObjectBucket.FS_ACCESS_ENABLED_TAG, objectBucket.getFsAccessEnabled()).field(ObjectBucket.LOCKED_TAG, objectBucket.getLocked()).field(ObjectBucket.V_POOL_TAG, objectBucket.getVpool()).field(ObjectBucket.NAMESPACE_TAG, objectBucket.getNamespace()).field(ObjectBucket.OWNER_TAG, objectBucket.getOwner()).field(ObjectBucket.IS_STALE_ALLOWED_TAG, objectBucket.getIsStaleAllowed()).field(ObjectBucket.IS_ENCRYPTION_ENABLED_TAG, objectBucket.getIsEncryptionEnabled()).field(ObjectBucket.DEFAULT_RETENTION_TAG, objectBucket.getDefaultRetention()).field(ObjectBucket.BLOCK_SIZE_TAG, objectBucket.getBlockSize()).field(ObjectBucket.NOTIFICATION_SIZE_TAG, objectBucket.getNotificationSize()).field(ObjectBucket.API_TYPE_TAG, objectBucket.getApiType());
        // TAG_SET_TAG
        if (objectBucket.getTagSet() != null && !objectBucket.getTagSet().isEmpty()) {
            builder.startArray(ObjectBucket.TAG_SET_TAG);
            for (Tag tag : objectBucket.getTagSet()) {
                builder.startObject().field("key", tag.getKey()).field("value", tag.getValue()).endObject();
            }
            builder.endArray();
        }
        builder.field(ObjectBucket.RETENTION_TAG, objectBucket.getRetention()).field(ObjectBucket.DEFAULT_GROUP_FILE_READ_PERMISSION_TAG, objectBucket.getDefaultGroupFileReadPermission()).field(ObjectBucket.DEFAULT_GROUP_FILE_WRITE_PERMISSION_TAG, objectBucket.getDefaultGroupFileWritePermission()).field(ObjectBucket.DEFAULT_GROUP_FILE_EXECUTE_PERMISSION_TAG, objectBucket.getDefaultGroupFileExecutePermission()).field(ObjectBucket.DEFAULT_GROUP_DIR_READ_PERMISSION_TAG, objectBucket.getDefaultGroupDirReadPermission()).field(ObjectBucket.DEFAULT_GROUP_DIR_WRITE_PERMISSION_TAG, objectBucket.getDefaultGroupDirWritePermission()).field(ObjectBucket.DEFAULT_GROUP_DIR_EXECUTE_PERMISSION_TAG, objectBucket.getDefaultGroupDirExecutePermission()).field(ObjectBucket.DEFAULT_GROUP_TAG, objectBucket.getDefaultGroup());
        // SEARCH_METADATA_TAG
        if (objectBucket.getSearchMetadata() != null && !objectBucket.getSearchMetadata().isEmpty()) {
            builder.startArray(ObjectBucket.SEARCH_METADATA_TAG);
            for (Metadata metadata : objectBucket.getSearchMetadata()) {
                builder.startObject().field("data_type", metadata.getDataType()).field("name", metadata.getName()).field("type", metadata.getType()).endObject();
            }
            builder.endArray();
        }
        builder.field(ObjectBucket.NAME_TAG, objectBucket.getName()).field(ObjectBucket.NAME_TAG + ANALYZED_TAG, objectBucket.getName()).field(ObjectBucket.ID_TAG, (objectBucket.getId() != null) ? objectBucket.getId().toString() : null).field(ObjectBucket.LINK_TAG, objectBucket.getLink()).field(ObjectBucket.CREATION_TIME_TAG, objectBucket.getCreationTime()).field(ObjectBucket.INACTIVE_TAG, objectBucket.getInactive()).field(ObjectBucket.GLOBAL_TAG, objectBucket.getGlobal()).field(ObjectBucket.REMOTE_TAG, objectBucket.getRemote()).field(ObjectBucket.VDC_TAG, (objectBucket.getVdc() != null) ? objectBucket.getVdc().toString() : null).field(ObjectBucket.INTERNAL_TAG, objectBucket.getInternal()).field(COLLECTION_TIME, collectionTime).endObject();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return builder;
}
Also used : Metadata(com.emc.ecs.management.entity.Metadata) Tag(com.emc.ecs.management.entity.Tag) IOException(java.io.IOException)

Example 2 with Metadata

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

the class QueryObjectsCollection method createQueryObjectRequest.

private QueryObjectsRequest createQueryObjectRequest(String queryString) {
    // create request
    QueryObjectsRequest queryRequest = new QueryObjectsRequest(objectBucket.getName());
    List<String> attributeList = new ArrayList<String>();
    List<String> attributeListDetails = new ArrayList<String>();
    StringBuilder queryBufferString = new StringBuilder();
    // add all attribute to attr list
    for (Metadata metadata : objectBucket.getSearchMetadata()) {
        if (metadata.getName() == null || metadata.getName().isEmpty()) {
            continue;
        }
        attributeList.add(metadata.getName());
        String attributeDetails = "Name: " + metadata.getName() + " Type:" + metadata.getDataType().trim().toLowerCase();
        attributeListDetails.add(attributeDetails);
    }
    // one search metadata key is defined
    if (attributeList.isEmpty()) {
        // return null to prevent any querying
        return null;
    } else {
        queryBufferString.append(queryString);
    }
    // append ( at beginning
    queryBufferString.insert(0, "( ");
    // append ) at end
    queryBufferString.append(" )");
    queryRequest.withQuery(queryString.toString());
    queryRequest.withAttributes(attributeList);
    queryRequest.setMaxKeys(maxObjectPerRequest);
    queryRequest.setNamespace(collectionConfig.getNamespace());
    logger.info("QueryObject Collection for Namespace: " + collectionConfig.getNamespace() + " Bucket: " + objectBucket.getName());
    logger.info("MD Keys details: " + attributeListDetails.toString());
    logger.info(" Using query string: `" + queryString.toString() + "`");
    return queryRequest;
}
Also used : ArrayList(java.util.ArrayList) Metadata(com.emc.ecs.management.entity.Metadata) QueryObjectsRequest(com.emc.object.s3.request.QueryObjectsRequest)

Example 3 with Metadata

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

the class QueryObjectsCollection method createQueryObjectRequest.

private QueryObjectsRequest createQueryObjectRequest() {
    // create request
    QueryObjectsRequest queryRequest = new QueryObjectsRequest(objectBucket.getName());
    List<String> attributeList = new ArrayList<String>();
    StringBuilder queryString = new StringBuilder();
    // add index keys to the search query
    for (Metadata metadata : objectBucket.getSearchMetadata()) {
        if (metadata.getName() == null || metadata.getName().isEmpty()) {
            continue;
        }
        attributeList.add(metadata.getName());
        // Only want to use MD keys (Last Modified Time or Size) which have
        // the better chance of being present on all objects
        // if( LAST_MODIFIED_KEY.equals(metadata.getName())
        // SIZE_KEY.equals(metadata.getName()) ) {
        String dataType = metadata.getDataType().trim().toLowerCase();
        if (dataType.equals("string")) {
            if (queryString.length() > 0) {
                queryString.append(" or ");
            }
            queryString.append("(" + metadata.getName() + " <= '') or (" + metadata.getName() + " >= '' )");
        } else if (dataType.equals("decimal")) {
            if (queryString.length() > 0) {
                queryString.append(" or ");
            }
            queryString.append("(" + metadata.getName() + " <= 1.0) or (" + metadata.getName() + " >= 1.0 )");
        } else if (dataType.equals("integer")) {
            if (queryString.length() > 0) {
                queryString.append(" or ");
            }
            queryString.append("(" + metadata.getName() + " <= 1) or (" + metadata.getName() + " >= 1 )");
        } else if (dataType.equals("datetime")) {
            if (queryString.length() > 0) {
                queryString.append(" or ");
            }
            queryString.append("( " + metadata.getName() + " > '1970-01-01T00:00:00Z' )");
        } else {
            logger.error("Unhandled data type: " + dataType);
        }
    }
    if (queryString.length() == 0) {
        // return null to trigger list operation instead
        return null;
    }
    // append ( at beginning
    queryString.insert(0, "( ");
    // append ) at end
    queryString.append(" )");
    queryRequest.withQuery(queryString.toString());
    queryRequest.withAttributes(attributeList);
    queryRequest.setMaxKeys(maxObjectPerRequest);
    queryRequest.setNamespace(collectionConfig.getNamespace());
    logger.info("QueryObject Collection for Namespace: " + collectionConfig.getNamespace() + " Bucket: " + objectBucket.getName());
    logger.debug(" Using query string: `" + queryString.toString() + "`");
    return queryRequest;
}
Also used : ArrayList(java.util.ArrayList) Metadata(com.emc.ecs.management.entity.Metadata) QueryObjectsRequest(com.emc.object.s3.request.QueryObjectsRequest)

Aggregations

Metadata (com.emc.ecs.management.entity.Metadata)3 QueryObjectsRequest (com.emc.object.s3.request.QueryObjectsRequest)2 ArrayList (java.util.ArrayList)2 Tag (com.emc.ecs.management.entity.Tag)1 IOException (java.io.IOException)1