Created
July 13, 2016 15:12
-
-
Save mrchristine/d4419cae9e449aaa7a86888ca1871d23 to your computer and use it in GitHub Desktop.
Deploy cluster on Databricks using REST Api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| IFS=$'\n' # make newlines the only separator | |
| while getopts ":o" opt; do | |
| case $opt in | |
| o) | |
| ondemand=true | |
| echo -e "Deploying on-demand cluster for mwc\n" | |
| ;; | |
| \?) | |
| echo -e "Deploying cluster for mwc\n" | |
| ;; | |
| esac | |
| done | |
| # Define input parameters | |
| user=`echo $DBCLOUD_USER` | |
| pass=`echo $DBCLOUD_PASSWORD` | |
| # Format: https://shardname.cloud.databricks.com | |
| shard=`echo $DBCLOUD_SHARD` | |
| cluster_template=$(cat << EOF | |
| { | |
| "cluster_name": "mwc", | |
| "spark_version": "1.6.2-ubuntu15.10-hadoop2", | |
| "aws_attributes": { | |
| "availability": "SPOT_WITH_FALLBACK", | |
| "zone_id": "us-west-2a" | |
| }, | |
| "num_workers": 3 | |
| } | |
| EOF | |
| ) | |
| if [ -z "$ondemand" ]; then | |
| ## Create cluster | |
| echo "$cluster_template" | jq . | |
| curl -H "Content-Type: application/json" -X POST -d "$cluster_template" -u $user:$pass $shard/api/2.0/clusters/create | |
| else | |
| cluster_od=$( echo $cluster_template | jq '.aws_attributes.availability |= "ON_DEMAND" | .cluster_name |= "mwc_od"' ) | |
| echo $cluster_od | jq . | |
| curl -H "Content-Type: application/json" -X POST -d "$cluster_template" -u $user:$pass $shard/api/2.0/clusters/create | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment