Forráskód Böngészése

AMBARI-3036. Ambari version check failing for local development/VM. (Dmytro Shkvyra via odiachenko)

Oleksandr Diachenko 11 éve
szülő
commit
88d69cb56c

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BootStrapImpl.java

@@ -36,6 +36,7 @@ import org.apache.ambari.server.controller.AmbariServer;
 
 @Singleton
 public class BootStrapImpl {
+  public static final String DEV_VERSION = "${ambariVersion}";
   private File bootStrapDir;
   private String bootScript;
   private String bootSetupAgentScript;
@@ -64,6 +65,7 @@ public class BootStrapImpl {
         InetAddress.getLocalHost().getCanonicalHostName());
     this.clusterOsType = conf.getServerOsType();
     this.projectVersion = ambariMetaInfo.getServerVersion();
+    this.projectVersion = (this.projectVersion.equals(DEV_VERSION)) ? DEV_VERSION.replace("$", "") : this.projectVersion;
     this.serverPort = (conf.getApiSSLAuthentication())? conf.getClientSSLApiPort() : conf.getClientApiPort();
   }
 

+ 6 - 0
ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java

@@ -17,6 +17,8 @@
  */
 package org.apache.ambari.server.utils;
 
+import org.apache.ambari.server.bootstrap.BootStrapImpl;
+
 /**
  * Provides various utility functions to be used for version handling.
  * The compatibility matrix between server, agent, store can also be maintained
@@ -44,6 +46,9 @@ public class VersionUtils {
       throw new IllegalArgumentException("maxLengthToCompare cannot be less than 0");
     }
 
+    
+    if(BootStrapImpl.DEV_VERSION.equals(version1.trim())) return 0;
+    
     String[] version1Parts = version1.split("\\.");
     String[] version2Parts = version2.split("\\.");
 
@@ -75,6 +80,7 @@ public class VersionUtils {
    */
   public static int compareVersions(String version1, String version2, boolean allowEmptyVersions) {
     if (allowEmptyVersions) {
+      if (version1 != null && version1.equals(BootStrapImpl.DEV_VERSION)) return 0;
       if (version1 == null && version2 == null) {
         return 0;
       } else {

+ 6 - 6
ambari-server/src/main/python/setupAgent.py

@@ -158,16 +158,16 @@ def main(argv=None):
   try:
     server_port = int(server_port)
   except (Exception), e:
-    server_port = 8080	 
-      
-  if projectVersion is None or projectVersion == "null":
-    projectVersion = ""
+    server_port = 8080
 
   checkServerReachability(hostname, server_port)
 
-  projectVersion = getOptimalVersion(projectVersion)
-  if projectVersion != "":
+  if projectVersion is None or projectVersion == "null":
+    projectVersion = getOptimalVersion("")
+  elif (projectVersion != "" and projectVersion != "{ambariVersion}"):
     projectVersion = "-" + projectVersion
+  elif projectVersion == "{ambariVersion}":
+    projectVersion = ""
 
   if is_suse():
     ret = installAgentSuse(projectVersion)

+ 4 - 0
ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java

@@ -18,6 +18,7 @@
 package org.apache.ambari.server.utils;
 
 import junit.framework.Assert;
+import org.apache.ambari.server.bootstrap.BootStrapImpl;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -34,6 +35,9 @@ public class TestVersionUtils {
     Assert.assertTrue(VersionUtils.areVersionsEqual("1.2.3", "1.2.3", true));
     Assert.assertTrue(VersionUtils.areVersionsEqual("", "", true));
     Assert.assertTrue(VersionUtils.areVersionsEqual(null, null, true));
+    Assert.assertTrue(VersionUtils.areVersionsEqual(BootStrapImpl.DEV_VERSION, "1.2.3", false));
+    Assert.assertTrue(VersionUtils.areVersionsEqual(BootStrapImpl.DEV_VERSION, "", true));
+    Assert.assertTrue(VersionUtils.areVersionsEqual(BootStrapImpl.DEV_VERSION, null, true));
 
     Assert.assertFalse(VersionUtils.areVersionsEqual("1.2.3.1", "1.2.3", false));
     Assert.assertFalse(VersionUtils.areVersionsEqual("2.1.3", "1.2.3", false));

+ 8 - 0
ambari-server/src/test/python/TestSetupAgent.py

@@ -297,9 +297,17 @@ class TestSetupAgent(TestCase):
     runAgent_mock.return_value = 0
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","1.1.1","8080"))
     self.assertTrue(exit_mock.called)
+    self.assertFalse(getOptimalVersion_mock.called)
     exit_mock.reset()
+    getOptimalVersion_mock.reset()
+    setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","{ambariVersion}","8080"))
+    self.assertFalse(getOptimalVersion_mock.called)
+    self.assertTrue(exit_mock.called)
+    exit_mock.reset()
+    getOptimalVersion_mock.reset()
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","null","8080"))
     self.assertTrue(exit_mock.called)
+    self.assertTrue(getOptimalVersion_mock.called)
     exit_mock.reset()
     is_suse_mock.return_value = False
     setup_agent.main(("setupAgent.py","agents_host","password", "server_hostname","null","null"))