Repository: ambari Updated Branches: refs/heads/trunk d91074a0c -> a5c6834d6
AMBARI-8321 HDP-UTILS repo URL reverts to default on ambari-server restart (trunk fix and unit tests) (dsen) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a5c6834d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a5c6834d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a5c6834d Branch: refs/heads/trunk Commit: a5c6834d6a51e8efe8a7ca4698242e33bc88a8d0 Parents: d91074a Author: Dmytro Sen <d...@apache.org> Authored: Fri Dec 5 14:09:32 2014 +0200 Committer: Dmytro Sen <d...@apache.org> Committed: Fri Dec 5 14:09:32 2014 +0200 ---------------------------------------------------------------------- .../server/api/services/AmbariMetaInfo.java | 2 +- .../ambari/server/stack/StackContext.java | 16 +++--- .../apache/ambari/server/stack/StackModule.java | 2 +- .../server/api/services/AmbariMetaInfoTest.java | 54 ++++++++++++++++++-- 4 files changed, 58 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a5c6834d/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java index 4b78216..8d404ca 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java @@ -712,7 +712,7 @@ public class AmbariMetaInfo { * @param field the field name * @return the key for any repo value override */ - public String generateRepoMetaKey(String stackName, String stackVersion, + public static String generateRepoMetaKey(String stackName, String stackVersion, String osType, String repoId, String field) { StringBuilder sb = new StringBuilder("repo:/"); http://git-wip-us.apache.org/repos/asf/ambari/blob/a5c6834d/ambari-server/src/main/java/org/apache/ambari/server/stack/StackContext.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackContext.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackContext.java index 5d1d098..da7f021 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackContext.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackContext.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.stack; +import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.metadata.ActionMetadata; import org.apache.ambari.server.orm.dao.MetainfoDAO; import org.apache.ambari.server.orm.entities.MetainfoEntity; @@ -88,22 +89,17 @@ public class StackContext { * Obtain an updated url for the repo. * This will check the database for a user update of the repo url. * - * @param repoName repository name + * @param stackName stack name * @param stackVersion stack version * @param osType OS type * @param repoId repo id * * @return an update url or null if the url has not been updated */ - public String getUpdatedRepoUrl(String repoName, String stackVersion, String osType, String repoId) { - StringBuilder sb = new StringBuilder("repo:/"); - sb.append(repoName).append('/'); - sb.append(stackVersion).append('/'); - sb.append(osType).append('/'); - sb.append(repoId); - sb.append(':').append(REPOSITORY_XML_PROPERTY_BASEURL); - - MetainfoEntity entity = metaInfoDAO.findByKey(sb.toString()); + public String getUpdatedRepoUrl(String stackName, String stackVersion, String osType, String repoId) { + String key = AmbariMetaInfo.generateRepoMetaKey(stackName, stackVersion, + osType, repoId, REPOSITORY_XML_PROPERTY_BASEURL); + MetainfoEntity entity = metaInfoDAO.findByKey(key); return entity != null ? entity.getMetainfoValue() : null; } http://git-wip-us.apache.org/repos/asf/ambari/blob/a5c6834d/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java index 20dba84..3629b36 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackModule.java @@ -482,7 +482,7 @@ public class StackModule extends BaseModule<StackModule, StackInfo> { ri.setLatestBaseUrl(r.getBaseUrl()); LOG.debug("Checking for override for base_url"); - String updatedUrl = stackContext.getUpdatedRepoUrl(r.getRepoName(), stackInfo.getVersion(), + String updatedUrl = stackContext.getUpdatedRepoUrl(stackInfo.getName(), stackInfo.getVersion(), osFamily, r.getRepoId()); if (null != updatedUrl) { http://git-wip-us.apache.org/repos/asf/ambari/blob/a5c6834d/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java index 8a4e627..98d2645 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java @@ -102,6 +102,9 @@ public class AmbariMetaInfoTest { private static String SERVICE_NAME_MAPRED2 = "MAPREDUCE2"; private static String SERVICE_COMPONENT_NAME = "NAMENODE"; private static final String OS_TYPE = "centos5"; + private static final String HDP_REPO_NAME = "HDP"; + private static final String HDP_REPO_ID = "HDP-2.1.1"; + private static final String HDP_UTILS_REPO_NAME = "HDP-UTILS"; private static final String REPO_ID = "HDP-UTILS-1.1.0.15"; private static final String PROPERTY_NAME = "hbase.regionserver.msginterval"; private static final String SHARED_PROPERTY_NAME = "content"; @@ -236,9 +239,9 @@ public class AmbariMetaInfoTest { // Updating the baseUrl String newBaseUrl = "http://myprivate-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0"; ambariMetaInfo.updateRepoBaseURL(STACK_NAME_HDP, "2.1.1", "redhat6", - STACK_NAME_HDP + "-2.1.1", newBaseUrl); + HDP_REPO_ID, newBaseUrl); RepositoryInfo repoInfo = ambariMetaInfo.getRepository(STACK_NAME_HDP, "2.1.1", "redhat6", - STACK_NAME_HDP + "-2.1.1"); + HDP_REPO_ID); assertEquals(newBaseUrl, repoInfo.getBaseUrl()); String prevBaseUrl = repoInfo.getDefaultBaseUrl(); @@ -258,7 +261,7 @@ public class AmbariMetaInfoTest { STACK_NAME_HDP, "2.1.1", "redhat6"); assertNotNull(redhat6Repo); for (RepositoryInfo ri : redhat6Repo) { - if (STACK_NAME_HDP.equals(ri.getRepoName())) { + if (HDP_REPO_NAME.equals(ri.getRepoName())) { assertEquals(newBaseUrl, ri.getBaseUrl()); // defaultBaseUrl and baseUrl should not be same, since it is updated. assertFalse(ri.getBaseUrl().equals(ri.getDefaultBaseUrl())); @@ -267,7 +270,50 @@ public class AmbariMetaInfoTest { // Reset the database with the original baseUrl ambariMetaInfo.updateRepoBaseURL(STACK_NAME_HDP, "2.1.1", "redhat6", - STACK_NAME_HDP + "-2.1.1", prevBaseUrl); + HDP_REPO_ID, prevBaseUrl); + } + + @Test + public void testGetRepositoryUpdatedUtilsBaseUrl() throws Exception { + // Scenario: user has internet and but calls to set repos via api + // use whatever they set + String stackVersion = "0.2"; + String buildDir = tmpFolder.getRoot().getAbsolutePath(); + TestAmbariMetaInfo ambariMetaInfo = setupTempAmbariMetaInfo(buildDir, true); + + // Updating the baseUrl + String newBaseUrl = "http://myprivate-repo-1.hortonworks.com/HDP-Utils/centos6/2.x/updates/2.0.6.0"; + ambariMetaInfo.updateRepoBaseURL(STACK_NAME_HDP, stackVersion, "redhat6", + REPO_ID, newBaseUrl); + RepositoryInfo repoInfo = ambariMetaInfo.getRepository(STACK_NAME_HDP, stackVersion, "redhat6", + REPO_ID); + assertEquals(newBaseUrl, repoInfo.getBaseUrl()); + String prevBaseUrl = repoInfo.getDefaultBaseUrl(); + + // mock expectations + MetainfoDAO metainfoDAO = ambariMetaInfo.metaInfoDAO; + reset(metainfoDAO); + MetainfoEntity entity = createNiceMock(MetainfoEntity.class); + expect(metainfoDAO.findByKey("repo:/HDP/0.2/redhat6/HDP-UTILS-1.1.0.15:baseurl")).andReturn(entity).atLeastOnce(); + expect(entity.getMetainfoValue()).andReturn(newBaseUrl).atLeastOnce(); + replay(metainfoDAO, entity); + + ambariMetaInfo.init(); + + List<RepositoryInfo> redhat6Repo = ambariMetaInfo.getRepositories( + STACK_NAME_HDP, stackVersion, "redhat6"); + assertNotNull(redhat6Repo); + for (RepositoryInfo ri : redhat6Repo) { + if (HDP_UTILS_REPO_NAME.equals(ri.getRepoName())) { + assertEquals(newBaseUrl, ri.getBaseUrl()); + // defaultBaseUrl and baseUrl should not be same, since it is updated. + assertFalse(ri.getBaseUrl().equals(ri.getDefaultBaseUrl())); + } + } + + // Reset the database with the original baseUrl + ambariMetaInfo.updateRepoBaseURL(STACK_NAME_HDP, stackVersion, "redhat6", + REPO_ID, prevBaseUrl); } @Test