Expiring Swift objects with jclouds

851 views Asked by At

I am attempting to set an object expiration during the PUT upload of my objects to my Swift ring using jclouds, so that the objects will be deleted from Swift at the assigned date/time.

I am able to do this manually with cURL and PUT an object to Swift with an expiration date. This makes use of the X-Delete-At or X-Delete-After headers. See openstack docs 1 and openstack docs 2 for details on these headers.

However, I have not had any luck doing the same through jclouds. A quick search through jclouds did not turn up either of the X-Delete- headers, so my assumption is that this is not directly supported, except by manually setting those headers in the message payload.

A point of clarification: These headers cannot be set as object user metadata. Setting a user metadata key of X-Delete-At on the object for example will result in a header of the form X-Object-Meta-x-delete-at, which swift will not recognize as an object expiration.

I am trying to figure out if there is a way to add a custom header to the HTTP PUT operation (not user metadata) to do this. With cURL, it is as simple as adding:

-H "X-Delete-After:60"

to the cURL command for the PUT operation (i.e., expire the object in 60 seconds). I assume the same can be done with jclouds. This is what I have so far:

public String writeToStore(String name, InputStream payload) {

    BlobStore bs = prepareContext().
            getBlobStore();

    Blob b = bs.
            blobBuilder(name).
            // userMetadata(mymeta).
            payload(payload).
            contentType("image/jpeg").
            build();

    // Get current headers
    Multimap<String,String> headers = b.getAllHeaders();
    // Add new header & set expire date to 1 year in the future (seconds since epoch)
    headers.put("X-Delete-At", "1418148027");
    // Set headers including new header just added
    b.setAllHeaders(headers);

    return bs.putBlob(containerName, b);
}

Despite adding the X-Delete-At header here, it does not seem to have an effect. I am not seeing the X-Delete-At header appearing at all in the Wireshark capture of the packet.

Any help is appreciated. Thanks!

1

There are 1 answers

0
Andrew Gaul On BEST ANSWER

jclouds does not presently support this but I proposed a commit which maps BlobBuilder.expires to X-Delete-At:

https://github.com/jclouds/jclouds/pull/227

Can you test it and open a JIRA issue here:

https://issues.apache.org/jira/browse/JCLOUDS

Thanks!