From f45c9ee11f932851dab61d30c1767f44af10ac82 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 28 Jun 2013 15:32:10 -0400 Subject: [PATCH] Adding the blobstore-scala-filesystem example to the overview --- README.md | 4 +++ blobstore-scala-filesystem/README.md | 18 ++++++++++++-- blobstore-scala-filesystem/build.sbt | 6 ++-- .../src/main/scala/Main.scala | 25 ++++++++----------- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8719bad..7deb85e 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ This repository contains various examples of using Example code to create a container, and list your containers using the portable blobstore2 functions + BlobStore Basics (Scala) + Example code to create a container and blob using the filesystem BlobStore API + + BlobStore via Karaf Shell Example to read and write to a blobstore from inside the Apache Karaf Shell. diff --git a/blobstore-scala-filesystem/README.md b/blobstore-scala-filesystem/README.md index f478049..7e557dd 100644 --- a/blobstore-scala-filesystem/README.md +++ b/blobstore-scala-filesystem/README.md @@ -1,10 +1,22 @@ # blobstore-scala-filesystem + This is a simple example command line client that creates a container and test blob in a filesystem [BlobStore](http://jclouds.incubator.apache.org/documentation/userguide/blobstore-guide/) using Scala. This example uses [scala-arm](https://github.com/jsuereth/scala-arm) to manage the [BlobStoreContext](http://javadocs.jclouds.cloudbees.net/org/jclouds/blobstore/BlobStoreContext.html) + ## Build -Ensure that sbt is installed. Tested with 0.12.2 + +Ensure that [sbt is installed](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html). Tested with 0.12.2 + ## Run -Run sbt from the root of your project and invoke run _basedir_, where basedir is a directory in which the container will be created. E.g. if your basedir is /home/blobstore, run -run /home/blobstore +Run `sbt` from the root of your project and invoke +``` +run _basedir_ +``` +where basedir is a directory in which the container will be created. E.g. if your basedir is `/home/blobstore`, run +``` +run /home/blobstore +``` + ## License + Licensed under the Apache License, Version 2.0 \ No newline at end of file diff --git a/blobstore-scala-filesystem/build.sbt b/blobstore-scala-filesystem/build.sbt index 6233ca3..d044bc8 100644 --- a/blobstore-scala-filesystem/build.sbt +++ b/blobstore-scala-filesystem/build.sbt @@ -1,8 +1,8 @@ -name :="blobstore-scala-filesystem" +name := "blobstore-scala-filesystem" -scalaVersion :="2.10.1" +scalaVersion := "2.10.1" -version :="1.0-SNAPSHOT" +version := "1.0-SNAPSHOT" libraryDependencies ++= Seq( "org.jclouds.api" % "filesystem" % "1.6.0", "com.google.code.findbugs" % "jsr305" % "1.3.+", diff --git a/blobstore-scala-filesystem/src/main/scala/Main.scala b/blobstore-scala-filesystem/src/main/scala/Main.scala index 2e9d206..11d27af 100644 --- a/blobstore-scala-filesystem/src/main/scala/Main.scala +++ b/blobstore-scala-filesystem/src/main/scala/Main.scala @@ -16,27 +16,27 @@ * specific language governing permissions and limitations * under the License. */ - import org.jclouds.blobstore.BlobStoreContext import org.jclouds.ContextBuilder import org.jclouds.filesystem.reference.FilesystemConstants import resource._ - /** * Demonstrates the use of the filesystem [[org.jclouds.blobstore.BlobStore]] in Scala * - * Usage is: run \"basedir\" + * Usage is: run \"basedir\" \"containername\" \"blobname\" * * @author adisesha */ object Main extends App { - require(args.length == 1, "Invalid number of parameters. Usage is: \"baseDir\" ") + require(args.length == 3, "Invalid number of parameters. Usage: run \"basedir\" \"containername\" \"blobname\"") - val baseDir = args(0) + val basedir = args(0) + val containerName = args(1) + val blobname = args(2) val properties = new java.util.Properties() - properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, baseDir) + properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, basedir) //Using scala-arm for context management. See https://github.com/jsuereth/scala-arm managed(ContextBuilder.newBuilder("filesystem") @@ -45,15 +45,12 @@ object Main extends App { .acquireAndGet(context => { val blobStore = context.getBlobStore - blobStore.createContainerInLocation(null, "test") - - val blob = blobStore.blobBuilder("test").payload("testdata").build() - blobStore.putBlob("test", blob) + blobStore.createContainerInLocation(null, containerName) - val filePath = baseDir + System.getProperty("file.separator") + "test" - println(s"File 'test' stored under, $filePath") + val blob = blobStore.blobBuilder(blobname).payload("testdata").build() + blobStore.putBlob(containerName, blob) + val filePath = basedir + System.getProperty("file.separator") + containerName + println(s"Blob '$blobname' stored under '$filePath'") }) - - } -- 1.7.9.msysgit.0