ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [5/6] ambari git commit: AMBARI-21766 - When Matching New VDFs for Parent Repos only Consider STANDARD Types (jonathanhurley)
Date Wed, 23 Aug 2017 19:24:29 GMT
AMBARI-21766 - When Matching New VDFs for Parent Repos only Consider STANDARD Types (jonathanhurley)


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

Branch: refs/heads/branch-2.6
Commit: 92d307c91ccfdfdabb505fbb454997374a2327e6
Parents: 4f6b67f
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Aug 21 11:52:03 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Aug 22 11:03:56 2017 -0400

----------------------------------------------------------------------
 .../VersionDefinitionResourceProvider.java      |  4 +++-
 .../server/orm/dao/RepositoryVersionDAO.java    | 20 ++++++++++++++++++++
 .../orm/entities/RepositoryVersionEntity.java   |  3 +++
 .../orm/dao/RepositoryVersionDAOTest.java       | 12 ++++++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/92d307c9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
index ea592e5..e676056 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
@@ -433,7 +433,9 @@ public class VersionDefinitionResourceProvider extends AbstractAuthorizedResourc
       return;
     }
 
-    List<RepositoryVersionEntity> entities = s_repoVersionDAO.findByStack(entity.getStackId());
+    List<RepositoryVersionEntity> entities = s_repoVersionDAO.findByStackAndType(
+        entity.getStackId(), RepositoryType.STANDARD);
+
     if (entities.isEmpty()) {
       throw new IllegalArgumentException(String.format("Patch %s was uploaded, but there
are no repositories for %s",
           entity.getVersion(), entity.getStackId().toString()));

http://git-wip-us.apache.org/repos/asf/ambari/blob/92d307c9/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
index 40bbd07..d4497b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java
@@ -134,6 +134,26 @@ public class RepositoryVersionDAO extends CrudDAO<RepositoryVersionEntity,
Long>
   }
 
   /**
+   * Retrieves repository version by stack.
+   *
+   * @param stackId
+   *          stack id stack with major version (like HDP-2.2)
+   * @param type
+   *          the repository type
+   *
+   * @return null if there is no suitable repository version
+   */
+  @RequiresSession
+  public List<RepositoryVersionEntity> findByStackAndType(StackId stackId, RepositoryType
type) {
+    final TypedQuery<RepositoryVersionEntity> query = entityManagerProvider.get().createNamedQuery(
+        "repositoryVersionByStackAndType", RepositoryVersionEntity.class);
+    query.setParameter("stackName", stackId.getStackName());
+    query.setParameter("stackVersion", stackId.getStackVersion());
+    query.setParameter("type", type);
+    return daoUtils.selectList(query);
+  }
+
+  /**
    * Gets the first repository which matches the specified version. There can be
    * multiple repositories matching a single version as long as they have
    * different stacks. This method is a fallback mechanism if the repository

http://git-wip-us.apache.org/repos/asf/ambari/blob/92d307c9/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 aed0aaf..f84f3a4 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
@@ -79,6 +79,9 @@ import com.google.inject.Provider;
         name = "repositoryVersionByStack",
         query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.stack.stackName=:stackName
AND repoversion.stack.stackVersion=:stackVersion"),
     @NamedQuery(
+        name = "repositoryVersionByStackAndType",
+        query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.stack.stackName=:stackName
AND repoversion.stack.stackVersion=:stackVersion AND repoversion.type=:type"),
+    @NamedQuery(
         name = "repositoryVersionByStackNameAndVersion",
         query = "SELECT repoversion FROM RepositoryVersionEntity repoversion WHERE repoversion.stack.stackName=:stackName
AND repoversion.version=:version"),
     @NamedQuery(

http://git-wip-us.apache.org/repos/asf/ambari/blob/92d307c9/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 d41b0ba..6fbd953 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
@@ -28,6 +28,7 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.StackId;
 import org.junit.After;
 import org.junit.Assert;
@@ -199,6 +200,17 @@ public class RepositoryVersionDAOTest {
         "1.0.1.0-1234"));
   }
 
+  @Test
+  public void testFindByStackAndType() {
+    createSingleRecord();
+
+    Assert.assertEquals(1,
+        repositoryVersionDAO.findByStackAndType(HDP_206, RepositoryType.STANDARD).size());
+
+    Assert.assertEquals(0,
+        repositoryVersionDAO.findByStackAndType(HDP_206, RepositoryType.MAINT).size());
+  }
+
   @After
   public void after() throws AmbariException, SQLException {
     H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);


Mime
View raw message