ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [06/11] ambari git commit: AMBARI-18774: Install Package for non-HDP stack fails with non-VDF repo version (jluniya)
Date Fri, 04 Nov 2016 13:26:51 GMT
AMBARI-18774: Install Package for non-HDP stack fails with non-VDF repo version (jluniya)


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

Branch: refs/heads/branch-feature-AMBARI-18634
Commit: 2da6fa789f6ac64c4e699469bde1185bb2ab126d
Parents: 574fd64
Author: Jayush Luniya <jluniya@hortonworks.com>
Authored: Thu Nov 3 13:17:44 2016 -0700
Committer: Jayush Luniya <jluniya@hortonworks.com>
Committed: Thu Nov 3 13:17:44 2016 -0700

----------------------------------------------------------------------
 .../orm/entities/RepositoryVersionEntity.java   | 39 +++++++-------------
 .../org/apache/ambari/server/state/StackId.java |  4 --
 ...leRepositoryVersionResourceProviderTest.java |  4 ++
 .../RepositoryVersionResourceProviderTest.java  | 14 +++++++
 .../orm/dao/RepositoryVersionDAOTest.java       | 35 ++++++++++++++++++
 5 files changed, 67 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2da6fa78/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 25aa62b..4e6451e 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
@@ -80,8 +80,6 @@ import static java.util.Arrays.asList;
 })
 @StaticallyInject
 public class RepositoryVersionEntity {
-
-  private static final List<String> STACK_PREFIXES = asList(StackId.HDP_STACK, StackId.HDPWIN_STACK);
   private static Logger LOG = LoggerFactory.getLogger(RepositoryVersionEntity.class);
 
   @Inject
@@ -158,10 +156,9 @@ public class RepositoryVersionEntity {
   @PreUpdate
   @PrePersist
   public void removePrefixFromVersion() {
-    for (String stackPrefix : STACK_PREFIXES) {
-      if (version.startsWith(stackPrefix + "-")) {
-        version = version.substring(stackPrefix.length() + 1);
-      }
+    String stackName = stack.getStackName();
+    if (version.startsWith(stackName)) {
+      version = version.substring(stackName.length() + 1);
     }
   }
   /**
@@ -394,38 +391,30 @@ public class RepositoryVersionEntity {
 
   /**
    * Determine if the version belongs to the stack.
-   * Right now, this is only applicable for the HDP stack.
    * @param stackId Stack, such as HDP-2.3
    * @param version Version number, such as 2.3.0.0, or 2.3.0.0-1234
    * @return Return true if the version starts with the digits of the stack.
    */
   public static boolean isVersionInStack(StackId stackId, String version) {
     if (null != version && !StringUtils.isBlank(version)) {
-      for (String stackPrefix : STACK_PREFIXES) {
-        if (version.startsWith(stackPrefix + "-")) {
-          version = version.substring(stackPrefix.length() + 1);
-        }
+      String stackName = stackId.getStackName();
+      if (version.startsWith(stackName + "-")) {
+        version = version.substring(stackName.length() + 1);
       }
-      // HDP Stack
-      if (stackId.getStackName().equalsIgnoreCase(StackId.HDP_STACK) ||
-          stackId.getStackName().equalsIgnoreCase(StackId.HDPWIN_STACK)) {
-
-        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("\\.");
-        if (null != leadingParts && leadingParts.length > 2) {
-          leading = leadingParts[0] + "." + leadingParts[1];
-        }
-        return version.startsWith(leading);
+
+      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("\\.");
+      if (null != leadingParts && leadingParts.length > 2) {
+        leading = leadingParts[0] + "." + leadingParts[1];
       }
-      // For other stacks, don't make the check.
-      return true;
+      return version.startsWith(leading);
     }
     return false;
   }
 
   /**
-   * @param parent
+   * @param entity parent entity
    */
   public void setParent(RepositoryVersionEntity entity) {
     parent = entity;

http://git-wip-us.apache.org/repos/asf/ambari/blob/2da6fa78/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java b/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
index 367775a..f5a440d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/StackId.java
@@ -25,10 +25,6 @@ public class StackId implements Comparable<StackId> {
 
   private static final String NAME_SEPARATOR = "-";
 
-  public static final String HDP_STACK = "HDP";
-  public static final String HDPWIN_STACK = "HDPWIN";
-  public static final String BIGTOP_STACK = "BIGTOP";
-
   private String stackName;
   private String stackVersion;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2da6fa78/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
index 78f0a48..dffc4f7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
@@ -250,9 +250,13 @@ public class CompatibleRepositoryVersionResourceProviderTest {
   public void testVersionInStack() {
     assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDP", "2.3"), "2.3.0.0"));
     assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDPWIN", "2.3"), "2.3.0.0"));
+    assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDP", "2.3.GlusterFS"),
"2.3.0.0"));
+    assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDF", "2.1"), "2.1.0.0"));
 
     assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDP", "2.3"), "HDP-2.3.0.0"));
     assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDPWIN", "2.3"), "HDPWIN-2.3.0.0"));
+    assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDP", "2.3.GlusterFS"),
"HDP-2.3.0.0"));
+    assertTrue(RepositoryVersionEntity.isVersionInStack(new StackId("HDF", "2.1"), "HDF-2.1.0.0"));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/2da6fa78/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 a43a1dc..b8d450b 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
@@ -609,17 +609,31 @@ public class RepositoryVersionResourceProviderTest {
   public void testVersionInStack(){
     StackId sid = new StackId("HDP-2.3");
     StackId sid2 = new StackId("HDP-2.3.NEW");
+    StackId sid3 = new StackId("HDF-2.3");
+
     Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid, "2.3"));
     Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid2, "2.3"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid3, "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(sid3, "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(true, RepositoryVersionEntity.isVersionInStack(sid3, "2.3.2.1-3562"));
+
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid, "HDP-2.3.2.0-2300"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid2, "HDP-2.3.2.1-3562"));
+    Assert.assertEquals(true, RepositoryVersionEntity.isVersionInStack(sid3, "HDF-2.3.2.1-3562"));
 
     Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid, "2.4.2.0-2300"));
     Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid2, "2.1"));
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid3, "2.1"));
+
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid, "HDP-2.4.2.0-2300"));
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid2, "HDP-2.1"));
+    Assert.assertEquals(false, RepositoryVersionEntity.isVersionInStack(sid3, "HDF-2.1"));
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2da6fa78/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
index 1267f96..6f6f05b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAOTest.java
@@ -48,6 +48,7 @@ public class RepositoryVersionDAOTest {
   private static Injector injector;
 
   private static final StackId HDP_206 = new StackId("HDP", "2.0.6");
+  private static final StackId OTHER_10 = new StackId("OTHER", "1.0");
   private static final StackId BAD_STACK = new StackId("BADSTACK", "1.0");
 
   private RepositoryVersionDAO repositoryVersionDAO;
@@ -198,6 +199,40 @@ public class RepositoryVersionDAOTest {
 
   }
 
+  @Test
+  public void testRemovePrefixFromVersion() {
+
+    StackEntity hdp206StackEntity = stackDAO.find(HDP_206.getStackName(),
+        HDP_206.getStackVersion());
+    Assert.assertNotNull(hdp206StackEntity);
+
+    final RepositoryVersionEntity hdp206RepoEntity = new RepositoryVersionEntity();
+    hdp206RepoEntity.setDisplayName("HDP-2.0.6.0-1234");
+    hdp206RepoEntity.setOperatingSystems("repositories");
+    hdp206RepoEntity.setStack(hdp206StackEntity);
+    hdp206RepoEntity.setVersion("HDP-2.0.6.0-1234");
+    repositoryVersionDAO.create(hdp206RepoEntity);
+    Assert.assertEquals("Failed to remove HDP stack prefix from version", "2.0.6.0-1234",
hdp206RepoEntity.getVersion());
+    Assert.assertNotNull(repositoryVersionDAO.findByDisplayName("HDP-2.0.6.0-1234"));
+    Assert.assertNotNull(repositoryVersionDAO.findByStackAndVersion(HDP_206,
+        "2.0.6.0-1234"));
+
+    StackEntity other10StackEntity = stackDAO.find(OTHER_10.getStackName(),
+        OTHER_10.getStackVersion());
+    Assert.assertNotNull(other10StackEntity);
+
+    final RepositoryVersionEntity other10RepoEntity = new RepositoryVersionEntity();
+    other10RepoEntity.setDisplayName("OTHER-1.0.1.0-1234");
+    other10RepoEntity.setOperatingSystems("repositories");
+    other10RepoEntity.setStack(other10StackEntity);
+    other10RepoEntity.setVersion("OTHER-1.0.1.0-1234");
+    repositoryVersionDAO.create(other10RepoEntity);
+    Assert.assertEquals("Failed to remove OTHER stack prefix from version", "1.0.1.0-1234",
other10RepoEntity.getVersion());
+    Assert.assertNotNull(repositoryVersionDAO.findByDisplayName("OTHER-1.0.1.0-1234"));
+    Assert.assertNotNull(repositoryVersionDAO.findByStackAndVersion(OTHER_10,
+        "1.0.1.0-1234"));
+  }
+
   @After
   public void after() {
     injector.getInstance(PersistService.class).stop();


Mime
View raw message