Repository: incubator-slider
Updated Branches:
  refs/heads/develop 226e27e45 -> e3021a045


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e3021a04/slider-core/src/test/groovy/org/apache/slider/client/TestPackageCommandOptions.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/client/TestPackageCommandOptions.groovy
 
b/slider-core/src/test/groovy/org/apache/slider/client/TestPackageCommandOptions.groovy
index 03f93ad..5439073 100644
--- 
a/slider-core/src/test/groovy/org/apache/slider/client/TestPackageCommandOptions.groovy
+++ 
b/slider-core/src/test/groovy/org/apache/slider/client/TestPackageCommandOptions.groovy
@@ -18,28 +18,29 @@
 
 package org.apache.slider.client
 
-import java.io.File;
-import java.io.IOException;
+import java.io.File
+import java.io.IOException
 
 import org.apache.commons.io.FileUtils
-import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.FileSystem
 import org.apache.hadoop.fs.FileUtil
 import org.apache.hadoop.fs.Path
 import org.apache.hadoop.fs.RawLocalFileSystem
 import org.apache.hadoop.yarn.conf.YarnConfiguration
 
 import org.apache.slider.agent.AgentMiniClusterTestBase
+import org.apache.slider.common.SliderKeys
 import org.apache.slider.common.params.Arguments
 import org.apache.slider.common.params.ClientArgs
 import org.apache.slider.common.params.SliderActions
-import org.apache.slider.common.tools.SliderFileSystem;
+import org.apache.slider.common.tools.SliderFileSystem
 import org.apache.slider.common.tools.SliderUtils
-import org.apache.slider.core.exceptions.SliderException;
+import org.apache.slider.core.exceptions.SliderException
 import org.apache.slider.core.main.ServiceLauncher
 import org.apache.slider.providers.agent.AgentKeys
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.Before
+import org.junit.Test
 
 /**
  * Test the package commands options
@@ -48,25 +49,29 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
   final shouldFail = new GroovyTestCase().&shouldFail
   private static SliderFileSystem testFileSystem
   private static String APP_NAME = "HBASE"
-
+  private static String APP_VERSION = "1.0.0"
+  
   @Before
   public void setupFilesystem() {
     FileSystem fileSystem = new RawLocalFileSystem()
     YarnConfiguration configuration = SliderUtils.createConfiguration()
     fileSystem.setConf(configuration)
     testFileSystem = new SliderFileSystem(fileSystem, configuration)
-    File testFolderDir = new File(testFileSystem.buildPackageDirPath(APP_NAME)
-      .toUri().path)
+    File testFolderDir = new File(testFileSystem.buildPackageDirPath(APP_NAME,
+      null).toUri().path)
     testFolderDir.deleteDir()
+    File testFolderDirWithVersion = new 
File(testFileSystem.buildPackageDirPath(
+      APP_NAME, APP_VERSION).toUri().path)
+    testFolderDirWithVersion.deleteDir()
   }
 
   @Test
   public void testPackageInstall() throws Throwable {
     // create a mock app package file
     File localPackage =
-        FileUtil.createLocalTempFile(tempLocation, "hbase.zip", false);
+        FileUtil.createLocalTempFile(tempLocation, "hbase.zip", false)
     String contents = UUID.randomUUID().toString()
-    FileUtils.write(localPackage, contents);
+    FileUtils.write(localPackage, contents)
     // install the package
     YarnConfiguration conf = SliderUtils.createConfiguration()
     ServiceLauncher launcher = launch(TestSliderClient,
@@ -79,8 +84,8 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
           ClientArgs.ARG_PACKAGE,
           localPackage.absolutePath
         ])
-    Path installedPath = new Path(testFileSystem.buildPackageDirPath(APP_NAME),
-      localPackage.getName())
+    Path installedPath = new Path(testFileSystem.buildPackageDirPath(APP_NAME,
+      null), localPackage.getName())
     File installedPackage = new File(installedPath.toUri().path)
     // verify file was installed successfully
     assert installedPackage.exists()
@@ -109,8 +114,8 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
           ClientArgs.ARG_PACKAGE,
           appDefFile.absolutePath
         ])
-    Path installedPath = new Path(testFileSystem.buildPackageDirPath(APP_NAME),
-      appDefFile.getName())
+    Path installedPath = new Path(testFileSystem.buildPackageDirPath(APP_NAME,
+      null), appDefFile.getName())
     File installedPackage = new File(installedPath.toUri().path)
     assert installedPackage.exists()
     describe("Installed app package to - " + installedPackage.toURI()
@@ -122,7 +127,7 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
     describe("Starting the app")
     launcher = createStandaloneAM(clustername, true, false)
     SliderClient sliderClient = launcher.service
-    addToTeardown(sliderClient);
+    addToTeardown(sliderClient)
 
     describe("Listing all instances of installed packages")
     String outFileName = "target/packageInstances.out"
@@ -136,6 +141,10 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
          outFileName
         ]
     )
+    // reset the app def path to orig value and remove app version
+    agentDefOptions.putAt(AgentKeys.APP_DEF, appDefPath)
+    agentDefOptions.remove(SliderKeys.APP_VERSION)
+
     assert launcher.serviceExitCode == 0
     def client = launcher.service
     def instances = client.enumSliderInstances(false, null, null)
@@ -152,8 +161,80 @@ class TestPackageCommandOptions extends 
AgentMiniClusterTestBase {
       + installedPackage.absolutePath + ".*")
   }
 
+  @Test
+  public void testPackageInstancesWithVersion() throws Throwable {
+    describe("Create mini cluster")
+    YarnConfiguration yarnConfig = new YarnConfiguration(configuration)
+    String clustername = createMiniCluster("", yarnConfig, 1, true)
+    describe("Created cluster - " + clustername)
+
+    // get the default application.def file and install it as a package
+    String appDefPath = agentDefOptions.getAt(AgentKeys.APP_DEF)
+    File appDefFile = new File(new URI(appDefPath))
+    YarnConfiguration conf = SliderUtils.createConfiguration()
+    ServiceLauncher<SliderClient> launcher = launch(TestSliderClient,
+        conf,
+        [
+          ClientArgs.ACTION_PACKAGE,
+          ClientArgs.ARG_INSTALL,
+          ClientArgs.ARG_NAME,
+          APP_NAME,
+          ClientArgs.ARG_PACKAGE,
+          appDefFile.absolutePath,
+          ClientArgs.ARG_VERSION,
+          APP_VERSION
+        ])
+    Path installedPath = new Path(testFileSystem.buildPackageDirPath(APP_NAME,
+      APP_VERSION), appDefFile.getName())
+    File installedPackage = new File(installedPath.toUri().path)
+    assert installedPackage.exists()
+    describe("Installed app package to - " + installedPackage.toURI()
+      .toString())
+    // overwrite the application.def property with the new installed path
+    agentDefOptions.putAt(AgentKeys.APP_DEF, installedPackage.toURI()
+      .toString())
+    // add the app version
+    agentDefOptions.putAt(SliderKeys.APP_VERSION, APP_VERSION)
+    // start the app and AM
+    describe("Starting the app")
+    launcher = createStandaloneAM(clustername, true, false)
+    SliderClient sliderClient = launcher.service
+    addToTeardown(sliderClient)
+
+    describe("Listing all instances of installed packages")
+    String outFileName = "target/packageInstancesWithVersion.out"
+    launcher = launchClientAgainstMiniMR(
+        //config includes RM binding info
+        yarnConfig,
+        //varargs list of command line params
+        [SliderActions.ACTION_PACKAGE,
+         Arguments.ARG_PKGINSTANCES,
+         ClientArgs.ARG_OUTPUT,
+         outFileName
+        ]
+    )
+    // reset the app def path to orig value and remove app version
+    agentDefOptions.putAt(AgentKeys.APP_DEF, appDefPath)
+    agentDefOptions.remove(SliderKeys.APP_VERSION)
+
+    assert launcher.serviceExitCode == 0
+    def client = launcher.service
+    def instances = client.enumSliderInstances(false, null, null)
+    def enumeratedInstance = instances[clustername]
+    assert enumeratedInstance != null
+    assert enumeratedInstance.applicationReport.name ==
+           clustername
+    File outFile = new File(outFileName)
+    def outText = outFile.text
+    assert outText.contains(installedPackage.absolutePath)
+    assert outText.contains(APP_NAME)
+    assert outText.contains(clustername)
+    assert outText.matches("(?s).*" + clustername + " +" + APP_NAME + " +"
+      + APP_VERSION + " +" + installedPackage.absolutePath + ".*")
+  }
+
   private File getTempLocation () {
-    return new File(System.getProperty("user.dir") + "/target/_");
+    return new File(System.getProperty("user.dir") + "/target/_")
   }
 
   static class TestSliderClient extends SliderClient {

Reply via email to