You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by el...@apache.org on 2020/10/05 11:49:31 UTC
[hadoop-ozone] branch master updated: HDDS-4242. Copy PrefixInfo
proto to new project hadoop-ozone/interface-storage (#1444)
This is an automated email from the ASF dual-hosted git repository.
elek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git
The following commit(s) were added to refs/heads/master by this push:
new d6d27e4 HDDS-4242. Copy PrefixInfo proto to new project hadoop-ozone/interface-storage (#1444)
d6d27e4 is described below
commit d6d27e4edb23490cb9d1496078e5bcd0e5e8d60c
Author: Rui Wang <am...@users.noreply.github.com>
AuthorDate: Mon Oct 5 04:49:22 2020 -0700
HDDS-4242. Copy PrefixInfo proto to new project hadoop-ozone/interface-storage (#1444)
---
hadoop-ozone/interface-storage/pom.xml | 30 +++++++++++
.../hadoop/ozone/om/codec/OmPrefixInfoCodec.java | 5 +-
.../hadoop/ozone/om/helpers/OmPrefixInfo.java | 13 ++---
.../hadoop/ozone/om/helpers/OzoneAclStorage.java | 63 ++++++++++++++++++++++
.../ozone/om/helpers/OzoneAclStorageUtil.java | 62 +++++++++++++++++++++
.../hadoop/ozone/om/helpers/package-info.java | 24 +++++++++
.../src/main/proto/OmStorageProtocol.proto | 60 +++++++++++++++++++++
.../hadoop/ozone/om/helpers/TestOmPrefixInfo.java | 0
.../hadoop/ozone/om/helpers/package-info.java | 24 +++++++++
9 files changed, 273 insertions(+), 8 deletions(-)
diff --git a/hadoop-ozone/interface-storage/pom.xml b/hadoop-ozone/interface-storage/pom.xml
index 43ba408..9f000bf 100644
--- a/hadoop-ozone/interface-storage/pom.xml
+++ b/hadoop-ozone/interface-storage/pom.xml
@@ -35,6 +35,11 @@
</dependency>
<dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-ozone-interface-client</artifactId>
</dependency>
@@ -63,4 +68,29 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.xolstice.maven.plugins</groupId>
+ <artifactId>protobuf-maven-plugin</artifactId>
+ <version>${protobuf-maven-plugin.version}</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>compile-protoc</id>
+ <goals>
+ <goal>compile</goal>
+ <goal>test-compile</goal>
+ </goals>
+ <configuration>
+ <protoSourceRoot>${basedir}/src/main/proto/</protoSourceRoot>
+ <protocArtifact>
+ com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
+ </protocArtifact>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmPrefixInfoCodec.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmPrefixInfoCodec.java
index 44a0741..919d972 100644
--- a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmPrefixInfoCodec.java
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmPrefixInfoCodec.java
@@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.om.codec;
import com.google.common.base.Preconditions;
import com.google.protobuf.InvalidProtocolBufferException;
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
-import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrefixInfo;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedPrefixInfo;
import org.apache.hadoop.hdds.utils.db.Codec;
@@ -44,7 +44,8 @@ public class OmPrefixInfoCodec implements Codec<OmPrefixInfo> {
.checkNotNull(rawData,
"Null byte array can't converted to real object.");
try {
- return OmPrefixInfo.getFromProtobuf(PrefixInfo.parseFrom(rawData));
+ return OmPrefixInfo.getFromProtobuf(
+ PersistedPrefixInfo.parseFrom(rawData));
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
"Can't encode the the raw data from the byte array", e);
diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java
similarity index 92%
rename from hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java
rename to hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java
index 80ca54d..a1ad55a 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java
@@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.om.helpers;
import com.google.common.base.Preconditions;
import org.apache.hadoop.ozone.OzoneAcl;
-import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrefixInfo;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedPrefixInfo;
import java.util.BitSet;
import java.util.HashMap;
@@ -150,11 +150,12 @@ public final class OmPrefixInfo extends WithObjectID {
/**
* Creates PrefixInfo protobuf from OmPrefixInfo.
*/
- public PrefixInfo getProtobuf() {
- PrefixInfo.Builder pib = PrefixInfo.newBuilder().setName(name)
+ public PersistedPrefixInfo getProtobuf() {
+ PersistedPrefixInfo.Builder pib =
+ PersistedPrefixInfo.newBuilder().setName(name)
.addAllMetadata(KeyValueUtil.toProtobuf(metadata));
if (acls != null) {
- pib.addAllAcls(OzoneAclUtil.toProtobuf(acls));
+ pib.addAllAcls(OzoneAclStorageUtil.toProtobuf(acls));
}
return pib.build();
}
@@ -164,7 +165,7 @@ public final class OmPrefixInfo extends WithObjectID {
* @param prefixInfo
* @return instance of OmPrefixInfo
*/
- public static OmPrefixInfo getFromProtobuf(PrefixInfo prefixInfo) {
+ public static OmPrefixInfo getFromProtobuf(PersistedPrefixInfo prefixInfo) {
OmPrefixInfo.Builder opib = OmPrefixInfo.newBuilder()
.setName(prefixInfo.getName());
if (prefixInfo.getMetadataList() != null) {
@@ -172,7 +173,7 @@ public final class OmPrefixInfo extends WithObjectID {
.getFromProtobuf(prefixInfo.getMetadataList()));
}
if (prefixInfo.getAclsList() != null) {
- opib.setAcls(OzoneAclUtil.fromProtobuf(prefixInfo.getAclsList()));
+ opib.setAcls(OzoneAclStorageUtil.fromProtobuf(prefixInfo.getAclsList()));
}
return opib.build();
}
diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorage.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorage.java
new file mode 100644
index 0000000..abc6359
--- /dev/null
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorage.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.ozone.om.helpers;
+
+import com.google.protobuf.ByteString;
+import java.util.BitSet;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.OzoneAcl.AclScope;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo.OzoneAclScope;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo.OzoneAclType;
+
+/**
+ * OzoneAclStorage classes define bucket ACLs used in OZONE.
+ * This class is used by storage proto only.
+ *
+ * ACLs in Ozone follow this pattern.
+ * <ul>
+ * <li>user:name:rw
+ * <li>group:name:rw
+ * <li>world::rw
+ * </ul>
+ */
+final class OzoneAclStorage {
+ /**
+ * Private constructor.
+ */
+ private OzoneAclStorage() {
+ }
+
+ public static OzoneAclInfo toProtobuf(OzoneAcl acl) {
+ OzoneAclInfo.Builder builder = OzoneAclInfo.newBuilder()
+ .setName(acl.getName())
+ .setType(OzoneAclType.valueOf(acl.getType().name()))
+ .setAclScope(OzoneAclScope.valueOf(acl.getAclScope().name()))
+ .setRights(ByteString.copyFrom(acl.getAclBitSet().toByteArray()));
+ return builder.build();
+ }
+
+ public static OzoneAcl fromProtobuf(OzoneAclInfo protoAcl) {
+ BitSet aclRights = BitSet.valueOf(protoAcl.getRights().toByteArray());
+ return new OzoneAcl(ACLIdentityType.valueOf(protoAcl.getType().name()),
+ protoAcl.getName(), aclRights,
+ AclScope.valueOf(protoAcl.getAclScope().name()));
+ }
+
+}
diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorageUtil.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorageUtil.java
new file mode 100644
index 0000000..06c6e82
--- /dev/null
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneAclStorageUtil.java
@@ -0,0 +1,62 @@
+/**
+ * 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.ozone.om.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.ozone.OzoneAcl;
+import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo;
+
+/**
+ * Helper class for ozone acls operations.
+ * This class is used by storage proto only.
+ */
+final class OzoneAclStorageUtil {
+ /**
+ * Private constructor.
+ */
+ private OzoneAclStorageUtil() {
+ }
+
+ /**
+ * Convert a list of OzoneAcl(java) to list of OzoneAclInfo(protoc).
+ * @param protoAcls
+ * @return list of OzoneAclInfo.
+ */
+ public static List<OzoneAclInfo> toProtobuf(List<OzoneAcl> protoAcls) {
+ List<OzoneAclInfo> ozoneAclInfos = new ArrayList<>();
+ for (OzoneAcl acl : protoAcls) {
+ ozoneAclInfos.add(OzoneAclStorage.toProtobuf(acl));
+ }
+ return ozoneAclInfos;
+ }
+
+ /**
+ * Convert a list of OzoneAclInfo(protoc) to list of OzoneAcl(java).
+ * @param protoAcls
+ * @return list of OzoneAcl.
+ */
+ public static List<OzoneAcl> fromProtobuf(List<OzoneAclInfo> protoAcls) {
+ List<OzoneAcl> ozoneAcls = new ArrayList<>();
+ for (OzoneAclInfo aclInfo : protoAcls) {
+ ozoneAcls.add(OzoneAclStorage.fromProtobuf(aclInfo));
+ }
+ return ozoneAcls;
+ }
+
+}
diff --git a/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/package-info.java b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/package-info.java
new file mode 100644
index 0000000..4101cf3
--- /dev/null
+++ b/hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ * <p>
+ * Utility classes to encode/decode DTO objects to/from byte array.
+ */
+
+/**
+ * Helpers for OM storage proto layer.
+ */
+package org.apache.hadoop.ozone.om.helpers;
\ No newline at end of file
diff --git a/hadoop-ozone/interface-storage/src/main/proto/OmStorageProtocol.proto b/hadoop-ozone/interface-storage/src/main/proto/OmStorageProtocol.proto
new file mode 100644
index 0000000..74b0109
--- /dev/null
+++ b/hadoop-ozone/interface-storage/src/main/proto/OmStorageProtocol.proto
@@ -0,0 +1,60 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/**
+ * These .proto interfaces are private and unstable.
+ * Please see http://wiki.apache.org/hadoop/Compatibility
+ * for what changes are allowed for a *unstable* .proto interface.
+ */
+
+syntax = "proto2";
+option java_package = "org.apache.hadoop.ozone.storage.proto";
+option java_outer_classname = "OzoneManagerStorageProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+package hadoop.ozone;
+
+import "hdds.proto";
+
+message OzoneAclInfo {
+ enum OzoneAclType {
+ USER = 1;
+ GROUP = 2;
+ WORLD = 3;
+ ANONYMOUS = 4;
+ CLIENT_IP = 5;
+ }
+
+ enum OzoneAclScope {
+ ACCESS = 0;
+ DEFAULT = 1;
+ }
+
+ required OzoneAclType type = 1;
+ required string name = 2;
+ required bytes rights = 3;
+ required OzoneAclScope aclScope = 4 [default = ACCESS];
+}
+
+message PersistedPrefixInfo {
+ required string name = 1;
+ repeated OzoneAclInfo acls = 2;
+ repeated hadoop.hdds.KeyValue metadata = 3;
+ optional uint64 objectID = 4;
+ optional uint64 updateID = 5;
+}
\ No newline at end of file
diff --git a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java b/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java
similarity index 100%
rename from hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java
rename to hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java
diff --git a/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/package-info.java b/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/package-info.java
new file mode 100644
index 0000000..bda29d2
--- /dev/null
+++ b/hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ * <p>
+ * Utility classes to encode/decode DTO objects to/from byte array.
+ */
+
+/**
+ * Unit tests for helpers in OM.
+ */
+package org.apache.hadoop.ozone.om.helpers;
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-commits-help@hadoop.apache.org