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 13:06:26 UTC

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

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



##########
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",
+      defaultValue = "^((STANDALONE|RATIS)/(ONE|THREE))|(EC/(3-2|6-3|10-4))$",
+      type = ConfigType.STRING,
+      description = "Regular expression to restrict enabled " +
+          "replication schemes",
+      tags = ConfigTag.STORAGE)
+  private String validationPattern;
+
+  private Pattern validationRegexp;
+
+  @PostConstruct
+  public void init() {
+    if (validationPattern != null && !validationPattern.equals("")) {
+      validationRegexp = Pattern.compile(validationPattern);
+    }
+  }
+
+  public ReplicationConfig validate(ReplicationConfig replicationConfig) {
+    if (validationRegexp != null) {
+      if (!validationRegexp.matcher(replicationConfig.toString()).find()) {

Review comment:
       I would like to suggest calling `matches()` instead of `find()`.  This would allow a bit simpler pattern and avoiding some potential mistakes in custom patterns (e.g. unintentionally omitting the enclosing `^()$`).

##########
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:
       To me `ozone.replication.enabled` key suggests that replication can be enabled or disabled completely.  Wouldn't `ozone.replication.enabled.schemes.pattern` be better?




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