Updated Branches: refs/heads/master a7b0d1326 -> 39c0a2e71
JCLOUDS-158: Adding blobstore-scala-filesystem to jclouds-examples Submitted by adisesha 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/d6fa92c8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/tree/d6fa92c8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/diff/d6fa92c8 Branch: refs/heads/master Commit: d6fa92c806de6221de853575021b0dc5e5898e32 Parents: a7b0d13 Author: Andrew Phillips <[email protected]> Authored: Fri Jun 28 15:49:22 2013 -0400 Committer: Andrew Phillips <[email protected]> Committed: Fri Jun 28 15:49:22 2013 -0400 ---------------------------------------------------------------------- blobstore-scala-filesystem/README.md | 10 ++++ blobstore-scala-filesystem/build.sbt | 10 ++++ .../src/main/scala/Main.scala | 59 ++++++++++++++++++++ 3 files changed, 79 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/d6fa92c8/blobstore-scala-filesystem/README.md ---------------------------------------------------------------------- diff --git a/blobstore-scala-filesystem/README.md b/blobstore-scala-filesystem/README.md new file mode 100644 index 0000000..f478049 --- /dev/null +++ b/blobstore-scala-filesystem/README.md @@ -0,0 +1,10 @@ +# 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 +## 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> +## 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/d6fa92c8/blobstore-scala-filesystem/build.sbt ---------------------------------------------------------------------- diff --git a/blobstore-scala-filesystem/build.sbt b/blobstore-scala-filesystem/build.sbt new file mode 100644 index 0000000..6233ca3 --- /dev/null +++ b/blobstore-scala-filesystem/build.sbt @@ -0,0 +1,10 @@ +name :="blobstore-scala-filesystem" + +scalaVersion :="2.10.1" + +version :="1.0-SNAPSHOT" + +libraryDependencies ++= Seq( "org.jclouds.api" % "filesystem" % "1.6.0", + "com.google.code.findbugs" % "jsr305" % "1.3.+", + "com.jsuereth" %% "scala-arm" % "1.3" + ) http://git-wip-us.apache.org/repos/asf/incubator-jclouds-examples/blob/d6fa92c8/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 new file mode 100644 index 0000000..2e9d206 --- /dev/null +++ b/blobstore-scala-filesystem/src/main/scala/Main.scala @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * 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\" + * + * @author adisesha + */ +object Main extends App { + require(args.length == 1, "Invalid number of parameters. Usage is: \"baseDir\" ") + + val baseDir = args(0) + + val properties = new java.util.Properties() + properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, baseDir) + + //Using scala-arm for context management. See https://github.com/jsuereth/scala-arm + managed(ContextBuilder.newBuilder("filesystem") + .overrides(properties) + .buildView(classOf[BlobStoreContext])) + .acquireAndGet(context => { + + val blobStore = context.getBlobStore + blobStore.createContainerInLocation(null, "test") + + val blob = blobStore.blobBuilder("test").payload("testdata").build() + blobStore.putBlob("test", blob) + + val filePath = baseDir + System.getProperty("file.separator") + "test" + println(s"File 'test' stored under, $filePath") + + }) + + +}
