Skip to content

Commit d6d27e4

Browse files
authored
HDDS-4242. Copy PrefixInfo proto to new project hadoop-ozone/interface-storage (#1444)
1 parent 4ad0318 commit d6d27e4

File tree

9 files changed

+273
-8
lines changed

9 files changed

+273
-8
lines changed

hadoop-ozone/interface-storage/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<artifactId>hadoop-ozone-common</artifactId>
3535
</dependency>
3636

37+
<dependency>
38+
<groupId>com.google.protobuf</groupId>
39+
<artifactId>protobuf-java</artifactId>
40+
</dependency>
41+
3742
<dependency>
3843
<groupId>org.apache.hadoop</groupId>
3944
<artifactId>hadoop-ozone-interface-client</artifactId>
@@ -63,4 +68,29 @@
6368
</dependency>
6469

6570
</dependencies>
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.xolstice.maven.plugins</groupId>
75+
<artifactId>protobuf-maven-plugin</artifactId>
76+
<version>${protobuf-maven-plugin.version}</version>
77+
<extensions>true</extensions>
78+
<executions>
79+
<execution>
80+
<id>compile-protoc</id>
81+
<goals>
82+
<goal>compile</goal>
83+
<goal>test-compile</goal>
84+
</goals>
85+
<configuration>
86+
<protoSourceRoot>${basedir}/src/main/proto/</protoSourceRoot>
87+
<protocArtifact>
88+
com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
89+
</protocArtifact>
90+
</configuration>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
</plugins>
95+
</build>
6696
</project>

hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/codec/OmPrefixInfoCodec.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.google.common.base.Preconditions;
2121
import com.google.protobuf.InvalidProtocolBufferException;
2222
import org.apache.hadoop.ozone.om.helpers.OmPrefixInfo;
23-
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrefixInfo;
23+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedPrefixInfo;
2424

2525
import org.apache.hadoop.hdds.utils.db.Codec;
2626

@@ -44,7 +44,8 @@ public OmPrefixInfo fromPersistedFormat(byte[] rawData) throws IOException {
4444
.checkNotNull(rawData,
4545
"Null byte array can't converted to real object.");
4646
try {
47-
return OmPrefixInfo.getFromProtobuf(PrefixInfo.parseFrom(rawData));
47+
return OmPrefixInfo.getFromProtobuf(
48+
PersistedPrefixInfo.parseFrom(rawData));
4849
} catch (InvalidProtocolBufferException e) {
4950
throw new IllegalArgumentException(
5051
"Can't encode the the raw data from the byte array", e);

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java renamed to hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/helpers/OmPrefixInfo.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import com.google.common.base.Preconditions;
2222
import org.apache.hadoop.ozone.OzoneAcl;
23-
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrefixInfo;
23+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedPrefixInfo;
2424

2525
import java.util.BitSet;
2626
import java.util.HashMap;
@@ -150,11 +150,12 @@ public OmPrefixInfo build() {
150150
/**
151151
* Creates PrefixInfo protobuf from OmPrefixInfo.
152152
*/
153-
public PrefixInfo getProtobuf() {
154-
PrefixInfo.Builder pib = PrefixInfo.newBuilder().setName(name)
153+
public PersistedPrefixInfo getProtobuf() {
154+
PersistedPrefixInfo.Builder pib =
155+
PersistedPrefixInfo.newBuilder().setName(name)
155156
.addAllMetadata(KeyValueUtil.toProtobuf(metadata));
156157
if (acls != null) {
157-
pib.addAllAcls(OzoneAclUtil.toProtobuf(acls));
158+
pib.addAllAcls(OzoneAclStorageUtil.toProtobuf(acls));
158159
}
159160
return pib.build();
160161
}
@@ -164,15 +165,15 @@ public PrefixInfo getProtobuf() {
164165
* @param prefixInfo
165166
* @return instance of OmPrefixInfo
166167
*/
167-
public static OmPrefixInfo getFromProtobuf(PrefixInfo prefixInfo) {
168+
public static OmPrefixInfo getFromProtobuf(PersistedPrefixInfo prefixInfo) {
168169
OmPrefixInfo.Builder opib = OmPrefixInfo.newBuilder()
169170
.setName(prefixInfo.getName());
170171
if (prefixInfo.getMetadataList() != null) {
171172
opib.addAllMetadata(KeyValueUtil
172173
.getFromProtobuf(prefixInfo.getMetadataList()));
173174
}
174175
if (prefixInfo.getAclsList() != null) {
175-
opib.setAcls(OzoneAclUtil.fromProtobuf(prefixInfo.getAclsList()));
176+
opib.setAcls(OzoneAclStorageUtil.fromProtobuf(prefixInfo.getAclsList()));
176177
}
177178
return opib.build();
178179
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.ozone.om.helpers;
19+
20+
import com.google.protobuf.ByteString;
21+
import java.util.BitSet;
22+
import org.apache.hadoop.ozone.OzoneAcl;
23+
import org.apache.hadoop.ozone.OzoneAcl.AclScope;
24+
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
25+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo;
26+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo.OzoneAclScope;
27+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo.OzoneAclType;
28+
29+
/**
30+
* OzoneAclStorage classes define bucket ACLs used in OZONE.
31+
* This class is used by storage proto only.
32+
*
33+
* ACLs in Ozone follow this pattern.
34+
* <ul>
35+
* <li>user:name:rw
36+
* <li>group:name:rw
37+
* <li>world::rw
38+
* </ul>
39+
*/
40+
final class OzoneAclStorage {
41+
/**
42+
* Private constructor.
43+
*/
44+
private OzoneAclStorage() {
45+
}
46+
47+
public static OzoneAclInfo toProtobuf(OzoneAcl acl) {
48+
OzoneAclInfo.Builder builder = OzoneAclInfo.newBuilder()
49+
.setName(acl.getName())
50+
.setType(OzoneAclType.valueOf(acl.getType().name()))
51+
.setAclScope(OzoneAclScope.valueOf(acl.getAclScope().name()))
52+
.setRights(ByteString.copyFrom(acl.getAclBitSet().toByteArray()));
53+
return builder.build();
54+
}
55+
56+
public static OzoneAcl fromProtobuf(OzoneAclInfo protoAcl) {
57+
BitSet aclRights = BitSet.valueOf(protoAcl.getRights().toByteArray());
58+
return new OzoneAcl(ACLIdentityType.valueOf(protoAcl.getType().name()),
59+
protoAcl.getName(), aclRights,
60+
AclScope.valueOf(protoAcl.getAclScope().name()));
61+
}
62+
63+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.ozone.om.helpers;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import org.apache.hadoop.ozone.OzoneAcl;
23+
import org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.OzoneAclInfo;
24+
25+
/**
26+
* Helper class for ozone acls operations.
27+
* This class is used by storage proto only.
28+
*/
29+
final class OzoneAclStorageUtil {
30+
/**
31+
* Private constructor.
32+
*/
33+
private OzoneAclStorageUtil() {
34+
}
35+
36+
/**
37+
* Convert a list of OzoneAcl(java) to list of OzoneAclInfo(protoc).
38+
* @param protoAcls
39+
* @return list of OzoneAclInfo.
40+
*/
41+
public static List<OzoneAclInfo> toProtobuf(List<OzoneAcl> protoAcls) {
42+
List<OzoneAclInfo> ozoneAclInfos = new ArrayList<>();
43+
for (OzoneAcl acl : protoAcls) {
44+
ozoneAclInfos.add(OzoneAclStorage.toProtobuf(acl));
45+
}
46+
return ozoneAclInfos;
47+
}
48+
49+
/**
50+
* Convert a list of OzoneAclInfo(protoc) to list of OzoneAcl(java).
51+
* @param protoAcls
52+
* @return list of OzoneAcl.
53+
*/
54+
public static List<OzoneAcl> fromProtobuf(List<OzoneAclInfo> protoAcls) {
55+
List<OzoneAcl> ozoneAcls = new ArrayList<>();
56+
for (OzoneAclInfo aclInfo : protoAcls) {
57+
ozoneAcls.add(OzoneAclStorage.fromProtobuf(aclInfo));
58+
}
59+
return ozoneAcls;
60+
}
61+
62+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
* <p>
18+
* Utility classes to encode/decode DTO objects to/from byte array.
19+
*/
20+
21+
/**
22+
* Helpers for OM storage proto layer.
23+
*/
24+
package org.apache.hadoop.ozone.om.helpers;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* These .proto interfaces are private and unstable.
21+
* Please see http://wiki.apache.org/hadoop/Compatibility
22+
* for what changes are allowed for a *unstable* .proto interface.
23+
*/
24+
25+
syntax = "proto2";
26+
option java_package = "org.apache.hadoop.ozone.storage.proto";
27+
option java_outer_classname = "OzoneManagerStorageProtos";
28+
option java_generic_services = true;
29+
option java_generate_equals_and_hash = true;
30+
package hadoop.ozone;
31+
32+
import "hdds.proto";
33+
34+
message OzoneAclInfo {
35+
enum OzoneAclType {
36+
USER = 1;
37+
GROUP = 2;
38+
WORLD = 3;
39+
ANONYMOUS = 4;
40+
CLIENT_IP = 5;
41+
}
42+
43+
enum OzoneAclScope {
44+
ACCESS = 0;
45+
DEFAULT = 1;
46+
}
47+
48+
required OzoneAclType type = 1;
49+
required string name = 2;
50+
required bytes rights = 3;
51+
required OzoneAclScope aclScope = 4 [default = ACCESS];
52+
}
53+
54+
message PersistedPrefixInfo {
55+
required string name = 1;
56+
repeated OzoneAclInfo acls = 2;
57+
repeated hadoop.hdds.KeyValue metadata = 3;
58+
optional uint64 objectID = 4;
59+
optional uint64 updateID = 5;
60+
}

hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java renamed to hadoop-ozone/interface-storage/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmPrefixInfo.java

File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
* <p>
18+
* Utility classes to encode/decode DTO objects to/from byte array.
19+
*/
20+
21+
/**
22+
* Unit tests for helpers in OM.
23+
*/
24+
package org.apache.hadoop.ozone.om.helpers;

0 commit comments

Comments
 (0)