Skip to content
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

YARN-11433. Router's main() should support generic options. #6012

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.yarn.server.globalpolicygenerator;

import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
Expand All @@ -36,6 +37,7 @@
import org.apache.hadoop.security.HttpCrossOriginFilterInitializer;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.service.CompositeService;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.JvmPauseMonitor;
import org.apache.hadoop.util.ShutdownHookManager;
import org.apache.hadoop.util.StringUtils;
Expand Down Expand Up @@ -290,7 +292,18 @@ private String getHostName(Configuration config)

public static void main(String[] argv) {
try {
startGPG(argv, new YarnConfiguration());
YarnConfiguration conf = new YarnConfiguration();
GenericOptionsParser hParser = new GenericOptionsParser(conf, argv);
argv = hParser.getRemainingArgs();
if (argv.length > 1) {
if (argv[0].equals("-format-policy-store")) {
// TODO: YARN-11561. [Federation] GPG Supports Format PolicyStateStore.
goiri marked this conversation as resolved.
Show resolved Hide resolved
} else {
printUsage(System.err);
}
} else {
startGPG(argv, conf);
}
} catch (Throwable t) {
LOG.error("Error starting global policy generator", t);
System.exit(-1);
Expand All @@ -305,4 +318,8 @@ public static long getGPGStartupTime() {
public WebApp getWebApp() {
return webApp;
}

private static void printUsage(PrintStream out) {
out.println("Usage: yarn gpg [-format-policy-store]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.assertTrue;

/**
* Unit test for GlobalPolicyGenerator.
*/
Expand Down Expand Up @@ -55,4 +59,15 @@ public void testGpgWithFederation() throws InterruptedException, TimeoutExceptio
return (services.size() == 1 && gpg.getWebApp() != null);
}, 100, 5000);
}

@Test
public void testGPGCLI() {
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
ByteArrayOutputStream dataErr = new ByteArrayOutputStream();
System.setOut(new PrintStream(dataOut));
System.setErr(new PrintStream(dataErr));
GlobalPolicyGenerator.main(new String[]{"-help", "-format-policy-store"});
assertTrue(dataErr.toString().contains(
"Usage: yarn gpg [-format-policy-store]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.yarn.server.router;

import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand All @@ -34,6 +35,7 @@
import org.apache.hadoop.security.HttpCrossOriginFilterInitializer;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.service.CompositeService;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.JvmPauseMonitor;
import org.apache.hadoop.util.ShutdownHookManager;
import org.apache.hadoop.util.StringUtils;
Expand Down Expand Up @@ -245,18 +247,26 @@ public static void main(String[] argv) {
StringUtils.startupShutdownMessage(Router.class, argv, LOG);
Router router = new Router();
try {

// Remove the old hook if we are rebooting.
if (null != routerShutdownHook) {
ShutdownHookManager.get().removeShutdownHook(routerShutdownHook);
GenericOptionsParser hParser = new GenericOptionsParser(conf, argv);
argv = hParser.getRemainingArgs();
if (argv.length > 1) {
if (argv[0].equals("-format-state-store")) {
// TODO: YARN-11548. [Federation] Router Supports Format FederationStateStore.
goiri marked this conversation as resolved.
Show resolved Hide resolved
} else if (argv[0].equals("-remove-application-from-state-store") && argv.length == 2) {
// TODO: YARN-11547. [Federation] Router Supports Remove individual application records from FederationStateStore.
} else {
printUsage(System.err);
}
} else {
// Remove the old hook if we are rebooting.
if (null != routerShutdownHook) {
ShutdownHookManager.get().removeShutdownHook(routerShutdownHook);
}
routerShutdownHook = new CompositeServiceShutdownHook(router);
ShutdownHookManager.get().addShutdownHook(routerShutdownHook, SHUTDOWN_HOOK_PRIORITY);
router.init(conf);
router.start();
}

routerShutdownHook = new CompositeServiceShutdownHook(router);
ShutdownHookManager.get().addShutdownHook(routerShutdownHook,
SHUTDOWN_HOOK_PRIORITY);

router.init(conf);
router.start();
} catch (Throwable t) {
LOG.error("Error starting Router", t);
System.exit(-1);
Expand Down Expand Up @@ -298,4 +308,8 @@ public static long getClusterTimeStamp() {
public FedAppReportFetcher getFetcher() {
return fetcher;
}

private static void printUsage(PrintStream out) {
out.println("Usage: yarn router [-format-state-store] | [-remove-application-from-state-store <appId>]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.router;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.apache.hadoop.conf.Configuration;
Expand All @@ -42,7 +43,9 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -377,4 +380,14 @@ public Locale getLocale() {
}
}

@Test
public void testRouterCLI() {
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
ByteArrayOutputStream dataErr = new ByteArrayOutputStream();
System.setOut(new PrintStream(dataOut));
System.setErr(new PrintStream(dataErr));
Router.main(new String[]{"-help", "-format-state-store"});
assertTrue(dataErr.toString().contains(
"Usage: yarn router [-format-state-store] | [-remove-application-from-state-store <appId>]"));
}
}
Loading