Prior to this, there was very sparse documentation linking these two software. It might be common sense to some, but there was hardly any mention for setting up both to be used in tandem. So let's cut to the chase.
The main draw for Apache jclouds is support for S3 API in Java, across many platforms. The main concern for us in particular, was their BlobStore API.
Addition to pom.xml
<jclouds.version>2.6.0</jclouds.version>
<dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-all</artifactId>
<version>${jclouds.version}</version>
</dependency>
Code snippet
//Initialise connectivity
BlobStoreContext context = ContextBuilder.newBuilder("s3")
.credentials(identity, credential)
.endpoint(weedMasterUrl)
.buildView(BlobStoreContext.class);
// Access the BlobStore
BlobStore blobStore = context.getBlobStore();
ByteSource payload = ByteSource.wrap(payloadStr.getBytes("UTF-8"));
Blob blob = blobStore.blobBuilder(uuid)
.payload(payload)
.contentLength(payload.size())
.build();
// Upload the Blob
blobStore.putBlob(containerName, blob);
// Don't forget to close the context when you're done!
context.close();
The above was practically lifted off the jclouds page. The specific point of attention would be the newBuilder("s3") that is used as a generic version of the "aws-s3" stated in their original sample.
"But SeaweedFS already has a large number of client libraries provided by the community!", you exclaimed.
And you'd be correct. Yet they'd only be used specifically for SeaweedFS however. I'd neglected to elaborate earlier, that the S3 API offerd by jclouds is generically usable with any other (enterprise-grade) product besides SeaweedFS. By integrating the two, our development can adopt a lightweight alternative like SeaweedFS, while the main production deployment takes on a heftier software, all while using the same library, which is offered by Apache no less.
This was still largely unexplored territory for some of us, so setting up SeaweedFS was more nuanced than we expected.
This is what it took:
- Start the master server: sudo ./weed master &
- Start a volume server: sudo ./weed volume -dir=”/data/seaweed/data1” -max=5 -mserver=”localhost:9333” -port=8080 &
- Start filer and S3 service: sudo ./weed filer -s3 &