ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-12597. Ambari should support custom stack names (smohanty)
Date Thu, 10 Sep 2015 18:54:47 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk f88ae30b2 -> f1d6ef340


AMBARI-12597. Ambari should support custom stack names (smohanty)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f1d6ef34
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f1d6ef34
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f1d6ef34

Branch: refs/heads/trunk
Commit: f1d6ef340718c93bba54bac661a6056a79882909
Parents: f88ae30
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Thu Sep 10 11:54:35 2015 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Thu Sep 10 11:54:35 2015 -0700

----------------------------------------------------------------------
 .../orm/entities/RepositoryVersionEntity.java   |  2 +-
 .../ambari/server/stack/ServiceDirectory.java   |  4 ++-
 .../ambari/server/stack/StackDirectory.java     | 12 ++++---
 .../ambari/server/utils/VersionUtils.java       | 34 +++++++++++++++++---
 .../RepositoryVersionResourceProviderTest.java  | 18 +++++++++++
 .../ambari/server/utils/TestVersionUtils.java   |  3 ++
 6 files changed, 63 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index 0fb2f10..dafd4b2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -269,7 +269,7 @@ public class RepositoryVersionEntity {
 
         String leading = stackId.getStackVersion();  // E.g, 2.3
         // In some cases during unit tests, the leading can contain 3 digits, so only the
major number (first two parts) are needed.
-        String[] leadingParts = leading.split(".");
+        String[] leadingParts = leading.split("\\.");
         if (null != leadingParts && leadingParts.length > 2) {
           leading = leadingParts[0] + "." + leadingParts[1];
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
index 25c2260..d574d60 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/ServiceDirectory.java
@@ -215,7 +215,9 @@ public abstract class ServiceDirectory extends StackDefinitionDirectory
{
     } catch (JAXBException e) {
       metaInfoXml = new ServiceMetainfoXml();
       metaInfoXml.setValid(false);
-      metaInfoXml.setErrors(String.format("Unable to parse service metainfo.xml file '%s'
", f.getAbsolutePath()));
+      String msg = String.format("Unable to parse service metainfo.xml file '%s' ", f.getAbsolutePath());
+      metaInfoXml.setErrors(msg);
+      LOG.warn(msg);
       metaInfoXml.setSchemaVersion(getAbsolutePath().replace(f.getParentFile().getParentFile().getParent()+File.separator,
""));
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
index 89c10c6..b849e88 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackDirectory.java
@@ -322,8 +322,10 @@ public class StackDirectory extends StackDefinitionDirectory {
         } catch (JAXBException e) {
           repoFile = new RepositoryXml();
           repoFile.setValid(false);
-          repoFile.setErrors("Unable to parse repo file at location: " +
-              repositoryFile.getAbsolutePath());
+          String msg = "Unable to parse repo file at location: " +
+                       repositoryFile.getAbsolutePath();
+          repoFile.setErrors(msg);
+          LOG.warn(msg);
         }
       }
     }
@@ -356,8 +358,10 @@ public class StackDirectory extends StackDefinitionDirectory {
       } catch (JAXBException e) {
         metaInfoXml = new StackMetainfoXml();
         metaInfoXml.setValid(false);
-        metaInfoXml.setErrors("Unable to parse stack metainfo.xml file at location: " +
-            stackMetaInfoFile.getAbsolutePath());
+        String msg = "Unable to parse stack metainfo.xml file at location: " +
+                     stackMetaInfoFile.getAbsolutePath();
+        metaInfoXml.setErrors(msg);
+        LOG.warn(msg);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
b/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
index 4d1fc48..b07f7da 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/VersionUtils.java
@@ -20,6 +20,9 @@ package org.apache.ambari.server.utils;
 import org.apache.ambari.server.bootstrap.BootStrapImpl;
 import org.apache.commons.lang.StringUtils;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * Provides various utility functions to be used for version handling.
  * The compatibility matrix between server, agent, store can also be maintained
@@ -28,6 +31,7 @@ import org.apache.commons.lang.StringUtils;
 public class VersionUtils {
   /**
    * Compares two versions strings of the form N.N.N.N or even N.N.N.N-### (which should
ignore everything after the dash).
+   * If the user has a custom stack, e.g., 2.3.MYNAME or MYNAME.2.3, then any segment that
contains letters should be ignored.
    *
    * @param version1
    * @param version2
@@ -72,11 +76,33 @@ public class VersionUtils {
 
     int length = Math.max(version1Parts.length, version2Parts.length);
     length = maxLengthToCompare == 0 || maxLengthToCompare > length ? length : maxLengthToCompare;
+
+    List<Integer> stack1Parts = new ArrayList<Integer>();
+    List<Integer> stack2Parts = new ArrayList<Integer>();
+
     for (int i = 0; i < length; i++) {
-      int stack1Part = i < version1Parts.length ?
-          Integer.parseInt(version1Parts[i]) : 0;
-      int stack2Part = i < version2Parts.length ?
-          Integer.parseInt(version2Parts[i]) : 0;
+      // Robust enough to handle strings in the version
+      try {
+        int stack1Part = i < version1Parts.length ?
+            Integer.parseInt(version1Parts[i]) : 0;
+        stack1Parts.add(stack1Part);
+      } catch (NumberFormatException e) {
+        stack1Parts.add(0);
+      }
+      try {
+        int stack2Part = i < version2Parts.length ?
+            Integer.parseInt(version2Parts[i]) : 0;
+        stack2Parts.add(stack2Part);
+      } catch (NumberFormatException e) {
+        stack2Parts.add(0);
+      }
+    }
+
+    length = Math.max(stack1Parts.size(), stack2Parts.size());
+    for (int i = 0; i < length; i++) {
+      Integer stack1Part = stack1Parts.get(i);
+      Integer stack2Part = stack2Parts.get(i);
+
       if (stack1Part < stack2Part) {
         return -1;
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
index 442bcb2..d55b5ce 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
@@ -47,6 +47,7 @@ import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.RepositoryVersionState;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.junit.After;
@@ -399,6 +400,23 @@ public class RepositoryVersionResourceProviderTest {
     }
   }
 
+  @Test
+  public void testVersionInStack(){
+    StackId sid = new StackId("HDP-2.3");
+    StackId sid2 = new StackId("HDP-2.3.NEW");
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid, "2.3"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid2, "2.3"));
+
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid, "2.3.1"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid2, "2.3.1"));
+
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid, "2.3.2.0-2300"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid2, "2.3.2.1-3562"));
+
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid, "2.4.2.0-2300"));
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid2, "2.1"));
+  }
+
   @After
   public void after() {
     injector.getInstance(PersistService.class).stop();

http://git-wip-us.apache.org/repos/asf/ambari/blob/f1d6ef34/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
index 433d1c9..371660b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/TestVersionUtils.java
@@ -45,6 +45,9 @@ public class TestVersionUtils {
     Assert.assertEquals(-1, VersionUtils.compareVersions("2.2.0.0-200", "2.2.0.1-100"));
     Assert.assertEquals(-1, VersionUtils.compareVersions("2.2.0.0-101", "2.2.0.10-20"));
     Assert.assertEquals(-1, VersionUtils.compareVersions("2.2.2.0.20-996", "2.2.2.145-846"));
+    Assert.assertEquals(0, VersionUtils.compareVersions("2.2", "2.2.VER"));
+    Assert.assertEquals(0, VersionUtils.compareVersions("2.2.VAR", "2.2.VER"));
+    Assert.assertEquals(0, VersionUtils.compareVersions("2.2.3", "2.2.3.VER1.V"));
   }
 
   @Test


Mime
View raw message