@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); }
@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 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 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(); }
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); }
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);  }