You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ma...@apache.org on 2013/09/09 06:40:37 UTC

git commit: Updated stratos installer to fetch user-data in Amazon EC2

Updated Branches:
  refs/heads/master dfaba15a4 -> 99c597a7b


Updated stratos installer to fetch user-data in Amazon EC2

Signed-off-by: Manula Thantriwatte <ma...@wso2.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/99c597a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/99c597a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/99c597a7

Branch: refs/heads/master
Commit: 99c597a7b469b5f93db25f615f7755c830013a0c
Parents: dfaba15
Author: Imesh Gunaratne <im...@wso2.com>
Authored: Sun Sep 8 22:45:32 2013 +0530
Committer: Manula Thantriwatte <ma...@wso2.com>
Committed: Mon Sep 9 10:10:00 2013 +0530

----------------------------------------------------------------------
 tools/stratos-installer/conf/setup.conf         |  42 +++---
 .../cc/repository/conf/cloud-controller.xml     |   2 +-
 tools/stratos-installer/ec2-user-data.sh        | 141 +++++++++++++++++++
 tools/stratos-installer/ec2.sh                  |   3 +
 tools/stratos-installer/setup.sh                |   4 +
 5 files changed, 169 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/99c597a7/tools/stratos-installer/conf/setup.conf
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/conf/setup.conf b/tools/stratos-installer/conf/setup.conf
index 1414146..be39685 100644
--- a/tools/stratos-installer/conf/setup.conf
+++ b/tools/stratos-installer/conf/setup.conf
@@ -38,17 +38,18 @@ export stratos_path= #Folder which stratos will be installed
 
 export JAVA_HOME= #Java home path
 
-export resource_path=$setup_path/resources
-export script_path=$setup_path/scripts
 export log_path=/var/log/apache-stratos
 export hostip="ip" #Machine ip on which setup script run
 export host_user="" #A host user account for stratos. If not provided deafult is assumed stratos. If no account #named stratos exist it will be created.
 export mysql_connector_jar=$stratos_pack_path/"mysql-connector-java-5.1.25.jar" #mysql connector jar file name
+export stratos_domain="stratos.apache.org"
+export resource_path=$setup_path/resources
+export script_path=$setup_path/scripts
 
 
 # MB configuration
 # ----------------------------------------------------------------------------
-export mb_hostname=mb.stratos.apache.org
+export mb_hostname=mb.$stratos_domain
 export mb_listen_port="5677"
 
 
@@ -57,15 +58,13 @@ export mb_listen_port="5677"
 export sc_path=$stratos_path/"apache-stratos-sc-3.0.0-SNAPSHOT"
 export sc_pack=$stratos_pack_path/"apache-stratos-sc-3.0.0-SNAPSHOT.zip"
 
-export stratos_domain="stratos.apache.org"
-
-export userstore_db_hostname="stratos.apache.org"
+export userstore_db_hostname="$stratos_domain"
 export userstore_db_schema="userstore"
 export userstore_db_port="3306"
 export userstore_db_user="root"
 export userstore_db_pass="mysql"
 
-export stratos_foundation_db_hostname="stratos.apache.org"
+export stratos_foundation_db_hostname="$stratos_domain"
 export stratos_foundation_db_schema="stratos_foundation"
 export stratos_foundation_db_port="3306"
 export stratos_foundation_db_user="root"
@@ -74,18 +73,18 @@ export stratos_foundation_db_pass="mysql"
 export sc_https_port="9445"
 export sc_http_port="9765"
 export sc_port_offset=2
-export sc_hostname="stratos.apache.org"
+export sc_hostname="$stratos_domain"
 export elb_ip=$hostip
 export cassandra_port="9163"
 export sc_ip=$hostip
 export agent_ip=$hostip
-export keypair_path=""
+export keypair_path="<keypair_path>"
 
 # Git repo cofiguration. This will be needed only if you need to setup an internal git repo.
 # ----------------------------------------------------------------------------
 export git_user="git"
-export email="git@stratos.apache.org"
-export git_hostname="stratos.apache.org"
+export email="git@$stratos_domain"
+export git_hostname="$stratos_domain"
 export git_ip=$hostip
 export axis2c_path="axis2c-1.6.2"
 export axis2c_pack="axis2-1.6.2-bin.zip"
@@ -99,7 +98,7 @@ export cc_pack=$stratos_pack_path/"apache-stratos-cc-3.0.0-SNAPSHOT.zip"
 
 export cc_https_port="9444"
 export cc_port_offset=1
-export cc_hostname="cc.stratos.apache.org"
+export cc_hostname="cc.$stratos_domain"
 export mb_cassandra_host="localhost"
 export mb_cassandra_port="9161"
 
@@ -109,7 +108,7 @@ export mb_cassandra_port="9161"
 
 export elb_path=$stratos_path/"apache-stratos-elb-3.0.0-SNAPSHOT"
 export elb_pack=$stratos_pack_path/"apache-stratos-elb-3.0.0-SNAPSHOT.zip"
-export elb_hostname="elb.stratos.apache.org"
+export elb_hostname="elb.$stratos_domain"
 export enable_autoscaler=true
 export enable_embedded_autoscaler=false
 export elb_port_offset=0
@@ -122,7 +121,7 @@ export elb_port="9443"
 export agent_path=$stratos_path/"apache-stratos-agent-3.0.0-SNAPSHOT"
 export agent_pack=$stratos_pack_path/"apache-stratos-agent-3.0.0-SNAPSHOT.zip"
 export agent_clustering_port="4025"
-export agent_hostname="agent.stratos.apache.org"
+export agent_hostname="agent.$stratos_domain"
 export agent_http_port="9767"
 export agent_https_port="9447"
 export agent_port_offset=4
@@ -135,7 +134,7 @@ export agent_port_offset=4
 #export bam_ip=$hostip
 #export bam_reciever_port="7614"
 #export bam_reciever_secured_port="7714"
-#export bam_hostname="stratos.apache.org"
+#export bam_hostname="$stratos_domain"
 #export bam_path="wso2bam-2.3.0"
 #export bam_pack="wso2bam-2.3.0.zip"
 
@@ -147,14 +146,15 @@ export agent_port_offset=4
 
 # EC2
 export ec2_provider_enabled=false
-export ec2_identity=""
-export ec2_credential=""
-export ec2_keypair_name=""
+export ec2_identity="<ec2_identity>"
+export ec2_credential="<ec2_credential>"
+export ec2_keypair_name="<ec2_keypair_name>"
+export ec2_owner_id="<ec2_owner_id>"
 export ec2_scaleup_order=1
 export ec2_scaledown_order=2
 export ec2_region="ap-southeast-1"
-export ec2_availability_zone="ap-southeast-1a"
-export ec2_security_groups="default"
+export ec2_availability_zone="<ec2_availability_zone>"
+export ec2_security_groups="<ec2_security_groups>"
 export ec2_instance_type="m1.large"
 export ec2_image_id=""
 export ec2_php_cartridge_image_id="ami-8a733bd8" 
@@ -170,9 +170,7 @@ export openstack_project_id=$openstack_tenant
 export openstack_jclouds_endpoint="http://hostname:5000/v2.0"
 export openstack_scaleup_order=2
 export openstack_scaledown_order=3
-
 export openstack_keypair_name=""
-
 export openstack_image_id="RegionOne/" #No need to change this as of now
 export nova_region="RegionOne"
 export openstack_instance_type_tiny="RegionOne\/1"

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/99c597a7/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml b/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml
index d0ce5c9..7167d87 100644
--- a/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml
+++ b/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml
@@ -58,7 +58,7 @@
                         <credential svns:secretAlias="elastic.scaler.openstack.credential">EC2_CREDENTIAL</credential>
                         <scaleUpOrder>EC2_SCALEUP_ORDER</scaleUpOrder>
                         <scaleDownOrder>EC2_SCALEDOWN_ORDER</scaleDownOrder>
-                        <property name="jclouds.ec2.ami-query" value="owner-id=XX-XX-XX;state=available;image-type=machine"/>
+                        <property name="jclouds.ec2.ami-query" value="owner-id=EC2_OWNER_ID;state=available;image-type=machine"/>
                         <property name="availabilityZone" value="EC2_AVAILABILITY_ZONE"/>
                         <property name="securityGroups" value="EC2_SECURITY_GROUPS"/>
                         <property name="instanceType" value="EC2_INSTANCE_TYPE"/>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/99c597a7/tools/stratos-installer/ec2-user-data.sh
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/ec2-user-data.sh b/tools/stratos-installer/ec2-user-data.sh
new file mode 100755
index 0000000..971a627
--- /dev/null
+++ b/tools/stratos-installer/ec2-user-data.sh
@@ -0,0 +1,141 @@
+#!/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.
+#
+# ----------------------------------------------------------------------------
+#
+#  This script is invoked by setup.sh for configuring Amazon EC2 user data.
+# ----------------------------------------------------------------------------
+
+# Die on any error:
+set -e
+
+export LOG=$log_path/stratos-ec2-user-data.log
+
+source "./conf/setup.conf"
+
+if [[ ! -d $log_path ]]; then
+    mkdir -p $log_path
+fi
+
+
+# Following is helpful if you've mistakenly added data in user-data and want to recover.
+read -p "Please confirm whether you want to be prompted, irrespective of the data available in user-data? [y/n] " answer
+if [[ $answer = n && `curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://169.254.169.254/latest/user-data` = "200" ]] ; then
+    echo "Trying to find values via user-data" >> $LOG
+    wget http://169.254.169.254/latest/user-data -O /opt/user-data.txt >> $LOG
+    userData=`cat /opt/user-data.txt`
+    echo "Extracted user-data: $userData" >> $LOG
+
+    # Assign values obtained through user-data
+    for i in {1..8}
+    do
+        entry=`echo $userData  | cut -d',' -f$i | sed 's/,//g'`
+        key=`echo $entry  | cut -d'=' -f1 | sed 's/=//g'`
+        value=`echo $entry  | cut -d'=' -f2 | sed 's/=//g'`
+        if [[ "$key" == *EC2_KEY_PATH* ]] ; then EC2_KEY_PATH=$value; 
+        elif [[ "$key" == *ACCESS_KEY* ]] ; then ACCESS_KEY=$value; 
+        elif [[ "$key" == *SECRET_KEY* ]] ; then SECRET_KEY=$value; 
+        elif [[ "$key" == *OWNER_ID* ]] ; then OWNER_ID=$value; 
+        elif [[ "$key" == *AVAILABILITY_ZONE* ]] ; then AVAILABILITY_ZONE=$value; 
+        elif [[ "$key" == *SECURITY_GROUP* ]] ; then SECURITY_GROUP=$value; 
+        elif [[ "$key" == *KEY_PAIR_NAME* ]] ; then KEY_PAIR_NAME=$value; 
+        elif [[ "$key" == *DOMAIN* ]] ; then DOMAIN=$value; 
+        fi
+    done
+fi
+
+# Get hostname
+wget http://169.254.169.254/latest/meta-data/public-hostname -O /opt/public-hostname
+stratos_hostname=`cat /opt/public-hostname`
+
+# Prompt for the values that are not retrieved via user-data
+if [[ -z $EC2_KEY_PATH ]]; then
+    echo -n "Please copy your EC2 public key and enter full path to it (eg: /home/ubuntu/EC2SKEY.pem):"
+    read EC2_KEY_PATH
+    if [ ! -e "$EC2_KEY_PATH" ]; then
+        echo "EC2 key file ($EC2_KEY_PATH) is not found. Installer cannot proceed."
+        exit 69
+    fi
+fi
+if [[ -z $ACCESS_KEY ]]; then
+    echo -n "Access Key of EC2 account (eg: Q0IAJDWGFM842UHQP27L) :"
+    read ACCESS_KEY
+fi
+if [[ -z $SECRET_KEY ]]; then
+    echo -n "Secret key of EC2 account (eg: DSKidmKS620mMWMBK5DED983HJSELA) :"
+    read SECRET_KEY
+fi
+if [[ -z $OWNER_ID ]]; then
+    echo -n "Owner id of EC2 account (eg: 927235126122165) :"
+    read OWNER_ID
+fi
+if [[ -z $AVAILABILITY_ZONE ]]; then
+    echo -n "Availability zone (default value: us-east-1c) :"
+    read AVAILABILITY_ZONE
+fi
+if [[ -z $SECURITY_GROUP ]]; then
+    echo -n "Name of the EC2 security group (eg: stratosdemo) :"
+    read SECURITY_GROUP
+fi
+if [[ -z $KEY_PAIR_NAME ]]; then
+    echo -n "Name of the key pair (eg: EC2SKEY) :"
+    read KEY_PAIR_NAME
+fi
+if [[ -z $DOMAIN ]]; then
+    echo -n "Domain name for Stratos (default value: stratos.apache.org) :"
+    read DOMAIN
+fi
+if  [ -z "$DOMAIN" ]; then
+    DOMAIN="stratos.apache.org"
+fi
+if  [ -z "$AVAILABILITY_ZONE" ]; then
+    AVAILABILITY_ZONE="us-east-1c"
+    echo "Default Availability Zone $AVAILABILITY_ZONE" >> $LOG
+fi
+if [ ! -e "$EC2_KEY_PATH" ]; then
+    echo "EC2 key file ($EC2_KEY_PATH) is not found. Installer cannot proceed."
+    exit 69
+fi
+
+echo "Updating conf/setup.conf with user data"
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export stratos_domain=\"*.*\"@export stratos_domain=\"$DOMAIN\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export keypair_path=\"*.*\"@export keypair_path=\"$EC2_KEY_PATH\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_keypair_name=\"*.*\"@export ec2_keypair_name=\"$KEY_PAIR_NAME\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_identity=\"*.*\"@export ec2_identity=\"$ACCESS_KEY\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_credential=\"*.*\"@export ec2_credential=\"$SECRET_KEY\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_owner_id=\"*.*\"@export ec2_owner_id=\"$OWNER_ID\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_availability_zone=\"*.*\"@export ec2_availability_zone=\"$AVAILABILITY_ZONE\"@g" > conf/setup.conf
+
+cp -f conf/setup.conf conf/setup.conf.orig
+cat conf/setup.conf.orig | sed -e "s@export ec2_security_groups=\"*.*\"@export ec2_security_groups=\"$SECURITY_GROUP\"@g" > conf/setup.conf
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/99c597a7/tools/stratos-installer/ec2.sh
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/ec2.sh b/tools/stratos-installer/ec2.sh
index 884557e..a146ab2 100755
--- a/tools/stratos-installer/ec2.sh
+++ b/tools/stratos-installer/ec2.sh
@@ -55,6 +55,9 @@ cp -f repository/conf/cloud-controller.xml repository/conf/cloud-controller.xml.
 cat repository/conf/cloud-controller.xml.orig | sed -e "s@EC2_SCALEDOWN_ORDER@$ec2_scaledown_order@g" > repository/conf/cloud-controller.xml
        
 cp -f repository/conf/cloud-controller.xml repository/conf/cloud-controller.xml.orig
+cat repository/conf/cloud-controller.xml.orig | sed -e "s@EC2_OWNER_ID@$ec2_owner_id@g" > repository/conf/cloud-controller.xml
+
+cp -f repository/conf/cloud-controller.xml repository/conf/cloud-controller.xml.orig
 cat repository/conf/cloud-controller.xml.orig | sed -e "s@EC2_AVAILABILITY_ZONE@$ec2_availability_zone@g" > repository/conf/cloud-controller.xml
        
 cp -f repository/conf/cloud-controller.xml repository/conf/cloud-controller.xml.orig

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/99c597a7/tools/stratos-installer/setup.sh
----------------------------------------------------------------------
diff --git a/tools/stratos-installer/setup.sh b/tools/stratos-installer/setup.sh
index 3759c9f..b6e8073 100755
--- a/tools/stratos-installer/setup.sh
+++ b/tools/stratos-installer/setup.sh
@@ -104,6 +104,10 @@ if [[ -z $product_list || $product_list = "" ]]; then
     exit 1
 fi
 
+if [[ $ec2_provider_enabled = "true" ]]; then
+    ./ec2-user-data.sh
+fi
+
 function helpsetup {
     echo ""
     echo "Set up the environment variables correctly in conf/setup.conf"