JCLOUDS-158: Adding blobstore-scala-filesystem to the jclouds-examples overview

Also added parameters to make the example more configurable


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/commit/39c0a2e7
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/tree/39c0a2e7
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/diff/39c0a2e7

Branch: refs/heads/master
Commit: 39c0a2e7142d3cf2be6f61f742c7cbbaa2eb8a17
Parents: d6fa92c
Author: Andrew Phillips <[email protected]>
Authored: Fri Jun 28 15:50:43 2013 -0400
Committer: Andrew Phillips <[email protected]>
Committed: Fri Jun 28 15:50:43 2013 -0400

----------------------------------------------------------------------
 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(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/39c0a2e7/README.md
----------------------------------------------------------------------
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
       <td>Example code to create a container, and list your containers using 
the portable <a 
href="https://github.com/jclouds/jclouds/blob/master/blobstore/src/main/clojure/org/jclouds/blobstore2.clj";>blobstore2
 functions</a></td>
     </tr>
     <tr>
+      <td><a href="blobstore-scala-filesystem/">BlobStore Basics 
(Scala)</a></td>
+      <td>Example code to create a container and blob using the filesystem <a 
href="http://jclouds.incubator.apache.org/documentation/userguide/blobstore-guide/";>BlobStore
 API</a></td>
+    </tr>
+    <tr>
       <td><a href="blobstore-karaf-shell">BlobStore via Karaf Shell</a></td>
       <td>Example to read and write to a blobstore from inside the Apache 
Karaf Shell.</td>
     </tr>

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/39c0a2e7/blobstore-scala-filesystem/README.md
----------------------------------------------------------------------
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 <code>run _basedir_</code>, 
where <em>basedir</em> is a directory in which the container will be created. 
E.g. if your basedir is <code>/home/blobstore</code>, run
 
-<code>run /home/blobstore</code>
+Run `sbt` from the root of your project and invoke
+```
+run _basedir_
+```
+where <em>basedir</em> 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

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/39c0a2e7/blobstore-scala-filesystem/build.sbt
----------------------------------------------------------------------
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.+",

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/39c0a2e7/blobstore-scala-filesystem/src/main/scala/Main.scala
----------------------------------------------------------------------
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'")
   })
-
-
 }

Reply via email to