You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2014/09/24 06:47:03 UTC
[7/7] git commit: Adding a graceful shutdown option for the VXQuery
cluster.
Adding a graceful shutdown option for the VXQuery cluster.
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/1fea6e3e
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/1fea6e3e
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/1fea6e3e
Branch: refs/heads/prestonc/exrt_benchmark_queries
Commit: 1fea6e3e6ae80841fb86e8e6f602988dc1f60f4a
Parents: 6b7aa1d
Author: Preston Carman <pr...@apache.org>
Authored: Tue Sep 23 21:46:01 2014 -0700
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Sep 23 21:46:01 2014 -0700
----------------------------------------------------------------------
vxquery-server/pom.xml | 4 +
.../vxquery/cli/VXQueryClusterShutdown.java | 93 ++++++++++++++++++++
.../main/resources/scripts/cluster_actions.py | 16 +++-
.../src/main/resources/scripts/cluster_cli.py | 6 +-
.../resources/scripts/cluster_information.py | 27 ++++--
.../src/main/resources/scripts/startcc.sh | 4 +-
.../src/main/resources/scripts/startnc.sh | 4 +-
.../src/main/resources/scripts/stopcc.sh | 3 +-
.../src/main/resources/scripts/stopcluster.sh | 45 ++++++++++
.../src/main/resources/scripts/stopnc.sh | 2 +-
10 files changed, 183 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/pom.xml
----------------------------------------------------------------------
diff --git a/vxquery-server/pom.xml b/vxquery-server/pom.xml
index ef8f348..6c99712 100644
--- a/vxquery-server/pom.xml
+++ b/vxquery-server/pom.xml
@@ -47,6 +47,10 @@
<configuration>
<programs>
<program>
+ <mainClass>org.apache.vxquery.cli.VXQueryClusterShutdown</mainClass>
+ <name>vxqueryshutdown</name>
+ </program>
+ <program>
<mainClass>edu.uci.ics.hyracks.control.cc.CCDriver</mainClass>
<name>vxquerycc</name>
</program>
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/java/org/apache/vxquery/cli/VXQueryClusterShutdown.java
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/java/org/apache/vxquery/cli/VXQueryClusterShutdown.java b/vxquery-server/src/main/java/org/apache/vxquery/cli/VXQueryClusterShutdown.java
new file mode 100644
index 0000000..34c69b9
--- /dev/null
+++ b/vxquery-server/src/main/java/org/apache/vxquery/cli/VXQueryClusterShutdown.java
@@ -0,0 +1,93 @@
+/*
+ * 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.vxquery.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.Option;
+
+import edu.uci.ics.hyracks.api.client.HyracksConnection;
+import edu.uci.ics.hyracks.api.client.IHyracksClientConnection;
+
+public class VXQueryClusterShutdown {
+ /**
+ * Main method to get command line options and execute query process.
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ final CmdLineOptions opts = new CmdLineOptions();
+ CmdLineParser parser = new CmdLineParser(opts);
+
+ System.err.println("prep");
+
+ // parse command line options
+ try {
+ parser.parseArgument(args);
+ } catch (Exception e) {
+ parser.printUsage(System.err);
+ return;
+ }
+ System.err.println("read");
+ System.err.println(opts.clientNetIpAddress);
+ System.err.println(opts.clientNetPort);
+
+ // give error message if missing arguments
+ if (opts.clientNetIpAddress == null || opts.clientNetPort == -1) {
+ parser.printUsage(System.err);
+ return;
+ }
+ System.err.println("ready");
+
+ IHyracksClientConnection hcc;
+ try {
+ hcc = new HyracksConnection(opts.clientNetIpAddress, opts.clientNetPort);
+ } catch (Exception e) {
+ System.err.println("Unable to connect to the Hyracks cluster.");
+ System.err.println(e);
+ return;
+ }
+
+ System.err.println("connected");
+ try {
+ hcc.stopCluster();
+ } catch (Exception e) {
+ System.err.println("Unable to shutdown the Hyracks cluster.");
+ System.err.println(e);
+ return;
+ }
+
+ System.err.println("done");
+ }
+
+ /**
+ * Helper class with fields and methods to handle all command line options
+ */
+ private static class CmdLineOptions {
+ @Option(name = "-client-net-ip-address", usage = "IP Address of the ClusterController")
+ private String clientNetIpAddress = null;
+
+ @Option(name = "-client-net-port", usage = "Port of the ClusterController")
+ private int clientNetPort = -1;
+
+ @Argument
+ private List<String> arguments = new ArrayList<String>();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/cluster_actions.py
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/cluster_actions.py b/vxquery-server/src/main/resources/scripts/cluster_actions.py
index a7cda17..deeee33 100644
--- a/vxquery-server/src/main/resources/scripts/cluster_actions.py
+++ b/vxquery-server/src/main/resources/scripts/cluster_actions.py
@@ -62,6 +62,10 @@ class ClusterActions:
time.sleep(5)
self.start_all_ncs()
+ def stop_cluster(self):
+ machine = self.ci.get_master_node_machine()
+ self.stop_cc_and_all_ncs(machine)
+
def stop(self):
self.stop_all_ncs()
time.sleep(2)
@@ -109,16 +113,22 @@ class ClusterActions:
def start_cc(self, machine):
print "Start Cluster Controller."
- print " " + machine.get_id() + " " + machine.get_ip() + ":" + machine.get_port()
- command = "./vxquery-server/target/appassembler/bin/startcc.sh " + machine.get_ip() + " \"" + machine.get_port() + "\" \"" + machine.get_java_opts() + "\""
+ print " " + machine.get_id() + " " + machine.get_client_ip() + ":" + machine.get_client_port()
+ command = "./vxquery-server/target/appassembler/bin/startcc.sh " + machine.get_client_ip() + " \"" + machine.get_client_port() + "\" \"" + machine.get_java_opts() + "\""
self.run_remote_command(machine.get_username(), machine.get_id(), command)
def start_nc(self, machine, cc):
print "Start Node Controller."
print " " + machine.get_id() + " " + machine.get_ip()
- command = "./vxquery-server/target/appassembler/bin/startnc.sh " + machine.get_id() + " " + machine.get_ip() + " " + cc.get_ip() + " \"" + cc.get_port() + "\" \"" + machine.get_java_opts() + "\""
+ command = "./vxquery-server/target/appassembler/bin/startnc.sh " + machine.get_id() + " " + machine.get_ip() + " " + cc.get_client_ip() + " \"" + cc.get_client_port() + "\" \"" + machine.get_java_opts() + "\""
self.run_remote_command(machine.get_username(), machine.get_id(), command)
+ def stop_cc_and_all_ncs(self, machine):
+ print "Stop Cluster and Node Controllers."
+ print " " + machine.get_id() + " " + machine.get_client_ip() + ":" + machine.get_client_port()
+ command = "./vxquery-server/target/appassembler/bin/stopcluster.sh " + machine.get_client_ip() + " \"" + machine.get_client_port() + "\" \"" + machine.get_java_opts() + "\""
+ self.run_remote_command(machine.get_username(), machine.get_id(), command)
+
def stop_cc(self, machine):
print "Stop Cluster Controller."
print " " + machine.get_id() + " " + machine.get_ip()
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/cluster_cli.py
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/cluster_cli.py b/vxquery-server/src/main/resources/scripts/cluster_cli.py
index 089ad08..bd5efa6 100644
--- a/vxquery-server/src/main/resources/scripts/cluster_cli.py
+++ b/vxquery-server/src/main/resources/scripts/cluster_cli.py
@@ -39,10 +39,10 @@ def main(argv):
sys.exit()
elif opt in ('-a', "--action"):
# check if file exists.
- if arg in ('deploy', 'start', 'stop'):
+ if arg in ('deploy', 'start', 'stop', 'kill'):
action = arg
else:
- print 'Error: Argument must be a string ("deploy", "start", or "stop") for --action (-a).'
+ print 'Error: Argument must be a string ("deploy", "start", "stop", or "kill") for --action (-a).'
sys.exit()
elif opt in ('-c', "--cluster"):
# check if file exists.
@@ -72,6 +72,8 @@ def main(argv):
if action == 'start':
cluster.start()
elif action == 'stop':
+ cluster.stop_cluster()
+ elif action == 'kill':
cluster.stop()
elif action == 'deploy':
if deploy_path != "":
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/cluster_information.py
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/cluster_information.py b/vxquery-server/src/main/resources/scripts/cluster_information.py
index 677204b..94b231d 100644
--- a/vxquery-server/src/main/resources/scripts/cluster_information.py
+++ b/vxquery-server/src/main/resources/scripts/cluster_information.py
@@ -32,12 +32,13 @@ class ClusterInformation:
master_node = self.config.getElementsByTagName("master_node")[0]
id = NodeXmlReader.get_cluster_id(master_node)
ip = NodeXmlReader.get_cluster_ip(master_node)
- port = NodeXmlReader.get_cluster_port(master_node)
+ client_ip = NodeXmlReader.get_client_ip(master_node)
+ client_port = NodeXmlReader.get_client_port(master_node)
java_opts = NodeXmlReader.get_java_opts(master_node)
if java_opts is "":
java_opts = self.get_java_opts()
username = self.get_username()
- return Machine(id, ip, username, port, java_opts)
+ return Machine(id, ip, username, client_ip, client_port, java_opts)
def get_node_machine_list(self):
nodes = []
@@ -48,7 +49,7 @@ class ClusterInformation:
java_opts = NodeXmlReader.get_java_opts(node)
if java_opts is "":
java_opts = self.get_java_opts()
- nodes.append(Machine(id, ip, username, "", java_opts))
+ nodes.append(Machine(id, ip, username, "", "", java_opts))
return nodes
class NodeXmlReader(object):
@@ -64,8 +65,12 @@ class NodeXmlReader(object):
return get_tag_text(node, "cluster_ip")
@staticmethod
- def get_cluster_port(node):
- return get_tag_text(node, "cluster_port")
+ def get_client_ip(node):
+ return get_tag_text(node, "client_ip")
+
+ @staticmethod
+ def get_client_port(node):
+ return get_tag_text(node, "client_port")
@staticmethod
def get_java_opts(node):
@@ -90,11 +95,12 @@ class Machine:
log_path = ""
port = ""
- def __init__(self, id, ip, username, port="", java_opts=""):
+ def __init__(self, id, ip, username, client_ip="", client_port="", java_opts=""):
self.id = id
self.ip = ip
self.username = username
- self.port = port
+ self.client_ip = client_ip
+ self.client_port = client_port
self.java_opts = java_opts
def get_id(self):
@@ -106,8 +112,11 @@ class Machine:
def get_java_opts(self):
return self.java_opts
- def get_port(self):
- return self.port
+ def get_client_ip(self):
+ return self.client_ip
+
+ def get_client_port(self):
+ return self.client_port
def get_username(self):
return self.username
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/startcc.sh
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/startcc.sh b/vxquery-server/src/main/resources/scripts/startcc.sh
index 002055c..26535ab 100755
--- a/vxquery-server/src/main/resources/scripts/startcc.sh
+++ b/vxquery-server/src/main/resources/scripts/startcc.sh
@@ -23,7 +23,7 @@ CCHOST=$1
CCPORT=$2
J_OPTS=$3
-#Export JAVA_HOME
+# Export JAVA_HOME
export JAVA_HOME=${JAVA_HOME}
# java opts added parameters
@@ -46,5 +46,5 @@ then
CC_OPTIONS=" ${CC_OPTIONS} -cluster-net-port ${CCPORT} "
fi
-#Launch hyracks cc script without toplogy
+# Launch hyracks cc script without toplogy
${VXQUERY_HOME}/vxquery-server/target/appassembler/bin/vxquerycc ${CC_OPTIONS} &> ${CCLOGS_DIR}/cc_$(date +%Y%m%d%H%M).log &
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/startnc.sh
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/startnc.sh b/vxquery-server/src/main/resources/scripts/startnc.sh
index c2bda3c..260512e 100755
--- a/vxquery-server/src/main/resources/scripts/startnc.sh
+++ b/vxquery-server/src/main/resources/scripts/startnc.sh
@@ -25,7 +25,7 @@ CCHOST=$3
CCPORT=$4
J_OPTS=$5
-#Set JAVA_HOME
+# Set JAVA_HOME
export JAVA_HOME=$JAVA_HOME
# java opts added parameters
@@ -49,5 +49,5 @@ then
fi
-#Launch hyracks nc
+# Launch hyracks nc
${VXQUERY_HOME}/vxquery-server/target/appassembler/bin/vxquerync ${NC_OPTIONS} &> ${NCLOGS_DIR}/nc_$(date +%Y%m%d%H%M).log &
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/stopcc.sh
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/stopcc.sh b/vxquery-server/src/main/resources/scripts/stopcc.sh
index 3290ec6..f2b6883 100755
--- a/vxquery-server/src/main/resources/scripts/stopcc.sh
+++ b/vxquery-server/src/main/resources/scripts/stopcc.sh
@@ -21,8 +21,7 @@ hostname
USER=$1
-#Kill process
-#Kill process
+# Kill process
PID=`ps -ef|grep ${USER}|grep java|grep 'Dapp.name=vxquerycc'|awk '{print $2}'`
if [ "$PID" == "" ]; then
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/stopcluster.sh
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/stopcluster.sh b/vxquery-server/src/main/resources/scripts/stopcluster.sh
new file mode 100755
index 0000000..5dbdd26
--- /dev/null
+++ b/vxquery-server/src/main/resources/scripts/stopcluster.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# 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.
+#
+
+CCHOST=$1
+CCPORT=$2
+J_OPTS=$3
+
+# Export JAVA_HOME
+export JAVA_HOME=${JAVA_HOME}
+
+# java opts added parameters
+if [ ! -z "${J_OPTS}" ]
+then
+ JAVA_OPTS="${JAVA_OPTS} ${J_OPTS}"
+ export JAVA_OPTS
+fi
+
+VXQUERY_HOME=`pwd`
+CCLOGS_DIR=${VXQUERY_HOME}/logs
+
+# logs dir
+mkdir -p ${CCLOGS_DIR}
+
+# Set up the options for the cc.
+CC_OPTIONS=" -client-net-ip-address ${CCHOST} -client-net-port ${CCPORT} "
+
+# Launch hyracks cc script without toplogy
+echo "${VXQUERY_HOME}/vxquery-server/target/appassembler/bin/vxqueryshutdown ${CC_OPTIONS} &> ${CCLOGS_DIR}/shutdown_$(date +%Y%m%d%H%M).log &"
+${VXQUERY_HOME}/vxquery-server/target/appassembler/bin/vxqueryshutdown ${CC_OPTIONS} &> ${CCLOGS_DIR}/shutdown_$(date +%Y%m%d%H%M).log &
http://git-wip-us.apache.org/repos/asf/vxquery/blob/1fea6e3e/vxquery-server/src/main/resources/scripts/stopnc.sh
----------------------------------------------------------------------
diff --git a/vxquery-server/src/main/resources/scripts/stopnc.sh b/vxquery-server/src/main/resources/scripts/stopnc.sh
index 56ffc66..8f29de5 100755
--- a/vxquery-server/src/main/resources/scripts/stopnc.sh
+++ b/vxquery-server/src/main/resources/scripts/stopnc.sh
@@ -21,7 +21,7 @@ hostname
USER=$1
-#Kill process
+# Kill process
PID=`ps -ef|grep ${USER}|grep java|grep 'Dapp.name=vxquerync'|awk '{print $2}'`
if [ "$PID" == "" ]; then