phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix-queryserver] joshelser commented on a change in pull request #5: PHOENIX-5255: Create Orchestrator for QueryServerCanaryTool in phoenix-queryserver project
Date Wed, 15 May 2019 14:57:28 GMT
joshelser commented on a change in pull request #5: PHOENIX-5255: Create Orchestrator for QueryServerCanaryTool
in phoenix-queryserver project
URL: https://github.com/apache/phoenix-queryserver/pull/5#discussion_r284300849
 
 

 ##########
 File path: queryserver-orchestrator/src/main/java/org/apache/phoenix/queryserver/orchestrator/QueryServerCanaryOrchestrator.java
 ##########
 @@ -0,0 +1,117 @@
+package org.apache.phoenix.queryserver.orchestrator;
+
+import net.sourceforge.argparse4j.ArgumentParsers;
+import net.sourceforge.argparse4j.inf.ArgumentParser;
+import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import net.sourceforge.argparse4j.inf.Namespace;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.BoundedExponentialBackoffRetry;
+
+import org.apache.curator.utils.CloseableUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class QueryServerCanaryOrchestrator {
+	private static final Logger logger = LoggerFactory.getLogger(QueryServerCanaryOrchestrator.class);
+
+	private static String PATH = "/pqs/leader";
+
+	private static Namespace parseArgs(String[] args) {
+
+		ArgumentParser parser = ArgumentParsers.newFor("PQS Canary Orchestrator").build()
+				.description("PQS Canary Orchestrator");
+
+		parser.addArgument("--zkpath", "-zkp").type(String.class).nargs("?").setDefault(PATH)
+				.help("ZKNode path default: " + PATH);
+
+		parser.addArgument("--hostname", "-hn").type(String.class).nargs("?").help("Hostname on
"
+				+ "which PQS is running.");
+
+		parser.addArgument("--port", "-p").type(String.class).nargs("?").help("Port on which PQS
" +
+				"" + "" + "" + "" + "" + "" + "" + "is running.");
+
+		parser.addArgument("--constring", "-cs").type(String.class).nargs("?").help("Pass an "
+
+				"explicit " + "connection String to connect to PQS. default: null");
+
+		parser.addArgument("--timeout", "-t").type(String.class).nargs("?").setDefault("120")
+				.help("Maximum time for " + "which the app should run before returning error. " +
+						"default: 120 sec");
+
+		parser.addArgument("--testtable", "-tt").type(String.class).nargs("?").setDefault
+				("PQSTEST").help("Custom " + "name for the test table. default: PQSTEST");
+
+		parser.addArgument("--logsinkclass", "-lsc").type(String.class).nargs("?").setDefault
+				("org.apache.phoenix" + ".queryserver.tool.QueryServerCanaryTool$StdOutSink")
+				.help("Path to a Custom implementation for log " + "sink class. default: stdout");
+
+		parser.addArgument("--zkurl", "-zk").type(String.class).help("URL for Zookeeper");
+
+		parser.addArgument("--interval", "-in").type(String.class).nargs("?").setDefault("900")
+				.help("Time interval " + "between 2 consecutive test suite runs");
+
+		Namespace res = null;
+		try {
+			res = parser.parseArgs(args);
+		} catch (ArgumentParserException e) {
+			parser.handleError(e);
+		}
+		return res;
+	}
+
+	public static Map<String, String> getArgs(Namespace cArgs) {
+
+		Map<String, String> params = new HashMap<>();
+
+		for (Map.Entry<String, Object> entry : cArgs.getAttrs().entrySet()) {
+			params.put(entry.getKey(), (String) entry.getValue());
+		}
+		return params;
+	}
+
+	public static void main(String[] args) {
+
+		logger.info("Starting PQS Canary Orchestrator...");
+		ToolWrapper tool = new ToolWrapper();
+		try {
+
+			Namespace cArgs = parseArgs(args);
+			if (cArgs == null) {
+				throw new RuntimeException("Argument parsing failed");
+			}
+
+			Map<String, String> params = getArgs(cArgs);
+			PATH = params.get("zkpath");
+
+			CuratorFramework client = CuratorFrameworkFactory.newClient(params.get("zkurl"), new
+					BoundedExponentialBackoffRetry(1000, 60000, 50000));
+
+
+			TestExecutorClient executorClient = new TestExecutorClient(client, PATH, params, tool);
+			client.start();
+			executorClient.start();
+
+			// A shutdown hook to cleanly terminate the application
+			Runtime.getRuntime().addShutdownHook(new Thread() {
+				public void run() {
+					logger.info("Shutdown Hook for PQS Canary Orchestrator running...");
+					CloseableUtils.closeQuietly(executorClient);
+					CloseableUtils.closeQuietly(client);
+					logger.info("Closed Curator Client");
+				}
+			});
+
+			while (true) {
 
 Review comment:
   You want to implement some logic in `TestExecutorClient` that this caller can block on.
   
   For `Thread`, this would be doing something like calling `join()` on a thread you started
which you want to wait to complete. Another way to do this would be to make a boolean method
`isDone()`on `TestExecutorClient` which this class can call periodically, e.g.
   ```
   while (!client.isDone()) {
     Thread.sleep(1, TimeUnit.SECOND);
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message