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/10/10 01:01:56 UTC

[3/4] git commit: SLIDER-365 slider "resolve" command : more tests, more fixes

SLIDER-365 slider "resolve" command : more tests, more fixes


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

Branch: refs/heads/develop
Commit: 67b383620f70244412d5d6765c1da1bb278cc970
Parents: bfaea96
Author: Steve Loughran <st...@apache.org>
Authored: Thu Oct 9 15:50:45 2014 -0700
Committer: Steve Loughran <st...@apache.org>
Committed: Thu Oct 9 15:50:45 2014 -0700

----------------------------------------------------------------------
 .../org/apache/slider/client/SliderClient.java  |  8 ++-
 .../slider/common/params/ActionResolveArgs.java | 14 +----
 .../slider/common/params/SliderActions.java     |  2 +
 .../TestStandaloneYarnRegistryAM.groovy         | 63 ++++++++++++++++----
 .../apache/slider/test/SliderTestUtils.groovy   |  2 +-
 5 files changed, 62 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/67b38362/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 2944e2a..476f300 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
@@ -22,6 +22,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.PathNotFoundException;
 import org.apache.hadoop.fs.permission.FsPermission;
@@ -2206,6 +2207,9 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
     try {
       if (args.list) {
         File destDir = args.destdir;
+        if (destDir != null) {
+          destDir.mkdirs();
+        }
 
         Map<String, ServiceRecord> recordMap =
             listServiceRecords(operations, path);
@@ -2237,12 +2241,14 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
           print(serviceRecordMarshal.toJson(instance));
         }
       }
-//      JDK7
+//      TODO JDK7
     } catch (PathNotFoundException e) {
       // no record at this path
       return EXIT_NOT_FOUND;
     } catch (NoRecordException e) {
       return EXIT_NOT_FOUND;
+    } catch (UnknownApplicationInstanceException e) {
+      return EXIT_NOT_FOUND;
     } catch (InvalidRecordException e) {
       // it is not a record
       log.error("{}", e);

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/67b38362/slider-core/src/main/java/org/apache/slider/common/params/ActionResolveArgs.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/ActionResolveArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/ActionResolveArgs.java
index 944be1b..4759bcb 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/ActionResolveArgs.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/ActionResolveArgs.java
@@ -38,7 +38,7 @@ import static org.apache.slider.common.params.SliderActions.DESCRIBE_ACTION_REGI
  * --verbose
  * --list
  */
-@Parameters(commandNames = {ACTION_REGISTRY},
+@Parameters(commandNames = {ACTION_RESOLVE},
             commandDescription = DESCRIBE_ACTION_REGISTRY)
 public class ActionResolveArgs extends AbstractActionArgs {
 
@@ -47,7 +47,6 @@ public class ActionResolveArgs extends AbstractActionArgs {
       + " "
       + ARG_PATH + " <path> "
       + "[" + ARG_LIST + "] "
-      + "[" + ARG_VERBOSE + "] "
       + "[" + ARG_OUTPUT + " <filename> ] "
       + "[" + ARG_DESTDIR + " <directory> ] "
       ;
@@ -84,10 +83,6 @@ public class ActionResolveArgs extends AbstractActionArgs {
       description = "dest file")
   public File out;
 
- @Parameter(names = {ARG_VERBOSE},
-      description = "verbose output")
-  public boolean verbose;
-
   @Override
   public String toString() {
     final StringBuilder sb =
@@ -156,11 +151,4 @@ public class ActionResolveArgs extends AbstractActionArgs {
     this.out = out;
   }
 
-  public boolean isVerbose() {
-    return verbose;
-  }
-
-  public void setVerbose(boolean verbose) {
-    this.verbose = verbose;
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/67b38362/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java b/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java
index 0c37b94..abb669a 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/SliderActions.java
@@ -72,6 +72,8 @@ public interface SliderActions {
                     "Monitor a running application";
   String DESCRIBE_ACTION_REGISTRY =
                       "Query the registry of a YARN application";
+  String DESCRIBE_ACTION_RESOLVE =
+                      "Resolve or list records in the YARN registry";
   String DESCRIBE_ACTION_STATUS =
                       "Get the status of an application";
   String DESCRIBE_ACTION_THAW =

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/67b38362/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy
index ca200fd..700a6d8 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy
@@ -20,9 +20,9 @@ package org.apache.slider.agent.standalone
 
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
-import org.apache.commons.io.IOUtils
 import org.apache.hadoop.fs.FileUtil
 import org.apache.hadoop.fs.PathNotFoundException
+import org.apache.hadoop.registry.client.binding.RegistryPathUtils
 import org.apache.hadoop.yarn.api.records.ApplicationReport
 import org.apache.hadoop.yarn.api.records.YarnApplicationState
 import org.apache.hadoop.yarn.conf.YarnConfiguration
@@ -187,11 +187,10 @@ class TestStandaloneYarnRegistryAM extends AgentMiniClusterTestBase {
     File resolveListDir= new File(destDir, "list")
     ActionResolveArgs resolveList = new ActionResolveArgs(
         path:recordsPath,
-        list:true,
-        verbose:true)
+        list:true)
 
     // to stdout
-    client.actionResolve(resolveList)
+    assert 0 == client.actionResolve(resolveList)
     // to a file
     resolveList.out = resolveListDir;
     try {
@@ -200,16 +199,47 @@ class TestStandaloneYarnRegistryAM extends AgentMiniClusterTestBase {
       assertExceptionDetails(ex, LauncherExitCodes.EXIT_COMMAND_ARGUMENT_ERROR,
           Arguments.ARG_OUTPUT)
     }
+    
+    // list to a destination dir
     resolveList.out = null
     resolveList.destdir = resolveListDir
-    client.actionResolve(resolveList)
-    File resolvedFile = new File(resolveListDir, clustername+".json")
+    assert 0 == client.actionResolve(resolveList)
+    File resolvedFile = new File(resolveListDir, clustername + ".json")
     assertFileExists("resolved file", resolvedFile)
-    def recordFromList = serviceRecordMarshal.fromFile(resolvedFile)
+    serviceRecordMarshal.fromFile(resolvedFile)
+
+    // list the parent path, expect success and no entries
+    File listParentDir = new File(destDir, "listParent")
+    String parentPath = RegistryPathUtils.parentOf(recordsPath)
+    assert 0 == client.actionResolve(new ActionResolveArgs(
+        path: parentPath,
+        list: true,
+        destdir: listParentDir))
+    assertFileExists("output dir", listParentDir)
+    assert null != listParentDir.list()
+    assert 0 == listParentDir.list().length
+
+    // look for a record a path not in the registry expect failure
+    ActionResolveArgs listUnknownPath = new ActionResolveArgs(
+        path: recordsPath +"/unknown",
+        list: true)
+    // the record is not there, even if the path is
+    assert SliderExitCodes.EXIT_NOT_FOUND == client.actionResolve(
+        listUnknownPath)
+    
     
+    // look for a record at the same path as the listing; expect failure
+    ActionResolveArgs resolveRecordAtListPath = new ActionResolveArgs(
+        path: recordsPath,
+        list: false)
+    // the record is not there, even if the path is
+    assert SliderExitCodes.EXIT_NOT_FOUND == client.actionResolve(
+        resolveRecordAtListPath)
+
     // look at a single record
+    def instanceRecordPath = recordsPath + "/" + clustername
     ActionResolveArgs resolveRecordCommand = new ActionResolveArgs(
-        path: recordsPath + "/" + clustername)
+        path: instanceRecordPath)
     // to stdout
     client.actionResolve(resolveRecordCommand)
     
@@ -218,7 +248,7 @@ class TestStandaloneYarnRegistryAM extends AgentMiniClusterTestBase {
     File singleFile = new File(destDir, "singlefile.json")
     singleFile.delete()
     resolveRecordCommand.out = singleFile
-    client.actionResolve(resolveRecordCommand)
+    assert 0 == client.actionResolve(resolveRecordCommand)
     assertFileExists("\"slider $resolveRecordCommand\"", singleFile)
     def recordFromFile = serviceRecordMarshal.fromFile(singleFile)
     assert recordFromFile[YarnRegistryAttributes.YARN_ID] ==
@@ -231,9 +261,18 @@ class TestStandaloneYarnRegistryAM extends AgentMiniClusterTestBase {
         CustomRegistryConstants.REGISTRY_REST_API)
     assert registryEndpoint != null
     def registryURL = RegistryTypeUtils.retrieveAddressURLs(registryEndpoint)[0]
-    
-    
-    // Look at the Registry WADL
+
+    // list the path at the record, expect success and no entries
+    File listUnderRecordDir = new File(destDir, "listUnderRecord")
+    ActionResolveArgs listUnderRecordCommand = new ActionResolveArgs(
+        path: instanceRecordPath,
+        list:true,
+        destdir: listUnderRecordDir)
+    assert 0 == client.actionResolve(listUnderRecordCommand)
+    assert 0 == listUnderRecordDir.list().length
+
+
+           // Look at the Registry WADL
     describe("Registry WADL @ $registryURL")
     def publisherEndpoint = serviceRecord.getExternalEndpoint(
         CustomRegistryConstants.PUBLISHER_REST_API)

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/67b38362/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 d09d280..61dfeb5 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
@@ -807,7 +807,7 @@ class SliderTestUtils extends Assert {
       StringBuilder builder = new StringBuilder()
       builder.append("${parent.absolutePath}:\n")
       files.each { String name-> builder.append("  $name\n")}
-      throw new FileNotFoundException("$text: file $file not found in $builder")
+      throw new FileNotFoundException("$text: $file not found in $builder")
     }
   }
 }