Skip to content

Commit

Permalink
LIHADOOP-69035: Add router address parameter to MountTableConverter (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu Zhang authored and GitHub AE committed Jan 23, 2023
1 parent b2dcc41 commit 0e035aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
*/
public class MountTableConverter extends Configured {
private static final Logger LOG = LoggerFactory.getLogger(MountTableConverter.class);
static final String ROUTER_ADMIN_ADDRESS_FORMATTER = "%s-linkfs.grid.linkedin.com:%s";
static final String ROUTER_ADMIN_ADDRESS_FORMATTER = "%s:%s";
static final String RBF_NS_INDICATOR = "/THIS_IS_LINKFS";
private final String rbfNsSuffix;
private final String keytabPrincipal;
private final String keytabPath;
private final String clusterName;
private final String routerAddr;
private final Path mountConfigPath;
private final boolean dryRun;
private final boolean removeOld;
Expand All @@ -84,15 +84,16 @@ public class MountTableConverter extends Configured {

public static final Option RBF_NAMESPACE_SUFFIX = new Option("rbfNsSuffix", true, "RBF namespace suffix");

public static final Option CLUSTER_NAME = new Option("cluster", true, "Cluster name used to construct router admin address");
public static final Option ROUTER_ADDRESS =
new Option("routerAddr", true, "Router RPC address used to construct router admin address");

private static final Options OPTIONS = new Options().addOption(MOUNT_CONFIG_PATH)
.addOption(KEYTAB_PRINCIPAL)
.addOption(KEYTAB_PATH)
.addOption(DRY_RUN)
.addOption(REMOVE_OLD)
.addOption(RBF_NAMESPACE_SUFFIX)
.addOption(CLUSTER_NAME);
.addOption(ROUTER_ADDRESS);

public static void main(String[] args) throws Exception {
Configuration conf = new HdfsConfiguration();
Expand All @@ -105,12 +106,13 @@ public static void main(String[] args) throws Exception {
String keytabPath = commandLine.getOptionValue(KEYTAB_PATH.getOpt());
String rbfNsSuffix = commandLine.getOptionValue(RBF_NAMESPACE_SUFFIX.getOpt());
Path mountConfigPath = new Path(commandLine.getOptionValue(MOUNT_CONFIG_PATH.getOpt()));
String clusterName = commandLine.getOptionValue(CLUSTER_NAME.getOpt());
String routerAddr = commandLine.getOptionValue(ROUTER_ADDRESS.getOpt());
boolean dryRun = commandLine.hasOption(DRY_RUN.getOpt());
boolean removeOld = commandLine.hasOption(REMOVE_OLD.getOpt());

MountTableConverter adminTool =
new MountTableConverter(conf, keytabPrincipal, keytabPath, mountConfigPath, dryRun, removeOld, rbfNsSuffix, clusterName);
new MountTableConverter(conf, keytabPrincipal, keytabPath, mountConfigPath, dryRun, removeOld, rbfNsSuffix,
routerAddr);
adminTool.initClient();
adminTool.convert();
} catch (ParseException ex) {
Expand All @@ -120,30 +122,29 @@ public static void main(String[] args) throws Exception {
}

public MountTableConverter(Configuration conf, String keytabPrincipal, String keytabPath, Path mountConfigPath,
boolean dryRun, boolean removeOld, String rbfNsSuffix, String clusterName) {
boolean dryRun, boolean removeOld, String rbfNsSuffix, String routerAddr) {
super(conf);
this.keytabPrincipal = keytabPrincipal;
this.keytabPath = keytabPath;
this.mountConfigPath = mountConfigPath;
this.dryRun = dryRun;
this.removeOld = removeOld;
this.rbfNsSuffix = rbfNsSuffix;
this.clusterName = clusterName;
this.routerAddr = routerAddr;
}

public void initClient() throws IOException {
// Load client's minimum set of configurations to use kerberos
Configuration.addDefaultResource("router-client-security.xml");

if (this.clusterName != null) {
// If clusterName is null, will fall back to use local configuration DFS_ROUTER_ADMIN_ADDRESS_KEY, if
if (this.routerAddr != null) {
// If routerAddr is null, will fall back to use local configuration DFS_ROUTER_ADMIN_ADDRESS_KEY, if
// DFS_ROUTER_ADMIN_ADDRESS_KEY is not set, will use DFS_ROUTER_ADMIN_ADDRESS_DEFAULT as router.admin-address.
final String routerAdminAddr =
String.format(ROUTER_ADMIN_ADDRESS_FORMATTER, this.clusterName, RBFConfigKeys.DFS_ROUTER_ADMIN_PORT_DEFAULT);
String.format(ROUTER_ADMIN_ADDRESS_FORMATTER, this.routerAddr, RBFConfigKeys.DFS_ROUTER_ADMIN_PORT_DEFAULT);
getConf().set(RBFConfigKeys.DFS_ROUTER_ADMIN_ADDRESS_KEY, routerAdminAddr);
}


UserGroupInformation.loginUserFromKeytab(keytabPrincipal, new File(keytabPath).getAbsolutePath());
try {
String address = getConf().getTrimmed(RBFConfigKeys.DFS_ROUTER_ADMIN_ADDRESS_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void clusterSetup() throws Exception {

Configuration routerConf = new Configuration();
InetSocketAddress routerSocket = router.getAdminServerAddress();
// clusterName is null, we use routerSocket to overwrite DFS_ROUTER_ADMIN_ADDRESS_KEY for unit tests.
// routerAddr is null, we use routerSocket to overwrite DFS_ROUTER_ADMIN_ADDRESS_KEY for unit tests.
routerConf.setSocketAddr(RBFConfigKeys.DFS_ROUTER_ADMIN_ADDRESS_KEY, routerSocket);
converter =
new MountTableConverter(routerConf, "hdfs", "/dummy.headless.keytab", new Path("file:///dummy.json"), true,
Expand All @@ -73,12 +73,12 @@ public static void tearDownCluster() {

@Test
public void testGetRouterAdminAddr() throws IOException {
String clusterName = "cluster01";
String routerAddr = "0.0.0.0";
String expectedRouterAdminAddr =
String.format(ROUTER_ADMIN_ADDRESS_FORMATTER, clusterName, RBFConfigKeys.DFS_ROUTER_ADMIN_PORT_DEFAULT);
String.format(ROUTER_ADMIN_ADDRESS_FORMATTER, routerAddr, RBFConfigKeys.DFS_ROUTER_ADMIN_PORT_DEFAULT);
MountTableConverter remoteConverter =
new MountTableConverter(new Configuration(), "hdfs", "/dummy.headless.keytab", new Path("file:///dummy.json"),
true, false, "fed", clusterName);
true, false, "fed", routerAddr);

remoteConverter.initClient();
assertEquals(expectedRouterAdminAddr,
Expand Down

0 comments on commit 0e035aa

Please sign in to comment.