You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2021/06/22 16:34:10 UTC

[GitHub] [ozone] umamaheswararao commented on a change in pull request #2345: HDDS-5354. Allow to restrict available ReplicationConfig

umamaheswararao commented on a change in pull request #2345:
URL: https://github.com/apache/ozone/pull/2345#discussion_r656392317



##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfigValidator.java
##########
@@ -0,0 +1,63 @@
+/**
+ * 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.hdds.client;
+
+import org.apache.hadoop.hdds.conf.Config;
+import org.apache.hadoop.hdds.conf.ConfigGroup;
+import org.apache.hadoop.hdds.conf.ConfigTag;
+import org.apache.hadoop.hdds.conf.ConfigType;
+import org.apache.hadoop.hdds.conf.PostConstruct;
+
+import java.util.regex.Pattern;
+
+/**
+ * Validator to check if replication config is enabled.
+ */
+@ConfigGroup(prefix = "ozone.replication")
+public class ReplicationConfigValidator {
+
+  @Config(key = "enabled",

Review comment:
       Good point. This default pattern covering all replication options available, but not only EC replications. Not sure using "schemes" is better here. May be ozone.replication.enabled.pattern or ozone.replicationconfig.supported.pattern ?
   Just a thought.

##########
File path: hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/client/TestReplicationConfigValidator.java
##########
@@ -0,0 +1,77 @@
+/**
+ * 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.hdds.client;
+
+import org.apache.hadoop.hdds.conf.InMemoryConfiguration;
+import org.apache.hadoop.hdds.conf.MutableConfigurationSource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE;
+import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.THREE;
+
+/**
+ * Test ReplicationConfig validator.
+ */
+public class TestReplicationConfigValidator {
+
+  @Test
+  public void testValidation() {
+    MutableConfigurationSource config = new InMemoryConfiguration();
+
+    final ReplicationConfigValidator validator =
+        config.getObject(ReplicationConfigValidator.class);
+
+    validator.validate(new RatisReplicationConfig(THREE));
+    validator.validate(new RatisReplicationConfig(ONE));
+    validator.validate(new StandaloneReplicationConfig(THREE));
+    validator.validate(new StandaloneReplicationConfig(ONE));
+
+  }
+
+  @Test
+  public void testWithoutValidation() {
+    MutableConfigurationSource config = new InMemoryConfiguration();
+    config.set("ozone.replication.enabled", "");
+
+    final ReplicationConfigValidator validator =
+        config.getObject(ReplicationConfigValidator.class);
+
+    validator.validate(new RatisReplicationConfig(THREE));
+    validator.validate(new StandaloneReplicationConfig(ONE));
+
+  }
+
+  @Test
+  public void testCustomValidation() {
+    MutableConfigurationSource config = new InMemoryConfiguration();
+    config.set("ozone.replication.enabled", "RATIS/THREE");
+
+    final ReplicationConfigValidator validator =
+        config.getObject(ReplicationConfigValidator.class);
+
+    validator.validate(new RatisReplicationConfig(THREE));
+
+    try {
+      validator.validate(new RatisReplicationConfig(ONE));
+      Assert.fail("Exception is expected");
+    } catch (IllegalArgumentException ex) {

Review comment:
       probably you can have expected exception annotation at testname header?




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org