YarnTimelineServerStatePreservingCheck extends AbstractCheckDescriptor { @Override public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { if (!super.isApplicable(request, Arrays.asList("YARN"), true)) { return false; } final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); String minApplicableStackVersion = null; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME)) { minApplicableStackVersion = checkProperties.get(MIN_APPLICABLE_STACK_VERSION_PROPERTY_NAME); } if(minApplicableStackVersion != null && !minApplicableStackVersion.isEmpty()) { String[] minStack = minApplicableStackVersion.split("-"); if(minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; String stackName = cluster.getCurrentStackVersion().getStackName(); if (minStackName.equals(stackName)) { String currentClusterRepositoryVersion = cluster.getCurrentClusterVersion().getRepositoryVersion().getVersion(); return VersionUtils.compareVersions(currentClusterRepositoryVersion, minStackVersion) >= 0; } } } return true; } YarnTimelineServerStatePreservingCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }
@Test public void testIsApplicable() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2")); Map<String, Service> services = new HashMap<String, Service>(); Mockito.when(cluster.getServices()).thenReturn(services); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity); RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); Map<String, String> checkProperties = new HashMap<String, String>(); checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( m_check.getClass().getName())).thenReturn(checkProperties); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setRepositoryVersion("2.3.0.0"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); Assert.assertFalse(m_check.isApplicable(request)); services.put("YARN", Mockito.mock(Service.class)); Assert.assertTrue(m_check.isApplicable(request)); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.0.0"); Assert.assertFalse(m_check.isApplicable(request)); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); Assert.assertTrue(m_check.isApplicable(request)); }
@SuppressWarnings("serial") @Test public void testIsApplicableMinimumHDPStackVersion() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>() { { put("YARN", null); } }); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2")); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity); RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity); Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); Map<String, String> checkProperties = new HashMap<String, String>(); checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( m_check.getClass().getName())).thenReturn(checkProperties); PrereqCheckRequest request = new PrereqCheckRequest("c1"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.1.1.1"); boolean isApplicable = m_check.isApplicable(request); Assert.assertFalse(isApplicable); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.1"); isApplicable = m_check.isApplicable(request); Assert.assertFalse(isApplicable); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2"); isApplicable = m_check.isApplicable(request); Assert.assertTrue(isApplicable); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.4"); isApplicable = m_check.isApplicable(request); Assert.assertTrue(isApplicable); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.1.1"); isApplicable = m_check.isApplicable(request); Assert.assertTrue(isApplicable); }
@SuppressWarnings("serial") @Test public void testIsApplicableMinimumStackVersion() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>() { { put("YARN", null); } }); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2")); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity); RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity); Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); Map<String, String> checkProperties = new HashMap<String, String>(); checkProperties.put("min-applicable-stack-version", "HDP-2.2.4.2"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( m_check.getClass().getName())).thenReturn(checkProperties); PrereqCheckRequest request = new PrereqCheckRequest("c1"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.3.0.1"); boolean isApplicable = m_check.isApplicable(request); Assert.assertTrue(isApplicable); }