steveloughran commented on code in PR #8196: URL: https://github.com/apache/hadoop/pull/8196#discussion_r2742982189
########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.apache.hadoop.test.LambdaTestUtils; +import org.junit.jupiter.api.Test; +import sample.SampleStep; + +import java.io.IOException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TestNodePlan { + + @Test + public void testNodePlan() throws IOException { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + MoveStep moveStep = new MoveStep(); + moveStep.setBandwidth(12345); + moveStep.setBytesToMove(98765); + moveStep.setIdealStorage(1.234); + moveStep.setMaxDiskErrors(4567); + moveStep.setVolumeSetID("id1234"); + nodePlan.addStep(moveStep); + String json = nodePlan.toJson(); + assertThat(NodePlan.parseJson(json)).isNotNull(); + } + + @Test + public void testNodePlanWithDisallowedStep() throws Exception { + NodePlan nodePlan = new NodePlan("datanode1234", 1234); + Step sampleStep = new SampleStep(); + sampleStep.setBandwidth(12345); + sampleStep.setMaxDiskErrors(4567); + nodePlan.addStep(sampleStep); + String json = nodePlan.toJson(); + IOException ex = LambdaTestUtils.intercept(IOException.class, () -> NodePlan.parseJson(json)); + assertThat(ex.getMessage()) + .isEqualTo("Invalid @class value in NodePlan JSON: sample.SampleStep"); Review Comment: Factor the toJson and intercept to a new assert, use everywhere, moving the string to check into intercept(). intercept() knows to include the rejected exception if there's no match, which is invaluable debugging things. (oh, it's a toString().contains() check, FWIW) ``` assertNodePlanInvalid(nodePlan) { LambdaTestUtils.intercept(IOException.class, "Invalid @class value in NodePlan JSON: sample.SampleStep", () -> NodePlan.parseJson(nodePlan.toJson())); } ``` Apply here and in the steps below, just to reduce duplication in test code. ########## hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSConfigKeys.java: ########## @@ -2110,4 +2110,6 @@ public class DFSConfigKeys extends CommonConfigurationKeys { public static final long DFS_LEASE_HARDLIMIT_DEFAULT = HdfsClientConfigKeys.DFS_LEASE_HARDLIMIT_DEFAULT; + public static final String SUPPORTED_PACKAGES_CONFIG_NAME = Review Comment: add a javadoc ```java /* * List of packages from which Step implementations will be loaded when deserializing * Node Plans: {@value}. */ ``` ########## hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/TestNodePlan.java: ########## @@ -0,0 +1,173 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.hdfs.server.diskbalancer.planner; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerVolume; +import org.apache.hadoop.test.LambdaTestUtils; +import org.junit.jupiter.api.Test; +import sample.SampleStep; Review Comment: can we have import ordering in new class of ``` java.* non-apache org.apache.* static imports ``` It's the nominal structure ########## hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/planner/NodePlan.java: ########## @@ -243,22 +244,11 @@ private static boolean stepClassIsAllowed(String className) { return false; } - private static List<String> getAllowedPackages() { - String packages = CONFIGURATION.get(SUPPORTED_PACKAGES_CONFIG_NAME); - return parseCsvLine(packages); - } - - static List<String> parseCsvLine(final String line) { - if (line == null) { - return Collections.emptyList(); - } - List<String> values = new LinkedList<>(); - for (String value : line.split(",")) { - String trimmedValue = value.trim(); - if (!trimmedValue.isBlank()) { - values.add(trimmedValue); - } - } - return values; + private static Collection<String> getAllowedPackages() { + return CONFIGURATION.getStringCollection(SUPPORTED_PACKAGES_CONFIG_NAME) + .stream() + .map(String::trim) Review Comment: needless, they get trimmed already. Do leave that filter in though as I'm not sure what happens there -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
