asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yingyi Bu (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Support stopping and resuming for AWS-based cluster.
Date Fri, 31 Mar 2017 01:30:25 GMT
Yingyi Bu has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1643

Change subject: Support stopping and resuming for AWS-based cluster.
......................................................................

Support stopping and resuming for AWS-based cluster.

Change-Id: I77fff4a8a5f6e5d8ebee52eb66d86cc18f32cd12
---
M asterixdb/asterix-server/src/main/opt/ansible/bin/stop.sh
A asterixdb/asterix-server/src/main/opt/aws/bin/resume.sh
M asterixdb/asterix-server/src/main/opt/aws/bin/stop.sh
A asterixdb/asterix-server/src/main/opt/aws/bin/terminate.sh
A asterixdb/asterix-server/src/main/opt/aws/yaml/aws_lifecycle.yml
A asterixdb/asterix-server/src/main/opt/aws/yaml/aws_resume.yml
M asterixdb/asterix-server/src/main/opt/aws/yaml/aws_start.yml
M asterixdb/asterix-server/src/main/opt/aws/yaml/aws_stop.yml
A asterixdb/asterix-server/src/main/opt/aws/yaml/aws_terminate.yml
A asterixdb/asterix-server/src/main/opt/aws/yaml/instance_resume.yml
10 files changed, 235 insertions(+), 16 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/43/1643/1

diff --git a/asterixdb/asterix-server/src/main/opt/ansible/bin/stop.sh b/asterixdb/asterix-server/src/main/opt/ansible/bin/stop.sh
index 200d6e6..247c32a 100755
--- a/asterixdb/asterix-server/src/main/opt/ansible/bin/stop.sh
+++ b/asterixdb/asterix-server/src/main/opt/ansible/bin/stop.sh
@@ -26,7 +26,7 @@
 
 INVENTORY=$ANSB_PATH/conf/inventory
 
-# Starts the cluster
+# Stops the cluster
 export ANSIBLE_HOST_KEY_CHECKING=false
 ansible-playbook -i $INVENTORY $ANSB_PATH/yaml/instance_stop.yml
 
diff --git a/asterixdb/asterix-server/src/main/opt/aws/bin/resume.sh b/asterixdb/asterix-server/src/main/opt/aws/bin/resume.sh
new file mode 100755
index 0000000..8c26deb
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/bin/resume.sh
@@ -0,0 +1,38 @@
+#!/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.
+# ------------------------------------------------------------
+
+# Gets the absolute path so that the script can work no matter where it is invoked.
+pushd `dirname $0` > /dev/null
+SCRIPT_PATH=`pwd -P`
+popd > /dev/null
+AWS_PATH=`dirname "${SCRIPT_PATH}"`
+OPT_PATH=`dirname "${AWS_PATH}"`
+DIST_PATH=`dirname "${OPT_PATH}"`
+
+# Resumes an AWS cluster.
+ansible-playbook -i "localhost," $AWS_PATH/yaml/aws_resume.yml
+
+# The Ansible inventory file and the AsterixDB configuration file.
+temp=$AWS_PATH/conf/instance
+inventory=$temp/inventory
+
+# Resumes the cluster.
+export ANSIBLE_HOST_KEY_CHECKING=false
+ansible-playbook -i $inventory $AWS_PATH/yaml/instance_resume.yml
diff --git a/asterixdb/asterix-server/src/main/opt/aws/bin/stop.sh b/asterixdb/asterix-server/src/main/opt/aws/bin/stop.sh
index 48f4ff7..90f1a6f 100755
--- a/asterixdb/asterix-server/src/main/opt/aws/bin/stop.sh
+++ b/asterixdb/asterix-server/src/main/opt/aws/bin/stop.sh
@@ -24,5 +24,11 @@
 popd > /dev/null
 AWS_PATH=`dirname "${SCRIPT_PATH}"`
 
-# Terminates an AWS cluster.
+INVENTORY=$AWS_PATH/conf/instance/inventory
+
+# Stops the cluster.
+export ANSIBLE_HOST_KEY_CHECKING=false
+ansible-playbook -i $INVENTORY $AWS_PATH/yaml/instance_stop.yml
+
+# Stops an AWS cluster.
 ansible-playbook -i "localhost," $AWS_PATH/yaml/aws_stop.yml
diff --git a/asterixdb/asterix-server/src/main/opt/aws/bin/terminate.sh b/asterixdb/asterix-server/src/main/opt/aws/bin/terminate.sh
new file mode 100755
index 0000000..58ff965
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/bin/terminate.sh
@@ -0,0 +1,28 @@
+#!/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.
+# ------------------------------------------------------------
+
+# Gets the absolute path so that the script can work no matter where it is invoked.
+pushd `dirname $0` > /dev/null
+SCRIPT_PATH=`pwd -P`
+popd > /dev/null
+AWS_PATH=`dirname "${SCRIPT_PATH}"`
+
+# Terminates an AWS cluster.
+ansible-playbook -i "localhost," $AWS_PATH/yaml/aws_terminate.yml
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_lifecycle.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_lifecycle.yml
new file mode 100644
index 0000000..654b7ce
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_lifecycle.yml
@@ -0,0 +1,39 @@
+# ------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------
+
+# The caller should pass in a variable called "state":  running, stopped, or absent
+- include_vars: ../conf/aws_settings.yml
+
+- include_vars: "{{ temp_dir }}/aws_ids.yml"
+
+- name: Stop or resume all instances
+  ec2:
+    key_name: "{{ keypair }}"
+    group: "{{ group }}"
+    instance_type: "{{ instance_type }}"
+    image: "{{ image }}"
+    wait: true
+    region: "{{ region }}"
+    aws_access_key: "{{ access_key_id }}"
+    aws_secret_key: "{{ secret_access_key }}"
+    instance_ids: "{{ instance_ids }}"
+    state: "{{ state }}"
+    count: "{{ count }}"
+    count_tag:
+      Name: "{{ tag }}"
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_resume.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_resume.yml
new file mode 100644
index 0000000..fce42e4
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_resume.yml
@@ -0,0 +1,26 @@
+# ------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------
+
+- name: Resume AWS cluster
+  hosts: localhost
+  gather_facts: false
+  vars:
+    temp_dir: "{{ playbook_dir }}/../conf/instance"
+  tasks:
+    - include: aws_lifecycle.yml state="running"
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_start.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_start.yml
index a35cf12..821bad6 100644
--- a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_start.yml
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_start.yml
@@ -25,6 +25,7 @@
      bin_dir: "{{ playbook_dir }}/../bin"
      inventory: "{{ temp_dir }}/inventory"
      ccconf: "{{ temp_dir }}/cc.conf"
+     aws_ids: "{{ temp_dir }}/aws_ids.yml"
      home_dir: "/home/{{ user }}"
      num_vols: "{{ ephemeral_volumes[instance_type]|default(0) }}"
   tasks:
@@ -63,6 +64,27 @@
         volumes: "{{ vols }}"
       register: ec2
 
+    - ec2_remote_facts:
+        region: "{{ region }}"
+        aws_access_key: "{{ access_key_id }}"
+        aws_secret_key: "{{ secret_access_key }}"
+        filters:
+          "tag:Name": "{{ tag }}"
+          instance-state-name: running
+      register: rfacts
+
+    - set_fact:
+        instance_ids: "{{ rfacts | json_query('instances[*].id') }}"
+
+    - name: Generate the file for instance ids
+      shell: printf "instance_ids:\n" > "{{ aws_ids }}"
+
+    - name: Write instance ids to file {{ aws_ids }}
+      shell: printf "  - {{ instance_id }}\n" >> "{{ aws_ids }}"
+      with_items: "{{ instance_ids }}"
+      loop_control:
+        loop_var: instance_id
+
     - name: Set CC node
       set_fact:
         cc: "{{ ec2.instances[0] }}"
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_stop.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_stop.yml
index b466ad4..3aa92b0 100644
--- a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_stop.yml
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_stop.yml
@@ -20,18 +20,7 @@
 - name: Stop AWS cluster
   hosts: localhost
   gather_facts: false
+  vars:
+    temp_dir: "{{ playbook_dir }}/../conf/instance"
   tasks:
-    - include_vars: ../conf/aws_settings.yml
-    - name: Stop all instance
-      ec2:
-        key_name: "{{ keypair }}"
-        group: "{{ group }}"
-        instance_type: "{{ instance_type }}"
-        image: "{{ image }}"
-        wait: true
-        region: "{{ region }}"
-        aws_access_key: "{{ access_key_id }}"
-        aws_secret_key: "{{ secret_access_key }}"
-        exact_count: 0
-        count_tag:
-          Name: "{{ tag }}"
+    - include: aws_lifecycle.yml state="stopped"
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_terminate.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_terminate.yml
new file mode 100644
index 0000000..cbfb21f
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/aws_terminate.yml
@@ -0,0 +1,37 @@
+# ------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------
+
+- name: Terminate AWS cluster
+  hosts: localhost
+  gather_facts: false
+  tasks:
+    - include_vars: ../conf/aws_settings.yml
+    - name: Terminate all instance
+      ec2:
+        key_name: "{{ keypair }}"
+        group: "{{ group }}"
+        instance_type: "{{ instance_type }}"
+        image: "{{ image }}"
+        wait: true
+        region: "{{ region }}"
+        aws_access_key: "{{ access_key_id }}"
+        aws_secret_key: "{{ secret_access_key }}"
+        exact_count: 0
+        count_tag:
+          Name: "{{ tag }}"
diff --git a/asterixdb/asterix-server/src/main/opt/aws/yaml/instance_resume.yml b/asterixdb/asterix-server/src/main/opt/aws/yaml/instance_resume.yml
new file mode 100644
index 0000000..80a6b65
--- /dev/null
+++ b/asterixdb/asterix-server/src/main/opt/aws/yaml/instance_resume.yml
@@ -0,0 +1,34 @@
+# ------------------------------------------------------------
+# 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.
+# ------------------------------------------------------------
+
+- hosts: [localhost,]
+  tasks:
+    - include: wait_ssh.yml
+
+- hosts: ncs
+  tasks:
+    - include_vars: ../conf/instance_settings.yml
+
+    - include: start_ncservice.yml
+
+- hosts: cc
+  tasks:
+    - include_vars: ../conf/instance_settings.yml
+
+    - include: start_cc.yml

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1643
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77fff4a8a5f6e5d8ebee52eb66d86cc18f32cd12
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Yingyi Bu <buyingyi@gmail.com>

Mime
View raw message