-
Couldn't load subscription status.
- Fork 9.1k
HDDS-2019. Handle Set DtService of token in S3Gateway for OM HA. #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
091b417
HDDS-2019. Handle Set DtService of token in S3Gateway for OM HA.
bharatviswa504 921d521
few minor changes.:
bharatviswa504 0f88603
fix review comments.
bharatviswa504 1507209
add test
bharatviswa504 5965226
fix jenkins issues.
bharatviswa504 9aebf0c
address review comments.
bharatviswa504 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
130 changes: 130 additions & 0 deletions
130
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestOzoneS3Util.java
This file contains hidden or 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,130 @@ | ||
| /** | ||
| * 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.s3.util; | ||
|
|
||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.OmUtils; | ||
| import org.apache.hadoop.ozone.om.OMConfigKeys; | ||
| import org.apache.hadoop.security.SecurityUtil; | ||
| import org.apache.hadoop.test.GenericTestUtils; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_TOKEN_SERVICE_USE_IP; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| /** | ||
| * Class used to test OzoneS3Util. | ||
| */ | ||
| public class TestOzoneS3Util { | ||
|
|
||
|
|
||
| private OzoneConfiguration configuration; | ||
| private String serviceID = "omService"; | ||
|
|
||
| @Before | ||
| public void setConf() { | ||
| configuration = new OzoneConfiguration(); | ||
|
|
||
| String nodeIDs = "om1,om2,om3"; | ||
| configuration.set(OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY, serviceID); | ||
| configuration.set(OMConfigKeys.OZONE_OM_NODES_KEY + "." + serviceID, | ||
| nodeIDs); | ||
| configuration.setBoolean(HADOOP_SECURITY_TOKEN_SERVICE_USE_IP, false); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBuildServiceNameForToken() { | ||
|
|
||
| Collection<String> nodeIDList = OmUtils.getOMNodeIds(configuration, | ||
| serviceID); | ||
|
|
||
| configuration.set(OmUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY, | ||
| serviceID, "om1"), "om1:9862"); | ||
| configuration.set(OmUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY, | ||
| serviceID, "om2"), "om2:9862"); | ||
| configuration.set(OmUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY, | ||
| serviceID, "om3"), "om3:9862"); | ||
|
|
||
| String expectedOmServiceAddress = buildServiceAddress(nodeIDList); | ||
|
|
||
| SecurityUtil.setConfiguration(configuration); | ||
| String omserviceAddr = OzoneS3Util.buildServiceNameForToken(configuration, | ||
| serviceID, nodeIDList); | ||
|
|
||
| Assert.assertEquals(expectedOmServiceAddress, omserviceAddr); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testBuildServiceNameForTokenIncorrectConfig() { | ||
|
|
||
| Collection<String> nodeIDList = OmUtils.getOMNodeIds(configuration, | ||
| serviceID); | ||
|
|
||
| // Don't set om3 node rpc address. Here we are skipping setting of one of | ||
| // the OM address. So buildServiceNameForToken will fail. | ||
| configuration.set(OmUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY, | ||
| serviceID, "om1"), "om1:9862"); | ||
| configuration.set(OmUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY, | ||
| serviceID, "om2"), "om2:9862"); | ||
|
|
||
|
|
||
| SecurityUtil.setConfiguration(configuration); | ||
|
|
||
| try { | ||
| OzoneS3Util.buildServiceNameForToken(configuration, | ||
| serviceID, nodeIDList); | ||
| fail("testBuildServiceNameForTokenIncorrectConfig failed"); | ||
| } catch (IllegalArgumentException ex) { | ||
| GenericTestUtils.assertExceptionContains("Could not find rpcAddress " + | ||
| "for", ex); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Build serviceName from list of node ids. | ||
| * @param nodeIDList | ||
| * @return service name for token. | ||
| */ | ||
| private String buildServiceAddress(Collection<String> nodeIDList) { | ||
| StringBuilder omServiceAddrBuilder = new StringBuilder(); | ||
| int nodesLength = nodeIDList.size(); | ||
| int counter = 0; | ||
| for (String nodeID : nodeIDList) { | ||
| counter++; | ||
| String addr = configuration.get(OmUtils.addKeySuffixes( | ||
| OMConfigKeys.OZONE_OM_ADDRESS_KEY, serviceID, nodeID)); | ||
|
|
||
| if (counter != nodesLength) { | ||
| omServiceAddrBuilder.append(addr + ","); | ||
| } else { | ||
| omServiceAddrBuilder.append(addr); | ||
| } | ||
| } | ||
|
|
||
| return omServiceAddrBuilder.toString(); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.