This is an automated email from the ASF dual-hosted git repository.
umamahesh pushed a commit to branch HDDS-3816-ec
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/HDDS-3816-ec by this push:
new 9e0a2fc HDDS-5247. EC: Create ECReplicationConfig on client side
based on input string (#2331)
9e0a2fc is described below
commit 9e0a2fc4e2bd9051a56da118111cc978e172dc46
Author: Elek, Márton <[email protected]>
AuthorDate: Mon Jun 21 17:08:21 2021 +0200
HDDS-5247. EC: Create ECReplicationConfig on client side based on input
string (#2331)
---
.../hadoop/hdds/client/ECReplicationConfig.java | 21 +++++++++-
.../hadoop/hdds/client/ReplicationConfig.java | 2 +
.../hdds/client/TestECReplicationConfig.java | 49 ++++++++++++++++++++++
3 files changed, 71 insertions(+), 1 deletion(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ECReplicationConfig.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ECReplicationConfig.java
index 5b7d033..6ec961e 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ECReplicationConfig.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ECReplicationConfig.java
@@ -21,12 +21,16 @@ package org.apache.hadoop.hdds.client;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Replication configuration for EC replication.
*/
public class ECReplicationConfig implements ReplicationConfig {
-
+
+ private static final Pattern STRING_FORMAT =
Pattern.compile("(\\d+)-(\\d+)");
+
private int data;
private int parity;
@@ -36,6 +40,21 @@ public class ECReplicationConfig implements
ReplicationConfig {
this.parity = parity;
}
+ public ECReplicationConfig(String string) {
+ final Matcher matcher = STRING_FORMAT.matcher(string);
+ if (!matcher.matches()) {
+ throw new IllegalArgumentException("EC replication config should be " +
+ "defined in the form 3-2, 6-3 or 10-4");
+ }
+
+ data = Integer.parseInt(matcher.group(1));
+ parity = Integer.parseInt(matcher.group(2));
+ if (data <= 0 || parity <= 0) {
+ throw new IllegalArgumentException("Data and parity part in EC " +
+ "replication config supposed to be positive numbers");
+ }
+ }
+
public ECReplicationConfig(
HddsProtos.ECReplicationConfig ecReplicationConfig) {
this.data = ecReplicationConfig.getData();
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
index a4b9f40..761f0a8 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/ReplicationConfig.java
@@ -131,6 +131,8 @@ public interface ReplicationConfig {
return new RatisReplicationConfig(replication);
case STAND_ALONE:
return new StandaloneReplicationConfig(replication);
+ case EC:
+ return new ECReplicationConfig(replication);
default:
throw new UnsupportedOperationException(
"String based replication config initialization is not supported for
"
diff --git
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/client/TestECReplicationConfig.java
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/client/TestECReplicationConfig.java
new file mode 100644
index 0000000..18956c2
--- /dev/null
+++
b/hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/client/TestECReplicationConfig.java
@@ -0,0 +1,49 @@
+/**
+ * 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.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit test for ECReplicationConfig.
+ */
+public class TestECReplicationConfig {
+
+
+ @Test
+ public void testStringParsing() {
+ final ECReplicationConfig ec = new ECReplicationConfig("3-2");
+ Assert.assertEquals(ec.getData(), 3);
+ Assert.assertEquals(ec.getParity(), 2);
+ }
+
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testStringParsingWithString() {
+ new ECReplicationConfig("x3-2");
+ }
+
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testStringParsingWithZero() {
+ new ECReplicationConfig("3-0");
+ }
+
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]