Friday, 19 March 2010

OpenCredo Cloud Storage

I would like to make short introduction to the new OpenCredo open source project - OpenCredo Cloud Storage v.1.0 . Readers should have basic understanding of Cloud computing especially storage in the cloud and be familiar with Spring-Integration (SI). OpenCredo Cloud Storage gives possibility to manage data (blobs) in the cloud from Java applications. At the moment it supports Amazon S3 and Windows Azure storage. We do have plans to support other cloud storage providers also. Current functionality provides:
  • List containers in cloud storage (you can think about container as folder or directory in your computer and off-course you know that already).
  • Create/Delete containers.
  • List blobs in containers (file in directory is good equivalent of blob in container - can't be more simpler).
  • Add/Delete blobs to/from containers.
That's basically it, except the most important bit - an extension to join Spring-Integration based Java applications with cloud storage.

Nutshell
OpenCredo Cloud Storage use Spring style 'template' concept for interacting with different cloud storage providers. There are two templates (each for different cloud storage provider):
  • AzureTemplate
    AzureCredentials credentials = new AzureCredentials("YOUR_ACCOUNT_NAME", "YOUR_SECRET_KEY");
    StorageOperations template = new AzureTemplate(credentials);
    
  • S3Template
    AwsCredentials credentials = new AwsCredentials("YOUR_ACCESS_KEY", "YOUR_SECRET_ACCESS_KEY");
    StorageOperations template = new S3Template(credentials);
    
As you can see both templates implements same interface ( StorageOperations ). That means you can switch between storage providers just by changing implementation classes ( Spring dependency injection gives you such possibility without changing the code and again you know that better than me). Anyway going forward that is how you can use templates (check API for full capabilities):
template.createContainer("container_name");
template.send("container_name", "blob-name", "blob-as-string");
List<BlobDetails> blobDetailsList = template.listContainerObjectDetails("container_name");
template.receiveAndSaveToFile(blobDetailsList.get(0).getName(), toFile);

Example with SI
Upload and download files to/from cloud storage using Spring-Integration (full example can be downloaded from here).

Files to cloud storage will be send by cloud outbound adapter:
<!-- Credentials used to connect to S3 -->
<beans:bean id="awsCredentials" class="org.opencredo.cloud.storage.s3.AwsCredentials">
  <beans:constructor-arg value="${awsKey}" />
  <beans:constructor-arg value="${awsSecretKey}" />
</beans:bean>

<!-- Template to access S3 cloud storage -->
<beans:bean id="template" class="org.opencredo.cloud.storage.s3.S3Template">
  <beans:constructor-arg ref="awsCredentials" />
  <beans:constructor-arg value="${defaultContainerName}" />
</beans:bean>

<!-- Adapter which sends file to the cloud storage -->
<cloud:outbound-channel-adapter container="${defaultContainerName}" template="template" channel="fileUploadChannel" />

Download blobs from cloud storage is done in two steps:
  • Get list of available blob details in specified container (is done by cloud inbound adapter):
    <!-- Filter to accept blob once -->
    <beans:bean id="acceptOnceBlobNameFilter" class="org.opencredo.cloud.storage.si.filter.internal.AcceptOnceBlobNameFilter" />
    
    <!-- Adapter which looks for blobs in cloud storage -->
    <cloud:inbound-channel-adapter container="${defaultContainerName}" template="template" channel="blobDetailsChannel" filter="acceptOnceBlobNameFilter">
      <poller>
        <interval-trigger interval="5000" />
      </poller>
    </cloud:inbound-channel-adapter>
    
  • Download blob specified in details (is done by transformer):
    <!-- Download blob specified in BlobDetails -->
    <service-activator input-channel="blobDetailsChannel" ref="blobDetailsTransformer" method="transform" output-channel="blobChannel" />
    
    <!-- BlobDetails Transformer bean -->
    <beans:bean id="blobDetailsTransformer" class="org.opencredo.cloud.storage.si.transformer.internal.BlobToByteArrayTransformer">
      <beans:constructor-arg ref="template" />
      <!-- This constructor argument tells to delete blob after download -->
      <beans:constructor-arg value="true" />
    </beans:bean>
    

It is important to notice that XML snippets above uses custom Spring-Integration namespace:
<beans:beans ...
 xmlns:cloud="http://www.opencredo.com/schema/si/cloud/storage"
 xsi:schemaLocation="...
   http://www.opencredo.com/schema/si/cloud/storage
   http://www.opencredo.com/schema/si/cloud/storage/opencredo-si-cloud-storage-1.0.xsd">

That's it for today.
P.S This is my first blog ever.