You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/06/05 03:24:27 UTC
svn commit: r1489681 - in /incubator/ambari/trunk/ambari-server/src:
main/java/org/apache/ambari/server/agent/
main/java/org/apache/ambari/server/utils/
test/java/org/apache/ambari/server/agent/
Author: smohanty
Date: Wed Jun 5 01:24:27 2013
New Revision: 1489681
URL: http://svn.apache.org/r1489681
Log:
AMBARI-2267. During registrations, ambari server does not properly handle empty version numbers from agent. (smohanty)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1489681&r1=1489680&r2=1489681&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java Wed Jun 5 01:24:27 2013
@@ -392,7 +392,7 @@ public class HeartBeatHandler {
String agentVersion = register.getAgentVersion();
String serverVersion = ambariMetaInfo.getServerVersion();
- if (!VersionUtils.areVersionsCompatible(serverVersion, agentVersion)) {
+ if (!VersionUtils.areVersionsEqual(serverVersion, agentVersion, true)) {
LOG.warn("Received registration request from host with non compatible"
+ " agent version"
+ ", hostname=" + hostname
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java?rev=1489681&r1=1489680&r2=1489681&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java Wed Jun 5 01:24:27 2013
@@ -32,7 +32,8 @@ public class VersionUtils {
* 0 to compare the whole version strings
* @return 0 if both are equal up to the length compared, -1 if first one is lower, +1 otherwise
*/
- public static int compareVersions(String version1, String version2, int maxLengthToCompare) {
+ public static int compareVersions(String version1, String version2, int maxLengthToCompare)
+ throws IllegalArgumentException {
if (version1 == null || version1.isEmpty()) {
throw new IllegalArgumentException("version1 cannot be null or empty");
}
@@ -69,33 +70,57 @@ public class VersionUtils {
*
* @param version1
* @param version2
- * @return 0 if both are equal, -1 if first one is lower, +1 otherwise
+ * @param allowEmptyVersions Allow one or both version values to be null or empty string
+ * @return 0 if both are equal up to the length compared, -1 if first one is lower, +1 otherwise
*/
- public static int compareVersions(String version1, String version2) {
+ public static int compareVersions(String version1, String version2, boolean allowEmptyVersions) {
+ if (allowEmptyVersions) {
+ if (version1 == null && version2 == null) {
+ return 0;
+ } else {
+ if (version1 == null) {
+ return -1;
+ }
+ if (version2 == null) {
+ return 1;
+ }
+ }
+
+ if (version1.isEmpty() && version2.isEmpty()) {
+ return 0;
+ } else {
+ if (version1.isEmpty()) {
+ return -1;
+ }
+ if (version2.isEmpty()) {
+ return 1;
+ }
+ }
+ }
+
return compareVersions(version1, version2, 0);
}
/**
- * Compares two version for equality
+ * Compares two versions strings of the form N.N.N.N
*
* @param version1
* @param version2
- * @return true if versions are equal; false otherwise
+ * @return 0 if both are equal, -1 if first one is lower, +1 otherwise
*/
- public static boolean areVersionsEqual(String version1, String version2) {
- return 0 == compareVersions(version1, version2, 0);
+ public static int compareVersions(String version1, String version2) {
+ return compareVersions(version1, version2, 0);
}
/**
- * Checks if the two versions are compatible.
- * TODO A relaxed check can be implemented where a server version is compatible to
- * TODO more than one versions of agent and store.
+ * Compares two version for equality, allows empty versions
*
- * @param serverVersion The version of the server
- * @param versionToCheck The version of the agent or the store
- * @return true if the versions are compatible
+ * @param version1
+ * @param version2
+ * @param allowEmptyVersions Allow one or both version values to be null or empty string
+ * @return true if versions are equal; false otherwise
*/
- public static boolean areVersionsCompatible(String serverVersion, String versionToCheck) {
- return areVersionsEqual(serverVersion, versionToCheck);
+ public static boolean areVersionsEqual(String version1, String version2, boolean allowEmptyVersions) {
+ return 0 == compareVersions(version1, version2, allowEmptyVersions);
}
}
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1489681&r1=1489680&r2=1489681&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java Wed Jun 5 01:24:27 2013
@@ -437,7 +437,47 @@ public class TestHeartbeatHandler {
assertEquals(hostObject.getLastHeartbeatTime(),
hostObject.getLastRegistrationTime());
}
-
+
+ @Test
+ public void testRegistrationWithBadVersion() throws AmbariException,
+ InvalidStateTransitionException {
+
+ ActionManager am = getMockActionManager();
+ Clusters fsm = clusters;
+ HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am,
+ injector);
+ clusters.addHost(DummyHostname1);
+ Host hostObject = clusters.getHost(DummyHostname1);
+ hostObject.setIPv4("ipv4");
+ hostObject.setIPv6("ipv6");
+
+ Register reg = new Register();
+ HostInfo hi = new HostInfo();
+ hi.setHostName(DummyHostname1);
+ hi.setOS(DummyOsType);
+ reg.setHostname(DummyHostname1);
+ reg.setHardwareProfile(hi);
+ reg.setAgentVersion(""); // Invalid agent version
+ try {
+ handler.handleRegistration(reg);
+ fail ("Expected failure for non compatible agent version");
+ } catch (AmbariException e) {
+ log.debug("Error:" + e.getMessage());
+ Assert.assertTrue(e.getMessage().contains(
+ "Cannot register host with non compatible agent version"));
+ }
+
+ reg.setAgentVersion(null); // Invalid agent version
+ try {
+ handler.handleRegistration(reg);
+ fail ("Expected failure for non compatible agent version");
+ } catch (AmbariException e) {
+ log.debug("Error:" + e.getMessage());
+ Assert.assertTrue(e.getMessage().contains(
+ "Cannot register host with non compatible agent version"));
+ }
+ }
+
@Test
public void testRegistrationPublicHostname() throws AmbariException, InvalidStateTransitionException {
ActionManager am = getMockActionManager();
@@ -524,7 +564,6 @@ public class TestHeartbeatHandler {
}
}
-
@Test
public void testRegisterNewNode()
throws AmbariException, InvalidStateTransitionException {