ClientRetryPropertyCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Map<String, Service> services = cluster.getServices(); List<String> errorMessages = new ArrayList<String>(); if (services.containsKey("HDFS")) { String clientRetryPolicyEnabled = getProperty(request, "hdfs-site", "dfs.client.retry.policy.enabled"); if (null != clientRetryPolicyEnabled && Boolean.parseBoolean(clientRetryPolicyEnabled)) { errorMessages.add(getFailReason(HDFS_CLIENT_RETRY_DISABLED_KEY, prerequisiteCheck, request)); prerequisiteCheck.getFailedOn().add("HDFS"); } } if (services.containsKey("HIVE")) { String hiveClientRetryCount = getProperty(request, "hive-site", "hive.metastore.failure.retries"); if (null != hiveClientRetryCount && Integer.parseInt(hiveClientRetryCount) <= 0) { errorMessages.add(getFailReason(HIVE_CLIENT_RETRY_MISSING_KEY, prerequisiteCheck, request)); prerequisiteCheck.getFailedOn().add("HIVE"); } } if (services.containsKey("OOZIE")) { String oozieClientRetry = getProperty(request, "oozie-env", "content"); if (null == oozieClientRetry || !oozieClientRetry.contains("-Doozie.connection.retry.count")) { errorMessages.add(getFailReason(OOZIE_CLIENT_RETRY_MISSING_KEY, prerequisiteCheck, request)); prerequisiteCheck.getFailedOn().add("OOZIE"); } } if (!errorMessages.isEmpty()) { prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); } } ClientRetryPropertyCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }
@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); Map<String, Service> services = new HashMap<String, Service>(); Mockito.when(cluster.getServices()).thenReturn(services); final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); Mockito.when(desiredConfig.getTag()).thenReturn("tag"); Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>(); configMap.put("hdfs-site", desiredConfig); configMap.put("hive-site", desiredConfig); configMap.put("oozie-env", 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); services.put("HDFS", Mockito.mock(Service.class)); properties.put("dfs.client.retry.policy.enabled", "true"); PrerequisiteCheck check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("dfs.client.retry.policy.enabled", "false"); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); services.put("HIVE", Mockito.mock(Service.class)); properties.put("hive.metastore.failure.retries", "0"); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("hive.metastore.failure.retries", "5"); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); services.put("OOZIE", Mockito.mock(Service.class)); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("template", "foo bar baz"); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("content", "foo bar baz -Doozie.connection.retry.count=5 foobarbaz"); check = new PrerequisiteCheck(null, null); m_check.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }