@Test public void testPerform() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); Mockito.when(desiredConfig.getTag()).thenReturn("tag"); Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>(); configMap.put("hive-site", desiredConfig); Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); final Config config = Mockito.mock(Config.class); Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); final Map<String, String> properties = new HashMap<String, String>(); Mockito.when(config.getProperties()).thenReturn(properties); Map<String, String> checkProperties = new HashMap<String, String>(); checkProperties.put("min-failure-stack-version","HDP-2.3.0.0"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( m_check.getClass().getName())).thenReturn(checkProperties); PrerequisiteCheck check = new PrerequisiteCheck(null, null); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); request.setSourceStackId(new StackId("HDP-2.2.4.2")); request.setTargetStackId(new StackId("HDP-2.2.8.4")); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); request.setSourceStackId(new StackId("HDP-2.2.4.2")); request.setTargetStackId(new StackId("HDP-2.3.8.4")); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); request.setSourceStackId(new StackId("HDP-2.3.4.2")); request.setTargetStackId(new StackId("HDP-2.3.8.4")); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); request.setSourceStackId(new StackId("HDP-2.3.4.2")); request.setTargetStackId(new StackId("HDP-2.4.8.4")); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("hive.server2.support.dynamic.service.discovery", "true"); properties.put("hive.zookeeper.quorum", "host"); properties.put("hive.server2.zookeeper.namespace", "namespace"); check = new PrerequisiteCheck(null, null); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { List<String> errorMessages = new ArrayList<String>(); String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperQuorum)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperNamespace)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, request)); } String minFailureStackVersion = 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_FAILURE_STACK_VERSION_PROPERTY_NAME)) { minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.getFailedOn().add("HIVE"); PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { String[] minStack = minFailureStackVersion.split("-"); if (minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; if (minStackName.equals(request.getSourceStackId().getStackName())) { if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), request.getTargetStackId().getStackVersion()) < 0) { checkStatus = PrereqCheckStatus.WARNING; } } } } prerequisiteCheck.setStatus(checkStatus); } }
HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { List<String> errorMessages = new ArrayList<String>(); String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperQuorum)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperNamespace)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, request)); } String minFailureStackVersion = 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_FAILURE_STACK_VERSION_PROPERTY_NAME)) { minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.getFailedOn().add("HIVE"); PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { String[] minStack = minFailureStackVersion.split("-"); if (minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; if (minStackName.equals(request.getSourceStackId().getStackName())) { if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), request.getTargetStackId().getStackVersion()) < 0) { checkStatus = PrereqCheckStatus.WARNING; } } } } prerequisiteCheck.setStatus(checkStatus); } } }
HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { List<String> errorMessages = new ArrayList<String>(); String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperQuorum)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperNamespace)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, request)); } String minFailureStackVersion = 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_FAILURE_STACK_VERSION_PROPERTY_NAME)) { minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.getFailedOn().add("HIVE"); PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { String[] minStack = minFailureStackVersion.split("-"); if (minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; if (minStackName.equals(request.getSourceStackId().getStackName())) { if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), request.getTargetStackId().getStackVersion()) < 0) { checkStatus = PrereqCheckStatus.WARNING; } } } } prerequisiteCheck.setStatus(checkStatus); } } HiveDynamicServiceDiscoveryCheck(); }
HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { List<String> errorMessages = new ArrayList<String>(); String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperQuorum)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperNamespace)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, request)); } String minFailureStackVersion = 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_FAILURE_STACK_VERSION_PROPERTY_NAME)) { minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.getFailedOn().add("HIVE"); PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { String[] minStack = minFailureStackVersion.split("-"); if (minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; if (minStackName.equals(request.getSourceStackId().getStackName())) { if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), request.getTargetStackId().getStackVersion()) < 0) { checkStatus = PrereqCheckStatus.WARNING; } } } } prerequisiteCheck.setStatus(checkStatus); } } HiveDynamicServiceDiscoveryCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
HiveDynamicServiceDiscoveryCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { List<String> errorMessages = new ArrayList<String>(); String dynamicServiceDiscoveryEnabled = getProperty(request, "hive-site", "hive.server2.support.dynamic.service.discovery"); String zookeeperQuorum = getProperty(request, "hive-site", "hive.zookeeper.quorum"); String zookeeperNamespace = getProperty(request, "hive-site", "hive.server2.zookeeper.namespace"); if (null == dynamicServiceDiscoveryEnabled || !Boolean.parseBoolean(dynamicServiceDiscoveryEnabled)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_DISCOVERY_ENABLED_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperQuorum)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_QUORUM_KEY, prerequisiteCheck, request)); } if (StringUtils.isBlank(zookeeperNamespace)) { errorMessages.add(getFailReason(HIVE_DYNAMIC_SERVICE_ZK_NAMESPACE_KEY, prerequisiteCheck, request)); } String minFailureStackVersion = 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_FAILURE_STACK_VERSION_PROPERTY_NAME)) { minFailureStackVersion = checkProperties.get(MIN_FAILURE_STACK_VERSION_PROPERTY_NAME); } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.getFailedOn().add("HIVE"); PrereqCheckStatus checkStatus = PrereqCheckStatus.FAIL; if(minFailureStackVersion != null && !minFailureStackVersion.isEmpty()) { String[] minStack = minFailureStackVersion.split("-"); if (minStack.length == 2) { String minStackName = minStack[0]; String minStackVersion = minStack[1]; if (minStackName.equals(request.getSourceStackId().getStackName())) { if (VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getTargetStackId().getStackVersion(), minStackVersion) < 0 && VersionUtils.compareVersions(request.getSourceStackId().getStackVersion(), request.getTargetStackId().getStackVersion()) < 0) { checkStatus = PrereqCheckStatus.WARNING; } } } } prerequisiteCheck.setStatus(checkStatus); } } HiveDynamicServiceDiscoveryCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }