YARN-3963. AddNodeLabel on duplicate label addition shows success. (Bibin A Chundatt via wangda)

This commit is contained in:
Wangda Tan 2015-07-30 09:42:55 -07:00
parent ddc867ceb9
commit 8acb30b016
3 changed files with 38 additions and 2 deletions

View File

@ -710,6 +710,9 @@ Release 2.8.0 - UNRELEASED
YARN-3919. NPEs' while stopping service after exception during YARN-3919. NPEs' while stopping service after exception during
CommonNodeLabelsManager#start. (varun saxane via rohithsharmaks) CommonNodeLabelsManager#start. (varun saxane via rohithsharmaks)
YARN-3963. AddNodeLabel on duplicate label addition shows success.
(Bibin A Chundatt via wangda)
Release 2.7.2 - UNRELEASED Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -288,7 +288,8 @@ public class CommonNodeLabelsManager extends AbstractService {
} }
List<NodeLabel> newLabels = new ArrayList<NodeLabel>(); List<NodeLabel> newLabels = new ArrayList<NodeLabel>();
normalizeNodeLabels(labels); normalizeNodeLabels(labels);
// check any mismatch in exclusivity no mismatch with skip
checkExclusivityMatch(labels);
// do a check before actual adding them, will throw exception if any of them // do a check before actual adding them, will throw exception if any of them
// doesn't meet label name requirement // doesn't meet label name requirement
for (NodeLabel label : labels) { for (NodeLabel label : labels) {
@ -931,6 +932,23 @@ public class CommonNodeLabelsManager extends AbstractService {
} }
} }
private void checkExclusivityMatch(Collection<NodeLabel> labels)
throws IOException {
ArrayList<NodeLabel> mismatchlabels = new ArrayList<NodeLabel>();
for (NodeLabel label : labels) {
RMNodeLabel rmNodeLabel = this.labelCollections.get(label.getName());
if (rmNodeLabel != null
&& rmNodeLabel.getIsExclusive() != label.isExclusive()) {
mismatchlabels.add(label);
}
}
if (mismatchlabels.size() > 0) {
throw new IOException(
"Exclusivity cannot be modified for an existing label with : "
+ StringUtils.join(mismatchlabels.iterator(), ","));
}
}
protected String normalizeLabel(String label) { protected String normalizeLabel(String label) {
if (label != null) { if (label != null) {
return label.trim(); return label.trim();

View File

@ -70,7 +70,22 @@ public class TestCommonNodeLabelsManager extends NodeLabelTestBase {
Assert.assertTrue(mgr.getClusterNodeLabelNames().containsAll( Assert.assertTrue(mgr.getClusterNodeLabelNames().containsAll(
Sets.newHashSet("hello", "world", "hello1", "world1"))); Sets.newHashSet("hello", "world", "hello1", "world1")));
try {
mgr.addToCluserNodeLabels(Arrays.asList(NodeLabel.newInstance("hello1",
false)));
Assert.fail("IOException not thrown on exclusivity change of labels");
} catch (Exception e) {
Assert.assertTrue("IOException is expected when exclusivity is modified",
e instanceof IOException);
}
try {
mgr.addToCluserNodeLabels(Arrays.asList(NodeLabel.newInstance("hello1",
true)));
} catch (Exception e) {
Assert.assertFalse(
"IOException not expected when no change in exclusivity",
e instanceof IOException);
}
// try to remove null, empty and non-existed label, should fail // try to remove null, empty and non-existed label, should fail
for (String p : Arrays.asList(null, CommonNodeLabelsManager.NO_LABEL, "xx")) { for (String p : Arrays.asList(null, CommonNodeLabelsManager.NO_LABEL, "xx")) {
boolean caught = false; boolean caught = false;