SLIDER 42. Fail fast with client side validation when app package is not .zip

git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1593585 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
index d8dc4d1..e15667b 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
@@ -86,7 +86,8 @@
 
     String appDef = instanceDefinition.getAppConfOperations().
         getGlobalOptions().getMandatoryOption(AgentKeys.APP_DEF);
-    sliderFileSystem.verifyFileExists(new Path(appDef));
+    Path appDefPath = new Path(appDef);
+    sliderFileSystem.verifyFileExists(appDefPath);
 
     String agentConf = instanceDefinition.getAppConfOperations().
         getGlobalOptions().getMandatoryOption(AgentKeys.AGENT_CONF);
@@ -150,6 +151,13 @@
     } catch (BadConfigException bce) {
       throw new BadConfigException("Application definition must be provided." + bce.getMessage());
     }
+    String appDef = instanceDefinition.getAppConfOperations().
+        getGlobalOptions().getMandatoryOption(AgentKeys.APP_DEF);
+    log.info("Validating app definition {}", appDef);
+    String extension = appDef.substring(appDef.lastIndexOf(".") + 1, appDef.length());
+    if (!"zip".equalsIgnoreCase(extension)) {
+      throw new BadConfigException("App definition must be packaged as a .zip file. File provided is " + appDef);
+    }
 
     String appHome = instanceDefinition.getAppConfOperations().
         getGlobalOptions().get(AgentKeys.PACKAGE_PATH);
diff --git a/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestBuildBasicAgent.groovy b/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestBuildBasicAgent.groovy
index 2b2ccaa..a597707 100644
--- a/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestBuildBasicAgent.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestBuildBasicAgent.groovy
@@ -47,7 +47,9 @@
   private static class TestResources {
     static File slider_core = new File(new File(".").absoluteFile, "src/test/python");
     static String app_def = "appdef_1.zip"
+    static String bad_app_def = "appdef_1.tar"
     static File app_def_path = new File(slider_core, app_def)
+    static File bad_app_def_path = new File(slider_core, bad_app_def)
     static String agt_conf = "agent.ini"
     static File agt_conf_path = new File(slider_core, agt_conf)
 
@@ -55,6 +57,10 @@
       return app_def_path;
     }
 
+    static public File getBadAppDef() {
+      return bad_app_def_path;
+    }
+
     static public File getAgentConf() {
       return agt_conf_path;
     }
@@ -312,6 +318,26 @@
       failWithBuildSucceeding(badArgs1, "bad agent conf file")
     } catch (BadConfigException expected) {
     }
+
+    try {
+      def badArgs1 = "test_bad_agent_args-6"
+      buildAgentCluster(clustername,
+          [:],
+          [
+              ARG_OPTION, CONTROLLER_URL, "http://localhost",
+              ARG_OPTION, AGENT_CONF, "file://" + TestResources.getAgentConf().absolutePath,
+              ARG_PACKAGE, ".",
+              ARG_OPTION, APP_DEF, "file://" + TestResources.getBadAppDef().absolutePath,
+              ARG_RESOURCES, TEST_FILES + "good/resources.json",
+              ARG_TEMPLATE, TEST_FILES + "good/appconf.json"
+          ],
+          true, false,
+          false)
+      failWithBuildSucceeding(badArgs1, "bad app def file")
+    } catch (BadConfigException expected) {
+      log.info("Expected failure.", expected)
+      assert expected.message.contains("App definition must be packaged as a .zip file")
+    }
   }
 
   @Test
diff --git a/slider-core/src/test/python/appdef_1.tar b/slider-core/src/test/python/appdef_1.tar
new file mode 100644
index 0000000..21a0621
--- /dev/null
+++ b/slider-core/src/test/python/appdef_1.tar
@@ -0,0 +1 @@
+This is not a pkg.