@Test public void testPerform() throws Exception { ConfigurationMergeCheck cmc = new ConfigurationMergeCheck(); final RepositoryVersionDAO repositoryVersionDAO = EasyMock.createMock(RepositoryVersionDAO.class); expect(repositoryVersionDAO.findByStackNameAndVersion("HDP", "1.0")).andReturn(createFor("1.0")).anyTimes(); expect(repositoryVersionDAO.findByStackNameAndVersion("HDP", "1.1")).andReturn(createFor("1.1")).anyTimes(); replay(repositoryVersionDAO); cmc.repositoryVersionDaoProvider = new Provider<RepositoryVersionDAO>() { @Override public RepositoryVersionDAO get() { return repositoryVersionDAO; } }; cmc.clustersProvider = new Provider<Clusters>() { @Override public Clusters get() { return clusters; } }; cmc.m_mergeHelper = new ConfigMergeHelper(); Field field = ConfigMergeHelper.class.getDeclaredField("m_clusters"); field.setAccessible(true); field.set(cmc.m_mergeHelper, cmc.clustersProvider); final AmbariMetaInfo ami = EasyMock.createMock(AmbariMetaInfo.class); field = ConfigMergeHelper.class.getDeclaredField("m_ambariMetaInfo"); field.setAccessible(true); field.set(cmc.m_mergeHelper, new Provider<AmbariMetaInfo>() { @Override public AmbariMetaInfo get() { return ami; } }); PropertyInfo pi10 = new PropertyInfo(); pi10.setFilename(CONFIG_FILE); pi10.setName(CONFIG_PROPERTY); pi10.setValue("1024"); PropertyInfo pi11 = new PropertyInfo(); pi11.setFilename(CONFIG_FILE); pi11.setName(CONFIG_PROPERTY); pi11.setValue("1024"); expect(ami.getServiceProperties("HDP", "1.0", "HDFS")).andReturn( Collections.singleton(pi10)).anyTimes(); expect(ami.getServiceProperties("HDP", "1.1", "HDFS")).andReturn( Collections.singleton(pi11)).anyTimes(); expect(ami.getStackProperties(anyObject(String.class), anyObject(String.class))).andReturn( Collections.<PropertyInfo>emptySet()).anyTimes(); replay(ami); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setTargetStackId(stackId_1_0); request.setRepositoryVersion("1.1"); PrerequisiteCheck check = new PrerequisiteCheck(null, "cluster"); cmc.perform(check, request); Assert.assertEquals("Expect no warnings", 0, check.getFailedOn().size()); check = new PrerequisiteCheck(null, "cluster"); m_configMap.put(CONFIG_PROPERTY, "1025m"); pi11.setValue("1026"); cmc.perform(check, request); Assert.assertEquals("Expect warning when user-set has changed from new default", 1, check.getFailedOn().size()); Assert.assertEquals(1, check.getFailedDetail().size()); ConfigurationMergeCheck.MergeDetail detail = (ConfigurationMergeCheck.MergeDetail) check.getFailedDetail().get(0); Assert.assertEquals("1025m", detail.current); Assert.assertEquals("1026m", detail.new_stack_value); Assert.assertEquals("1025m", detail.result_value); Assert.assertEquals(CONFIG_TYPE, detail.type); Assert.assertEquals(CONFIG_PROPERTY, detail.property); check = new PrerequisiteCheck(null, "cluster"); pi11.setName(CONFIG_PROPERTY + ".foo"); cmc.perform(check, request); Assert.assertEquals("Expect no warning when user new stack is empty", 0, check.getFailedOn().size()); Assert.assertEquals(0, check.getFailedDetail().size()); check = new PrerequisiteCheck(null, "cluster"); pi11.setName(CONFIG_PROPERTY); pi10.setName(CONFIG_PROPERTY + ".foo"); cmc.perform(check, request); Assert.assertEquals("Expect warning when user old stack is empty, and value changed", 1, check.getFailedOn().size()); Assert.assertEquals(1, check.getFailedDetail().size()); detail = (ConfigurationMergeCheck.MergeDetail) check.getFailedDetail().get(0); Assert.assertEquals("1025m", detail.current); Assert.assertEquals("1026m", detail.new_stack_value); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String stackName = request.getTargetStackId().getStackName(); RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); Map<String, Map<String, ThreeWayValue>> changes = m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId()); Set<String> failedTypes = new HashSet<String>(); for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) { for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) { ThreeWayValue twv = configEntry.getValue(); if (null == twv.oldStackValue) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } else if (!twv.oldStackValue.equals(twv.savedValue)) { if (null == twv.newStackValue || !twv.oldStackValue.equals(twv.newStackValue)) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } } } } if (prerequisiteCheck.getFailedOn().size() > 0) { prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join( failedTypes, ", "))); } else { prerequisiteCheck.setStatus(PrereqCheckStatus.PASS); } }
ConfigurationMergeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String stackName = request.getTargetStackId().getStackName(); RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); Map<String, Map<String, ThreeWayValue>> changes = m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId()); Set<String> failedTypes = new HashSet<String>(); for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) { for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) { ThreeWayValue twv = configEntry.getValue(); if (null == twv.oldStackValue) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } else if (!twv.oldStackValue.equals(twv.savedValue)) { if (null == twv.newStackValue || !twv.oldStackValue.equals(twv.newStackValue)) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } } } } if (prerequisiteCheck.getFailedOn().size() > 0) { prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join( failedTypes, ", "))); } else { prerequisiteCheck.setStatus(PrereqCheckStatus.PASS); } } }
ConfigurationMergeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String stackName = request.getTargetStackId().getStackName(); RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); Map<String, Map<String, ThreeWayValue>> changes = m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId()); Set<String> failedTypes = new HashSet<String>(); for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) { for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) { ThreeWayValue twv = configEntry.getValue(); if (null == twv.oldStackValue) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } else if (!twv.oldStackValue.equals(twv.savedValue)) { if (null == twv.newStackValue || !twv.oldStackValue.equals(twv.newStackValue)) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } } } } if (prerequisiteCheck.getFailedOn().size() > 0) { prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join( failedTypes, ", "))); } else { prerequisiteCheck.setStatus(PrereqCheckStatus.PASS); } } ConfigurationMergeCheck(); }
ConfigurationMergeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String stackName = request.getTargetStackId().getStackName(); RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); Map<String, Map<String, ThreeWayValue>> changes = m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId()); Set<String> failedTypes = new HashSet<String>(); for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) { for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) { ThreeWayValue twv = configEntry.getValue(); if (null == twv.oldStackValue) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } else if (!twv.oldStackValue.equals(twv.savedValue)) { if (null == twv.newStackValue || !twv.oldStackValue.equals(twv.newStackValue)) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } } } } if (prerequisiteCheck.getFailedOn().size() > 0) { prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join( failedTypes, ", "))); } else { prerequisiteCheck.setStatus(PrereqCheckStatus.PASS); } } ConfigurationMergeCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
ConfigurationMergeCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String stackName = request.getTargetStackId().getStackName(); RepositoryVersionEntity rve = repositoryVersionDaoProvider.get().findByStackNameAndVersion(stackName, request.getRepositoryVersion()); Map<String, Map<String, ThreeWayValue>> changes = m_mergeHelper.getConflicts(request.getClusterName(), rve.getStackId()); Set<String> failedTypes = new HashSet<String>(); for (Entry<String, Map<String, ThreeWayValue>> entry : changes.entrySet()) { for (Entry<String, ThreeWayValue> configEntry : entry.getValue().entrySet()) { ThreeWayValue twv = configEntry.getValue(); if (null == twv.oldStackValue) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } else if (!twv.oldStackValue.equals(twv.savedValue)) { if (null == twv.newStackValue || !twv.oldStackValue.equals(twv.newStackValue)) { failedTypes.add(entry.getKey()); prerequisiteCheck.getFailedOn().add(entry.getKey() + "/" + configEntry.getKey()); MergeDetail md = new MergeDetail(); md.type = entry.getKey(); md.property = configEntry.getKey(); md.current = twv.savedValue; md.new_stack_value = twv.newStackValue; md.result_value = md.current; prerequisiteCheck.getFailedDetail().add(md); } } } } if (prerequisiteCheck.getFailedOn().size() > 0) { prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join( failedTypes, ", "))); } else { prerequisiteCheck.setStatus(PrereqCheckStatus.PASS); } } ConfigurationMergeCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }