Repository: ambari Updated Branches: refs/heads/trunk 4f636865f -> 30424f72d
AMBARI-14281. EU/RU can fail if register a repo without a build number that already exists, add PreCheck (alejandro) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/30424f72 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/30424f72 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/30424f72 Branch: refs/heads/trunk Commit: 30424f72d35351e8bacc285d7e93c66bc3e56d1f Parents: 4f63686 Author: Alejandro Fernandez <afernan...@hortonworks.com> Authored: Tue Dec 8 18:22:19 2015 -0800 Committer: Alejandro Fernandez <afernan...@hortonworks.com> Committed: Wed Dec 9 13:32:29 2015 -0800 ---------------------------------------------------------------------- .../server/checks/InstallPackagesCheck.java | 14 ++++++++++++++ .../server/checks/InstallPackagesCheckTest.java | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/30424f72/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java index 15b6140..1099418 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/InstallPackagesCheck.java @@ -26,6 +26,7 @@ import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.controller.PrereqCheckRequest; import org.apache.ambari.server.orm.entities.ClusterVersionEntity; import org.apache.ambari.server.orm.entities.HostVersionEntity; +import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.MaintenanceState; @@ -56,7 +57,20 @@ public class InstallPackagesCheck extends AbstractCheckDescriptor { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final StackId targetStackId = request.getTargetStackId(); + final String stackName = targetStackId.getStackName(); final String repoVersion = request.getRepositoryVersion(); + + final RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); + if (StringUtils.isBlank(rve.getVersion()) || !rve.getVersion().matches("^\\d+(\\.\\d+)*\\-\\d+$")) { + String message = MessageFormat.format("The Repository Version {0} for Stack {1} must contain a \"-\" followed by a build number. " + + "Make sure that another registered repository does not have the same repo URL or " + + "shares the same build number. Next, try reinstalling the Repository Version.", rve.getVersion(), rve.getStackVersion()); + prerequisiteCheck.getFailedOn().add("Repository Version " + rve.getVersion()); + prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); + prerequisiteCheck.setFailReason(message); + return; + } + final ClusterVersionEntity clusterVersion = clusterVersionDAOProvider.get().findByClusterAndStackAndVersion( clusterName, targetStackId, repoVersion); final Set<String> failedHosts = new HashSet<String>(); http://git-wip-us.apache.org/repos/asf/ambari/blob/30424f72/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java index 56aa1f3..080ca3a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java @@ -26,9 +26,11 @@ import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.PrereqCheckRequest; import org.apache.ambari.server.orm.dao.ClusterVersionDAO; import org.apache.ambari.server.orm.dao.HostVersionDAO; +import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; import org.apache.ambari.server.orm.entities.ClusterVersionEntity; import org.apache.ambari.server.orm.entities.HostVersionEntity; import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; +import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.ambari.server.orm.models.HostComponentSummary; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; @@ -60,6 +62,7 @@ public class InstallPackagesCheckTest { private final Clusters clusters = Mockito.mock(Clusters.class); private final ClusterVersionDAO clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class); private final HostVersionDAO hostVersionDAO = Mockito.mock(HostVersionDAO.class); + private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(RepositoryVersionDAO.class); private AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class); private StackId sourceStackId = new StackId("HDP", "2.2"); private StackId targetStackId = new StackId("HDP", "2.2"); @@ -81,6 +84,7 @@ public class InstallPackagesCheckTest { @Test public void testPerform() throws Exception { + StackId stackId = new StackId("HDP", "2.2"); PowerMockito.mockStatic(HostComponentSummary.class); final InstallPackagesCheck installPackagesCheck = new InstallPackagesCheck(); @@ -113,10 +117,22 @@ public class InstallPackagesCheckTest { } }; + installPackagesCheck.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() { + @Override + public RepositoryVersionDAO get() { + return repositoryVersionDAO; + } + }; + StackEntity stack = new StackEntity(); + stack.setStackName(stackId.getStackName()); + stack.setStackVersion(stackId.getStackVersion()); + RepositoryVersionEntity rve = new RepositoryVersionEntity(stack, repositoryVersion, repositoryVersion, "rhel6"); + Mockito.when(repositoryVersionDAO.findByStackNameAndVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(rve); final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterName()).thenReturn(clusterName); Mockito.when(cluster.getClusterId()).thenReturn(1L); - Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP", "2.2")); + + Mockito.when(cluster.getCurrentStackVersion()).thenReturn(stackId); Mockito.when(clusters.getCluster(clusterName)).thenReturn(cluster); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(clusterVersionEntity.getState()).thenReturn(RepositoryVersionState.INSTALLED); @@ -126,8 +142,6 @@ public class InstallPackagesCheckTest { hostNames.add("host1"); hostNames.add("host2"); hostNames.add("host3"); - RepositoryVersionEntity rve = Mockito.mock(RepositoryVersionEntity.class); - Mockito.when(rve.getVersion()).thenReturn(repositoryVersion); final List<Host> hosts = new ArrayList<Host>(); final List<HostVersionEntity> hostVersionEntities = new ArrayList<HostVersionEntity>();