forked from apache/ozone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDDS-7830. SCM API for OM and Datanode to get secret keys (apache#4345)
- Loading branch information
Showing
17 changed files
with
672 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
hadoop-hdds/common/src/main/java/org/apache/hadoop/util/ProtobufUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.apache.hadoop.util; | ||
|
||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Contains utilities to ease common protobuf to java object conversions. | ||
*/ | ||
public final class ProtobufUtils { | ||
private ProtobufUtils() { | ||
} | ||
|
||
public static HddsProtos.UUID toProtobuf(UUID uuid) { | ||
return HddsProtos.UUID.newBuilder() | ||
.setMostSigBits(uuid.getMostSignificantBits()) | ||
.setLeastSigBits(uuid.getLeastSignificantBits()) | ||
.build(); | ||
} | ||
|
||
public static UUID fromProtobuf(HddsProtos.UUID proto) { | ||
return new UUID(proto.getMostSigBits(), proto.getLeastSigBits()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/utils/TestProtobufUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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.utils; | ||
|
||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.apache.hadoop.util.ProtobufUtils.fromProtobuf; | ||
import static org.apache.hadoop.util.ProtobufUtils.toProtobuf; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Test-cases for {@link org.apache.hadoop.util.ProtobufUtils}. | ||
*/ | ||
public class TestProtobufUtils { | ||
@Test | ||
public void testUuidToProtobuf() { | ||
UUID object = UUID.randomUUID(); | ||
HddsProtos.UUID protobuf = toProtobuf(object); | ||
assertEquals(object.getLeastSignificantBits(), protobuf.getLeastSigBits()); | ||
assertEquals(object.getMostSignificantBits(), protobuf.getMostSigBits()); | ||
} | ||
|
||
@Test | ||
public void testUuidConversion() { | ||
UUID original = UUID.randomUUID(); | ||
HddsProtos.UUID protobuf = toProtobuf(original); | ||
UUID deserialized = fromProtobuf(protobuf); | ||
assertEquals(original, deserialized); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.