Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions hadoop-ozone/interface-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>hadoop-ozone-common</artifactId>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-ozone-interface-client</artifactId>
Expand Down Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;

Expand All @@ -44,7 +44,8 @@ public OmPrefixInfo fromPersistedFormat(byte[] rawData) throws IOException {
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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;
Expand Down Expand Up @@ -150,11 +150,12 @@ public OmPrefixInfo build() {
/**
* 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();
}
Expand All @@ -164,15 +165,15 @@ public PrefixInfo getProtobuf() {
* @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) {
opib.addAllMetadata(KeyValueUtil
.getFromProtobuf(prefixInfo.getMetadataList()));
}
if (prefixInfo.getAclsList() != null) {
opib.setAcls(OzoneAclUtil.fromProtobuf(prefixInfo.getAclsList()));
opib.setAcls(OzoneAclStorageUtil.fromProtobuf(prefixInfo.getAclsList()));
}
return opib.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to duplicate this class because the original one was used by different places. That's why I make this class package-private to make it only useable by codec classes.

/**
* 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()));
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;