usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/9] git commit: Adding support for REST instance.
Date Wed, 19 Mar 2014 01:20:48 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/asyncqueue 79fa0cb02 -> 4901214c6


Adding support for REST instance.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/28bb791f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/28bb791f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/28bb791f

Branch: refs/heads/asyncqueue
Commit: 28bb791fc3eb3bd092546ea251e1777d3c4008c6
Parents: 4ba3650
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Fri Mar 14 08:37:40 2014 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Fri Mar 14 08:37:40 2014 -0400

----------------------------------------------------------------------
 stack/awscluster/pom.xml                        |   6 +-
 .../main/dist/init_instance/init_db_server.sh   |  54 ++
 .../main/dist/init_instance/init_rest_server.sh |  41 ++
 .../dist/init_instance/install_cassandra.sh     |  63 +-
 stack/awscluster/src/main/dist/update.sh        |  16 +
 .../src/main/groovy/configure_cassandra.groovy  |   2 +-
 .../src/main/groovy/configure_portal_new.groovy |  17 +
 .../src/main/groovy/configure_usergrid.groovy   | 126 ++++
 stack/awscluster/ugcluster-cf.json              | 647 +++++++++++++++++++
 9 files changed, 938 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/pom.xml
----------------------------------------------------------------------
diff --git a/stack/awscluster/pom.xml b/stack/awscluster/pom.xml
index 358f24e..9362f9f 100644
--- a/stack/awscluster/pom.xml
+++ b/stack/awscluster/pom.xml
@@ -2,16 +2,16 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
-    <artifactId>priamcluster</artifactId>
+    <artifactId>awscluster</artifactId>
     <groupId>org.usergrid</groupId>
     <version>1.0-SNAPSHOT</version>
 
-    <name>priamcluster</name>
+    <name>awscluster</name>
     <description>Creates bundle for initializing a Cassandra and Priam cluster via
CloudFormation</description>
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <aws.s3.release-bucket>ug-cloudformation-priam</aws.s3.release-bucket>
+        <aws.s3.release-bucket>ug-cloudformation</aws.s3.release-bucket>
     </properties>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
new file mode 100644
index 0000000..4c2e8c6
--- /dev/null
+++ b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+echo "${HOSTNAME}" > /etc/hostname
+echo "127.0.0.1 ${HOSTNAME}" >> /etc/hosts
+hostname `cat /etc/hostname`
+
+echo "US/Eastern" > /etc/timezone
+dpkg-reconfigure -f noninteractive tzdata
+
+# Build environment for scripts
+. /etc/profile.d/aws-credentials.sh
+. /etc/profile.d/usergrid-env.sh
+
+cd /usr/share/usergrid/init_instance
+./create_raid0.sh
+
+# Install the easy stuff
+PKGS="ntp unzip groovy tomcat7 curl"
+apt-get update
+apt-get -y install ${PKGS}
+/etc/init.d/tomcat7 stop
+
+# Install AWS Java SDK and get it into the Groovy classpath
+curl http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip > /tmp/aws-sdk-java.zip
+cd /usr/share/
+unzip /tmp/aws-sdk-java.zip 
+mkdir -p /home/ubuntu/.groovy/lib
+cp /usr/share/aws-java-sdk-*/third-party/*/*.jar /home/ubuntu/.groovy/lib
+cp /usr/share/aws-java-sdk-*/lib/* /home/ubuntu/.groovy/lib 
+# except for evil stax
+rm /home/ubuntu/.groovy/lib/stax*
+ln -s /home/ubuntu/.groovy /root/.groovy
+
+cd /usr/share/usergrid/init_instance
+./install_oraclejdk.sh 
+
+# Install and stop Cassandra 
+cd /usr/share/usergrid/init_instance
+./install_cassandra.sh
+
+# Install and start ElasticSearch
+cd /usr/share/usergrid/init_instance
+./install_elasticsearch.sh
+/etc/init.d/elasticsearch start
+
+# Starting Tomcat starts Priam which starts Priam
+#/etc/init.d/tomcat7 restart
+
+# Priam consistently craps out on first run
+# making this ugly kludge necessary
+#sleep 90
+#/etc/init.d/tomcat7 restart
+
+cd /usr/share/usergrid/scripts
+groovy tag_instance.groovy

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
new file mode 100644
index 0000000..3eaf58c
--- /dev/null
+++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+echo "${HOSTNAME}" > /etc/hostname
+echo "127.0.0.1 ${HOSTNAME}" >> /etc/hosts
+hostname `cat /etc/hostname`
+
+echo "US/Eastern" > /etc/timezone
+dpkg-reconfigure -f noninteractive tzdata
+
+PKGS="openjdk-7-jdk tomcat7 s3cmd ntp unzip groovy"
+apt-get update
+apt-get -y install ${PKGS}
+
+# Install AWS Java SDK and get it into the Groovy classpath
+curl http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip > /tmp/aws-sdk-java.zip
+cd /usr/share/
+unzip /tmp/aws-sdk-java.zip 
+mkdir -p /home/ubuntu/.groovy/lib
+cp /usr/share/aws-java-sdk-*/third-party/*/*.jar /home/ubuntu/.groovy/lib
+cp /usr/share/aws-java-sdk-*/lib/* /home/ubuntu/.groovy/lib 
+# except for evil stax
+rm /home/ubuntu/.groovy/lib/stax*
+ln -s /home/ubuntu/.groovy /root/.groovy
+
+# Build environment for Groovy scripts
+. /etc/profile.d/aws-credentials.sh
+. /etc/profile.d/usergrid-env.sh
+
+# Wait for enough Cassandra nodes then deploy and restart Tomcat 
+cd /usr/share/usergrid/scripts
+groovy wait_for_cassandra.groovy
+
+mkdir -p /usr/share/tomcat7/lib 
+groovy configure_usergrid.groovy > /usr/share/tomcat7/lib/usergrid-deployment.properties

+
+rm -rf /var/lib/tomcat7/webapps/*
+cp -r /usr/share/usergrid/webapps/* /var/lib/tomcat7/webapps
+groovy configure_portal_new.groovy > /var/lib/tomcat7/webapps/portal/config.js 
+
+# Go
+/etc/init.d/tomcat7 restart
+groovy tag_instance.groovy

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
index 5bf7d04..0467753 100644
--- a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
+++ b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
@@ -19,38 +19,41 @@ cd /usr/share/usergrid/scripts
 groovy registry_register.groovy
 groovy wait_for_instances.groovy
 
-# Configure Priam
 cd /usr/share/usergrid/scripts
 groovy configure_cassandra.groovy > /etc/cassandra/cassandra.yaml
-groovy configure_priam.groovy
-
-# Copy Priam extension into Cassandra and Priam WAR into Tomcat
-rm -rf /var/lib/tomcat7/webapps/*
-mkdir -p /usr/share/cassandra/lib 
-cp /usr/share/usergrid/lib/priam-cass-extensions-1.2.24.jar /usr/share/cassandra/lib 
-cp /usr/share/usergrid/webapps/priam-web-1.2.24.war /var/lib/tomcat7/webapps/Priam.war
-
-# Make sure Priam via Tomcat can write to /etc/cassandra
-# TODO: do this without 777
-chmod -R 777 /etc/cassandra
-chmod 777 /etc/init.d/cassandra
-
-# Configure sudo for no passwords to please Priam
-cat >> /tmp/sudoers.new << EOF
-Defaults    env_reset
-Defaults    mail_badpass
-Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-root    ALL=(ALL:ALL) ALL
-%admin  ALL=(ALL) ALL
-%sudo   ALL=(ALL:ALL) NOPASSWD:ALL
-EOF
-visudo -c -f /tmp/sudoers.new
-if [ "$?" -eq "0" ]; then
-    cp /tmp/sudoers.new /etc/sudoers
-fi
-# Add tomat user to sudoers to please Priam
-adduser tomcat7 sudo
-/etc/init.d/sudo restart
+
+/etc/init.d/cassandra start
+
+## Configure Priam
+#groovy configure_priam.groovy
+#
+## Copy Priam extension into Cassandra and Priam WAR into Tomcat
+#rm -rf /var/lib/tomcat7/webapps/*
+#mkdir -p /usr/share/cassandra/lib 
+#cp /usr/share/usergrid/lib/priam-cass-extensions-1.2.24.jar /usr/share/cassandra/lib 
+#cp /usr/share/usergrid/webapps/priam-web-1.2.24.war /var/lib/tomcat7/webapps/Priam.war
+#
+## Make sure Priam via Tomcat can write to /etc/cassandra
+## TODO: do this without 777
+#chmod -R 777 /etc/cassandra
+#chmod 777 /etc/init.d/cassandra
+#
+## Configure sudo for no passwords to please Priam
+#cat >> /tmp/sudoers.new << EOF
+#Defaults    env_reset
+#Defaults    mail_badpass
+#Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
+#root    ALL=(ALL:ALL) ALL
+#%admin  ALL=(ALL) ALL
+#%sudo   ALL=(ALL:ALL) NOPASSWD:ALL
+#EOF
+#visudo -c -f /tmp/sudoers.new
+#if [ "$?" -eq "0" ]; then
+#    cp /tmp/sudoers.new /etc/sudoers
+#fi
+## Add tomat user to sudoers to please Priam
+#adduser tomcat7 sudo
+#/etc/init.d/sudo restart
 
 popd
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/dist/update.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/update.sh b/stack/awscluster/src/main/dist/update.sh
new file mode 100644
index 0000000..a908d55
--- /dev/null
+++ b/stack/awscluster/src/main/dist/update.sh
@@ -0,0 +1,16 @@
+sudo mkdir __tmpupdate__
+pushd __tmpupdate__
+
+    sudo s3cmd --config=/etc/s3cfg get s3://${RELEASE_BUCKET}/usergrid-cloudformation-1.0-SNAPSHOT-any.tar.gz
+    sudo tar xzvf usergrid-cloudformation-1.0-SNAPSHOT-any.tar.gz 
+    sudo /etc/init.d/tomcat7 stop
+    sudo cp -r webapps/* /var/lib/tomcat7/webapps
+
+    pushd /usr/share/usergrid/scripts
+        sudo groovy configure_portal_new.groovy > /var/lib/tomcat7/webapps/portal/config.js

+    popd
+
+    sudo /etc/init.d/tomcat7 start
+
+popd 
+sudo rm -rf __tmpupdate__

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/groovy/configure_cassandra.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_cassandra.groovy b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
index a71e071..7edccbe 100644
--- a/stack/awscluster/src/main/groovy/configure_cassandra.groovy
+++ b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
@@ -37,7 +37,7 @@ seed_provider:
     - class_name: org.apache.cassandra.locator.SimpleSeedProvider
       parameters:
           - seeds: "${seeds}"
-auto_bootstrap: true
+auto_bootstrap: false 
 initial_token:
 hinted_handoff_enabled: true
 hinted_handoff_throttle_in_kb: 1024

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/groovy/configure_portal_new.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_portal_new.groovy b/stack/awscluster/src/main/groovy/configure_portal_new.groovy
new file mode 100644
index 0000000..2f15223
--- /dev/null
+++ b/stack/awscluster/src/main/groovy/configure_portal_new.groovy
@@ -0,0 +1,17 @@
+//
+// Emits dash/app/config.js file 
+//
+def baseUrl = "http://${System.getenv().get("DNS_NAME")}.${System.getenv().get("DNS_DOMAIN")}"
+config = """
+var VERSION = 'R-2013-07-02-02';
+var Usergrid = Usergrid || {};
+Usergrid.showNotifcations = true;
+
+// used only if hostname does not match a real server name
+Usergrid.overrideUrl = '${baseUrl}';
+
+Usergrid.settings = {
+  hasMonitoring:true //change to false to remove monitoring
+};
+"""
+println config

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/src/main/groovy/configure_usergrid.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_usergrid.groovy b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
new file mode 100644
index 0000000..a3e710b
--- /dev/null
+++ b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
@@ -0,0 +1,126 @@
+// 
+// configure_usergrid.groovy 
+// 
+// Emits usergrid properties file based on environment and Cassandra node registry in SimpleDB
+//
+import com.amazonaws.auth.*
+import com.amazonaws.services.simpledb.*
+import com.amazonaws.services.simpledb.model.*
+
+String domain = "UGCloudFormation"
+
+String accessKey = (String)System.getenv().get("AWS_ACCESS_KEY")
+String secretKey = (String)System.getenv().get("AWS_SECRET_KEY")
+
+def baseUrl      = "http://${System.getenv().get("DNS_NAME")}.${System.getenv().get("DNS_DOMAIN")}"
+String stackName = (String)System.getenv().get("STACK_NAME")
+String hostName  = (String)System.getenv().get("PUBLIC_HOSTNAME")
+def replFactor   = System.getenv().get("CASSANDRA_REPLICATION_FACTOR")
+def clusterName  = System.getenv().get("CASSANDRA_CLUSTER_NAME")
+
+def superUserEmail     = System.getenv().get("SUPER_USER_EMAIL")
+def testAdminUserEmail = System.getenv().get("TEST_ADMIN_USER_EMAIL")
+
+// build seed list by listing all Cassandra nodes found in SimpleDB domain with our stackName
+def creds = new BasicAWSCredentials(accessKey, secretKey)
+def sdbClient = new AmazonSimpleDBClient(creds)
+def selectResult = sdbClient.select(new SelectRequest((String)"select * from ${domain}"))
+def seeds = ""
+def sep = ""
+for (item in selectResult.getItems()) {
+    def att = item.getAttributes().get(0)
+    if (att.getValue().equals(stackName)) {
+        seeds = "${seeds}${sep}${item.getName()}:9160"
+        sep = ","
+    }
+}
+
+def usergridConfig = """
+######################################################
+# Minimal Usergrid configuration properties for local Tomcat and Cassandra 
+#
+
+cassandra.url=${seeds}
+cassanrda.cluster=${clusterName}
+cassandra.keyspace.strategy.options.replication_factor=${replFactor}
+cassandra.keyspace.strategy.options.us-west=${replFactor}
+cassandra.keyspace.strategy.options.us-west=${replFactor}
+cassandra.keyspace.strategy=org.apache.cassandra.locator.SimpleStrategy
+
+# These settings seem to cause problems at startup time
+#cassandra.keyspace.strategy=org.apache.cassandra.locator.NetworkTopologyStrategy
+#cassandra.writecl=LOCAL_QUORUM
+#cassandra.readcl=LOCAL_QUORUM
+
+
+######################################################
+# Custom mail transport 
+
+mail.transport.protocol=smtps
+mail.smtps.host=smtp.gmail.com
+mail.smtps.port=465
+mail.smtps.auth=true
+mail.smtps.quitwait=false
+
+# CAUTION: THERE IS A PASSWORD HERE!
+mail.smtps.username=usergridtest@gmail.com
+mail.smtps.password=shy-rtol
+
+######################################################
+# Admin and test user setup
+
+usergrid.sysadmin.login.allowed=true
+usergrid.sysadmin.login.name=superuser
+usergrid.sysadmin.login.password=test
+usergrid.sysadmin.login.email=${superUserEmail}
+
+usergrid.sysadmin.email=${superUserEmail}
+usergrid.sysadmin.approve.users=true
+usergrid.sysadmin.approve.organizations=true
+
+# Base mailer account - default for all outgoing messages
+usergrid.management.mailer=Admin <${superUserEmail}>
+
+usergrid.setup-test-account=true
+
+usergrid.test-account.app=test-app
+usergrid.test-account.organization=test-organization
+usergrid.test-account.admin-user.username=test
+usergrid.test-account.admin-user.name=Test User
+usergrid.test-account.admin-user.email=${testAdminUserEmail}
+usergrid.test-account.admin-user.password=test
+
+######################################################
+# Auto-confirm and sign-up notifications settings
+
+usergrid.management.admin_users_require_confirmation=false
+usergrid.management.admin_users_require_activation=false
+
+usergrid.management.organizations_require_activation=false
+usergrid.management.notify_sysadmin_of_new_organizations=true
+usergrid.management.notify_sysadmin_of_new_admin_users=true
+
+######################################################
+# URLs
+
+# Redirect path when request come in for TLD
+usergrid.redirect_root=${baseUrl}/status
+
+usergrid.view.management.organizations.organization.activate=${baseUrl}/accounts/welcome
+usergrid.view.management.organizations.organization.confirm=${baseUrl}/accounts/welcome
+\n\
+usergrid.view.management.users.user.activate=${baseUrl}/accounts/welcome
+usergrid.view.management.users.user.confirm=${baseUrl}/accounts/welcome
+
+usergrid.admin.confirmation.url=${baseUrl}/management/users/%s/confirm
+usergrid.user.confirmation.url=${baseUrl}/%s/%s/users/%s/confirm\n\\n\
+
+usergrid.organization.activation.url=${baseUrl}/management/organizations/%s/activate\n\
+usergrid.admin.activation.url=${baseUrl}/management/users/%s/activate
+usergrid.user.activation.url=${baseUrl}%s/%s/users/%s/activate
+
+usergrid.admin.resetpw.url=${baseUrl}/management/users/%s/resetpw
+usergrid.user.resetpw.url=${baseUrl}/%s/%s/users/%s/resetpw
+"""
+
+println usergridConfig 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/28bb791f/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
new file mode 100644
index 0000000..a1c79aa
--- /dev/null
+++ b/stack/awscluster/ugcluster-cf.json
@@ -0,0 +1,647 @@
+{
+    "AWSTemplateFormatVersion": "2010-09-09",
+    "Description": "Usergrid AWS Cluster",
+    "Parameters": {
+        "DnsSubDomain": {
+            "Description": "DNS name for stack, must not already exist in Route53.",
+            "Type": "String",
+            "Default": "ugtest"
+        },
+        "DnsDomain": {
+            "Description": "DNS domain for stack, must already exist in Route53",
+            "Type": "String",
+            "Default": "usergrid.com"
+        },
+        "ReleaseBucket": {
+            "Description": "S3 Bucket where Usergrid assembly is to be found.",
+            "Type": "String",
+            "Default": "ug-cloudformation"
+        },
+        "RestMinServers": {
+            "Description": "Minimum number of REST servers.",
+            "Type": "Number",
+            "Default": "1",
+            "MinValue": "1"
+        },
+        "RestMaxServers": {
+            "Description": "Maximum number REST servers.",
+            "Type": "Number",
+            "Default": "1",
+            "MinValue": "1"
+        },
+        "RestInstanceType": {
+            "Description": "Instance type for REST servers",
+            "Type": "String",
+            "Default": "m1.small",
+            "AllowedValues": ["m1.small", "m1.medium", "m1.large", "m1.xlarge", "m3.xlarge",
"m3.2xlarge"],
+            "ConstraintDescription": "must be valid instance type."
+        },
+        "KeyPair": {
+            "Description": "EC2 key pair to be use for SSH access",
+            "Type": "String",
+            "Default": "ug-cloudformation"
+        },
+        "CassClusterName": {
+            "Description": "Name to be used for Cassandra cluster.",
+            "Type": "String",
+            "Default": "usergrid"
+        },
+        "CassNumServers": {
+            "Description": "Number of Cass servers to start.",
+            "Type": "Number",
+            "Default": "3",
+            "MinValue": "3"
+        },
+        "CassInstanceType": {
+            "Description": "Instance type for Cass servers",
+            "Type": "String",
+            "Default": "m1.xlarge",
+            "AllowedValues": ["m1.small", "m1.medium", "m1.large", "m1.xlarge", "m3.xlarge",
"m3.2xlarge"],
+            "ConstraintDescription": "must be valid instance type."
+        },
+        "CassReplicationFactor": {
+            "Description": "Cassandra replication factor",
+            "Type": "Number",
+            "Default": "2",
+            "MinValue": "1"
+        },
+        "SuperUserEmail": {
+            "Description": "Email for superuser user",
+            "Type": "String",
+            "Default": "dmjohnson+super@apigee.com"
+        },
+        "TestAdminUserEmail": {
+            "Description": "Email for test admin user",
+            "Type": "String",
+            "Default": "dmjohnson+admin@apigee.com"
+        },
+        "NotificationEmail": {
+            "Description": "Email for notifications",
+            "Type": "String",
+            "Default": "dmjohnson+super@apigee.com"
+        }
+    },
+    "Mappings": {
+        "AWSInstanceType2Arch": {
+            "m1.small": {"Arch": "64"},
+            "m1.medium": {"Arch": "64"},
+            "m1.large": {"Arch": "64"},
+            "m1.xlarge": {"Arch": "64"}
+        },
+        "AWSRegionArch2AMI": {
+            "ap-southeast-2": {"64": "ami-db8611e1"},
+            "us-east-1": {"64": "ami-e864da81"},
+            "us-west-2": {"64": "ami-50f97060"}
+        },
+        "TwoAZs": {
+            "ap-southeast-2": {"AZ1": "ap-southeast-2a", "AZ2": "ap-southeast-2b"},
+            "us-east-1": {"AZ1": "us-east-1a", "AZ2": "us-east-1b"},
+            "us-west-2": {"AZ1": "us-west-2a", "AZ2": "us-west-2b"}
+        }
+    },
+    "Resources": {
+                "RestUser": {
+            "Type": "AWS::IAM::User",
+            "Properties": {
+                "Path": "/",
+                "Policies": [{
+                        "PolicyName": "root",
+                        "PolicyDocument": {"Statement": [{
+                                    "Effect": "Allow",
+                                    "Action": "*",
+                                    "Resource": "*"
+                                }]}
+                    }]
+            }
+        },
+        "RestKey": {
+            "Type": "AWS::IAM::AccessKey",
+            "Properties": {
+                "UserName": {"Ref": "RestUser"}
+            }
+        },
+        "CassUser": {
+            "Type": "AWS::IAM::User",
+            "Properties": {
+                "Path": "/",
+                "Policies": [{
+                        "PolicyName": "root",
+                        "PolicyDocument": {"Statement": [{
+                                    "Effect": "Allow",
+                                    "Action": "*",
+                                    "Resource": "*"
+                                }]}
+                    }]
+            }
+        },
+        "CassKey": {
+            "Type": "AWS::IAM::AccessKey",
+            "Properties": {
+                "UserName": {"Ref": "CassUser"}
+            }
+        },
+        "CassAutoScalingLaunchConfiguration": {
+            "Type": "AWS::AutoScaling::LaunchConfiguration",
+            "Properties": {
+                "UserData": {
+                    "Fn::Base64": {"Fn::Join": ["", [
+
+                                "#!/bin/bash -ex\n",
+
+                                "# CASSANDRA NODE STARTUP \n",
+
+                                "exec >/var/log/usergrid-bootstrap.log 2>&1\n",
+                                "\n",
+                                "mkdir -p /usr/share/usergrid\n",
+                                "\n",
+
+                                "# create script that sets our environment variables\n",
+                                "cat >/etc/profile.d/usergrid-env.sh <<EOF\n",
+                                    "alias sudo='sudo -E'\n",
+                                    "\n",
+                                    "export TYPE=cass\n",
+                                    "export STACK_NAME=", {"Ref": "AWS::StackName"}, "\n",
+                                    "\n",
+                                    "export PUBLIC_HOSTNAME=`(curl -s http://169.254.169.254/latest/meta-data/public-hostname)`\n",
+                                    "export INTERNAL_HOSTNAME=`(curl http://169.254.169.254/latest/meta-data/local-ipv4)`\n",
+                                    "\n",
+                                    "export EC2_INSTANCE_ID=`ec2metadata --instance-id`\n",
+                                    "export EC2_REGION=", {"Ref": "AWS::Region"}, "\n",
+                                    "export EC2_URL=https://ec2.amazonaws.com/\n",
+                                    "\n",
+                                    "export CASS_SECURITY_GROUP_NAME=", {"Ref": "CassSecurityGroup"},
"\n",
+                                    "\n",
+                                    "#export JVM_EXTRA_OPTS=-javaagent:/usr/share/cassandra/lib/priam-cass-extensions-1.2.24.jar",
"\n",
+                                    "\n",
+                                    "export CASSANDRA_CLUSTER_NAME=", {"Ref": "CassClusterName"},
"\n",
+                                    "export CASSANDRA_NUM_SERVERS=", {"Ref": "CassNumServers"},
"\n",
+                                    "export CASSANDRA_KEYSPACE_NAME=usergrid", "\n",
+                                    "export CASSANDRA_REPLICATION_FACTOR=", {"Ref": "CassReplicationFactor"},
"\n",
+                                    "\n",
+                                    "export RELEASE_BUCKET=", {"Ref": "ReleaseBucket"}, "\n",
+                                    "\n",
+                                "EOF\n",
+                                "\n",
+
+                                "# put AWS creds in environment\n",
+                                "cat >/etc/profile.d/aws-credentials.sh <<EOF\n",
+                                "export AWS_ACCESS_KEY=", {"Ref": "CassKey"}, "\n",
+                                "export AWS_SECRET_KEY=", {"Fn::GetAtt": ["CassKey", "SecretAccessKey"]},
"\n",
+                                "EOF\n",
+                                "\n",
+
+                                "# put AWS creds Priam's config file\n",
+                                "cat >/etc/awscredential.properties <<EOF\n",
+                                "AWSACCESSID=", {"Ref": "CassKey"}, "\n",
+                                "AWSKEY=", {"Fn::GetAtt": ["CassKey", "SecretAccessKey"]},
"\n",
+                                "EOF\n",
+                                "\n",
+
+                                "# setup s3cmd (will be installed by init script) \n",
+                                "cat >/etc/s3cfg <<EOF\n",
+                                "access_key=", {"Ref": "CassKey"}, "\n",
+                                "secret_key=", {"Fn::GetAtt": ["CassKey", "SecretAccessKey"]},
"\n",
+                                "EOF\n",
+                                "chmod 644 /etc/s3cfg\n",
+                                "ln -s /etc/s3cfg ~ubuntu/.s3cfg\n",
+                                "ln -s /etc/s3cfg ~root/.s3cfg\n",
+                                "\n",
+
+                                "# download usergrid and init script bundle from S3\n",
+                                "apt-get update\n",
+                                "apt-get -y install s3cmd\n",
+                                "cd /usr/share/usergrid\n",
+                                "s3cmd --config=/etc/s3cfg get s3://", {"Ref": "ReleaseBucket"},
"/awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "tar xvf awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "rm -fr awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "chmod 755 ./init_instance/*.sh\n",
+                                "cd ./init_instance\n",
+
+                                "# init as a Cassandra node \n",
+                                "sh ./init_db_server.sh\n"
+
+                            ]]}
+                },
+                "KeyName": {"Ref": "KeyPair"},
+                "ImageId": {
+                    "Fn::FindInMap": [
+                        "AWSRegionArch2AMI",
+                        {
+                            "Ref": "AWS::Region"
+                        },
+                        {
+                            "Fn::FindInMap": [
+                                "AWSInstanceType2Arch",
+                                {
+                                    "Ref": "CassInstanceType"
+                                },
+                                "Arch"
+                            ]
+                        }
+                    ]
+                },
+                "InstanceType": {
+                    "Ref": "CassInstanceType"
+                },
+                "IamInstanceProfile": {
+                    "Ref": "RootInstanceProfile"
+                },
+                "SecurityGroups": [{"Ref": "CassSecurityGroup"}]
+            }
+        },
+        "CassAutoScalingGroup": {
+            "Type": "AWS::AutoScaling::AutoScalingGroup",
+            "Version": "2009-05-15",
+            "Properties": {
+                "AvailabilityZones": {
+                    "Fn::GetAZs": ""
+                },
+                "LaunchConfigurationName": {
+                    "Ref": "CassAutoScalingLaunchConfiguration"
+                },
+                "MinSize": {"Ref": "CassNumServers"},
+                "MaxSize": {"Ref": "CassNumServers"},
+                "NotificationConfiguration": {
+                    "TopicARN": {"Ref": "NotificationTopic"},
+                    "NotificationTypes": [
+                        "autoscaling:EC2_INSTANCE_LAUNCH",
+                        "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
+                        "autoscaling:EC2_INSTANCE_TERMINATE",
+                        "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
+                    ]
+                }
+            }
+        },
+        "RestAutoScalingLaunchConfiguration": {
+            "Type": "AWS::AutoScaling::LaunchConfiguration",
+            "Properties": {
+                "UserData": {
+                    "Fn::Base64": {"Fn::Join": ["", [
+
+                                "#!/bin/bash -ex\n",
+
+                                "# REST SERVER STARTUP \n",
+
+                                "exec >/var/log/usergrid-bootstrap.log 2>&1\n",
+
+                                "\n",
+                                "mkdir -p /usr/share/usergrid\n",
+                                "\n",
+
+                                "# create script that sets our environment variables\n",
+                                "cat >/etc/profile.d/usergrid-env.sh <<EOF\n",
+                                    "alias sudo='sudo -E'\n",
+                                    "\n",
+                                    "export TYPE=rest\n",
+                                    "export STACK_NAME=", {"Ref": "AWS::StackName"}, "\n",
+                                    "\n",
+                                    "export DNS_NAME=", {"Ref": "DnsSubDomain"}, "\n",
+                                    "export DNS_DOMAIN=", {"Ref": "DnsDomain"}, "\n",
+                                    "export PUBLIC_HOSTNAME=`(curl -s http://169.254.169.254/latest/meta-data/public-hostname)`\n",
+                                    "export INTERNAL_HOSTNAME=`(curl http://169.254.169.254/latest/meta-data/local-ipv4)`\n",
+                                    "export ELB_NAME=", {"Ref": "RestElasticLoadBalancer"},
"\n",
+                                    "\n",
+                                    "export EC2_INSTANCE_ID=`ec2metadata --instance-id`\n",
+                                    "export EC2_REGION=", {"Ref": "AWS::Region"}, "\n",
+                                    "export EC2_URL=https://ec2.amazonaws.com/\n",
+                                    "\n",
+                                    "export REST_SECURITY_GROUP_NAME=", {"Ref": "RestSecurityGroup"},
"\n",
+                                    "export DB_SECURITY_GROUP_NAME=", {"Ref": "CassSecurityGroup"},
"\n",
+                                    "\n",
+                                    "export CASSANDRA_CLUSTER_NAME=", {"Ref": "CassClusterName"},
"\n",
+                                    "export CASSANDRA_KEYSPACE_NAME=usergrid", "\n",
+                                    "export CASSANDRA_REPLICATION_FACTOR=", {"Ref": "CassReplicationFactor"},
"\n",
+                                    "\n",
+                                    "export RELEASE_BUCKET=", {"Ref": "ReleaseBucket"}, "\n",
+                                    "\n",
+                                    "export SUPER_USER_EMAIL=", {"Ref": "SuperUserEmail"},
"\n",
+                                    "export TEST_ADMIN_USER_EMAIL=", {"Ref": "TestAdminUserEmail"},
"\n",
+                                    "\n",
+                                "EOF\n",
+                                "\n",
+
+                                "# put AWS creds in environment\n",
+                                "cat >/etc/profile.d/aws-credentials.sh <<EOF\n",
+                                "export AWS_ACCESS_KEY=", {"Ref": "RestKey"}, "\n",
+                                "export AWS_SECRET_KEY=", {"Fn::GetAtt": ["RestKey", "SecretAccessKey"]},
"\n",
+                                "EOF\n",
+                                "\n",
+
+                                "# setup s3cmd (will be installed by init script) \n",
+                                "cat >/etc/s3cfg <<EOF\n",
+                                "access_key=", {"Ref": "RestKey"}, "\n",
+                                "secret_key=", {"Fn::GetAtt": ["RestKey", "SecretAccessKey"]},
"\n",
+                                "EOF\n",
+                                "chmod 644 /etc/s3cfg\n",
+                                "ln -s /etc/s3cfg ~ubuntu/.s3cfg\n",
+                                "ln -s /etc/s3cfg ~root/.s3cfg\n",
+                                "\n",
+
+                                "# download usergrid and init script bundle from S3\n",
+                                "apt-get update\n",
+                                "apt-get -y install s3cmd\n",
+                                "cd /usr/share/usergrid\n",
+                                "s3cmd --config=/etc/s3cfg get s3://", {"Ref": "ReleaseBucket"},
"/awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "tar xvf awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "rm -fr awscluster-1.0-SNAPSHOT-any.tar.gz\n",
+                                "chmod 755 ./init_instance/*.sh\n",
+                                "cd ./init_instance\n",
+
+                                "# Init as a REST intance \n",
+                                "sh ./init_rest_server.sh\n"
+
+                            ]]}
+                },
+                "KeyName": {"Ref": "KeyPair"},
+                "ImageId": {
+                    "Fn::FindInMap": [
+                        "AWSRegionArch2AMI",
+                        {
+                            "Ref": "AWS::Region"
+                        },
+                        {
+                            "Fn::FindInMap": [
+                                "AWSInstanceType2Arch",
+                                {
+                                    "Ref": "RestInstanceType"
+                                },
+                                "Arch"
+                            ]
+                        }
+                    ]
+                },
+                "InstanceType": {
+                    "Ref": "RestInstanceType"
+                },
+                "IamInstanceProfile": {
+                    "Ref": "RootInstanceProfile"
+                },
+                "SecurityGroups": [{"Ref": "RestSecurityGroup"}]
+            }
+        },
+        "RestAutoScalingGroup": {
+            "Type": "AWS::AutoScaling::AutoScalingGroup",
+            "Version": "2009-05-15",
+            "Properties": {
+                "AvailabilityZones": [
+                    {"Fn::FindInMap": ["TwoAZs", {"Ref": "AWS::Region"}, "AZ1"]},
+                    {"Fn::FindInMap": ["TwoAZs", {"Ref": "AWS::Region"}, "AZ2"]}
+                ],
+                "LaunchConfigurationName": {
+                    "Ref": "RestAutoScalingLaunchConfiguration"
+                },
+                "MinSize": {"Ref": "RestMinServers"},
+                "MaxSize": {"Ref": "RestMaxServers"},
+                "HealthCheckType": "ELB",
+                "HealthCheckGracePeriod": "1800",
+                "LoadBalancerNames": [{"Ref": "RestElasticLoadBalancer"}],
+                "NotificationConfiguration": {
+                    "TopicARN": {"Ref": "NotificationTopic"},
+                    "NotificationTypes": [
+                        "autoscaling:EC2_INSTANCE_LAUNCH",
+                        "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
+                        "autoscaling:EC2_INSTANCE_TERMINATE",
+                        "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
+                    ]
+                }
+            }
+        },
+        "RestServerScaleUpPolicy": {
+            "Type": "AWS::AutoScaling::ScalingPolicy",
+            "Properties": {
+                "AdjustmentType": "ChangeInCapacity",
+                "AutoScalingGroupName": {
+                    "Ref": "RestAutoScalingGroup"
+                },
+                "Cooldown": "60",
+                "ScalingAdjustment": "1"
+            }
+        },
+        "RestServerScaleDownPolicy": {
+            "Type": "AWS::AutoScaling::ScalingPolicy",
+            "Properties": {
+                "AdjustmentType": "ChangeInCapacity",
+                "AutoScalingGroupName": {
+                    "Ref": "RestAutoScalingGroup"
+                },
+                "Cooldown": "60",
+                "ScalingAdjustment": "-1"
+            }
+        },
+        "CPUAlarmHigh": {
+            "Type": "AWS::CloudWatch::Alarm",
+            "Properties": {
+                "AlarmDescription": "Scale-up if CPU > 60% for 10 minutes",
+                "MetricName": "CPUUtilization",
+                "Namespace": "AWS/EC2",
+                "Statistic": "Average",
+                "Period": "600",
+                "EvaluationPeriods": "2",
+                "Threshold": "60",
+                "AlarmActions": [{
+                        "Ref": "RestServerScaleUpPolicy"
+                    }],
+                "Dimensions": [
+                    {
+                        "Name": "AutoScalingGroupName",
+                        "Value": {
+                            "Ref": "RestAutoScalingGroup"
+                        }
+                    }],
+                "ComparisonOperator": "GreaterThanThreshold"
+            }
+        },
+        "CPUAlarmLow": {
+            "Type": "AWS::CloudWatch::Alarm",
+            "Properties": {
+                "AlarmDescription": "Scale-down if CPU < 10% for 10 minutes",
+                "MetricName": "CPUUtilization",
+                "Namespace": "AWS/EC2",
+                "Statistic": "Average",
+                "Period": "600",
+                "EvaluationPeriods": "2",
+                "Threshold": "10",
+                "AlarmActions": [{
+                        "Ref": "RestServerScaleDownPolicy"
+                    }],
+                "Dimensions": [
+                    {
+                        "Name": "AutoScalingGroupName",
+                        "Value": {
+                            "Ref": "RestAutoScalingGroup"
+                        }
+                    }],
+                "ComparisonOperator": "LessThanThreshold"
+            }
+        },
+        "RestElasticLoadBalancer": {
+            "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
+            "Properties": {
+                "AvailabilityZones": [
+                    {"Fn::FindInMap": ["TwoAZs", {"Ref": "AWS::Region"}, "AZ1"]},
+                    {"Fn::FindInMap": ["TwoAZs", {"Ref": "AWS::Region"}, "AZ2"]}
+                ],
+                "Listeners": [{
+                        "LoadBalancerPort": "80",
+                        "InstancePort": "8080",
+                        "Protocol": "HTTP"
+                    }],
+                "HealthCheck": {
+                    "Target": "HTTP:8080/status",
+                    "HealthyThreshold": "2",
+                    "UnhealthyThreshold": "4",
+                    "Interval": "30",
+                    "Timeout": "5"
+                }
+            }
+        },
+        "NotificationTopic": {
+            "Type": "AWS::SNS::Topic",
+            "Properties": {
+                "Subscription": [{
+                        "Endpoint": {"Ref": "NotificationEmail"},
+                        "Protocol": "email"
+                    }]
+            }
+        },
+        "DnsRecord": {
+            "Type": "AWS::Route53::RecordSetGroup",
+            "Properties": {
+                "HostedZoneName": {"Fn::Join": [".", [{"Ref": "DnsDomain"}, ""]]},
+                "RecordSets": [{
+                        "Name": {"Fn::Join": [".", [{"Ref": "DnsSubDomain"}, {"Ref": "DnsDomain"}]]},
+                        "Type": "A",
+                        "AliasTarget": {
+                            "HostedZoneId": {"Fn::GetAtt": ["RestElasticLoadBalancer", "CanonicalHostedZoneNameID"]},
+                            "DNSName": {"Fn::GetAtt": ["RestElasticLoadBalancer", "CanonicalHostedZoneName"]}
+                        }
+                    }]
+            }
+        },
+
+        "RootRole": {
+            "Type": "AWS::IAM::Role",
+            "Properties": {
+                "AssumeRolePolicyDocument": {
+                    "Statement": [
+                        {
+                            "Effect": "Allow",
+                            "Principal": {
+                                "Service": [
+                                    "ec2.amazonaws.com"
+                                ]
+                            },
+                            "Action": [
+                                "sts:AssumeRole"
+                            ]
+                        }
+                    ]
+                },
+                "Path": "/"
+            }
+        },
+        "RolePolicies": {
+            "Type": "AWS::IAM::Policy",
+            "Properties": {
+                "PolicyName": "root",
+                "PolicyDocument": {
+                    "Statement": [
+                        {
+                            "Effect": "Allow",
+                            "Action": "*",
+                            "Resource": "*"
+                        }
+                    ]
+                },
+                "Roles": [
+                    {
+                        "Ref": "RootRole"
+                    }
+                ]
+            }
+        },
+        "RootInstanceProfile": {
+            "Type": "AWS::IAM::InstanceProfile",
+            "Properties": {
+                "Path": "/",
+                "Roles": [
+                    {
+                        "Ref": "RootRole"
+                    }
+                ]
+            }
+        },
+        "CassSecurityGroup": {
+            "Type": "AWS::EC2::SecurityGroup",
+            "Properties": {
+                "GroupDescription": "Database Machines",
+                "SecurityGroupIngress": [{
+                        "IpProtocol": "tcp",
+                        "FromPort": "22",
+                        "ToPort": "22",
+                        "CidrIp": "0.0.0.0/0"
+                    }]
+            }
+        },
+        "CassSecurityGroupPort7000": {
+            "Type": "AWS::EC2::SecurityGroupIngress",
+            "Properties": {
+                "GroupName": {"Ref": "CassSecurityGroup"},
+                "IpProtocol": "tcp",
+                "FromPort": "7000",
+                "ToPort": "7000",
+                "SourceSecurityGroupName": {"Ref": "CassSecurityGroup"}
+            }
+        },
+        "CassSecurityGroupPort9160": {
+            "Type": "AWS::EC2::SecurityGroupIngress",
+            "Properties": {
+                "GroupName": {"Ref": "CassSecurityGroup"},
+                "IpProtocol": "tcp",
+                "FromPort": "9160",
+                "ToPort": "9160",
+                "SourceSecurityGroupName": {"Ref": "CassSecurityGroup"}
+            }
+        },
+        "CassSecurityGroupPort9200": {
+            "Type": "AWS::EC2::SecurityGroupIngress",
+            "Properties": {
+                "GroupName": {"Ref": "CassSecurityGroup"},
+                "IpProtocol": "tcp",
+                "FromPort": "9200",
+                "ToPort": "9200",
+                "SourceSecurityGroupName": {"Ref": "CassSecurityGroup"}
+            }
+        },
+        "CassSecurityGroupPort9300": {
+            "Type": "AWS::EC2::SecurityGroupIngress",
+            "Properties": {
+                "GroupName": {"Ref": "CassSecurityGroup"},
+                "IpProtocol": "tcp",
+                "FromPort": "9300",
+                "ToPort": "9300",
+                "SourceSecurityGroupName": {"Ref": "CassSecurityGroup"}
+            }
+        },
+        "RestSecurityGroup": {
+            "Type": "AWS::EC2::SecurityGroup",
+            "Properties": {
+                "GroupDescription": "REST Machines",
+                "SecurityGroupIngress": [{
+                        "IpProtocol": "tcp",
+                        "FromPort": "22",
+                        "ToPort": "22",
+                        "CidrIp": "0.0.0.0/0"
+                    }, {
+                        "IpProtocol": "tcp",
+                        "FromPort": "8080",
+                        "ToPort": "8080",
+                        "CidrIp": "0.0.0.0/0"
+                    }]
+            }
+        }
+    }
+
+
+
+}


Mime
View raw message