AMBARI-21884. Installation should ignore OS that are not managed by Ambari (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/249bb97a Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/249bb97a Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/249bb97a Branch: refs/heads/feature-branch-AMBARI-21307 Commit: 249bb97a864c0f18278d37d87c2c3117809e5ca4 Parents: f3232d2 Author: Nate Cole <nc...@hortonworks.com> Authored: Wed Sep 6 11:44:40 2017 -0400 Committer: Nate Cole <nc...@hortonworks.com> Committed: Wed Sep 6 11:44:40 2017 -0400 ---------------------------------------------------------------------- .../libraries/functions/repository_util.py | 32 +++++++--- .../ambari/server/agent/CommandRepository.java | 20 +++++- .../AmbariCustomCommandExecutionHelper.java | 44 ++++---------- .../ClusterStackVersionResourceProvider.java | 28 ++++++--- .../HostStackVersionResourceProvider.java | 30 ++++----- .../stack/upgrade/RepositoryVersionHelper.java | 16 +++-- .../src/main/resources/version_definition.xsd | 3 +- .../ExecutionCommandWrapperTest.java | 64 ++++++++++++++++++++ .../AmbariCustomCommandExecutionHelperTest.java | 14 ++--- ...ClusterStackVersionResourceProviderTest.java | 8 ++- 10 files changed, 175 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-common/src/main/python/resource_management/libraries/functions/repository_util.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/repository_util.py b/ambari-common/src/main/python/resource_management/libraries/functions/repository_util.py index 6ad1aee..120d464 100644 --- a/ambari-common/src/main/python/resource_management/libraries/functions/repository_util.py +++ b/ambari-common/src/main/python/resource_management/libraries/functions/repository_util.py @@ -40,7 +40,10 @@ def create_repo_files(template, command_repository): raise Fail("The command repository was not parsed correctly") if 0 == len(command_repository.repositories): - raise Fail("Cannot create repository files when no repositories are defined") + Logger.warning( + "Repository for {0}/{1} has no repositories. Ambari may not be managing this version.".format( + command_repository.stack_name, command_repository.version_string)) + return # add the stack name to the file name just to make it a little easier to debug # version_id is the primary id of the repo_version table in the database @@ -54,15 +57,20 @@ def create_repo_files(template, command_repository): if repository.repo_id is None: raise Fail("Repository with url {0} has no id".format(repository.base_url)) - Repository(repository.repo_id, - action = "create", - base_url = repository.base_url, - mirror_list = repository.mirrors_list, - repo_file_name = file_name, - repo_template = template, - components = repository.ubuntu_components, - append_to_file = append_to_file) - append_to_file = True + if not repository.ambari_managed: + Logger.warning( + "Repository for {0}/{1}/{2} is not managed by Ambari".format( + command_repository.stack_name, command_repository.version_string, repository.repo_id)) + else: + Repository(repository.repo_id, + action = "create", + base_url = repository.base_url, + mirror_list = repository.mirrors_list, + repo_file_name = file_name, + repo_template = template, + components = repository.ubuntu_components, + append_to_file = append_to_file) + append_to_file = True def _find_value(dictionary, key): @@ -116,6 +124,10 @@ class _CommandRepositoryEntry(object): self.repo_name = _find_value(json_dict, 'repoName') self.base_url = _find_value(json_dict, 'baseUrl') self.mirrors_list = _find_value(json_dict, 'mirrorsList') + self.ambari_managed = _find_value(json_dict, 'ambariManaged') + + if self.ambari_managed is None: + self.ambari_managed = True # if repoName is changed on the java side, this will fail for ubuntu since we rely on the # name being the same as how the repository was built http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java index 3d96122..858a55f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java @@ -108,6 +108,17 @@ public class CommandRepository { } /** + * Sets fields for non-managed + */ + public void setNonManaged() { + for (Repository repo : m_repositories) { + repo.m_baseUrl = null; + repo.m_mirrorsList = null; + repo.m_ambariManaged = false; + } + } + + /** * Minimal information required to generate repo files on the agent. These are copies * of the repository objects from repo versions that can be changed for URL overrides, etc. */ @@ -119,6 +130,9 @@ public class CommandRepository { @SerializedName("repoId") private String m_repoId; + @SerializedName("ambariManaged") + private boolean m_ambariManaged = true; + /** * The name should not change. Ubuntu requires that it match exactly as the repo was built. */ @@ -167,6 +181,10 @@ public class CommandRepository { return m_baseUrl; } + public boolean isAmbariManaged() { + return m_ambariManaged; + } + /** * {@inheritDoc} */ @@ -179,6 +197,6 @@ public class CommandRepository { .append("baseUrl", m_baseUrl) .toString(); } - } + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java index 6d97854..822539f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java @@ -1273,49 +1273,31 @@ public class AmbariCustomCommandExecutionHelper { * @throws AmbariException */ @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES) - public CommandRepository getCommandRepository(final Cluster cluster, ServiceComponent component, Host host) throws AmbariException { - - Function<List<RepositoryInfo>, List<RepositoryInfo>> function = new Function<List<RepositoryInfo>, List<RepositoryInfo>>() { - @Override - public List<RepositoryInfo> apply(List<RepositoryInfo> input) { - // !!! just return what is given - return input; - } - }; - - final List<RepositoryInfo> repoInfos = getBaseUrls(cluster, component, host, function); - - if (null == repoInfos) { - return null; - } + public CommandRepository getCommandRepository(final Cluster cluster, ServiceComponent component, final Host host) throws AmbariException { final CommandRepository command = new CommandRepository(); StackId stackId = component.getDesiredStackId(); - command.setRepositories(repoInfos); + command.setRepositories(Collections.<RepositoryInfo>emptyList()); command.setStackName(stackId.getStackName()); final BaseUrlUpdater<Void> updater = new BaseUrlUpdater<Void>(null) { @Override public Void apply(RepositoryVersionEntity rve) { - command.setRepositoryVersionId(rve.getId()); command.setRepositoryVersion(rve.getVersion()); command.setStackName(rve.getStackName()); - command.setUniqueSuffix(String.format("-repo-%s", rve.getId())); - for (CommandRepository.Repository commandRepo : command.getRepositories()) { - String osType = commandRepo.getOsType(); - String repoName = commandRepo.getRepoName(); - String baseUrl = commandRepo.getBaseUrl(); - - for (OperatingSystemEntity ose : rve.getOperatingSystems()) { - if (ose.getOsType().equals(osType) && ose.isAmbariManagedRepos()) { - for (RepositoryEntity re : ose.getRepositories()) { - if (re.getName().equals(repoName) && - !re.getBaseUrl().equals(baseUrl)) { - commandRepo.setBaseUrl(re.getBaseUrl()); - } - } + // !!! a repository version entity has all the repos worked out. We shouldn't use + // the stack at all. + for (OperatingSystemEntity osEntity : rve.getOperatingSystems()) { + String osEntityFamily = os_family.find(osEntity.getOsType()); + if (osEntityFamily.equals(host.getOsFamily())) { + command.setRepositories(osEntity.getOsType(), osEntity.getRepositories()); + + if (!osEntity.isAmbariManagedRepos()) { + command.setNonManaged(); + } else { + command.setUniqueSuffix(String.format("-repo-%s", rve.getId())); } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java index 3e4d4fd..1766da3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java @@ -85,6 +85,7 @@ import org.apache.ambari.server.state.repository.VersionDefinitionXml; import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper; import org.apache.ambari.server.utils.StageUtils; import org.apache.ambari.server.utils.VersionUtils; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -579,7 +580,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou Host host = hostIterator.next(); if (hostHasVersionableComponents(cluster, serviceNames, ami, stackId, host)) { ActionExecutionContext actionContext = getHostVersionInstallCommand(repoVersionEnt, - cluster, managementController, ami, stackId, serviceNames, perOsRepos, stage, host); + cluster, managementController, ami, stackId, serviceNames, stage, host); if (null != actionContext) { try { actionExecutionHelper.get().addExecutionCommandsToStage(actionContext, stage, null); @@ -639,20 +640,24 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou private ActionExecutionContext getHostVersionInstallCommand(RepositoryVersionEntity repoVersion, Cluster cluster, AmbariManagementController managementController, AmbariMetaInfo ami, - final StackId stackId, Set<String> repoServices, Map<String, List<RepositoryEntity>> perOsRepos, Stage stage1, Host host) + final StackId stackId, Set<String> repoServices, Stage stage1, Host host) throws SystemException { + // Determine repositories for host String osFamily = host.getOsFamily(); - final List<RepositoryEntity> repoInfo = perOsRepos.get(osFamily); - if (repoInfo == null) { - throw new SystemException(String.format("Repositories for os type %s are " + - "not defined. Repo version=%s, stackId=%s", - osFamily, repoVersion.getVersion(), stackId)); + OperatingSystemEntity osEntity = null; + for (OperatingSystemEntity os : repoVersion.getOperatingSystems()) { + if (os.getOsType().equals(osFamily)) { + osEntity = os; + break; + } } - if (repoInfo.isEmpty()){ - LOG.error(String.format("Repository list is empty. Ambari may not be managing the repositories for %s", osFamily)); + if (null == osEntity || CollectionUtils.isEmpty(osEntity.getRepositories())) { + throw new SystemException(String.format("Repositories for os type %s are " + + "not defined. Repo version=%s, stackId=%s", + osFamily, repoVersion.getVersion(), stackId)); } // determine packages for all services that are installed on host @@ -683,7 +688,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou actionContext.setRepositoryVersion(repoVersion); actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true))); - repoVersionHelper.addCommandRepository(actionContext, osFamily, repoVersion, repoInfo); + repoVersionHelper.addCommandRepository(actionContext, repoVersion, osEntity); return actionContext; } @@ -748,6 +753,9 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou * compares build numbers */ private static int compareVersions(String version1, String version2) { + version1 = (null == version1) ? "0" : version1; + version2 = (null == version2) ? "0" : version2; + // check _exact_ equality if (StringUtils.equals(version1, version2)) { return 0; http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java index bcd4089..ba5fccc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java @@ -53,7 +53,6 @@ import org.apache.ambari.server.orm.dao.HostVersionDAO; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; import org.apache.ambari.server.orm.entities.HostVersionEntity; import org.apache.ambari.server.orm.entities.OperatingSystemEntity; -import org.apache.ambari.server.orm.entities.RepositoryEntity; import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Host; @@ -62,6 +61,7 @@ import org.apache.ambari.server.state.ServiceComponentHost; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper; import org.apache.ambari.server.utils.StageUtils; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; @@ -379,25 +379,27 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource } } - List<OperatingSystemEntity> operatingSystems = repoVersionEnt.getOperatingSystems(); - Map<String, List<RepositoryEntity>> perOsRepos = new HashMap<>(); - for (OperatingSystemEntity operatingSystem : operatingSystems) { - perOsRepos.put(operatingSystem.getOsType(), operatingSystem.getRepositories()); - } - // Determine repositories for host String osFamily = host.getOsFamily(); - final List<RepositoryEntity> repoInfo = perOsRepos.get(osFamily); - if (repoInfo == null) { + OperatingSystemEntity osEntity = null; + for (OperatingSystemEntity operatingSystem : repoVersionEnt.getOperatingSystems()) { + if (osFamily.equals(operatingSystem.getOsType())) { + osEntity = operatingSystem; + break; + } + } + + if (null == osEntity) { + throw new SystemException(String.format("Operating System matching %s could not be found", + osFamily)); + } + + if (CollectionUtils.isEmpty(osEntity.getRepositories())) { throw new SystemException(String.format("Repositories for os type %s are " + "not defined. Repo version=%s, stackId=%s", osFamily, desiredRepoVersion, stackId)); } - if (repoInfo.isEmpty()){ - LOG.error(String.format("Repository list is empty. Ambari may not be managing the repositories for %s", osFamily)); - } - Set<String> servicesOnHost = new HashSet<>(); if (forceInstallOnNonMemberHost) { @@ -441,7 +443,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource roleParams); actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true))); - repoVersionHelper.addCommandRepository(actionContext, osFamily, repoVersionEnt, repoInfo); + repoVersionHelper.addCommandRepository(actionContext, repoVersionEnt, osEntity); String caption = String.format(INSTALL_PACKAGES_FULL_NAME + " on host %s", hostName); RequestStageContainer req = createRequest(caption); http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java index 60ad446..9524c09 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java @@ -303,16 +303,20 @@ public class RepositoryVersionHelper { * @param repoVersion the repository version entity * @param repos the repository entities */ - public void addCommandRepository(ActionExecutionContext context, String osFamily, - RepositoryVersionEntity repoVersion, List<RepositoryEntity> repos) { - StackId stackId = repoVersion.getStackId(); + public void addCommandRepository(ActionExecutionContext context, + RepositoryVersionEntity repoVersion, OperatingSystemEntity osEntity) { final CommandRepository commandRepo = new CommandRepository(); - commandRepo.setRepositories(osFamily, repos); + commandRepo.setRepositories(osEntity.getOsType(), osEntity.getRepositories()); commandRepo.setRepositoryVersion(repoVersion.getVersion()); commandRepo.setRepositoryVersionId(repoVersion.getId()); - commandRepo.setStackName(stackId.getStackName()); - commandRepo.setUniqueSuffix(String.format("-repo-%s", repoVersion.getId())); + commandRepo.setStackName(repoVersion.getStackId().getStackName()); + + if (!osEntity.isAmbariManagedRepos()) { + commandRepo.setNonManaged(); + } else { + commandRepo.setUniqueSuffix(String.format("-repo-%s", repoVersion.getId())); + } context.addVisitor(new ExecutionCommandVisitor() { @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/main/resources/version_definition.xsd ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/version_definition.xsd b/ambari-server/src/main/resources/version_definition.xsd index 851e0d5..832d7f9 100644 --- a/ambari-server/src/main/resources/version_definition.xsd +++ b/ambari-server/src/main/resources/version_definition.xsd @@ -126,7 +126,8 @@ <xs:element name="baseurl" type="xs:string" /> <xs:element name="repoid" type="xs:string" /> <xs:element name="reponame" type="xs:string" /> - <xs:element name="unique" type="xs:boolean" minOccurs="0" maxOccurs="1"/> + <xs:element name="mirrorslist" type="xs:string" minOccurs="0" maxOccurs="1" /> + <xs:element name="unique" type="xs:boolean" minOccurs="0" maxOccurs="1" /> </xs:sequence> </xs:complexType> </xs:element> http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java index 76160cc..fb84df5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java @@ -337,6 +337,70 @@ public class ExecutionCommandWrapperTest { Assert.assertEquals("0.1-0000", commandParams.get(KeyNames.VERSION)); } + /** + * Test that the execution command wrapper ignores repository file when there are none to use. + */ + @Test + public void testExecutionCommandNoRepositoryFile() throws Exception { + Cluster cluster = clusters.getCluster(CLUSTER1); + + StackId stackId = cluster.getDesiredStackVersion(); + RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(stackId, "0.1-0000"); + Service service = cluster.getService("HDFS"); + service.setDesiredRepositoryVersion(repositoryVersion); + + repositoryVersion.setOperatingSystems("[]"); + + ormTestHelper.repositoryVersionDAO.merge(repositoryVersion); + + // first try with an INSTALL command - this should not populate version info + ExecutionCommand executionCommand = new ExecutionCommand(); + Map<String, String> commandParams = new HashMap<>(); + + executionCommand.setClusterName(CLUSTER1); + executionCommand.setTaskId(1); + executionCommand.setRequestAndStage(1, 1); + executionCommand.setHostname(HOST1); + executionCommand.setRole("NAMENODE"); + executionCommand.setRoleParams(Collections.<String, String>emptyMap()); + executionCommand.setRoleCommand(RoleCommand.INSTALL); + executionCommand.setServiceName("HDFS"); + executionCommand.setCommandType(AgentCommandType.EXECUTION_COMMAND); + executionCommand.setCommandParams(commandParams); + + String json = StageUtils.getGson().toJson(executionCommand, ExecutionCommand.class); + ExecutionCommandWrapper execCommWrap = new ExecutionCommandWrapper(json); + injector.injectMembers(execCommWrap); + + ExecutionCommand processedExecutionCommand = execCommWrap.getExecutionCommand(); + commandParams = processedExecutionCommand.getCommandParams(); + Assert.assertFalse(commandParams.containsKey(KeyNames.VERSION)); + + // now try with a START command which should populate the version even + // though the state is INSTALLING + executionCommand = new ExecutionCommand(); + commandParams = new HashMap<>(); + + executionCommand.setClusterName(CLUSTER1); + executionCommand.setTaskId(1); + executionCommand.setRequestAndStage(1, 1); + executionCommand.setHostname(HOST1); + executionCommand.setRole("NAMENODE"); + executionCommand.setRoleParams(Collections.<String, String> emptyMap()); + executionCommand.setRoleCommand(RoleCommand.START); + executionCommand.setServiceName("HDFS"); + executionCommand.setCommandType(AgentCommandType.EXECUTION_COMMAND); + executionCommand.setCommandParams(commandParams); + + json = StageUtils.getGson().toJson(executionCommand, ExecutionCommand.class); + execCommWrap = new ExecutionCommandWrapper(json); + injector.injectMembers(execCommWrap); + + processedExecutionCommand = execCommWrap.getExecutionCommand(); + commandParams = processedExecutionCommand.getCommandParams(); + Assert.assertEquals("0.1-0000", commandParams.get(KeyNames.VERSION)); + } + @AfterClass public static void tearDown() throws AmbariException, SQLException { H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector); http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java index 7384464..883e891 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java @@ -581,9 +581,7 @@ public class AmbariCustomCommandExecutionHelperTest { CommandRepository commandRepo = helper.getCommandRepository(cluster, componentRM, host); - Assert.assertEquals(1, commandRepo.getRepositories().size()); - CommandRepository.Repository repo = commandRepo.getRepositories().iterator().next(); - Assert.assertEquals("http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0", repo.getBaseUrl()); + Assert.assertEquals(0, commandRepo.getRepositories().size()); RepositoryInfo ri = new RepositoryInfo(); ri.setBaseUrl("http://foo"); @@ -592,7 +590,6 @@ public class AmbariCustomCommandExecutionHelperTest { ri.setOsType("redhat6"); String operatingSystems = repoVersionHelper.serializeOperatingSystems(Collections.singletonList(ri)); - StackEntity stackEntity = stackDAO.find(cluster.getDesiredStackVersion().getStackName(), cluster.getDesiredStackVersion().getStackVersion()); @@ -616,15 +613,12 @@ public class AmbariCustomCommandExecutionHelperTest { commandRepo = helper.getCommandRepository(cluster, componentRM, host); Assert.assertEquals(1, commandRepo.getRepositories().size()); - repo = commandRepo.getRepositories().iterator().next(); + CommandRepository.Repository repo = commandRepo.getRepositories().iterator().next(); Assert.assertEquals("http://foo", repo.getBaseUrl()); - // verify that ZK is NOT overwritten + // verify that ZK has no repositories, since we haven't defined a repo version for ZKC commandRepo = helper.getCommandRepository(cluster, componentZKC, host); - - Assert.assertEquals(1, commandRepo.getRepositories().size()); - repo = commandRepo.getRepositories().iterator().next(); - Assert.assertEquals("http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0", repo.getBaseUrl()); + Assert.assertEquals(0, commandRepo.getRepositories().size()); } private void createClusterFixture(String clusterName, StackId stackId, http://git-wip-us.apache.org/repos/asf/ambari/blob/249bb97a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java index 0e0e1c6..654067b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java @@ -55,6 +55,7 @@ import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper; import org.apache.ambari.server.actionmanager.HostRoleCommand; import org.apache.ambari.server.actionmanager.Stage; import org.apache.ambari.server.actionmanager.StageFactory; +import org.apache.ambari.server.agent.CommandRepository; import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.agent.ExecutionCommand.KeyNames; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -1069,7 +1070,12 @@ public class ClusterStackVersionResourceProviderTest { Assert.assertEquals(Float.valueOf(0.85f), successFactor); Assert.assertNotNull(executionCommand.getRepositoryFile()); - Assert.assertEquals(0, executionCommand.getRepositoryFile().getRepositories().size()); + Assert.assertEquals(2, executionCommand.getRepositoryFile().getRepositories().size()); + + for (CommandRepository.Repository repo : executionCommand.getRepositoryFile().getRepositories()) { + Assert.assertFalse(repo.isAmbariManaged()); + } + } @Test