From 3bfd214a59a60263aff67850c4d646c64fd76a01 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Tue, 16 Oct 2018 18:54:40 -0400 Subject: [PATCH] YARN-8810. Fixed a YARN service bug in comparing ConfigFile object. Contributed by Chandni Singh --- .../yarn/service/UpgradeComponentsFinder.java | 2 +- .../yarn/service/api/records/ConfigFile.java | 3 +- .../TestDefaultUpgradeComponentsFinder.java | 40 +++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/UpgradeComponentsFinder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/UpgradeComponentsFinder.java index 19ff6db2a4..96a34f4d3e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/UpgradeComponentsFinder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/UpgradeComponentsFinder.java @@ -88,7 +88,7 @@ public List findTargetComponentSpecs(Service currentDef, } if (!Objects.equals(currentDef.getConfiguration(), - currentDef.getConfiguration())) { + targetDef.getConfiguration())) { return targetDef.getComponents(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/api/records/ConfigFile.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/api/records/ConfigFile.java index cd9dc8460b..1cdae86835 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/api/records/ConfigFile.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/api/records/ConfigFile.java @@ -199,7 +199,8 @@ public boolean equals(java.lang.Object o) { ConfigFile configFile = (ConfigFile) o; return Objects.equals(this.type, configFile.type) && Objects.equals(this.destFile, configFile.destFile) - && Objects.equals(this.srcFile, configFile.srcFile); + && Objects.equals(this.srcFile, configFile.srcFile) + && Objects.equals(this.properties, configFile.properties); } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java index b0a01b39e2..304e74078e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestDefaultUpgradeComponentsFinder.java @@ -17,14 +17,15 @@ */ package org.apache.hadoop.yarn.service; +import com.google.common.collect.Lists; import org.apache.hadoop.yarn.service.api.records.Component; +import org.apache.hadoop.yarn.service.api.records.ConfigFile; +import org.apache.hadoop.yarn.service.api.records.Configuration; import org.apache.hadoop.yarn.service.api.records.Service; import org.junit.Assert; import org.junit.Test; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; import static org.junit.Assert.assertEquals; @@ -86,4 +87,37 @@ public void testComponentArtifactChange() { expected, finder.findTargetComponentSpecs(currentDef, targetDef)); } + + @Test + public void testChangeInConfigFileProperty() { + ConfigFile file = new ConfigFile().srcFile("src").destFile("dest") + .type(ConfigFile.TypeEnum.HADOOP_XML); + + Map props = new HashMap<>(); + props.put("k1", "v1"); + file.setProperties(props); + + Configuration conf = new Configuration().files(Lists.newArrayList(file)); + + Service currentDef = TestServiceManager.createBaseDef("test"); + currentDef.setConfiguration(conf); + + // new spec has changes in config file property + file = new ConfigFile().srcFile("src").destFile("dest") + .type(ConfigFile.TypeEnum.HADOOP_XML); + Map changedProps = new HashMap<>(); + changedProps.put("k1", "v2"); + file.setProperties(changedProps); + + conf = new Configuration().files(Lists.newArrayList(file)); + + Service targetDef = TestServiceManager.createBaseDef("test"); + targetDef.setConfiguration(conf); + + List expected = new ArrayList<>(); + expected.addAll(targetDef.getComponents()); + + assertEquals("all components needs upgrade", + expected, finder.findTargetComponentSpecs(currentDef, targetDef)); + } } \ No newline at end of file