integration of asterix-installer: checkpoint 1
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_installer@1219 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh b/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh
new file mode 100755
index 0000000..532e559
--- /dev/null
+++ b/asterix-events/src/main/resources/events/asterix_deploy/asterix_deploy.sh
@@ -0,0 +1,11 @@
+MANAGIX_HOME=$1
+HYRACKS_CLI=$MANAGIX_HOME/asterix/hyracks-cli/bin/hyrackscli
+if ! [ -x $HYRACKS_CLI ]
+then
+ chmod +x $HYRACKS_CLI
+fi
+ASTERIX_ZIP=$2
+HOST=$3
+echo "connect to \"$HOST\";" > temp
+echo "create application asterix \"$ASTERIX_ZIP\";" >> temp
+($HYRACKS_CLI < temp)
diff --git a/asterix-events/src/main/resources/events/backup/backup.sh b/asterix-events/src/main/resources/events/backup/backup.sh
new file mode 100755
index 0000000..cff37df
--- /dev/null
+++ b/asterix-events/src/main/resources/events/backup/backup.sh
@@ -0,0 +1,19 @@
+WORKING_DIR=$1
+ASTERIX_INSTANCE_NAME=$2
+ASTERIX_DATA_DIR=$3
+BACKUP_ID=$4
+HDFS_URL=$5
+HADOOP_VERSION=$6
+HDFS_BACKUP_DIR=$7
+NODE_ID=$8
+
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+
+nodeStores=$(echo $ASTERIX_DATA_DIR | tr "," "\n")
+for nodeStore in $nodeStores
+do
+ NODE_BACKUP_DIR=$HDFS_BACKUP_DIR/$ASTERIX_INSTANCE_NAME/$BACKUP_ID/$NODE_ID/$nodeStore
+ $HADOOP_HOME/bin/hadoop fs -mkdir $HDFS_URL/$NODE_BACKUP_DIR
+ echo "$HADOOP_HOME/bin/hadoop fs -copyFromLocal $nodeStore/$NODE_ID $HDFS_URL/$NODE_BACKUP_DIR" >> ~/backup.log
+ $HADOOP_HOME/bin/hadoop fs -copyFromLocal $nodeStore/$NODE_ID/$ASTERIX_INSTANCE_NAME/* $HDFS_URL/$NODE_BACKUP_DIR/
+done
diff --git a/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh b/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh
new file mode 100755
index 0000000..0855f5f
--- /dev/null
+++ b/asterix-events/src/main/resources/events/cc_failure/cc_failure.sh
@@ -0,0 +1,6 @@
+#kill -9 `ps -ef | grep hyracks | grep -v grep | cut -d "/" -f1 | tr -s " " | cut -d " " -f2`
+CC_PARENT_ID_INFO=`ps -ef | grep hyracks | grep cc_start | grep -v ssh`
+CC_PARENT_ID=`echo $CC_PARENT_ID_INFO | tr -s " " | cut -d " " -f2`
+CC_ID_INFO=`ps -ef | grep hyracks | grep $CC_PARENT_ID | grep -v bash`
+CC_ID=`echo $CC_ID_INFO | tr -s " " | cut -d " " -f2`
+kill -9 $CC_ID
diff --git a/asterix-events/src/main/resources/events/cc_start/cc_start.sh b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
new file mode 100755
index 0000000..e0b29e0
--- /dev/null
+++ b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
@@ -0,0 +1,9 @@
+if [ ! -d $LOG_DIR ];
+then
+ mkdir -p $LOG_DIR
+fi
+if [ ! -z $1 ];
+then
+ JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=$1,server=y,suspend=n"
+fi
+$HYRACKS_HOME/bin/hyrackscc -client-net-ip-address $CLIENT_NET_IP -client-net-port 1098 -cluster-net-ip-address $CLUSTER_NET_IP -cluster-net-port 1099 -http-port 8888 &> $LOG_DIR/cc.log
diff --git a/asterix-events/src/main/resources/events/events.xml b/asterix-events/src/main/resources/events/events.xml
new file mode 100644
index 0000000..857ee5a
--- /dev/null
+++ b/asterix-events/src/main/resources/events/events.xml
@@ -0,0 +1,100 @@
+<events xmlns="events">
+ <event>
+ <type>node_join</type>
+ <script>node_join/nc_join.sh</script>
+ <description>Creates a NodeController process at a specified location.</description>
+ <args>location_of_cc location(hostname/ip_address) node_controller_id</args>
+ <daemon>true</daemon>
+ </event>
+ <event>
+ <type>node_failure</type>
+ <script>node_failure/nc_failure.sh</script>
+ <description>Kills a NodeController process at a specified location.</description>
+ <args>node_controller_id</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>cc_start</type>
+ <script>cc_start/cc_start.sh</script>
+ <description>Starts a ClusterController process at a specified location.</description>
+ <args></args>
+ <daemon>true</daemon>
+ </event>
+ <event>
+ <type>cc_failure</type>
+ <script>cc_failure/cc_failure.sh</script>
+ <description>Kills the Cluster Controller process running at a specified location.</description>
+ <args></args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>node_restart</type>
+ <script>node_restart/nc_restart.sh</script>
+ <description>Shuts and restarts a NodeControllerProcess after a specified time interval, at a specified location</description>
+ <args>address of cc, node controller id and sleep interval(seconds)</args>
+ <daemon>true</daemon>
+ </event>
+ <event>
+ <type>asterix_deploy</type>
+ <script>asterix_deploy/asterix_deploy.sh</script>
+ <description>Deploys Asterix application on a cluster running hyracks</description>
+ <args>IP address of the node running the hyracks cluster controller</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>zookeeper_start</type>
+ <script>zookeeper/start.sh</script>
+ <description>Launches ZooKeeper server process</description>
+ <args>IP address of the ZooKeeper server</args>
+ <daemon>true</daemon>
+ </event>
+ <event>
+ <type>zookeeper_stop</type>
+ <script>zookeeper/stop.sh</script>
+ <description>Terminates ZooKeeper server process</description>
+ <args>IP address of the ZooKeeper server</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>file_transfer</type>
+ <script>file/transfer.sh</script>
+ <description>Copies a file on the local file system to a remote node</description>
+ <args>local_source_path destination_node destination_path</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>directory_transfer</type>
+ <script>file/dir_transfer.sh</script>
+ <description>Copies a directory (and its contents) on the local file system to a remote node</description>
+ <args>local_source_path destination_node destination_path</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>file_delete</type>
+ <script>file/delete.sh</script>
+ <description>Deletes a file on the local file system to a remote node</description>
+ <args>local_source_path destination_node destination_path</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>backup</type>
+ <script>backup/backup.sh</script>
+ <description>Takes a backup of an Asterix instance</description>
+ <args>Asterix_data_dir HDFSurl</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>restore</type>
+ <script>restore/restore.sh</script>
+ <description>Restores an Asterix instance from a back up</description>
+ <args>Asterix_data_dir HDFSurl</args>
+ <daemon>false</daemon>
+ </event>
+ <event>
+ <type>hdfs_delete</type>
+ <script>hdfs/delete.sh</script>
+ <description>Deletes an HDFS path</description>
+ <args>WorkingDir HadoopVersion HDFSUrl Path_to_Delete</args>
+ <daemon>false</daemon>
+ </event>
+</events>
diff --git a/asterix-events/src/main/resources/events/file/delete.sh b/asterix-events/src/main/resources/events/file/delete.sh
new file mode 100755
index 0000000..d5ac3ff
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/delete.sh
@@ -0,0 +1,3 @@
+PATH_TO_DELETE=$1
+echo "rm -rf $PATH_TO_DELETE" >> ~/backup.log
+rm -rf $PATH_TO_DELETE
diff --git a/asterix-events/src/main/resources/events/file/dir_transfer.sh b/asterix-events/src/main/resources/events/file/dir_transfer.sh
new file mode 100755
index 0000000..af7da70
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/dir_transfer.sh
@@ -0,0 +1,7 @@
+USERNAME=$1
+DIR_TO_TRANSFER=$2
+DEST_HOST=$3
+DEST_DIR=$4
+ssh -l $USERNAME $DEST_HOST "mkdir -p $DEST_DIR"
+echo "scp -r $DIR_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/"
+scp -r $DIR_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/
diff --git a/asterix-events/src/main/resources/events/file/transfer.sh b/asterix-events/src/main/resources/events/file/transfer.sh
new file mode 100755
index 0000000..08f0b43
--- /dev/null
+++ b/asterix-events/src/main/resources/events/file/transfer.sh
@@ -0,0 +1,23 @@
+USERNAME=$1
+FILE_TO_TRANSFER=$2
+DEST_HOST=$3
+DEST_DIR=$4
+POST_ACTION=$5
+ssh -l $USERNAME $DEST_HOST "mkdir -p $DEST_DIR"
+echo "scp $FILE_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/"
+scp $FILE_TO_TRANSFER $USERNAME@$DEST_HOST:$DEST_DIR/
+if [ $POST_ACTION == "unpack" ]
+ then
+ filename=`echo ${FILE_TO_TRANSFER##*/}`
+ fileType=`echo ${FILE_TO_TRANSFER##*.}`
+ if [ $fileType == "tar" ]
+ then
+ echo "ssh -l $USERNAME $DEST_HOST cd $DEST_DIR && tar xf $filename"
+ ssh -l $USERNAME $DEST_HOST "cd $DEST_DIR && tar xf $filename"
+ else if [ $fileType == "zip" ]
+ then
+ echo "ssh -l $USERNAME $DEST_HOST unzip -o -q -d $DEST_DIR $DEST_DIR/$filename"
+ ssh -l $USERNAME $DEST_HOST "unzip -o -q -d $DEST_DIR $DEST_DIR/$filename"
+ fi
+ fi
+fi
diff --git a/asterix-events/src/main/resources/events/hdfs/delete.sh b/asterix-events/src/main/resources/events/hdfs/delete.sh
new file mode 100755
index 0000000..6ff54ee
--- /dev/null
+++ b/asterix-events/src/main/resources/events/hdfs/delete.sh
@@ -0,0 +1,7 @@
+WORKING_DIR=$1
+HADOOP_VERSION=$2
+HDFS_URL=$3
+HDFS_PATH=$4
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+echo "$HADOOP_HOME/bin/hadoop fs -rmr $HDFS_URL/$HDFS_PATH"
+$HADOOP_HOME/bin/hadoop fs -rmr $HDFS_URL/$HDFS_PATH
diff --git a/asterix-events/src/main/resources/events/node_failure/nc_failure.sh b/asterix-events/src/main/resources/events/node_failure/nc_failure.sh
new file mode 100755
index 0000000..b853be1
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_failure/nc_failure.sh
@@ -0,0 +1,19 @@
+NC_ID=$1
+
+#if [ $NC_ID == 'ANY' ]
+#then
+# NC_ID="."
+#fi
+#
+#USER=`who am i | tr -s " " | cut -d " " -f1`
+#PARENT_ID=`ps -ef | tr -s " " | grep nc_join | grep -v grep | grep -v ssh | grep $NC_ID | cut -d " " -f2 | head -n 1`
+#PID=`ps -ef | tr -s " " | grep hyracks | grep -v grep | grep -v nc_join | grep $PARENT_ID | cut -d " " -f2 | head -n 1`
+#kill -9 $PID
+#
+
+
+INFO=`ps -ef | grep nc_join | grep -v grep | grep -v ssh| grep $NC_ID | head -n 1`
+PARENT_ID=`echo $INFO | cut -d " " -f2`
+PID_INFO=`ps -ef | grep hyracks | grep -v grep | grep -v nc_join | grep $PARENT_ID`
+PID=`echo $PID_INFO | cut -d " " -f2`
+kill -9 $PID
diff --git a/asterix-events/src/main/resources/events/node_join/nc_join.sh b/asterix-events/src/main/resources/events/node_join/nc_join.sh
new file mode 100755
index 0000000..62d71ce
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_join/nc_join.sh
@@ -0,0 +1,11 @@
+CC_HOST=$1
+NC_ID=$2
+if [ ! -d $LOG_DIR ];
+then
+ mkdir -p $LOG_DIR
+fi
+if [ ! -z $3 ];
+then
+ JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=$3,server=y,suspend=n"
+fi
+$HYRACKS_HOME/bin/hyracksnc -node-id $NC_ID -cc-host $CC_HOST -cc-port 1099 -cluster-net-ip-address $IP_LOCATION -data-ip-address $IP_LOCATION &> $LOG_DIR/${NC_ID}.log
diff --git a/asterix-events/src/main/resources/events/node_restart/nc_restart.sh b/asterix-events/src/main/resources/events/node_restart/nc_restart.sh
new file mode 100755
index 0000000..961ce8d
--- /dev/null
+++ b/asterix-events/src/main/resources/events/node_restart/nc_restart.sh
@@ -0,0 +1,21 @@
+CC_HOST=$1
+NC_ID=$2
+SLEEP_TIME=$3
+
+if [ $NC_ID == 'ANY' ]
+then
+ NC_ID="."
+ PARENT_ID=`ps -ej | tr -s " " | grep nc_join | grep -v grep | grep -v ssh | cut -d " " -f2 | head -n 1`
+ PARENT_PROCESS_ENTRY=`ps -ef | grep $PARENT_ID | grep -v grep | head -n 1`
+ NC_ID=`echo ${PARENT_PROCESS_ENTRY##* }`
+ echo "NCid is $NC_ID" >> ~/try.txt
+else
+ PARENT_ID=`ps -ej | tr -s " " | grep nc_join | grep -v grep | grep -v ssh | grep $NC_ID | cut -d " " -f2 | head -n 1`
+fi
+
+PID=`ps -ej | tr -s " " | grep hyracks | grep -v grep | grep -v nc_join | grep $PARENT_ID | cut -d " " -f2 | head -n 1`
+kill -9 $PID
+
+sleep $3
+
+$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.2.2-SNAPSHOT-binary-assembly/bin/hyracksnc -node-id $NC_ID -cc-host $CC_HOST -cc-port 1099 -cluster-net-ip-address $IP_LOCATION -data-ip-address $IP_LOCATION
diff --git a/asterix-events/src/main/resources/events/restore/restore.sh b/asterix-events/src/main/resources/events/restore/restore.sh
new file mode 100755
index 0000000..96f3db4
--- /dev/null
+++ b/asterix-events/src/main/resources/events/restore/restore.sh
@@ -0,0 +1,25 @@
+WORKING_DIR=$1
+ASTERIX_INSTANCE_NAME=$2
+ASTERIX_DATA_DIR=$3
+BACKUP_ID=$4
+HDFS_URL=$5
+HADOOP_VERSION=$6
+HDFS_BACKUP_DIR=$7
+NODE_ID=$8
+
+export HADOOP_HOME=$WORKING_DIR/hadoop-$HADOOP_VERSION
+
+nodeStores=$(echo $ASTERIX_DATA_DIR | tr "," "\n")
+for nodeStore in $nodeStores
+do
+ NODE_BACKUP_DIR=$HDFS_BACKUP_DIR/$ASTERIX_INSTANCE_NAME/$BACKUP_ID/$NODE_ID/$nodeStore
+ DEST_DIR=$nodeStore/$NODE_ID/$ASTERIX_INSTANCE_NAME
+ if [ ! -d $DEST_DIR ]
+ then
+ mkdir -p $DEST_DIR
+ else
+ rm -rf $DEST_DIR/*
+ fi
+ echo "$HADOOP_HOME/bin/hadoop fs -copyToLocal $HDFS_URL/$NODE_BACKUP_DIR/ $DEST_DIR/" >> ~/restore.log
+ $HADOOP_HOME/bin/hadoop fs -copyToLocal $HDFS_URL/$NODE_BACKUP_DIR/* $DEST_DIR/
+done