Skip to main content
  • Place orders quickly and easily
  • View orders and track your shipping status
  • Create and access a list of your products
  • Manage your Dell EMC sites, products, and product-level contacts using Company Administration.

Dell ObjectScale 1.3 Administration Guide

ObjectScale Java S3 client SDK

The ObjectScale Java S3 client SDK is a library to assist users of the ObjectScale platform. This includes an API to interact with ObjectScale's own API..

Requirements:

  • Java 11 or higher
  • ObjectScale 1.0.0 or higher.

An example of using this SDK (S3Client) is shown below for metadatasearch.

package main.java.metadatasearch;

import com.dellemc.objectscale.s3.ObjectScaleS3Client;
import com.dellemc.objectscale.s3.model.*;
import com.dellemc.objectscale.s3.ObjectScaleS3ClientBuilder;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.Bucket;
import software.amazon.awssdk.services.s3.model.ListBucketsRequest;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;

import java.net.URI;

// This is an example of a program which creates 10 buckets with
// ObjectScale's metadata search enabled, and then queries all buckets in a store
// for all objects created after Jan 1 2015.
public abstract class SearchMetadata {

    // You can adjust these according to your setup.
    static final String S3_IP = "127.0.0.1";
    static final String S3_PORT = "80";
    static final String ACCESS_KEY = "OKIA----------------";
    static final String SECRET = "----------------------------------------";
    static final String BUCKET = "bucket-metadata-search-example";

    static ObjectScaleS3Client client;

    // This is an example of how one can create buckets with ObjectScale's metadata search feature
    // enable, get a list of all buckets, and search for metadata using the query objects endpoint
    // with selectors.
    public static void main( String[] args ) {
        ObjectScaleS3ClientBuilder builder = ObjectScaleS3Client.builder()
                .endpointOverride(URI.create("http://"+S3_IP+":"+S3_PORT))
                .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCESS_KEY, SECRET)));
        client = builder.build();

        // Create a set of buckets
        for ( int i = 1; i <= 10; i++ ) {
            createTestBuckets(client, BUCKET+"-"+i);
        }

        // Get a list of the current buckets
        ListBucketsRequest listRequest = ListBucketsRequest.builder().build();
        ListBucketsResponse listResponse = client.listBuckets(listRequest);


        for ( Bucket b : listResponse.buckets() ){
            System.out.println("===== Bucket " + b.name() + " =====");
            try {
                // Query the objects in the bucket for anything modified after january 1st, 2015.
                QueryObjectsRequest qo = QueryObjectsRequest.builder().bucket(b.name()).query("LastModified>2015-01-01T00:00:00Z").build();
                QueryObjectsResponse resp = client.queryObjects(qo);
                // For every Object...
                for ( QueryObject o : resp.objects() ) {
                    // For every queried metadata set
                    for ( QueryMetadata m : o.queryMetadata() ) {
                        // For every key in the metadata map
                        for ( String s : m.metadataMap().keySet() ) {
                            // Print out the info.
                            System.out.println(o.objectName() + ": " + m.typeAsString() + ": " + s + " " + m.metadataMap().get(s));
                        }
                    }
                }
            } catch ( S3Exception e ){
                if( e.getLocalizedMessage().startsWith("Invalid search index key name") ){}
                System.out.println("metadata search not enabled on this bucket, or key not searchable");
            }
        }
    }

    // Create a bucket with a given name and client where one can query / filter based
    // on the LastModified field.
    public static void createTestBuckets( S3Client client, String name ){
        CreateBucketRequest createBucketRequest = CreateBucketRequest.builder()
                .metadataSearchKeys("LastModified;datetime").bucket(name).build();
        // Use toStandardRequest to use this as a CreateBucketRequest
        client.createBucket(createBucketRequest.toStandardRequest());
    }
}

Rate this content

Accurate
Useful
Easy to understand
Was this article helpful?
0/3000 characters
  Please provide ratings (1-5 stars).
  Please provide ratings (1-5 stars).
  Please provide ratings (1-5 stars).
  Please select whether the article was helpful or not.
  Comments cannot contain these special characters: <>()\