@Test public void testPerformWithCheckConfig() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(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("mapred-site", desiredConfig); configMap.put("core-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("dfs-protocols-regex","^([^:]*dfs|wasb|ecs):.*"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( servicesMapReduceDistributedCacheCheck.getClass().getName())).thenReturn(checkProperties); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); PrerequisiteCheck check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); properties.put("fs.defaultFS", "anything"); properties.put("mapreduce.application.framework.path", "hdfs: properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "anything"); properties.put("mapreduce.application.framework.path", "dfs: properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "anything"); properties.put("mapreduce.application.framework.path", "wasb: properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "anything"); properties.put("mapreduce.application.framework.path", "ecs: properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "hdfs: properties.put("mapreduce.application.framework.path", "/some/path"); properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "dfs: properties.put("mapreduce.application.framework.path", "/some/path"); properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "wasb: properties.put("mapreduce.application.framework.path", "/some/path"); properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "ecs: properties.put("mapreduce.application.framework.path", "/some/path"); properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("fs.defaultFS", "anything"); properties.put("mapreduce.application.framework.path", "/some/path"); properties.put("mapreduce.application.classpath", "anything"); request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); check = new PrerequisiteCheck(null, null); servicesMapReduceDistributedCacheCheck.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); } final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final String mrConfigType = "mapred-site"; final String coreSiteConfigType = "core-site"; final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs(); final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); List<String> errorMessages = new ArrayList<String>(); if (applicationClasspath == null || applicationClasspath.isEmpty()) { errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); } if (frameworkPath == null || frameworkPath.isEmpty()) { errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); } if (!errorMessages.isEmpty()) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); return; } if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); } }
ServicesMapReduceDistributedCacheCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); } final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final String mrConfigType = "mapred-site"; final String coreSiteConfigType = "core-site"; final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs(); final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); List<String> errorMessages = new ArrayList<String>(); if (applicationClasspath == null || applicationClasspath.isEmpty()) { errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); } if (frameworkPath == null || frameworkPath.isEmpty()) { errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); } if (!errorMessages.isEmpty()) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); return; } if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); } } }
ServicesMapReduceDistributedCacheCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); } final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final String mrConfigType = "mapred-site"; final String coreSiteConfigType = "core-site"; final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs(); final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); List<String> errorMessages = new ArrayList<String>(); if (applicationClasspath == null || applicationClasspath.isEmpty()) { errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); } if (frameworkPath == null || frameworkPath.isEmpty()) { errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); } if (!errorMessages.isEmpty()) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); return; } if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); } } ServicesMapReduceDistributedCacheCheck(); }
ServicesMapReduceDistributedCacheCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); } final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final String mrConfigType = "mapred-site"; final String coreSiteConfigType = "core-site"; final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs(); final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); List<String> errorMessages = new ArrayList<String>(); if (applicationClasspath == null || applicationClasspath.isEmpty()) { errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); } if (frameworkPath == null || frameworkPath.isEmpty()) { errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); } if (!errorMessages.isEmpty()) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); return; } if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); } } ServicesMapReduceDistributedCacheCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
ServicesMapReduceDistributedCacheCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String dfsProtocolsRegex = DFS_PROTOCOLS_REGEX_DEFAULT; PrerequisiteCheckConfig prerequisiteCheckConfig = request.getPrerequisiteCheckConfig(); Map<String, String> checkProperties = null; if(prerequisiteCheckConfig != null) { checkProperties = prerequisiteCheckConfig.getCheckProperties(this.getClass().getName()); } if(checkProperties != null && checkProperties.containsKey(DFS_PROTOCOLS_REGEX_PROPERTY_NAME)) { dfsProtocolsRegex = checkProperties.get(DFS_PROTOCOLS_REGEX_PROPERTY_NAME); } final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); final String mrConfigType = "mapred-site"; final String coreSiteConfigType = "core-site"; final Map<String, DesiredConfig> desiredConfigs = cluster.getDesiredConfigs(); final DesiredConfig mrDesiredConfig = desiredConfigs.get(mrConfigType); final DesiredConfig coreSiteDesiredConfig = desiredConfigs.get(coreSiteConfigType); final Config mrConfig = cluster.getConfig(mrConfigType, mrDesiredConfig.getTag()); final Config coreSiteConfig = cluster.getConfig(coreSiteConfigType, coreSiteDesiredConfig.getTag()); final String applicationClasspath = mrConfig.getProperties().get("mapreduce.application.classpath"); final String frameworkPath = mrConfig.getProperties().get("mapreduce.application.framework.path"); final String defaultFS = coreSiteConfig.getProperties().get("fs.defaultFS"); List<String> errorMessages = new ArrayList<String>(); if (applicationClasspath == null || applicationClasspath.isEmpty()) { errorMessages.add(getFailReason(KEY_APP_CLASSPATH, prerequisiteCheck, request)); } if (frameworkPath == null || frameworkPath.isEmpty()) { errorMessages.add(getFailReason(KEY_FRAMEWORK_PATH, prerequisiteCheck, request)); } if (!errorMessages.isEmpty()) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(errorMessages, " ")); return; } if (!frameworkPath.matches(dfsProtocolsRegex) && (defaultFS == null || !defaultFS.matches(dfsProtocolsRegex))) { prerequisiteCheck.getFailedOn().add("MAPREDUCE2"); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(getFailReason(KEY_NOT_DFS, prerequisiteCheck, request)); } } ServicesMapReduceDistributedCacheCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }