Updated Branches:
  refs/heads/1.6.x ddb59ab9e -> 3595d2528

JCLOUDS-76: Add blobstore-blob-exists command

This is less confusing than overloading blobstore-read.


Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/commit/3595d252
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/tree/3595d252
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/diff/3595d252

Branch: refs/heads/1.6.x
Commit: 3595d2528487a59400439618c7dca584afc7ed5f
Parents: ddb59ab
Author: Andrew Gaul <[email protected]>
Authored: Mon May 20 18:24:58 2013 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Fri May 24 10:49:11 2013 -0700

----------------------------------------------------------------------
 .../commands/blobstore/BlobExistsCommand.java      |   59 +++++++++++++++
 .../karaf/commands/blobstore/BlobReadCommand.java  |   12 +---
 .../services/org/apache/karaf/shell/commands       |    3 +-
 .../OSGI-INF/blueprint/jclouds-commands.xml        |   16 ++++
 4 files changed, 78 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/blob/3595d252/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobExistsCommand.java
----------------------------------------------------------------------
diff --git 
a/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobExistsCommand.java
 
b/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobExistsCommand.java
new file mode 100644
index 0000000..dafd668
--- /dev/null
+++ 
b/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobExistsCommand.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  jclouds 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.
+ */
+
+package org.jclouds.karaf.commands.blobstore;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
+import org.jclouds.blobstore.BlobStore;
+import org.jclouds.blobstore.KeyNotFoundException;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Strings;
+import com.google.common.io.CharStreams;
+import com.google.common.io.Files;
+import com.google.common.io.InputSupplier;
+
+/**
+ * @author: Andrew Gaul
+ */
+@Command(scope = "jclouds", name = "blobstore-blob-exists", description = 
"Checks existence of blob on the blobstore")
+public class BlobExistsCommand extends BlobStoreCommandWithOptions {
+
+   @Argument(index = 0, name = "containerName", description = "The name of the 
container", required = true, multiValued = false)
+   String containerName;
+
+   @Argument(index = 1, name = "blobName", description = "The name of the 
blob", required = true, multiValued = false)
+   String blobName;
+
+   @Override
+   protected Object doExecute() throws Exception {
+      BlobStore blobStore = getBlobStore();
+
+      if (!blobStore.blobExists(containerName, blobName)) {
+          throw new KeyNotFoundException(containerName, blobName, "while 
checking existence");
+      }
+      return null;
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/blob/3595d252/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobReadCommand.java
----------------------------------------------------------------------
diff --git 
a/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobReadCommand.java
 
b/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobReadCommand.java
index 39402de..51dfa58 100644
--- 
a/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobReadCommand.java
+++ 
b/commands/src/main/java/org/jclouds/karaf/commands/blobstore/BlobReadCommand.java
@@ -52,20 +52,10 @@ public class BlobReadCommand extends 
BlobStoreCommandWithOptions {
    @Option(name = "-d", aliases = "--display", description = "Display the 
content to the console", required = false, multiValued = false)
    boolean display;
 
-   @Option(name = "-e", aliases = "--exists", description = "Test whether a 
blob exists", required = false, multiValued = false)
-   boolean exists;
-
    @Override
    protected Object doExecute() throws Exception {
       BlobStore blobStore = getBlobStore();
 
-      if (exists) {
-          if (!blobStore.blobExists(containerName, blobName)) {
-              throw new KeyNotFoundException(containerName, blobName, "while 
checking existence");
-          }
-          return null;
-      }
-
       InputSupplier<InputStream> supplier = getBlobInputStream(blobStore, 
containerName, blobName);
 
       if (display) {
@@ -73,7 +63,7 @@ public class BlobReadCommand extends 
BlobStoreCommandWithOptions {
          System.out.flush();
       } else {
          if (fileName == null) {
-            throw new CommandException("Must specify --exists, --display, or 
file name");
+            throw new CommandException("Must specify --display or file name");
          }
          File file = new File(fileName);
          if (!file.exists() && !file.createNewFile()) {

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/blob/3595d252/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
----------------------------------------------------------------------
diff --git 
a/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands 
b/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
index e25e736..b619f3c 100644
--- 
a/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
+++ 
b/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
@@ -29,10 +29,11 @@ org.jclouds.karaf.commands.compute.NodeResumeCommand
 org.jclouds.karaf.commands.compute.NodeRunScriptCommand
 org.jclouds.karaf.commands.compute.GroupDestroyCommand
 org.jclouds.karaf.commands.compute.GroupRunScriptCommand
-org.jclouds.karaf.commands.blobstore.BlobRemoveCommand
+org.jclouds.karaf.commands.blobstore.BlobExistsCommand
 org.jclouds.karaf.commands.blobstore.BlobListCommand
 org.jclouds.karaf.commands.blobstore.BlobMetadataCommand
 org.jclouds.karaf.commands.blobstore.BlobReadCommand
+org.jclouds.karaf.commands.blobstore.BlobRemoveCommand
 org.jclouds.karaf.commands.blobstore.BlobWriteCommand
 org.jclouds.karaf.commands.blobstore.ContainerClearCommand
 org.jclouds.karaf.commands.blobstore.ContainerCreateCommand

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-karaf/blob/3595d252/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
----------------------------------------------------------------------
diff --git 
a/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml 
b/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
index 09bd1dd..7c143ab 100644
--- a/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
+++ b/commands/src/main/resources/OSGI-INF/blueprint/jclouds-commands.xml
@@ -284,6 +284,22 @@ limitations under the License.
             </optional-completers>
         </command>
 
+        <command name="jclouds/blobstore-blob-exists">
+            <action 
class="org.jclouds.karaf.commands.blobstore.BlobExistsCommand">
+                <property name="blobStoreServices" ref="blobStoreServices"/>
+                <property name="cacheProvider" ref="cacheProvider"/>
+            </action>
+            <completers>
+                <ref component-id="containerCompleter"/>
+                <ref component-id="blobCompleter"/>
+                <null/>
+            </completers>
+            <optional-completers>
+                <entry key="--name" value-ref="blobStoreContextNameCompleter"/>
+                <entry key="--provider" 
value-ref="blobStoreProviderCompleter"/>
+                <entry key="--api" value-ref="blobStoreApiCompleter"/>
+            </optional-completers>
+        </command>
         <command name="jclouds/blobstore-read">
             <action 
class="org.jclouds.karaf.commands.blobstore.BlobReadCommand">
                 <property name="blobStoreServices" ref="blobStoreServices"/>

Reply via email to