Skip to content

Commit d5ef38b

Browse files
adoroszlaixiaoyuyao
authored andcommitted
HDDS-1822. NPE in SCMCommonPolicy.chooseDatanodes (#1120)
1 parent 9838a47 commit d5ef38b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMCommonPolicy.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public List<DatanodeDetails> chooseDatanodes(
109109
int nodesRequired, final long sizeRequired) throws SCMException {
110110
List<DatanodeDetails> healthyNodes =
111111
nodeManager.getNodes(HddsProtos.NodeState.HEALTHY);
112-
healthyNodes.removeAll(excludedNodes);
112+
if (excludedNodes != null) {
113+
healthyNodes.removeAll(excludedNodes);
114+
}
113115
String msg;
114116
if (healthyNodes.size() == 0) {
115117
msg = "No healthy node found to allocate container.";

hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/TestContainerPlacementFactory.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public class TestContainerPlacementFactory {
6363
public void setup() {
6464
//initialize network topology instance
6565
conf = new OzoneConfiguration();
66+
}
67+
68+
@Test
69+
public void testRackAwarePolicy() throws IOException {
70+
conf.set(ScmConfigKeys.OZONE_SCM_CONTAINER_PLACEMENT_IMPL_KEY,
71+
SCMContainerPlacementRackAware.class.getName());
72+
6673
NodeSchema[] schemas = new NodeSchema[]
6774
{ROOT_SCHEMA, RACK_SCHEMA, LEAF_SCHEMA};
6875
NodeSchemaManager.getInstance().init(schemas, true);
@@ -91,11 +98,7 @@ public void setup() {
9198
.thenReturn(new SCMNodeMetric(storageCapacity, 80L, 20L));
9299
when(nodeManager.getNodeStat(datanodes.get(4)))
93100
.thenReturn(new SCMNodeMetric(storageCapacity, 70L, 30L));
94-
}
95-
96101

97-
@Test
98-
public void testDefaultPolicy() throws IOException {
99102
ContainerPlacementPolicy policy = ContainerPlacementPolicyFactory
100103
.getPolicy(conf, nodeManager, cluster, true);
101104

@@ -111,14 +114,21 @@ public void testDefaultPolicy() throws IOException {
111114
datanodeDetails.get(2)));
112115
}
113116

117+
@Test
118+
public void testDefaultPolicy() throws IOException {
119+
ContainerPlacementPolicy policy = ContainerPlacementPolicyFactory
120+
.getPolicy(conf, null, null, true);
121+
Assert.assertSame(SCMContainerPlacementRandom.class, policy.getClass());
122+
}
123+
114124
/**
115125
* A dummy container placement implementation for test.
116126
*/
117-
public class DummyImpl implements ContainerPlacementPolicy {
127+
public static class DummyImpl implements ContainerPlacementPolicy {
118128
@Override
119129
public List<DatanodeDetails> chooseDatanodes(
120130
List<DatanodeDetails> excludedNodes, List<DatanodeDetails> favoredNodes,
121-
int nodesRequired, long sizeRequired) throws IOException {
131+
int nodesRequired, long sizeRequired) {
122132
return null;
123133
}
124134
}
@@ -127,8 +137,7 @@ public List<DatanodeDetails> chooseDatanodes(
127137
public void testConstuctorNotFound() throws SCMException {
128138
// set a placement class which does't have the right constructor implemented
129139
conf.set(ScmConfigKeys.OZONE_SCM_CONTAINER_PLACEMENT_IMPL_KEY,
130-
"org.apache.hadoop.hdds.scm.container.placement.algorithms." +
131-
"TestContainerPlacementFactory$DummyImpl");
140+
DummyImpl.class.getName());
132141
ContainerPlacementPolicyFactory.getPolicy(conf, null, null, true);
133142
}
134143

0 commit comments

Comments
 (0)