You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/09/17 23:03:08 UTC

[03/13] git commit: All reg commands throw a UsageException; base validate() method declares that it can throw it.

All reg commands throw a UsageException; base validate() method declares that it can throw it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/3096eeb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/3096eeb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/3096eeb5

Branch: refs/heads/feature/SLIDER-149_Support_a_YARN_service_registry
Commit: 3096eeb53fe918e64f59278e210fc4beb08a5397
Parents: f6cd0aa
Author: Steve Loughran <st...@apache.org>
Authored: Tue Sep 16 12:10:51 2014 +0100
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Sep 16 12:10:51 2014 +0100

----------------------------------------------------------------------
 .../org/apache/slider/client/SliderClient.java  |  9 ++----
 .../common/params/AbstractActionArgs.java       |  3 +-
 .../common/params/ActionRegistryArgs.java       | 30 +++++++++++------
 .../apache/slider/common/params/CommonArgs.java |  5 +--
 .../slider/core/exceptions/UsageException.java  | 34 ++++++++++++++++++++
 .../slider/client/TestClientBadArgs.groovy      | 14 ++++++++
 .../slider/client/TestClientBasicArgs.groovy    |  1 +
 .../apache/slider/test/SliderTestUtils.groovy   |  2 ++
 8 files changed, 79 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index f76a089..3df5b18 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -2328,17 +2328,12 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
         outputConfig(publishedConfiguration, registryArgs);
       } else {
         // it's an unknown command
-        log.info(
-            "Unknown registry operation." +
-            "Supported operations:"  
-            + Arguments.ARG_LIST +" ,"
-            + Arguments.ARG_LISTCONF +" ,"
-            + Arguments.ARG_GETCONF );
+        log.info(ActionRegistryArgs.USAGE);
         return EXIT_USAGE;
       }
     } catch (FileNotFoundException e) {
       log.info("{}", e.toString());
-      log.debug("{}",e, e);
+      log.debug("{}", e, e);
       return EXIT_NOT_FOUND;
     }
     return EXIT_SUCCESS;

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/main/java/org/apache/slider/common/params/AbstractActionArgs.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/AbstractActionArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/AbstractActionArgs.java
index 41f6a3f..22473d5 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/AbstractActionArgs.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/AbstractActionArgs.java
@@ -22,6 +22,7 @@ import com.beust.jcommander.Parameter;
 import org.apache.hadoop.fs.Path;
 import org.apache.slider.core.exceptions.BadCommandArgumentsException;
 import org.apache.slider.core.exceptions.ErrorStrings;
+import org.apache.slider.core.exceptions.UsageException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -118,7 +119,7 @@ public abstract class AbstractActionArgs extends ArgOps implements Arguments {
     return getMinParams();
   }
 
-  public void validate() throws BadCommandArgumentsException {
+  public void validate() throws BadCommandArgumentsException, UsageException {
     
     int minArgs = getMinParams();
     int actionArgSize = parameters.size();

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/main/java/org/apache/slider/common/params/ActionRegistryArgs.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/ActionRegistryArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/ActionRegistryArgs.java
index 95b5fd2..b3d2f9c 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/ActionRegistryArgs.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/ActionRegistryArgs.java
@@ -22,7 +22,7 @@ import com.beust.jcommander.Parameter;
 import com.beust.jcommander.Parameters;
 import org.apache.slider.common.SliderKeys;
 import org.apache.slider.core.exceptions.BadCommandArgumentsException;
-import org.apache.slider.core.exceptions.ErrorStrings;
+import org.apache.slider.core.exceptions.UsageException;
 import org.apache.slider.core.registry.docstore.ConfigFormat;
 
 import static org.apache.slider.common.params.SliderActions.ACTION_REGISTRY;
@@ -42,6 +42,19 @@ import java.io.File;
 
 public class ActionRegistryArgs extends AbstractActionArgs {
 
+
+  public static final String USAGE =
+      "Usage: " + SliderActions.ACTION_REGISTRY
+      + " <"
+      + Arguments.ARG_LIST + "|"
+      + Arguments.ARG_LISTCONF + "|"
+      + Arguments.ARG_LISTFILES + "|"
+      + Arguments.ARG_GETCONF + "> "
+      + Arguments.ARG_NAME + " <name> "
+      + "[" + Arguments.ARG_VERBOSE + "] "
+      + "[" + Arguments.ARG_SERVICETYPE + " <servicetype> ] "
+      + "[" + Arguments.ARG_FORMAT + " <xml|json|properties>] "
+      ;
   public ActionRegistryArgs() {
   }
 
@@ -87,7 +100,7 @@ public class ActionRegistryArgs extends AbstractActionArgs {
 
   //--format 
   @Parameter(names = ARG_FORMAT,
-      description = "Format for a response: [xml|json|properties]")
+      description = "Format for a response: <xml|json|properties>")
   public String format = ConfigFormat.XML.toString() ;
 
   @Parameter(names = {ARG_DEST},
@@ -115,7 +128,7 @@ public class ActionRegistryArgs extends AbstractActionArgs {
    * @throws BadCommandArgumentsException
    */
   @Override
-  public void validate() throws BadCommandArgumentsException {
+  public void validate() throws BadCommandArgumentsException, UsageException {
     super.validate();
 
     //verify that at most one of the operations is set
@@ -123,16 +136,15 @@ public class ActionRegistryArgs extends AbstractActionArgs {
     int lists = s(list) + s(listConf) + s(listFiles);
     int set = lists + gets;
     if (set > 1) {
-      throw new BadCommandArgumentsException(
-          ErrorStrings.ERROR_TOO_MANY_ARGUMENTS);
+      throw new UsageException(USAGE);
     }
     if (dest != null && (lists > 0 || set == 0)) {
-      throw new BadCommandArgumentsException("Argument " + ARG_DEST
-           + " is only supported on 'get' operations");
+      throw new UsageException("Argument " + ARG_DEST
+           + " is only supported on 'get' operations: " + USAGE);
     }
     if (!list && !is(name)) {
-      throw new BadCommandArgumentsException("Argument " + ARG_NAME
-           +" missing");
+      throw new UsageException("Argument " + ARG_NAME
+           +" missing: " + USAGE);
 
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/main/java/org/apache/slider/common/params/CommonArgs.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/CommonArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/CommonArgs.java
index 5d94182..f4c974b 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/CommonArgs.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/CommonArgs.java
@@ -27,6 +27,7 @@ import org.apache.slider.common.tools.SliderUtils;
 import org.apache.slider.core.exceptions.BadCommandArgumentsException;
 import org.apache.slider.core.exceptions.ErrorStrings;
 import org.apache.slider.core.exceptions.SliderException;
+import org.apache.slider.core.exceptions.UsageException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -193,9 +194,9 @@ public abstract class CommonArgs extends ArgOps implements SliderActions,
   /**
    * Validate the arguments against the action requested
    */
-  public void validate() throws BadCommandArgumentsException {
+  public void validate() throws BadCommandArgumentsException, UsageException {
     if (coreAction == null) {
-      throw new BadCommandArgumentsException(ErrorStrings.ERROR_NO_ACTION
+      throw new UsageException(ErrorStrings.ERROR_NO_ACTION
                                              + usage());
     }
     log.debug("action={}", getAction());

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/main/java/org/apache/slider/core/exceptions/UsageException.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/exceptions/UsageException.java b/slider-core/src/main/java/org/apache/slider/core/exceptions/UsageException.java
new file mode 100644
index 0000000..8684294
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/core/exceptions/UsageException.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.apache.slider.core.exceptions;
+
+/**
+ * Used to raise a usage exception ... this has the exit code
+ * {@link #EXIT_USAGE}
+ */
+public class UsageException extends SliderException {
+  public UsageException(String s, Object... args) {
+    super(EXIT_USAGE, s, args);
+  }
+
+  public UsageException(Throwable throwable, String message,
+      Object... args) {
+    super(EXIT_USAGE, throwable, message, args);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/test/groovy/org/apache/slider/client/TestClientBadArgs.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestClientBadArgs.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestClientBadArgs.groovy
index 088fdb3..d1f8a8f 100644
--- a/slider-core/src/test/groovy/org/apache/slider/client/TestClientBadArgs.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/client/TestClientBadArgs.groovy
@@ -19,10 +19,13 @@
 package org.apache.slider.client
 
 import groovy.transform.CompileStatic
+import groovy.util.logging.Slf4j
 import org.apache.hadoop.conf.Configuration
+import org.apache.slider.common.params.ActionRegistryArgs
 import org.apache.slider.common.params.Arguments
 import org.apache.slider.common.params.SliderActions
 import org.apache.slider.core.exceptions.ErrorStrings
+import org.apache.slider.core.exceptions.UsageException
 import org.apache.slider.core.main.ServiceLauncherBaseTest
 import org.junit.Test
 
@@ -30,6 +33,7 @@ import org.junit.Test
  * Test the argument parsing/validation logic
  */
 @CompileStatic
+@Slf4j
 class TestClientBadArgs extends ServiceLauncherBaseTest {
   @Test
   public void testNoAction() throws Throwable {
@@ -73,5 +77,15 @@ class TestClientBadArgs extends ServiceLauncherBaseTest {
                             [SliderActions.ACTION_HELP,
                              Arguments.ARG_IMAGE])
   }
+  
+  @Test
+  public void testRegistryUsage() throws Throwable {
+    def exception = launchExpectingException(SliderClient,
+        new Configuration(),
+        ActionRegistryArgs.USAGE,
+        [SliderActions.ACTION_REGISTRY])
+    assert exception instanceof UsageException
+    log.info(exception.toString())
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/test/groovy/org/apache/slider/client/TestClientBasicArgs.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestClientBasicArgs.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestClientBasicArgs.groovy
index 803389b..161bafe 100644
--- a/slider-core/src/test/groovy/org/apache/slider/client/TestClientBasicArgs.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/client/TestClientBasicArgs.groovy
@@ -74,4 +74,5 @@ class TestClientBasicArgs extends ServiceLauncherBaseTest {
 
   }
 
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/3096eeb5/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index cbf4749..9266634 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -516,6 +516,8 @@ class SliderTestUtils extends Assert {
     } catch (Throwable thrown) {
       if (expectedText && !thrown.toString().contains(expectedText)) {
         //not the right exception -rethrow
+        log.warn("Caught Exception did not contain expected text" +
+                 "\""+ expectedText +"\"")
         throw thrown;
       }
       return thrown;